Commit | Line | Data |
---|---|---|
1164bae9 ER |
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 | ||
10 | ;; This file is part of GNU Emacs. | |
11 | ||
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) | |
15 | ;; any later version. | |
16 | ||
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. | |
21 | ||
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. | |
25 | ||
101dad14 | 26 | ;;; Commentary: |
1164bae9 ER |
27 | |
28 | ;; This mode uses the Keywords library header to provide code-finding | |
29 | ;; services by keyword. | |
30 | ;; | |
31 | ;; Things to do: | |
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. | |
37 | ||
38 | ;;; Code: | |
39 | ||
40 | (require 'lisp-mnt) | |
41 | (require 'finder-inf) | |
42 | (require 'picture) | |
43 | ||
44 | (defvar finder-known-keywords | |
45 | '( | |
dea24479 | 46 | (abbrev . "abbreviation handling, typing shortcuts, macros") |
1164bae9 ER |
47 | (bib . "code related to the bib(1) bibliography processor") |
48 | (c . "C and C++ language support") | |
49 | (calendar . "calendar and time management support") | |
e9571d2a | 50 | (comm . "communications, networking, remote access to files") |
1164bae9 ER |
51 | (docs . "support for Emacs documentation") |
52 | (emulations . "emulations of other editors") | |
53 | (extensions . "Emacs Lisp language extensions") | |
54 | (games . "games, jokes and amusements") | |
55 | (hardware . "support for interfacing with exotic hardware") | |
56 | (help . "support for on-line help systems") | |
57 | (i14n . "internationalization and alternate character-set support") | |
58 | (internal . "code for Emacs internals, build process, defaults") | |
59 | (languages . "specialized modes for editing programming languages") | |
60 | (lisp . "Lisp support, including Emacs Lisp") | |
61 | (local . "code local to your site") | |
62 | (maint . "maintenance aids for the Emacs development group") | |
63 | (mail . "modes for electronic-mail handling") | |
64 | (news . "support for netnews reading and posting") | |
65 | (processes . "process, subshell, compilation, and job control support") | |
66 | (terminals . "support for terminal types") | |
67 | (tex . "code related to the TeX formatter") | |
68 | (tools . "programming tools") | |
69 | (unix . "front-ends/assistants for, or emulators of, UNIX features") | |
70 | (vms . "support code for vms") | |
71 | (wp . "word processing") | |
72 | )) | |
73 | ||
101dad14 ER |
74 | (defvar finder-mode-map nil) |
75 | ;(if finder-mode-map | |
76 | ; nil | |
77 | (setq finder-mode-map (make-sparse-keymap)) | |
78 | (define-key finder-mode-map " " 'finder-select) | |
79 | (define-key finder-mode-map "?" 'finder-summary) | |
527da106 | 80 | (define-key finder-mode-map "q" 'finder-exit) |
101dad14 ER |
81 | (define-key finder-mode-map "f" 'finder-list-keywords) |
82 | ; ) | |
83 | ||
1164bae9 ER |
84 | ;;; Code for regenerating the keyword list. |
85 | ||
86 | (defvar finder-package-info nil | |
87 | "Assoc list mapping file names to description & keyword lists.") | |
88 | ||
89 | (defun finder-compile-keywords (&rest dirs) | |
90 | "Regenerate the keywords association list into the file finder-inf.el. | |
91 | Optional arguments are a list of Emacs Lisp directories to compile from; no | |
fe668515 | 92 | arguments compiles from `load-path'." |
1164bae9 | 93 | (save-excursion |
c5d87135 ER |
94 | (let ((processed nil)) |
95 | (find-file "finder-inf.el") | |
96 | (erase-buffer) | |
e9571d2a ER |
97 | (insert ";;; finder-inf.el --- keyword-to-package mapping\n") |
98 | (insert ";; Keywords: help\n") | |
0cbe967f ER |
99 | (insert ";;; Commentary:\n") |
100 | (insert ";; Don't edit this file. It's generated by finder.el\n\n") | |
101 | (insert ";;; Code:\n") | |
c5d87135 ER |
102 | (insert "\n(setq finder-package-info '(\n") |
103 | (mapcar | |
104 | (function | |
105 | (lambda (d) | |
106 | (mapcar | |
107 | (function | |
108 | (lambda (f) | |
109 | (if (and (string-match "\\.el$" f) (not (member f processed))) | |
110 | (let (summary keystart) | |
111 | (setq processed (cons f processed)) | |
112 | (save-excursion | |
113 | (set-buffer (get-buffer-create "*finder-scratch*")) | |
114 | (erase-buffer) | |
115 | (insert-file-contents | |
116 | (concat (file-name-as-directory (or d ".")) f)) | |
117 | (setq summary (lm-synopsis)) | |
118 | (setq keywords (lm-keywords))) | |
119 | (insert | |
120 | (format " (\"%s\"\n " f)) | |
121 | (prin1 summary (current-buffer)) | |
122 | (insert | |
123 | "\n ") | |
124 | (setq keystart (point)) | |
125 | (insert | |
126 | (if keywords (format "(%s)" keywords) "nil") | |
127 | ")\n") | |
128 | (subst-char-in-region keystart (point) ?, ? ) | |
129 | ) | |
130 | ))) | |
131 | (directory-files (or d "."))) | |
132 | )) | |
133 | (or dirs load-path)) | |
0cbe967f | 134 | (insert "))\n\n(provide 'finder-inf)\n\n;;; finder-inf.el ends here\n") |
c5d87135 | 135 | (kill-buffer "*finder-scratch*") |
3688bf22 | 136 | (eval-current-buffer) ;; So we get the new keyword list immediately |
c5d87135 ER |
137 | (basic-save-buffer) |
138 | ))) | |
1164bae9 ER |
139 | |
140 | ;;; Now the retrieval code | |
141 | ||
101dad14 ER |
142 | (defun finder-list-keywords () |
143 | "Display descriptions of the keywords in the Finder buffer." | |
144 | (interactive) | |
145 | (setq buffer-read-only nil) | |
146 | (erase-buffer) | |
147 | (mapcar | |
148 | (function (lambda (assoc) | |
149 | (let ((keyword (car assoc))) | |
150 | (insert (symbol-name keyword)) | |
151 | (insert-at-column 14 (concat (cdr assoc) "\n")) | |
152 | (cons (symbol-name keyword) keyword)))) | |
153 | finder-known-keywords) | |
154 | (goto-char (point-min)) | |
155 | (setq headmark (point)) | |
156 | (setq buffer-read-only t) | |
157 | (set-buffer-modified-p nil) | |
158 | (balance-windows) | |
159 | (finder-summary)) | |
160 | ||
161 | (defun finder-list-matches (key) | |
162 | (setq buffer-read-only nil) | |
163 | (erase-buffer) | |
164 | (let ((id (intern key))) | |
165 | (insert | |
166 | "The following packages match the keyword `" key "':\n\n") | |
167 | (setq headmark (point)) | |
168 | (mapcar | |
169 | (function (lambda (x) | |
170 | (if (memq id (car (cdr (cdr x)))) | |
171 | (progn | |
172 | (insert (car x)) | |
173 | (insert-at-column 16 | |
174 | (concat (car (cdr x)) "\n")) | |
175 | )) | |
176 | )) | |
177 | finder-package-info) | |
178 | (goto-char (point-min)) | |
179 | (forward-line) | |
180 | (setq buffer-read-only t) | |
181 | (set-buffer-modified-p nil) | |
182 | (shrink-window-if-larger-than-buffer) | |
183 | (finder-summary))) | |
184 | ||
185 | (defun finder-commentary (file) | |
186 | (interactive) | |
187 | (let* ((str (lm-commentary file))) | |
188 | (if (null str) | |
189 | (error "Can't find any Commentary section.")) | |
190 | (pop-to-buffer "*Finder*") | |
191 | (setq buffer-read-only nil) | |
192 | (erase-buffer) | |
193 | (insert str) | |
194 | (goto-char (point-min)) | |
195 | (delete-blank-lines) | |
196 | (goto-char (point-max)) | |
197 | (delete-blank-lines) | |
198 | (goto-char (point-min)) | |
199 | (while (re-search-forward "^;+ ?" nil t) | |
200 | (replace-match "" nil nil)) | |
201 | (goto-char (point-min)) | |
202 | (setq buffer-read-only t) | |
203 | (set-buffer-modified-p nil) | |
204 | (shrink-window-if-larger-than-buffer) | |
205 | (finder-summary) | |
206 | )) | |
207 | ||
208 | (defun finder-current-item () | |
209 | (if (and headmark (< (point) headmark)) | |
210 | (error "No keyword or filename on this line") | |
211 | (save-excursion | |
212 | (beginning-of-line) | |
213 | (current-word)))) | |
214 | ||
215 | (defun finder-select () | |
216 | (interactive) | |
217 | (let ((key (finder-current-item))) | |
218 | (if (string-match "\\.el$" key) | |
219 | (finder-commentary key) | |
220 | (finder-list-matches key)))) | |
221 | ||
1164bae9 ER |
222 | (defun finder-by-keyword () |
223 | "Find packages matching a given keyword." | |
224 | (interactive) | |
101dad14 ER |
225 | (finder-mode) |
226 | (finder-list-keywords)) | |
227 | ||
228 | (defun finder-mode () | |
229 | "Major mode for browsing package documentation. | |
527da106 | 230 | \\<finder-mode-map> |
101dad14 ER |
231 | \\[finder-select] more help for the item on the current line |
232 | \\[finder-exit] exit Finder mode and fill the Finder buffer. | |
233 | " | |
234 | (interactive) | |
235 | (pop-to-buffer "*Finder*") | |
236 | (setq buffer-read-only nil) | |
1164bae9 | 237 | (erase-buffer) |
101dad14 ER |
238 | (use-local-map finder-mode-map) |
239 | (set-syntax-table emacs-lisp-mode-syntax-table) | |
240 | (setq mode-name "Finder") | |
241 | (setq major-mode 'finder-mode) | |
242 | (make-local-variable 'headmark) | |
243 | (setq headmark nil) | |
244 | ) | |
245 | ||
246 | (defun finder-summary () | |
247 | "Summarize basic Finder commands." | |
248 | (interactive) | |
249 | (message | |
527da106 JB |
250 | (substitute-command-keys |
251 | "\\<finder-mode-map>\\[finder-select] = select, \\[finder-list-keywords] = back to finder, \\[finder-exit] = quit, \\[finder-summary] = help"))) | |
f5a16823 | 252 | |
101dad14 ER |
253 | (defun finder-exit () |
254 | "Exit Finder mode and kill the buffer" | |
255 | (interactive) | |
256 | (delete-window) | |
257 | (kill-buffer "*Finder*")) | |
1164bae9 ER |
258 | |
259 | (provide 'finder) | |
260 | ||
261 | ;;; finder.el ends here |