Glow: Syntax Highlighting for Clojure Source Code

Today I'm happy to announce the release of Glow, a very small library for syntax highlighting strings of Clojure source code.


You may be thinking to yourself: why did you write this? After all, Ultra and Whidbey already provide syntax highlighting at the REPL, and you can pretty-print most EDN and Clojure objects using the underlying pretty-printing engines, Fipp and Puget.

The short answer is that I really, really wanted a way to get a syntax-highlighted drop-in solution for clojure.repl/source which I could inject into Ultra. The current functionality (in ultra.repl) relies on the (somewhat questionable) use of read-string to accomplish syntax highlighting via Puget, which unfortunately also does macro expansion and hides metadata.

Most of the time, macro expansion isn't a problem, but if I want to quickly look at the source code for something (e.g., a macro), I don't want to be looking at what could potentially be an extremely large macro-expanded form.

Similarly, I don't want any attached metadata to be hidden from me either. I want to look at the code as it was written.



Let's say you've got a Clojure file with the following contents:

(ns sample)

(defn func
 [^Throwable x & y]
 (conj {} [:a (+ 1.1 x)]))

(def variable
     (if-let [x 5]

Usage is quite straightforward:

Obviously I think the default colorscheme is great, but there's no accounting for taste. Glow supports whatever colorscheme you feel like:

Go nuts.

Contributions Wanted!

I'm interested in making the regular expressions in Glow faster and more robust. Frankly, I'm not an expert in regexes (he said, putting it mildly), and some of them could use a more critical eye.

To that end, I'm actively soliciting pull requests to expand the regular expression test coverage and to detect and resolve failure cases.

...and, that's it! Shoo, go have fun. As always, feel free to reach out at @venantius if you've got questions, comments, etc.

~ V