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 2, 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 .
"support for the C language and related languages")
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 (frames .
"support for Emacs frames and window systems")
60 (games .
"games, jokes and amusements")
61 (hardware .
"support for interfacing with exotic hardware")
62 (help .
"support for on-line help systems")
63 (hypermedia .
"support for links between text or other media types")
64 (i18n .
"internationalization and alternate character-set support")
65 (internal .
"code for Emacs internals, build process, defaults")
66 (languages .
"specialized modes for editing programming languages")
67 (lisp .
"Lisp support, including Emacs Lisp")
68 (local .
"code local to your site")
69 (maint .
"maintenance aids for the Emacs development group")
70 (mail .
"modes for electronic-mail handling")
71 (matching .
"various sorts of searching and matching")
72 (mouse .
"mouse support")
73 (news .
"support for netnews reading and posting")
74 (oop .
"support for object-oriented programming")
75 (outlines .
"support for hierarchical outlining")
76 (processes .
"process, subshell, compilation, and job control support")
77 (terminals .
"support for terminal types")
78 (tex .
"code related to the TeX formatter")
79 (tools .
"programming tools")
80 (unix .
"front-ends/assistants for, or emulators of, UNIX features")
81 (vms .
"support code for vms")
82 (wp .
"word processing")
85 (defvar finder-mode-map nil
)
87 (let ((map (make-sparse-keymap)))
88 (define-key map
" " 'finder-select
)
89 (define-key map
"f" 'finder-select
)
90 (define-key map
"\C-m" 'finder-select
)
91 (define-key map
"?" 'finder-summary
)
92 (define-key map
"q" 'finder-exit
)
93 (define-key map
"d" 'finder-list-keywords
)
94 (setq finder-mode-map map
)))
97 ;;; Code for regenerating the keyword list.
99 (defvar finder-package-info nil
100 "Assoc list mapping file names to description & keyword lists.")
102 (defun finder-compile-keywords (&rest dirs
)
103 "Regenerate the keywords association list into the file `finder-inf.el'.
104 Optional arguments are a list of Emacs Lisp directories to compile from; no
105 arguments compiles from `load-path'."
107 (let ((processed nil
))
108 (find-file "finder-inf.el")
110 (insert ";;; finder-inf.el --- keyword-to-package mapping\n")
111 (insert ";; Keywords: help\n")
112 (insert ";;; Commentary:\n")
113 (insert ";; Don't edit this file. It's generated by finder.el\n\n")
114 (insert ";;; Code:\n")
115 (insert "\n(setq finder-package-info '(\n")
122 (if (and (string-match "^[^=].*\\.el$" f
)
123 (not (member f processed
)))
124 (let (summary keystart keywords
)
125 (setq processed
(cons f processed
))
127 (set-buffer (get-buffer-create "*finder-scratch*"))
128 (buffer-disable-undo (current-buffer))
130 (insert-file-contents
131 (concat (file-name-as-directory (or d
".")) f
))
132 (setq summary
(lm-synopsis))
133 (setq keywords
(lm-keywords)))
135 (format " (\"%s\"\n " f
))
136 (prin1 summary
(current-buffer))
139 (setq keystart
(point))
141 (if keywords
(format "(%s)" keywords
) "nil")
143 (subst-char-in-region keystart
(point) ?
, ?
)
146 (directory-files (or d
".")))
149 (insert "))\n\n(provide 'finder-inf)\n\n;;; finder-inf.el ends here\n")
150 (kill-buffer "*finder-scratch*")
151 (eval-current-buffer) ;; So we get the new keyword list immediately
155 ;;; Now the retrieval code
157 (defun finder-list-keywords ()
158 "Display descriptions of the keywords in the Finder buffer."
160 (setq buffer-read-only nil
)
163 (function (lambda (assoc)
164 (let ((keyword (car assoc
)))
165 (insert (symbol-name keyword
))
166 (insert-at-column 14 (concat (cdr assoc
) "\n"))
167 (cons (symbol-name keyword
) keyword
))))
168 finder-known-keywords
)
169 (goto-char (point-min))
170 (setq finder-headmark
(point))
171 (setq buffer-read-only t
)
172 (set-buffer-modified-p nil
)
176 (defun finder-list-matches (key)
177 (setq buffer-read-only nil
)
179 (let ((id (intern key
)))
181 "The following packages match the keyword `" key
"':\n\n")
182 (setq finder-headmark
(point))
184 (function (lambda (x)
185 (if (memq id
(car (cdr (cdr x
))))
189 (concat (car (cdr x
)) "\n"))
193 (goto-char (point-min))
195 (setq buffer-read-only t
)
196 (set-buffer-modified-p nil
)
197 (shrink-window-if-larger-than-buffer)
200 ;; Search for a file named FILE the same way `load' would search.
201 (defun finder-find-library (file)
202 (if (file-name-absolute-p file
)
204 (let ((dirs load-path
)
206 (while (and dirs
(not found
))
207 (if (file-exists-p (expand-file-name (concat file
".el") (car dirs
)))
208 (setq found
(expand-file-name file
(car dirs
)))
209 (if (file-exists-p (expand-file-name file
(car dirs
)))
210 (setq found
(expand-file-name file
(car dirs
)))))
211 (setq dirs
(cdr dirs
)))
214 (defun finder-commentary (file)
216 (let* ((str (lm-commentary (finder-find-library file
))))
218 (error "Can't find any Commentary section"))
219 (pop-to-buffer "*Finder*")
220 (setq buffer-read-only nil
)
223 (goto-char (point-min))
225 (goto-char (point-max))
227 (goto-char (point-min))
228 (while (re-search-forward "^;+ ?" nil t
)
229 (replace-match "" nil nil
))
230 (goto-char (point-min))
231 (setq buffer-read-only t
)
232 (set-buffer-modified-p nil
)
233 (shrink-window-if-larger-than-buffer)
237 (defun finder-current-item ()
238 (if (and finder-headmark
(< (point) finder-headmark
))
239 (error "No keyword or filename on this line")
244 (defun finder-select ()
246 (let ((key (finder-current-item)))
247 (if (string-match "\\.el$" key
)
248 (finder-commentary key
)
249 (finder-list-matches key
))))
251 (defun finder-by-keyword ()
252 "Find packages matching a given keyword."
255 (finder-list-keywords))
257 (defun finder-mode ()
258 "Major mode for browsing package documentation.
260 \\[finder-select] more help for the item on the current line
261 \\[finder-exit] exit Finder mode and kill the Finder buffer.
264 (pop-to-buffer "*Finder*")
265 (setq buffer-read-only nil
)
267 (use-local-map finder-mode-map
)
268 (set-syntax-table emacs-lisp-mode-syntax-table
)
269 (setq mode-name
"Finder")
270 (setq major-mode
'finder-mode
)
271 (make-local-variable 'finder-headmark
)
272 (setq finder-headmark nil
)
275 (defun finder-summary ()
276 "Summarize basic Finder commands."
279 (substitute-command-keys
280 "\\<finder-mode-map>\\[finder-select] = select, \\[finder-list-keywords] = to finder directory, \\[finder-exit] = quit, \\[finder-summary] = help")))
282 (defun finder-exit ()
283 "Exit Finder mode and kill the buffer"
286 (kill-buffer "*Finder*"))
290 ;;; finder.el ends here