August 31, 2005
Lisp for Spotlight

Richard Cook recently posted code for a Spotlight plugin to index Lisp files. His plugin takes what's probably the absolute simplest approach: Indexing a Lisp source file as if it were plain text.

When I saw his post I played around with Spotlight a little. I noticed that at least some, but not all of my Lisp files were already being indexed. It turned out that the ones that were being indexed were some pretty old files, ones that I'd created or edited in MCL. They had an HFS+ file type attribute (yeah, file types and creator codes still exist in HFS+) of TEXT, which seemed to lead to their kMDItemContentType being com.apple.traditional-mac-plain-text, which meant that they get indexed by one of the standard Spotlight plugins.

It seemed like there must be some easy way to convince OS X that all files with a .lisp extension are text files that can be indexed like any other text file without going to the trouble of actually writing an indexing plugin, but Pierre Mai did some experiments along those lines that didn't pan out.

I'm not convinced that there isn't some tweaky little thing that might be preventing Pierre's attempt from succeeding, but maybe there are other easy hacks. For example, a simple modification of the existing SourceCode.mdimporter or RichText.mdimporter to convince them to index Lisp files.

But who wants dumb plaintext indexing, anyway? We should be able to do better. Function definitions, class definitions, who-calls info, package definitions, ASDF or other system definitions—There is lots of potentially useful stuff we could index.

Jonathan Wight's Spotlight plugin for Python should be an inspiration. It indexes file-level comments, author information, version, defined functions and defined classes, so you can do queries like this:

# Find all files containing a function called "main" and a class called "Foobar"
$ mdfind "org_python_functions == 'main' and org_python_classes == 'Foobar'"

It also hooks into the Spotlight GUI:

python spotlight plugin screenshot

As well as the Finder:

python spotlight plugin screenshot

Appealingly, the Python plugin uses the built-in Python code walker to parse files. A more static approach might be the way to go for Lisp (Lisp code walkers seem to get so nasty), in the style of the old approximation of looking for lines that begin with “(def” to find function, class, variables, etc. definitions.

Get to it, Lazy Web!

Update: The lazy web, she is not reliable. I had to do it myself.

Posted by jjwiseman at August 31, 2005 12:02 AM
Comments

I first looked into just updating the plist of the SourceCode or RichText importers, but following that MacOSXhints thread made me reject that option.

Lisp doesn't have its own built in kMDItemContentType, like PHP, Python etc. do. Other extensions get their own dynamic ones, starting with "dyn.", but apparently they change with each restart.

Since those are built in importers from Apple, your changes could get wiped out after an OS upgrade.

Posted by: Richard Cook on September 6, 2005 09:48 AM

After my experiments with just defining a suitable UTI didn't pan out, I implemented a simple importer, which more or less does what the Apple SourceCode importer does, which is available at

http://www.pmsf.de/resources/lisp/CLMDImporter.html

in both binary and source form. That might provide a good starting point for more advanced parsing.

Posted by: Pierre R. Mai on September 6, 2005 09:48 AM

Thanks for linking to my importer.

I don't know how to call lisp from C but it might quite easy to modify my Python import to import lisp files as well?

I'd be willing to help anyone trying this.

Posted by: Jonathan Wight on September 8, 2005 12:11 AM
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?