April 02, 2006
Trac Syntax Coloring for Lisp

I've been experimenting with Trac, which integrates a wiki with simple bug tracking and subversion repository browing.

Trac supports syntax coloring of any programming language that either GNU Enscript or SilverCity support, which seems to include every single thing other than Common Lisp. Sometimes I use Lisp, so this annoyed me. I used XML-RPC to glue Brian Mastenbrook's colorize (which is used by the paste service at paste.lisp.org) to Trac.

The result:

Trac knows Lisp

colorization-server.tar.gz has the Lisp side of the XML-RPC glue, a small patch to colorize to add the option of not doing fancy paren matching (which didn't fit into Trac's output very well) and a little SBCL-specific startup script.

trac-lisp.py is the Python/Trac side glue. Drop it into Trac's mimeview directory, rename it to lisp.py, change the COLORIZER_URL to point to the machine you're going to run the colorization server on, add a 'lisp':'text/x-lisp' entry to MIME_MAP in mimeview/api.py, add 'trac.mimeview.lisp' to the default_components in db_default.py.

Copy the CSS that's in colorize's *coloring-css* variable into a file called lisp.css and put that file in Trac's htdocs/css directory. Start up a lisp running the colorization server, restart Trac and you're set.

I put in a small LRU cache to avoid hitting the XML-RPC server every single time Trac needs to render a page containing Lisp source code, but even with cache misses the XML-RPC roundtrip is barely noticeable. I use Trac in standalone mode, which is probably the only reason the caching works—if you use CGI mode, you're on your own.

Of course, trac-lisp.py could easily be modified to be a more general interface between Trac and colorize, with support for any language colorize understands.

Later: I didn't realize Trac had syntax to turn on language-specific coloring of code blocks on wiki pages, in which case my caching would do the bad thing. I've fixed the code.

inline lisp in trac

Posted by jjwiseman at April 02, 2006 05:03 PM
Comments

That looks pretty sweet!

As a lot of Lisp projects are currently darcs based instead of svn you might want to check out: http://www.darcs.net/DarcsWiki/TracOnDarcs as well.

Posted by: Nathan Bird on April 2, 2006 06:32 PM

That's very nice!

Posted by: Gary King on April 3, 2006 02:44 PM
Post a comment
Name:


Email Address:


URL:




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”.)

Comments:


Remember info?