1 ;;; finder.el --- topic & keyword-based code finder
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Created: 16 Jun 1992
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 1, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 ;; This mode uses the Keywords library header to provide code-finding
29 ;; services by keyword.
32 ;; 1. Support multiple keywords per search. This could be extremely hairy;
33 ;; there doesn't seem to be any way to get completing-read to exit on
34 ;; an EOL with no substring pending, which is what we'd want to end the loop.
35 ;; 2. Search by string in synopsis line?
36 ;; 3. Function to check finder-package-info for unknown keywords.
44 ;; Local variable in finder buffer.
45 (defvar finder-headmark
)
47 (defvar finder-known-keywords
49 (abbrev .
"abbreviation handling, typing shortcuts, macros")
50 (bib .
"code related to the `bib' bibliography processor")
51 (c .
"C and C++ language support")
52 (calendar .
"calendar and time management support")
53 (comm .
"communications, networking, remote access to files")
54 (data .
"support editing files of data")
55 (docs .
"support for Emacs documentation")
56 (emulations .
"emulations of other editors")
57 (extensions .
"Emacs Lisp language extensions")
58 (faces .
"support for multiple fonts")
59 (games .
"games, jokes and amusements")
60 (hardware .
"support for interfacing with exotic hardware")
61 (help .
"support for on-line help systems")
62 (i18n .
"internationalization and alternate character-set support")
63 (internal .
"code for Emacs internals, build process, defaults")
64 (languages .
"specialized modes for editing programming languages")
65 (lisp .
"Lisp support, including Emacs Lisp")
66 (local .
"code local to your site")
67 (maint .
"maintenance aids for the Emacs development group")
68 (mail .
"modes for electronic-mail handling")
69 (matching .
"various sorts of searching and matching")
70 (mouse .
"mouse support")
71 (news .
"support for netnews reading and posting")
72 (processes .
"process, subshell, compilation, and job control support")
73 (terminals .
"support for terminal types")
74 (tex .
"code related to the TeX formatter")
75 (tools .
"programming tools")
76 (unix .
"front-ends/assistants for, or emulators of, UNIX features")
77 (vms .
"support code for vms")
78 (wp .
"word processing")
81 (defvar finder-mode-map nil
)
83 (let ((map (make-sparse-keymap)))
84 (define-key map
" " 'finder-select
)
85 (define-key map
"f" 'finder-select
)
86 (define-key map
"\C-m" 'finder-select
)
87 (define-key map
"?" 'finder-summary
)
88 (define-key map
"q" 'finder-exit
)
89 (define-key map
"d" 'finder-list-keywords
)
90 (setq finder-mode-map map
)))
93 ;;; Code for regenerating the keyword list.
95 (defvar finder-package-info nil
96 "Assoc list mapping file names to description & keyword lists.")
98 (defun finder-compile-keywords (&rest dirs
)
99 "Regenerate the keywords association list into the file `finder-inf.el'.
100 Optional arguments are a list of Emacs Lisp directories to compile from; no
101 arguments compiles from `load-path'."
103 (let ((processed nil
))
104 (find-file "finder-inf.el")
106 (insert ";;; finder-inf.el --- keyword-to-package mapping\n")
107 (insert ";; Keywords: help\n")
108 (insert ";;; Commentary:\n")
109 (insert ";; Don't edit this file. It's generated by finder.el\n\n")
110 (insert ";;; Code:\n")
111 (insert "\n(setq finder-package-info '(\n")
118 (if (and (string-match "^[^=].*\\.el$" f
)
119 (not (member f processed
)))
120 (let (summary keystart keywords
)
121 (setq processed
(cons f processed
))
123 (set-buffer (get-buffer-create "*finder-scratch*"))
124 (buffer-disable-undo (current-buffer))
126 (insert-file-contents
127 (concat (file-name-as-directory (or d
".")) f
))
128 (setq summary
(lm-synopsis))
129 (setq keywords
(lm-keywords)))
131 (format " (\"%s\"\n " f
))
132 (prin1 summary
(current-buffer))
135 (setq keystart
(point))
137 (if keywords
(format "(%s)" keywords
) "nil")
139 (subst-char-in-region keystart
(point) ?
, ?
)
142 (directory-files (or d
".")))
145 (insert "))\n\n(provide 'finder-inf)\n\n;;; finder-inf.el ends here\n")
146 (kill-buffer "*finder-scratch*")
147 (eval-current-buffer) ;; So we get the new keyword list immediately
151 ;;; Now the retrieval code
153 (defun finder-list-keywords ()
154 "Display descriptions of the keywords in the Finder buffer."
156 (setq buffer-read-only nil
)
159 (function (lambda (assoc)
160 (let ((keyword (car assoc
)))
161 (insert (symbol-name keyword
))
162 (insert-at-column 14 (concat (cdr assoc
) "\n"))
163 (cons (symbol-name keyword
) keyword
))))
164 finder-known-keywords
)
165 (goto-char (point-min))
166 (setq finder-headmark
(point))
167 (setq buffer-read-only t
)
168 (set-buffer-modified-p nil
)
172 (defun finder-list-matches (key)
173 (setq buffer-read-only nil
)
175 (let ((id (intern key
)))
177 "The following packages match the keyword `" key
"':\n\n")
178 (setq finder-headmark
(point))
180 (function (lambda (x)
181 (if (memq id
(car (cdr (cdr x
))))
185 (concat (car (cdr x
)) "\n"))
189 (goto-char (point-min))
191 (setq buffer-read-only t
)
192 (set-buffer-modified-p nil
)
193 (shrink-window-if-larger-than-buffer)
196 ;; Search for a file named FILE the same way `load' would search.
197 (defun finder-find-library (file)
198 (if (file-name-absolute-p file
)
200 (let ((dirs load-path
)
202 (while (and dirs
(not found
))
203 (if (file-exists-p (expand-file-name (concat file
".el") (car dirs
)))
204 (setq found
(expand-file-name file
(car dirs
)))
205 (if (file-exists-p (expand-file-name file
(car dirs
)))
206 (setq found
(expand-file-name file
(car dirs
)))))
207 (setq dirs
(cdr dirs
)))
210 (defun finder-commentary (file)
212 (let* ((str (lm-commentary (finder-find-library file
))))
214 (error "Can't find any Commentary section"))
215 (pop-to-buffer "*Finder*")
216 (setq buffer-read-only nil
)
219 (goto-char (point-min))
221 (goto-char (point-max))
223 (goto-char (point-min))
224 (while (re-search-forward "^;+ ?" nil t
)
225 (replace-match "" nil nil
))
226 (goto-char (point-min))
227 (setq buffer-read-only t
)
228 (set-buffer-modified-p nil
)
229 (shrink-window-if-larger-than-buffer)
233 (defun finder-current-item ()
234 (if (and finder-headmark
(< (point) finder-headmark
))
235 (error "No keyword or filename on this line")
240 (defun finder-select ()
242 (let ((key (finder-current-item)))
243 (if (string-match "\\.el$" key
)
244 (finder-commentary key
)
245 (finder-list-matches key
))))
247 (defun finder-by-keyword ()
248 "Find packages matching a given keyword."
251 (finder-list-keywords))
253 (defun finder-mode ()
254 "Major mode for browsing package documentation.
256 \\[finder-select] more help for the item on the current line
257 \\[finder-exit] exit Finder mode and kill the Finder buffer.
260 (pop-to-buffer "*Finder*")
261 (setq buffer-read-only nil
)
263 (use-local-map finder-mode-map
)
264 (set-syntax-table emacs-lisp-mode-syntax-table
)
265 (setq mode-name
"Finder")
266 (setq major-mode
'finder-mode
)
267 (make-local-variable 'finder-headmark
)
268 (setq finder-headmark nil
)
271 (defun finder-summary ()
272 "Summarize basic Finder commands."
275 (substitute-command-keys
276 "\\<finder-mode-map>\\[finder-select] = select, \\[finder-list-keywords] = to finder directory, \\[finder-exit] = quit, \\[finder-summary] = help")))
278 (defun finder-exit ()
279 "Exit Finder mode and kill the buffer"
282 (kill-buffer "*Finder*"))
286 ;;; finder.el ends here