August 12, 2005
Five Approaches to S-Expression Highlighting

sexpr highlighting's popular paste service for IRC users has fancy Javascript CSS to color code matching parentheses as you mouse over expressions. Unobtrusive, but not really all that helpful, either. B-.

sexpr highlighting

The Community-Scheme-Wiki has mouseover Javascript CSS magic, but highlights entire expressions (including whitespace). Helpful, but the coloring of the indenting whitespace looks weird. C.

sexpr highlighting

foom's emacs hack focuses on indentation. Clear and harmonious, B+.

sexpr highlighting

michaelw's emacs hack is a hybrid of indentation-based and nested boxes, and removes parens completely. Deleting parens is bold, but... too bold. And grayscale looks techy but cold. C+.

sexpr highlighting

pkhuong's emacs hack is a rainbow of expression-coloring, minus the whitespace. Nice try, that changing the hue according to an expression's position in its parent expression thing, but in the end it is most valuable for what we learn from its failure. D.

(All examples culled from #lisp.)

(Nobody using pastel colors gets an A.)

Posted by jjwiseman at August 12, 2005 03:29 PM

Both lisppaste and csw are using CSS, not Javascript. I don't write Javascript anymore :-)

Lisppaste's code coloring is done with a small parser in Common Lisp.

Posted by: Brian on August 12, 2005 03:50 PM

I use hl-sexp-mode in Emacs - its' not as fancy or as pretty as your pictures, and it just highlights the sexp about the point, but it's useful. Coloring every sexp is information overload.

Posted by: rps on August 13, 2005 08:37 AM

you will probably like (though ((i imagine, (((much like I do here, in my turn))) upon first visit, contentwise)) understand little of) what you see there.

Posted by: piet on August 13, 2005 08:59 AM

foom's is pretty, but it looks like the nesting colors might conflict with the keyword colors. What happens to pink-on-pink, for example?

As for color choice, the chief advantage to pastels, it seems to me, is that one can have some confidence that black text will have decent contrast. On the other hand, pastel text on a white background can be problematical.

I'd be curious to see a mockup of an A method.

Posted by: jonathan Lundell on August 13, 2005 12:42 PM

Pastels aren't that bad, particularly if you're going to hilight large areas. Save the saturated colors for the small regions.

I suggest that if you want to write a syntax highlighter you find a copy of R. Baecker and A. Marcus. "Human Factors and Typography for More Readable Programs." Addison--Wesley, Reading, MA, USA, 1990.

It focuses on C, but many of the concerns it discusses are not related to any particular language.

Posted by: john Dougan on August 13, 2005 08:17 PM

Please, for the love of God, do you have one of these highlighters for Fortran?

Posted by: A Nun on August 14, 2005 04:22 PM

I wonder if anyone's done something similar for Python, given the syntactically-significant indentation.

Posted by: Joe Grossberg on August 15, 2005 09:19 AM

Hey, I passed. Quite surprising! I think the main problems with my hack (incidentally, my introduction to the wonderful world of elisp) are that the colours fade out into each other, especially at the top levels, and that it's conveying information about the structure of the code rather than its meaning (sexp VS indentation). IIRC, what I was tring to at the time was to make it easier to have access to the information we get when using using expression paren-matching mode, without moving the point everywhere. It was almost usable on regions or sexps with a small number of top-level elements (short LENGTH), but again, the colours faded into each other when there were too many elements, especially at shallow depths (deeper depths get more solid colours). It definitely proved itself to be useless, but at least it let starseeker, who had thought about a similar mode, and me to know that for sure. I'm now back to only using good old indentation and blinking parens, but if I were to try a colouring mode, I'd definitely try foom's.

Posted by: pkhuong on August 17, 2005 05:20 PM

I've generally not gone for syntax highlighting. Especially with a white background where lighter colored text has poor contrast. I've recently tried it again with global-font-lock-mode no less and the color-theme.el package because I didn't want to go hacking the miriad possibilities myself.

I actually kind of like color-theme-clarity. I'll see how well it survives the test of time.

Posted by: David Steuber on August 22, 2005 09:39 AM

None of the 5 examples of hilighting score well.
Can you cite an example that scores an A or A+?

Posted by: thenry on August 31, 2005 05:51 AM

Yes, would be useful to know your ideas about an A or A+ syntax highlighter. No syntax highlighting not being an option.

Alternatively, what do you use for daily coding?

Posted by: Alok on July 9, 2006 07:01 AM
Post a comment

Email Address:


Unless you answer this question, your comment will be classified as spam and will not be posted.
(I'll give you a hint: the answer is “lisp”.)


Remember info?