Browse code
Add README.org
Ed Langley authored on 10/03/2019 21:07:10
Showing 1 changed files
Showing 1 changed files
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,177 @@ |
1 |
+* Lisp Metadata Importer, a Spotlight Plugin. |
|
2 |
+ |
|
3 |
+fiddlerwoaroof's note: I took this code from |
|
4 |
+http://lemonodor.com/archives/001232.html and cleaned it up to work |
|
5 |
+with modern OS X/macOS: I removed AGRegex and just use |
|
6 |
+NSRegularExpression and made other minor tweaks to get it to build and |
|
7 |
+run on High Sierrra |
|
8 |
+ |
|
9 |
+This importer plugin indexes files with .lisp, .lsp and .cl extensions |
|
10 |
+using the Spotlight search engine that was introduced by Apple in OS X |
|
11 |
+10.4. You might notice that even before you install this plugin that |
|
12 |
+some of your Lisp files have already been indexed by Spotlight. It is |
|
13 |
+possible that something on your system set the type of some files as |
|
14 |
+“TEXT”, in which case the default Spotlight text indexer will process |
|
15 |
+the files. This only happens on a file-by-file basis, though, whereas |
|
16 |
+the Lisp Metadata Importer instructs the system to index all files |
|
17 |
+with the extensions listed above, regardless of whether or not the |
|
18 |
+system already thinks they’re text files. The Lisp importer also does |
|
19 |
+some Lisp-specific indexing that you might find more useful than the |
|
20 |
+default text indexing. |
|
21 |
+ |
|
22 |
+* How do I install it? |
|
23 |
+ |
|
24 |
+Copy the Lisp Metadata Importer.mdimporter file into the |
|
25 |
+/Library/Spotlight folder. |
|
26 |
+ |
|
27 |
+* How do I uninstall it? |
|
28 |
+ |
|
29 |
+Remove the Lisp Metadata Importer.mdimporter file from the |
|
30 |
+/Library/Spotlight folder. |
|
31 |
+ |
|
32 |
+* How do I test it once it is installed? |
|
33 |
+ |
|
34 |
+Try indexing a single Lisp file using the mdimport command. When you |
|
35 |
+run mdimport with the –d1 flag it will tell you which plugin it’s |
|
36 |
+using, if any, to index the file. You should see a reference to the |
|
37 |
+Lisp Metadata Importer.mdimporter file. Once you’ve run mdimport, use |
|
38 |
+the mdls command to look at the metadata associated with the file. The |
|
39 |
+important things to look for are that the kMDItemContentType is |
|
40 |
+“com.lemonodor.lisp-source”, and that there are some attributes with |
|
41 |
+names that begin with “org_lisp”, like “org_lisp_defmacros” or |
|
42 |
+“org_lisp_defuns”. |
|
43 |
+ |
|
44 |
+#+BEGIN_SRC sh |
|
45 |
+ lem:~ $ mdimport -d1 variables.lisp |
|
46 |
+ 2005-09-15 12:05:55.493 mdimport[6962] Import '/Users/wiseman/variables.lisp' type |
|
47 |
+ 'com.lemonodor.lisp-source' using |
|
48 |
+ 'file://localhost/Library/Spotlight/Lisp%20Metadata%20Importer.mdimporter/' |
|
49 |
+ lem:~ $ mdls variables.lisp |
|
50 |
+ variables.lisp ------------- |
|
51 |
+ kMDItemAttributeChangeDate = 2005-09-08 11:30:18 -0700 |
|
52 |
+ kMDItemContentCreationDate = 2005-09-02 17:41:07 -0700 |
|
53 |
+ kMDItemContentModificationDate = 2005-09-02 17:41:08 -0700 |
|
54 |
+ kMDItemContentType = "com.lemonodor.lisp-source" |
|
55 |
+ kMDItemContentTypeTree = ( |
|
56 |
+ "com.lemonodor.lisp-source", |
|
57 |
+ "public.source-code", |
|
58 |
+ "public.plain-text", |
|
59 |
+ "public.text", |
|
60 |
+ "public.data", |
|
61 |
+ "public.item", |
|
62 |
+ "public.content" |
|
63 |
+ ) |
|
64 |
+ kMDItemDisplayName = "variables.lisp" |
|
65 |
+ # and on and on, until finally... |
|
66 |
+ org_lisp_defclasses |
|
67 |
+ org_lisp_defgenerics |
|
68 |
+ org_lisp_definitions |
|
69 |
+ foo, |
|
70 |
+ "(setf foo)", |
|
71 |
+ "oh-noe", |
|
72 |
+ "*oh-no*", |
|
73 |
+ "*hee-ho*", |
|
74 |
+ "+thing+", |
|
75 |
+ "i-dont-think-so", |
|
76 |
+ "BRAIN-CELL", |
|
77 |
+ "(RAT-BRAIN-CELL", |
|
78 |
+ attack, |
|
79 |
+ attack, |
|
80 |
+ "(setf mood)", |
|
81 |
+ "(setf mood)" |
|
82 |
+ ) |
|
83 |
+ org_lisp_defmacros |
|
84 |
+ org_lisp_defmethods |
|
85 |
+ org_lisp_defstructs |
|
86 |
+ org_lisp_defuns |
|
87 |
+ org_lisp_defvars |
|
88 |
+ = ("i-dont-think-so") |
|
89 |
+ = (attack, "(setf mood)", "(setf mood)") |
|
90 |
+ = ( |
|
91 |
+ = ("oh-noe") |
|
92 |
+ = (attack, "(setf mood)") |
|
93 |
+ = ("BRAIN-CELL", "RAT-BRAIN-CELL") |
|
94 |
+ = (foo, "(setf foo)") |
|
95 |
+ = ("*oh-no*", "*hee-ho*", "+thing+") |
|
96 |
+#+END_SRC |
|
97 |
+ |
|
98 |
+If you see those attributes then the importer is working correctly. |
|
99 |
+If the importer doesn’t seem to be working and you’ve double checked |
|
100 |
+to make sure you copied it to the correct folder, try the mdimport –r |
|
101 |
+trick in the next question & answer; it’s the equivalent of kicking a |
|
102 |
+malfunctioning jukebox. |
|
103 |
+ |
|
104 |
+* How do I index all my Lisp files? |
|
105 |
+ |
|
106 |
+Use mdimport again, this time with the –r flag, and passing it the |
|
107 |
+path to the Lisp plugin. |
|
108 |
+ |
|
109 |
+#+BEGIN_SRC sh |
|
110 |
+ lem:~ $ mdimport -r /Library/Spotlight/Lisp\ Metadata\ Importer.mdimporter/ |
|
111 |
+ 2005-09-15 12:41:38.650 mdimport[7169] Asking server to reimport files with UTIs: ( |
|
112 |
+ "dyn.ah62d4rv4ge8024pxsa", |
|
113 |
+ "com.lemonodor.lisp-source", |
|
114 |
+ "dyn.ah62d4rv4gq81k3p2su11uppqrf31appxr741e25f", |
|
115 |
+ "dyn.ah62d4rv4ge80265u", |
|
116 |
+ "dyn.ah62d4rv4ge80g5a" |
|
117 |
+ ) |
|
118 |
+#+END_SRC |
|
119 |
+ |
|
120 |
+* What exactly is being indexed? |
|
121 |
+The Lisp metadata importer indexes the definitions contained in a |
|
122 |
+file. This includes functions, macros, classes, methods, generic |
|
123 |
+functions, structures, defvars, defparameters and defconstants. It |
|
124 |
+also includes any object FOO defined by a form that looks like |
|
125 |
+(“defsomething FOO ...)”. In addition to definitions, the entire |
|
126 |
+contents of the file are indexed for full text queries. |
|
127 |
+ |
|
128 |
+* How do I search for something? |
|
129 |
+The GUI way is to hit Command-F in the finder to bring up a Find |
|
130 |
+window. Click on one one of the attributes and select “Other...”. to |
|
131 |
+see a list of other attributes: Choose one of the Lisp importer’s |
|
132 |
+attributes from the list that comes up (you can type “lisp” into the |
|
133 |
+search field on the upper right to filter out the non-Lisp |
|
134 |
+attributes): |
|
135 |
+Now enter the text you’d like to search for and watch the matching |
|
136 |
+files appear: |
|
137 |
+Some people have reported that the Lisp-specific attributes weren’t |
|
138 |
+available in the Find dialog until they re-launched the Finder (to |
|
139 |
+re-launch the finder, hit Command-Option-Esc and then select the |
|
140 |
+Finder in the “Force Quit Applications” dialog that pops up). The |
|
141 |
+non-GUI way to do Spotlight searches is to use the mdfind command. I |
|
142 |
+did this the other day when someone on IRC asked how to do |
|
143 |
+search-and-replace on a string. I knew I had written a function to do |
|
144 |
+that, but I couldn’t remember which project the code was in. (It |
|
145 |
+turned out I had a couple implementations lying around.) |
|
146 |
+The Spotlight query language used by mdfind is documented online by |
|
147 |
+Apple. |
|
148 |
+ |
|
149 |
+* What are the attributes I can search on and where do they come from in the Lisp file? |
|
150 |
+ |
|
151 |
+The following metadata attributes are defined by the Lisp Metadata Importer: |
|
152 |
+ |
|
153 |
+ | Metadata Attribute | Defining Forms | |
|
154 |
+ |----------------------+-----------------------------------------| |
|
155 |
+ | org_lisp_defuns | defun | |
|
156 |
+ | org_lisp_defmacros | defmacro | |
|
157 |
+ | org_lisp_defclasses | defclass | |
|
158 |
+ | org_lisp_defgeneric | defgeneric | |
|
159 |
+ | org_lisp_defmethod | defmethod | |
|
160 |
+ | org_lisp_defstructs | defstruct | |
|
161 |
+ | org_lisp_defvars | defvar, defparameter, defconstant | |
|
162 |
+ | org_lisp_definitions | Anything defined with a “(def...” form. | |
|
163 |
+ |----------------------+-----------------------------------------| |
|
164 |
+ |
|
165 |
+In addition, the importer sets the kMDItemTextContent attribute to be |
|
166 |
+the entire contents of the file, so you can do full text searches. |
|
167 |
+ |
|
168 |
+* What shortcuts did you take? |
|
169 |
+ |
|
170 |
+Here are a few I can think of: |
|
171 |
+- The importer only indexes definition forms that are at the beginning of a line. |
|
172 |
+- It has a very simple, limited concept of symbol names and Lisp reader syntax, so it can easily become confused. |
|
173 |
+- I shouldn’t really use the org_lisp prefix for attribute names. |
|
174 |
+- I should try to coordinate with the people writing plugins for Ruby, Python and other languages so we can come up with a common set of source code metadata attributes. |
|
175 |
+ |
|
176 |
+* Who should you thank? |
|
177 |
+Justin Wight, Pierre Mai, Ralph Richard Cook and Bryan O’Connor all helped me to some extent. Thanks, guys! |