Brent Benson's patch to support `cd -'.
[emacs.git] / lisp / finder.el
blob5be96e85b21ac5c4483a2185ed6b4c649373ccc4
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
7 ;; Version: 1.0
8 ;; Keywords: help
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)
15 ;; any later version.
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.
26 ;; Commentary:
28 ;; This mode uses the Keywords library header to provide code-finding
29 ;; services by keyword.
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.
38 ;;; Code:
40 (require 'lisp-mnt)
41 (require 'finder-inf)
42 (require 'picture)
44 (defvar finder-known-keywords
46 (abbrev . "abbreviation handling, typing shortcuts, macros")
47 (bib . "code related to the bib(1) bibliography processor")
48 (c . "C and C++ language support")
49 (calendar . "calendar and time management support")
50 (comm . "communications, networking, remote access to files")
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")
74 ;;; Code for regenerating the keyword list.
76 (defvar finder-package-info nil
77 "Assoc list mapping file names to description & keyword lists.")
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
82 arguments compiles from `load-path'."
83 (save-excursion
84 (let ((processed nil))
85 (find-file "finder-inf.el")
86 (erase-buffer)
87 (insert ";;; finder-inf.el --- keyword-to-package mapping\n")
88 (insert ";; Keywords: help\n")
89 (insert ";;; Don't edit this file. It's generated by finder.el\n\n")
90 (insert "\n(setq finder-package-info '(\n")
91 (mapcar
92 (function
93 (lambda (d)
94 (mapcar
95 (function
96 (lambda (f)
97 (if (and (string-match "\\.el$" f) (not (member f processed)))
98 (let (summary keystart)
99 (setq processed (cons f processed))
100 (save-excursion
101 (set-buffer (get-buffer-create "*finder-scratch*"))
102 (erase-buffer)
103 (insert-file-contents
104 (concat (file-name-as-directory (or d ".")) f))
105 (setq summary (lm-synopsis))
106 (setq keywords (lm-keywords)))
107 (insert
108 (format " (\"%s\"\n " f))
109 (prin1 summary (current-buffer))
110 (insert
111 "\n ")
112 (setq keystart (point))
113 (insert
114 (if keywords (format "(%s)" keywords) "nil")
115 ")\n")
116 (subst-char-in-region keystart (point) ?, ? )
119 (directory-files (or d ".")))
121 (or dirs load-path))
122 (insert "))\n\n(provide 'finder-inf)\n")
123 (kill-buffer "*finder-scratch*")
124 (eval-current-buffer) ;; So we get the new keyword list immediately
125 (basic-save-buffer)
128 ;;; Now the retrieval code
130 (defun finder-by-keyword ()
131 "Find packages matching a given keyword."
132 (interactive)
133 (pop-to-buffer "*Help*")
134 (erase-buffer)
135 (mapcar
136 (function (lambda (x)
137 (insert (symbol-name (car x)))
138 (insert-at-column 14 (cdr x) "\n")
140 finder-known-keywords)
141 (goto-char (point-min))
142 (let (key
143 (known (mapcar (function (lambda (x) (car x))) finder-known-keywords)))
144 (let ((key (completing-read
145 "Package keyword: "
146 (vconcat known)
147 (function (lambda (arg) (memq arg known)))
150 (erase-buffer)
151 (if (equal key "")
152 (delete-window (get-buffer-window "*Help*"))
153 (setq id (intern key))
154 (insert
155 "The following packages match the keyword `" key "':\n\n")
156 (mapcar
157 (function (lambda (x)
158 (if (memq id (car (cdr (cdr x))))
159 (progn
160 (insert (car x))
161 (insert-at-column 16 (car (cdr x)) "\n")
164 finder-package-info)
165 (goto-char (point-min))
166 ))))
168 (provide 'finder)
170 ;;; finder.el ends here