9
votes

I'm in search of a tool which will allow me to customize dynamic syntax highlight rules :

Examples of static syntax highlighting (most IDEs already do this).

  1. Highlight all occurences of the word int as red.

  2. Highlight all strings (enclosed in ") in blue.

Examples of DYNAMIC syntax highlighting

  1. Given a string of txt that appears > twice, I want it highlighted purple.

  2. If I click on a block of text, I would like all blocks of txt on the same file highlighted green.

I'm assuming that someone may have built such a highlighter before, but I can't find anything on the web. Any feedback on how:

  1. I can extend an existing project (ideally, I'd like this to be an IDE plugin) to customize my dynamic requirements?

  2. In case 1 is not in existence, any templating languages that might be maximally effective for this sort of project ? i.e. any frameworks that highlight text on the fly, dynamically, while enabling editing - that are easily extended.

4
Update : I've found XText which looks like a good framework for this, but its a little too heavyweight for this project (i want something that i dont have to recompile every time i want to add a new rule or validation hook). However, it is powerful. any other ideas ?jayunit100
Any suggestions? This sounds like a useful IDE pluginAlex L
I've stumbled across EclipseColorer which seems to extend Eclipse's highlighting abilities a bit - might be a good place to start.Alex L
For your dynamic example #1, do you mean a particular string that occurs more than twice? I'm assuming you don't mean every string of text of every length that occurs more than twice but wanted to check... And for #2, could you give an example? It sounds confusing (are you talking about matching blocks?).Rob I

4 Answers

4
votes

Emacs (www.gnu.org/s/emacs/) should be able to do this.

Emacs is extremely customizable; you code (e)Lisp functions to make it do what you want. Many of Emacs's language-specific modes do "fixed" highlighting of keywords; you should be able to hijack that machinery and make the highlighting dynamic as interests you. Huge libraries of eLisp code for such modes is available from GNU.

3
votes

Eclipse does something that might be exactly what you want, or at least very close.

Enable "mark occurrences" in Preferences > Java > Editor > Mark Occurrences

As soon as you click on something like a local variable you will mark all occurrences of that variable in the current source file.

This can be very helpful in combination with "annotations". Disable "Include in next/previous navigation" for all annotations except "occurrences". The easiest way is through the up/down arrows in the UI. You click the small black down arrow immediately next to the big yellow up or down arrow in the toolbar. Now you can use comma and period to move through all the occurrences you highlighted.

3
votes

Netbeans highlighting tool is also quite complete and configurable.

Highlight all occurences of the word "int" as red.

  • In Netbeans, there is no default entry for this particular keyword, primitive are in the goup of Keyword.

Highlight all strings (enclosed in "'s) in blue.

  • Yes it's possible ; category : String

Given a string of txt that appears > twice, I want it highlighted purple.

  • Maybe I don't understand good this point, because if you highlight all words written more than one time I fear all your code will be purple after some line of code!

If I click on a block of text, I would like all blocks of txt on the same file highlighted green.

  • When you select a word by double clicking, all occurrences will be highlighted and a mark will appear in the right column at every line containing the keyword. You can click on the mark to quickly go to the line containing the occurrence.
  • You can also use the shortcut Ctrl+F3 to find a selection and highlight all occurrences (it can be all you want, not only keywords). And then use Shift+F3 to find previous occurence and F3 to find next one

I can extend an existing project (ideally, I'd like this to be an IDE plugin) to customize my dynamic requirements ?

  • I've never tried to extend highlight categories, it seems that it's possible but with a lot of work! See this link and this one.
3
votes

I'm not sure if you set on using a full IDE but Sublime Text 2 has some really nice auto highlighting: http://www.sublimetext.com/2