A CodeRay Scanner for Lisp

Posted September 5, 2007

After I got syntax highlighting working, I went through all my old posts and retroactively set up syntax highlighting. Bringing color to a world that had only known black and white. It was pretty cool.

Except for my post about my Emacs blog client. All the code in that post is in Emacs Lisp, and sadly there does not exist a CodeRay scanner (and thus highlighter) for Lisp.

This was kind of a bummer. I didn’t like having unhighlit code. Since I plan on doing more posts about Emacs, I also didn’t like the idea that I would have to continue writing unhighlit code.

So, being industrious and having a little time on my hands, I made my own scanner. It turns out it’s not that hard; CodeRay has a nice little framework set up that makes scanning pretty painless.

So now the code is all pretty and highlit. As an example, here’s the code for the psychoanalyze-pinhead function1:

(defun psychoanalyze-pinhead ()
  "Zippy goes to the analyst." 
  (interactive)
  (doctor) ; start the psychotherapy
  (message "")
  (switch-to-buffer "*doctor*")
  (sit-for 0)
  (while (not (input-pending-p))
    (insert-string (yow))
    (sit-for 0)
    (doctor-ret-or-read 1)
    (doctor-ret-or-read 1)))

If you can’t guess what the function does from the code, boot up Emacs and run M-x psychoanalyze-pinhead to test it out. It’s pretty snazzy.

I’ve Pastied the code, if you want to check it out or use it yourself. I plan to let the Pastie folks know of its existance, too, so if you find yourself being able to Pastie Lisp, you know who to thank. Or yell at. Whatever.

1 This code is under the GPL. See this page for full copyright info.

Make your comments snazzy with Textile!