0
|
1 ;;; finder.el --- topic & keyword-based code finder
|
|
2
|
|
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
|
|
6 ;; Created: 16 Jun 1992
|
|
7 ;; Version: 1.0
|
|
8 ;; Keywords: help
|
|
9 ;; X-Modified-by: Bob Weiner <weiner@mot.com>, 4/18/95, to include Lisp
|
|
10 ;; library directory names in finder-program-info, for fast display of
|
|
11 ;; Lisp libraries and associated commentaries. Added {v}, finder-view,
|
|
12 ;; and {e}, finder-edit commands for displaying libraries.
|
|
13 ;;
|
|
14 ;; Added user variable, 'finder-abbreviate-directory-list', used to
|
|
15 ;; abbreviate directories before they are saved to finder-program-info.
|
|
16 ;; Such relative directories can be portable from one Emacs installation
|
|
17 ;; to another. Default value is based upon the value of Emacs'
|
|
18 ;; data-directory variable.
|
|
19
|
|
20 ;; This file is part of XEmacs.
|
|
21
|
|
22 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
23 ;; under the terms of the GNU General Public License as published by
|
|
24 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
25 ;; any later version.
|
|
26
|
|
27 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
28 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
29 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
30 ;; General Public License for more details.
|
|
31
|
|
32 ;; You should have received a copy of the GNU General Public License
|
|
33 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
34 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
35 ;; 02111-1307, USA.
|
0
|
36
|
2
|
37 ;;; Synched up with: FSF 19.34.
|
0
|
38
|
|
39 ;;; Commentary:
|
|
40
|
|
41 ;; This mode uses the Keywords library header to provide code-finding
|
|
42 ;; services by keyword.
|
|
43 ;;
|
|
44 ;; Things to do:
|
|
45 ;; 1. Support multiple keywords per search. This could be extremely hairy;
|
|
46 ;; there doesn't seem to be any way to get completing-read to exit on
|
|
47 ;; an EOL with no substring pending, which is what we'd want to end the loop.
|
|
48 ;; 2. Search by string in synopsis line?
|
|
49 ;; 3. Function to check finder-package-info for unknown keywords.
|
|
50
|
|
51 ;;; Code:
|
|
52
|
|
53 (require 'lisp-mnt)
|
|
54 (require 'finder-inf)
|
2
|
55 ;; XEmacs addition
|
0
|
56 (require 'picture)
|
|
57 (require 'mode-motion)
|
|
58
|
|
59 (defvar finder-emacs-root-directory
|
|
60 (file-name-directory (directory-file-name data-directory))
|
|
61 "Root directory of current emacs tree.")
|
|
62
|
|
63 (defvar finder-abbreviate-directory-list
|
|
64 (list finder-emacs-root-directory)
|
|
65 "*List of directory roots to remove from finder-package-info directory entries.
|
|
66 The first element in the list is used when expanding relative package
|
|
67 directories to view or extract information from package source code.")
|
|
68
|
|
69 (defvar finder-file-regexp "\\.el$"
|
|
70 "Regexp which matches file names but not Emacs Lisp finder keywords.")
|
|
71
|
|
72 ;; Local variable in finder buffer.
|
|
73 (defvar finder-headmark)
|
|
74
|
|
75 (defvar finder-known-keywords
|
|
76 '(
|
|
77 (abbrev . "abbreviation handling, typing shortcuts, macros")
|
|
78 (bib . "code related to the `bib' bibliography processor")
|
2
|
79 (c . "support for the C language and related languages")
|
0
|
80 (calendar . "calendar and time management support")
|
|
81 (comm . "communications, networking, remote access to files")
|
|
82 (data . "support editing files of data")
|
|
83 (docs . "support for Emacs documentation")
|
|
84 (emulations . "emulations of other editors")
|
|
85 (extensions . "Emacs Lisp language extensions")
|
|
86 (faces . "support for multiple fonts")
|
2
|
87 (frames . "support for Emacs frames and window systems")
|
0
|
88 (games . "games, jokes and amusements")
|
|
89 (hardware . "support for interfacing with exotic hardware")
|
|
90 (help . "support for on-line help systems")
|
|
91 (hypermedia . "support for links between text or other media types")
|
|
92 (i18n . "internationalization and alternate character-set support")
|
|
93 (internal . "code for Emacs internals, build process, defaults")
|
|
94 (languages . "specialized modes for editing programming languages")
|
|
95 (lisp . "Lisp support, including Emacs Lisp")
|
|
96 (local . "code local to your site")
|
|
97 (maint . "maintenance aids for the Emacs development group")
|
|
98 (mail . "modes for electronic-mail handling")
|
|
99 (matching . "various sorts of searching and matching")
|
|
100 (mouse . "mouse support")
|
|
101 (news . "support for netnews reading and posting")
|
|
102 (oop . "support for object-oriented programming")
|
|
103 (outlines . "support for hierarchical outlining")
|
|
104 (processes . "process, subshell, compilation, and job control support")
|
|
105 (terminals . "support for terminal types")
|
|
106 (tex . "code related to the TeX formatter")
|
|
107 (tools . "programming tools")
|
|
108 (unix . "front-ends/assistants for, or emulators of, UNIX features")
|
|
109 (vms . "support code for vms")
|
|
110 (wp . "word processing")
|
|
111 ))
|
|
112
|
|
113 (defvar finder-mode-map nil)
|
|
114 (or finder-mode-map
|
|
115 (let ((map (make-sparse-keymap)))
|
|
116 (define-key map " " 'finder-select)
|
|
117 (define-key map "f" 'finder-select)
|
|
118 (define-key map "\C-m" 'finder-select)
|
2
|
119 ;; XEmacs changes
|
0
|
120 (define-key map "e" 'finder-edit)
|
|
121 (define-key map "v" 'finder-view)
|
|
122 (define-key map "?" 'finder-summary)
|
|
123 (define-key map "q" 'finder-exit)
|
|
124 (define-key map "d" 'finder-list-keywords)
|
2
|
125 ;; XEmacs change
|
0
|
126 (define-key map [button2] 'finder-mouse-select)
|
|
127 (setq finder-mode-map map)))
|
|
128
|
|
129
|
|
130 ;;; Code for regenerating the keyword list.
|
|
131
|
|
132 (defvar finder-package-info nil
|
|
133 "Assoc list mapping file names to description & keyword lists.")
|
|
134
|
|
135 (defvar finder-compile-keywords-quiet nil
|
|
136 "If non-nil finder-compile-keywords will not print any messages.")
|
|
137
|
|
138 (defun finder-compile-keywords (&rest dirs)
|
|
139 "Regenerate the keywords association list into the file `finder-inf.el'.
|
|
140 Optional arguments are a list of Emacs Lisp directories to compile from; no
|
|
141 arguments compiles from `load-path'."
|
|
142 (save-excursion
|
2
|
143 ;; XEmacs change
|
0
|
144 (find-file "finder-inf.el")
|
|
145 (let ((processed nil)
|
|
146 (directory-abbrev-alist
|
|
147 (append
|
|
148 (mapcar (function (lambda (dir) (cons dir "")))
|
|
149 finder-abbreviate-directory-list)
|
|
150 directory-abbrev-alist))
|
|
151 (using-load-path))
|
|
152 (or dirs (setq dirs load-path))
|
|
153 (setq using-load-path (equal dirs load-path))
|
|
154 (erase-buffer)
|
|
155 (insert ";;; finder-inf.el --- keyword-to-package mapping\n")
|
|
156 (insert ";; Keywords: help\n")
|
|
157 (insert ";;; Commentary:\n")
|
|
158 (insert ";; Don't edit this file. It's generated by finder.el\n\n")
|
|
159 (insert ";;; Code:\n")
|
|
160 (insert "\n(setq finder-package-info '(\n")
|
|
161 (mapcar
|
|
162 (function
|
|
163 (lambda (d)
|
|
164 (mapcar
|
|
165 (function
|
|
166 (lambda (f)
|
|
167 (if (not (member f processed))
|
|
168 (let (summary keystart keywords)
|
|
169 (setq processed (cons f processed))
|
|
170 (if (not finder-compile-keywords-quiet)
|
|
171 (message "Processing %s ..." f))
|
|
172 (save-excursion
|
|
173 (set-buffer (get-buffer-create "*finder-scratch*"))
|
|
174 (buffer-disable-undo (current-buffer))
|
|
175 (erase-buffer)
|
|
176 (insert-file-contents (expand-file-name f d))
|
|
177 (setq summary (lm-synopsis)
|
|
178 keywords (lm-keywords)))
|
|
179 (if (not summary)
|
|
180 nil
|
|
181 (insert (format " (\"%s\"\n " f))
|
|
182 (prin1 summary (current-buffer))
|
|
183 (insert "\n ")
|
|
184 (setq keystart (point))
|
|
185 (insert (if keywords (format "(%s)" keywords) "nil"))
|
|
186 (subst-char-in-region keystart (point) ?, ? )
|
|
187 (insert "\n ")
|
|
188 (prin1 (abbreviate-file-name d) (current-buffer))
|
|
189 (insert ")\n"))))))
|
|
190 ;;
|
|
191 ;; Skip null, non-existent or relative pathnames, e.g. "./", if
|
|
192 ;; using load-path, so that they do not interfere with a scan of
|
|
193 ;; library directories only.
|
|
194 (if (and using-load-path
|
|
195 (not (and d (file-name-absolute-p d) (file-exists-p d))))
|
|
196 nil
|
|
197 (setq d (file-name-as-directory (or d ".")))
|
|
198 (directory-files d nil "^[^=].*\\.el$")))))
|
|
199 dirs)
|
|
200 (insert "))\n\n(provide 'finder-inf)\n\n;;; finder-inf.el ends here\n")
|
|
201 (kill-buffer "*finder-scratch*")
|
|
202 (eval-current-buffer) ;; So we get the new keyword list immediately
|
|
203 (basic-save-buffer))))
|
|
204
|
2
|
205 (defun finder-compile-keywords-make-dist ()
|
|
206 "Regenerate `finder-inf.el' for the Emacs distribution."
|
|
207 (finder-compile-keywords default-directory))
|
|
208
|
0
|
209 ;;; Now the retrieval code
|
|
210
|
2
|
211 (defun finder-insert-at-column (column &rest strings)
|
|
212 "Insert list of STRINGS, at column COLUMN."
|
16
|
213 (if (>= (current-column) column) (insert "\n"))
|
2
|
214 (move-to-column column)
|
|
215 (let ((col (current-column)))
|
|
216 (if (< col column)
|
|
217 (indent-to column)
|
|
218 (if (and (/= col column)
|
|
219 (= (preceding-char) ?\t))
|
|
220 (let (indent-tabs-mode)
|
|
221 (delete-char -1)
|
|
222 (indent-to col)
|
|
223 (move-to-column column)))))
|
|
224 (apply 'insert strings))
|
|
225
|
0
|
226 (defun finder-list-keywords ()
|
|
227 "Display descriptions of the keywords in the Finder buffer."
|
|
228 (interactive)
|
|
229 (setq buffer-read-only nil)
|
|
230 (erase-buffer)
|
|
231 (mapcar
|
2
|
232 (lambda (assoc)
|
|
233 (let ((keyword (car assoc)))
|
|
234 (insert (symbol-name keyword))
|
|
235 (finder-insert-at-column 14 (concat (cdr assoc) "\n"))
|
|
236 (cons (symbol-name keyword) keyword)))
|
0
|
237 finder-known-keywords)
|
|
238 (goto-char (point-min))
|
|
239 (setq finder-headmark (point))
|
|
240 (setq buffer-read-only t)
|
|
241 (set-buffer-modified-p nil)
|
2
|
242 ;; XEmacs change
|
0
|
243 (if (not (one-window-p))
|
|
244 (balance-windows))
|
|
245 (finder-summary))
|
|
246
|
|
247 (defun finder-list-matches (key)
|
|
248 (setq buffer-read-only nil)
|
|
249 (erase-buffer)
|
|
250 (let ((id (intern key)))
|
|
251 (insert
|
|
252 "The following packages match the keyword `" key "':\n\n")
|
|
253 (setq finder-headmark (point))
|
|
254 (mapcar
|
2
|
255 (lambda (x)
|
|
256 (if (memq id (car (cdr (cdr x))))
|
|
257 (progn
|
|
258 (insert (car x))
|
|
259 (finder-insert-at-column 16 (concat (car (cdr x)) "\n")))))
|
0
|
260 finder-package-info)
|
|
261 (goto-char (point-min))
|
|
262 (forward-line)
|
|
263 (setq buffer-read-only t)
|
|
264 (set-buffer-modified-p nil)
|
|
265 (shrink-window-if-larger-than-buffer)
|
|
266 (finder-summary)))
|
|
267
|
2
|
268 ;; Search for a file named FILE the same way `load' would search.
|
0
|
269 (defun finder-find-library (file)
|
|
270 (if (file-name-absolute-p file)
|
|
271 file
|
|
272 (let ((dirs load-path)
|
|
273 found)
|
|
274 (while (and dirs (not found))
|
|
275 (if (file-exists-p (expand-file-name (concat file ".el") (car dirs)))
|
|
276 (setq found (expand-file-name file (car dirs)))
|
|
277 (if (file-exists-p (expand-file-name file (car dirs)))
|
|
278 (setq found (expand-file-name file (car dirs)))))
|
|
279 (setq dirs (cdr dirs)))
|
|
280 found)))
|
|
281
|
|
282 (defun finder-commentary (file)
|
|
283 (interactive)
|
|
284 (let* ((str (lm-commentary (finder-find-library file))))
|
|
285 (if (null str)
|
|
286 (error "Can't find any Commentary section"))
|
|
287 (pop-to-buffer "*Finder*")
|
2
|
288 ;; XEmacs change
|
0
|
289 (setq buffer-read-only nil
|
|
290 mode-motion-hook 'mode-motion-highlight-line)
|
|
291 (erase-buffer)
|
|
292 (insert str)
|
|
293 (goto-char (point-min))
|
|
294 (delete-blank-lines)
|
|
295 (goto-char (point-max))
|
|
296 (delete-blank-lines)
|
|
297 (goto-char (point-min))
|
|
298 (while (re-search-forward "^;+ ?" nil t)
|
|
299 (replace-match "" nil nil))
|
|
300 (goto-char (point-min))
|
|
301 (setq buffer-read-only t)
|
|
302 (set-buffer-modified-p nil)
|
|
303 (shrink-window-if-larger-than-buffer)
|
2
|
304 (finder-summary)))
|
0
|
305
|
|
306 (defun finder-current-item ()
|
|
307 (if (and finder-headmark (< (point) finder-headmark))
|
|
308 (error "No keyword or filename on this line")
|
|
309 (save-excursion
|
|
310 (beginning-of-line)
|
|
311 (current-word))))
|
|
312
|
2
|
313 ;; XEmacs change
|
0
|
314 (defun finder-edit ()
|
|
315 (interactive)
|
|
316 (let ((entry (finder-current-item)))
|
|
317 (if (string-match finder-file-regexp entry)
|
|
318 (let ((path (finder-find-library entry)))
|
|
319 (if path
|
|
320 (find-file-other-window path)
|
|
321 (error "Can't find Emacs Lisp library: '%s'" entry)))
|
|
322 ;; a finder keyword
|
|
323 (error "Finder-edit works on Emacs Lisp libraries only"))))
|
|
324
|
2
|
325 ;; XEmacs change
|
0
|
326 (defun finder-view ()
|
|
327 (interactive)
|
|
328 (let ((entry (finder-current-item)))
|
|
329 (if (string-match finder-file-regexp entry)
|
|
330 (let ((path (finder-find-library entry)))
|
|
331 (if path
|
|
332 (view-file-other-window path)
|
|
333 (error "Can't find Emacs Lisp library: '%s'" entry)))
|
|
334 ;; a finder keyword
|
|
335 (error "Finder-view works on Emacs Lisp libraries only"))))
|
|
336
|
|
337 (defun finder-select ()
|
|
338 (interactive)
|
|
339 (let ((key (finder-current-item)))
|
2
|
340 ;; XEmacs change
|
0
|
341 (if (string-match finder-file-regexp key)
|
|
342 (finder-commentary key)
|
|
343 (finder-list-matches key))))
|
|
344
|
2
|
345 ;; XEmacs change
|
0
|
346 (defun finder-mouse-select (ev)
|
|
347 (interactive "e")
|
|
348 (goto-char (event-point ev))
|
|
349 (finder-select))
|
|
350
|
|
351 (defun finder-by-keyword ()
|
|
352 "Find packages matching a given keyword."
|
|
353 (interactive)
|
|
354 (finder-mode)
|
|
355 (finder-list-keywords))
|
|
356
|
|
357 (defun finder-mode ()
|
|
358 "Major mode for browsing package documentation.
|
|
359 \\<finder-mode-map>
|
|
360 \\[finder-select] more help for the item on the current line
|
|
361 \\[finder-edit] edit Lisp library in another window
|
|
362 \\[finder-view] view Lisp library in another window
|
|
363 \\[finder-exit] exit Finder mode and kill the Finder buffer.
|
|
364 "
|
|
365 (interactive)
|
|
366 (pop-to-buffer "*Finder*")
|
2
|
367 ;; XEmacs change
|
0
|
368 (setq buffer-read-only nil
|
|
369 mode-motion-hook 'mode-motion-highlight-line)
|
|
370 (erase-buffer)
|
|
371 (use-local-map finder-mode-map)
|
|
372 (set-syntax-table emacs-lisp-mode-syntax-table)
|
|
373 (setq mode-name "Finder")
|
|
374 (setq major-mode 'finder-mode)
|
|
375 (make-local-variable 'finder-headmark)
|
2
|
376 (setq finder-headmark nil))
|
0
|
377
|
|
378 (defun finder-summary ()
|
|
379 "Summarize basic Finder commands."
|
|
380 (interactive)
|
2
|
381 (message "%s"
|
0
|
382 (substitute-command-keys
|
2
|
383 ;; XEmacs change
|
0
|
384 "\\<finder-mode-map>\\[finder-select] = select, \\[finder-list-keywords] = keywords, \\[finder-edit] = edit, \\[finder-view] = view, \\[finder-exit] = quit, \\[finder-summary] = help")))
|
|
385
|
|
386 (defun finder-exit ()
|
|
387 "Exit Finder mode and kill the buffer"
|
|
388 (interactive)
|
2
|
389 ;; XEmacs change
|
0
|
390 (or (one-window-p t 0)
|
|
391 (delete-window))
|
|
392 (kill-buffer "*Finder*"))
|
|
393
|
|
394 (provide 'finder)
|
|
395
|
|
396 ;;; finder.el ends here
|