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: https://bugs.eclipse.org/bugs/show_bug.cgi?id=370745

9 comments:

  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.

    ReplyDelete
  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.

    ReplyDelete
    Replies
    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.

      Delete
  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.

    ReplyDelete
  4. I remember I worked in an IDE that had that feature and it was really convenient. I can't remember what it was though. I'll post again if I remember. I'm almost certain it was Eclipse or a variety of it. It might've been Notepad++ on windows... NVM, I just remembered, it's Excel cell colouring when you choose more than one in a formula *facepalm*

    ReplyDelete
    Replies
    1. Thanks for this info Leo...I've updated the text above...

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

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

      Delete
  6. The Bracketeer plugin for Eclipse also does this:

    https://github.com/chookapp/Bracketeer

    ReplyDelete