Thursday, February 2, 2012

Better Syntax Coloring for IDEs

Modern IDEs like Eclipse already provide excellent syntax highlighting. Still I think there is room for improvement.

One idea of my ideas would be to color brackets differently. Instead of drawing them all in the same color, rotating through a color wheel would make it much easier to check, where which bracket is closed.

So this example code:

Would look like this:

Of course it's a detail, but a visual cue like this can help when you would try to extract the inner expression in FTFilter.notAnalyzed - Just start your selection from the green bracket, to the closing green bracket and you're done.

I already downloaded the JDT sources of Eclipse, but in order to have a fast and precise syntax coloring, the code is quite complex and I don't have the time to work into this. Still I believe a JDT developer could implement this feature very quickly - if you happen to know one, you might want to forward the URL ;-)

If you think this is a good idea, vote me up on DZone, or retweet this or +1 it on google... If there is enough positive feedback I'll go and file a bug for Eclipse, maybe it'll be in one of the next versions...

Update 1: I received a lot of positive feedback, thanks everybody. Three other programs seem to already support this feature: Microsoft Excel, Pharo Smalltalk (I think, only when the cursor is near a brace) and the Closure Plugin for Eclipse.

Additionally I hacked this functionality into a subclass of QSyntaxHighlighter for one of my Qt toy projects. As I've written here, this is quite simple.

Update 2: Just filed a Bug for Eclipse JDT-Text:


  1. Sounds like a good idea to me; I would be even happier if IDEs highlighted the background of the enclosing block, in addition to matching the brackets.

  2. I agree that syntax highlighting could be improved, but personally don't like the idea of coloring every single pair of braces in different color. Firstly, if there are too many braces, then probably code needs to be refactored. Secondly, text colored in every rainbow color looks awful.

    1. Mathew: You're right, there are too many braces to color each pair differently. That's what I meant with "color wheel". The idea would be to have 2-4 (or n..) different colors and rotate through them. Many tables used this scheme to color rows differently. If you'd limit this to 4 colors, the user even could customize this to his own favorite rainbow colors ;-)

      Actually I'm also a bit afarid thath the code could look too colorful. Maybe this feature should only be turned on in certain situations, like when the caret is between braces.

  3. From Eclipse documentation

    "To find a matching bracket select an opening or closing bracket and press Ctrl+Shift+P or select Navigate > Go To > Matching Bracket"

    abahgat, here's your feature:

    "You can also double click before an opening or after a closing bracket - this selects the text between the two brackets."

    I'm not saying the coloring is a bad idea - in fact it many work much better for many people. I just wanted abahgat to know the highlighting was already possible.

  4. I think the Clojure plugin for Eclipse does something like this.

    1. Thanks for this info Vadim...I've updated the text above...

  5. Thanks for this info Leo...I've updated the text above...

  6. The Bracketeer plugin for Eclipse also does this: