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:
As well as the Finder:
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