Clojure Source Files in Quick Look on MacOSX

Do you like to see the content of Clojure source files in Quick Look? I do.

Unfortunately this is not as straightforward as it should be. Having XCode on my machine didn’t help either. It took me a while to get this working. Maybe this will safe you some time. :-)

Here we go..

Quick Look doesn’t know about clj files. Which is ok because it can’t possibly know every programming language out there. The quick look default behaviour for unknown files is to simply show some not so interesting file information:

I found a plugin called QLColorCode (version 2.0.2) which adds Quick Look support for a large number of programming languages including syntax highlighting.

The plugin has some installation notes and how to handle the XCode issue. Nevertheless it takes a couple of manual steps to get it running for clj source files.

First a few words about the way Quick Look works.

Quick Look uses something called UTI (Uniform Type Identifiers Reference) to identify the type of a file and to select the proper plugin for displaying it.

It is possible to check what Quick Look knows about a clojure files by running qlmanage. The -d 1 prints debug information and the -p option takes the file.

Here is the output:

$ qlmanage -d 1 -p src/clj/clojure/core.clj
Testing Quick Look preview with files:
[DEBUG] Registering for public.image
[DEBUG] Preview test for src/clj/clojure/core.clj -- /Users/hauner/Development/clojure.git/. Content type UTI: dyn.ah62d4rv4ge80g5dn
[DEBUG] Previewing /Users/hauner/Development/clojure.git/src/clj/clojure/core.clj. Content type UTI: dyn.ah62d4rv4ge80g5dn. Generator used: None

The Content Type UTI (Lines 5 & 6) is only “garbage”. Which means that Quick Look has no idea how to handle clj files.

Back to the installation.

Disabling XCodes “source-code” plugin

The QLColorCode plugin will register itself for the “public.source-code” UTI.

With XCode installed the “public.source-code” UTI is already registered to a plugin provided by XCode (XCode issue) as can be seen by running qlmanage again.

$ qlmanage -m | grep source-code
public.source-code -> /Developer/Applications/ (1613)

To get rid of it, I used the Disable XCode QL from QLColorCodeScripts-1.0. It will rename the XCode to SourceCode.qlgenerator.disabled which is enough to remove it. Simply renaming it will work too.

Running qlmanage again, it is gone.

$ qlmanage -m | grep source-code

Before installing the QLColorCode plugin is has to be tweaked a littel bit which I will describe next.

Adjusting the plugin

MacOSX doesn’t offer any convinient way to register new or change file types (in this case the clojure files). To register it with MacOSX I added an xml to qlcolorcode’s Info.plist file, which is in QLColorCode-2.0.2/QLColorCode.qlgenerator/Contents/Info.plist.

I simply copied and adjusted the scala entry.

    <string>Clojure Source Code</string>

There is another small tweak required to make the plugin use syntax highlighting. The plugin contains highlighting rules for Clojure but expects .clojure as filename extension instead of .clj. To fix it I simply copied clojure.lang to clj.lang in the plugin folder QLColorCode-2.0.2/QLColorCode.qlgenerator/Contents/Resources/highlight/share/highlight/.

Nearly done, only one step left :-)

Installing the QLColorCode plugin

After tweaking the plugin I copied the plugin to ~/Library/QuickLook (/Library/QuickLook would be fine too).

Installation is described in the plugins ReadMe.txt along with some instructions for customizing font, font size and other options.

I had to run

$ qlmanage -r
qlmanage: resetting quicklookd

before Quick Look recognized the new plugin and qlmanage -m reported QLColorCode
as plugin for “source-code”.

$ qlmanage -m | grep source-code
public.source-code -> /Users/hauner/Library/QuickLook/QLColorCode.qlgenerator (2.0.1)

And then finally the reward… :-)


3 thoughts on “Clojure Source Files in Quick Look on MacOSX

  1. Many, *many* thanks for your far-beyond-the-call-of-duty description of this problem and its solution. Even with your detailed instructions, I had to fiddle with things–but I got it to work! This is going to make my Clojure work on Snow Leopard much, much nicer.

    I’ll add two hints from elsewhere that helped me. First, if you don’t get the expected behavior, try again, using a newly created user account; if it works there but not in your account, this means that the remaining problem is in your particular configuration, not in the installation and modification of QLColorCode.

    Second (and this hint is of the last-ditch “wave a dead chicken” sort), one netizen swore by “dragging the QLColorCode.qlgenerator file out of the /Library/QuickLook folder and onto the Desktop, then dragging the file back into the QuickLook folder,” which the author claims causes something significant to happen. (Mine didn’t work until *after* I had done this.)

    Other things to try include relaunching the Finder (Ctrl + Option/Alt + right-click the Finder dock icon, then choose “Relaunch”) and, as a last resort, rebooting your Mac.

    • Hi Gregg,

      thanks for your feedback. It took me a couple of hours to collect it, so it is nice to know that the time was not wasted :-)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s