August 12, 2005
Five Approaches to S-Expression Highlighting
paste.lisp.org's popular paste service for IRC users has fancy
The Community-Scheme-Wiki has mouseover
foom's emacs hack focuses on indentation. Clear and harmonious, B+.
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+.
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
Lisppaste's code coloring is done with a small parser in Common Lisp.
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.
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.
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.
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. http://citeseer.ist.psu.edu/context/98445/0
It focuses on C, but many of the concerns it discusses are not related to any particular language.
Please, for the love of God, do you have one of these highlighters for Fortran?
I wonder if anyone's done something similar for Python, given the syntactically-significant indentation.
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.
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.
None of the 5 examples of hilighting score well.
Can you cite an example that scores an A or A+?
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?