Mercurial > emacs
annotate lisp/finder.el @ 2502:190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
completing-read, instead of building an invalid obarray.
* finder.el (finder-by-keyword): If the user quits or enters the
empty string in response to the keyword prompt, restore the old
window configuration properly.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sat, 10 Apr 1993 06:20:55 +0000 |
parents | 3d2f74e16e54 |
children | 93015b63b041 |
rev | line source |
---|---|
867 | 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 | |
26 ;; Commentary: | |
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 '( | |
2270 | 46 (abbrev . "abbreviation handling, typing shortcuts, macros") |
867 | 47 (bib . "code related to the bib(1) bibliography processor") |
48 (c . "C and C++ language support") | |
49 (calendar . "calendar and time management support") | |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2228
diff
changeset
|
50 (comm . "communications, networking, remote access to files") |
867 | 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 | |
74 ;;; Code for regenerating the keyword list. | |
75 | |
76 (defvar finder-package-info nil | |
77 "Assoc list mapping file names to description & keyword lists.") | |
78 | |
79 (defun finder-compile-keywords (&rest dirs) | |
80 "Regenerate the keywords association list into the file finder-inf.el. | |
81 Optional arguments are a list of Emacs Lisp directories to compile from; no | |
1475 | 82 arguments compiles from `load-path'." |
867 | 83 (save-excursion |
2228
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
84 (let ((processed nil)) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
85 (find-file "finder-inf.el") |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
86 (erase-buffer) |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2228
diff
changeset
|
87 (insert ";;; finder-inf.el --- keyword-to-package mapping\n") |
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2228
diff
changeset
|
88 (insert ";; Keywords: help\n") |
2457
3d2f74e16e54
Added or corrected documentation headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2271
diff
changeset
|
89 (insert ";;; Commentary:\n") |
3d2f74e16e54
Added or corrected documentation headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2271
diff
changeset
|
90 (insert ";; Don't edit this file. It's generated by finder.el\n\n") |
3d2f74e16e54
Added or corrected documentation headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2271
diff
changeset
|
91 (insert ";;; Code:\n") |
2228
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
92 (insert "\n(setq finder-package-info '(\n") |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
93 (mapcar |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
94 (function |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
95 (lambda (d) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
96 (mapcar |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
97 (function |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
98 (lambda (f) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
99 (if (and (string-match "\\.el$" f) (not (member f processed))) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
100 (let (summary keystart) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
101 (setq processed (cons f processed)) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
102 (save-excursion |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
103 (set-buffer (get-buffer-create "*finder-scratch*")) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
104 (erase-buffer) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
105 (insert-file-contents |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
106 (concat (file-name-as-directory (or d ".")) f)) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
107 (setq summary (lm-synopsis)) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
108 (setq keywords (lm-keywords))) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
109 (insert |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
110 (format " (\"%s\"\n " f)) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
111 (prin1 summary (current-buffer)) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
112 (insert |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
113 "\n ") |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
114 (setq keystart (point)) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
115 (insert |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
116 (if keywords (format "(%s)" keywords) "nil") |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
117 ")\n") |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
118 (subst-char-in-region keystart (point) ?, ? ) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
119 ) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
120 ))) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
121 (directory-files (or d "."))) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
122 )) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
123 (or dirs load-path)) |
2457
3d2f74e16e54
Added or corrected documentation headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2271
diff
changeset
|
124 (insert "))\n\n(provide 'finder-inf)\n\n;;; finder-inf.el ends here\n") |
2228
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
125 (kill-buffer "*finder-scratch*") |
2271
026941de1886
Make sure that when new keywords are compiled, we see them
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2270
diff
changeset
|
126 (eval-current-buffer) ;; So we get the new keyword list immediately |
2228
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
127 (basic-save-buffer) |
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
128 ))) |
867 | 129 |
130 ;;; Now the retrieval code | |
131 | |
132 (defun finder-by-keyword () | |
133 "Find packages matching a given keyword." | |
134 (interactive) | |
2502
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
135 (set-buffer (get-buffer-create "*Help*")) |
867 | 136 (erase-buffer) |
2502
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
137 |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
138 ;; Display descriptions of the keywords in the help buffer, and |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
139 ;; build an assoc list mapping the names of known keywords to their |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
140 ;; symbols. |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
141 (let ((keyword-names |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
142 (mapcar (lambda (assoc) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
143 (let ((keyword (car assoc))) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
144 (insert (symbol-name keyword)) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
145 (insert-at-column 14 (cdr assoc) "\n") |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
146 (cons (symbol-name keyword) keyword))) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
147 finder-known-keywords))) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
148 (let ((key |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
149 (save-window-excursion |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
150 (pop-to-buffer "*Help*") |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
151 (goto-char (point-min)) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
152 (completing-read "Package keyword: " keyword-names nil t))) |
2228
d40154ca6354
(finder-compile-keywords) Treat nil in a path argument as $PWD.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1475
diff
changeset
|
153 id) |
2502
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
154 (or (equal key "") |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
155 (progn |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
156 (erase-buffer) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
157 (pop-to-buffer "*Help*") |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
158 (setq id (intern key)) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
159 (insert |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
160 "The following packages match the keyword `" key "':\n\n") |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
161 (mapcar |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
162 (function (lambda (x) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
163 (if (memq id (car (cdr (cdr x)))) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
164 (progn |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
165 (insert (car x)) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
166 (insert-at-column 16 (car (cdr x)) "\n") |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
167 )) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
168 )) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
169 finder-package-info) |
190371d9bc2e
* finder.el (finder-by-keyword): Build an alist to pass to
Jim Blandy <jimb@redhat.com>
parents:
2457
diff
changeset
|
170 (goto-char (point-min))))))) |
867 | 171 |
172 (provide 'finder) | |
173 | |
174 ;;; finder.el ends here |