Mercurial > hg > xemacs-beta
comparison lisp/finder.el @ 217:d44af0c54775 r20-4b7
Import from CVS: tag r20-4b7
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:08:34 +0200 |
parents | |
children | 41f2f0e326e9 |
comparison
equal
deleted
inserted
replaced
216:43306a74e31c | 217:d44af0c54775 |
---|---|
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 ;; X-Modified-by: Bob Weiner <weiner@mot.com>, 4/18/95, to include Lisp | |
10 ;; library directory names in finder-program-info, for fast display of | |
11 ;; Lisp libraries and associated commentaries. Added {v}, finder-view, | |
12 ;; and {e}, finder-edit commands for displaying libraries. | |
13 ;; | |
14 ;; Added user variable, 'finder-abbreviate-directory-list', used to | |
15 ;; abbreviate directories before they are saved to finder-program-info. | |
16 ;; Such relative directories can be portable from one Emacs installation | |
17 ;; to another. Default value is based upon the value of Emacs' | |
18 ;; data-directory variable. | |
19 | |
20 ;; This file is part of XEmacs. | |
21 | |
22 ;; XEmacs is free software; you can redistribute it and/or modify it | |
23 ;; under the terms of the GNU General Public License as published by | |
24 ;; the Free Software Foundation; either version 2, or (at your option) | |
25 ;; any later version. | |
26 | |
27 ;; XEmacs is distributed in the hope that it will be useful, but | |
28 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
29 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
30 ;; General Public License for more details. | |
31 | |
32 ;; You should have received a copy of the GNU General Public License | |
33 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
34 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
35 ;; 02111-1307, USA. | |
36 | |
37 ;;; Synched up with: FSF 19.34. | |
38 | |
39 ;;; Commentary: | |
40 | |
41 ;; This mode uses the Keywords library header to provide code-finding | |
42 ;; services by keyword. | |
43 ;; | |
44 ;; Things to do: | |
45 ;; 1. Support multiple keywords per search. This could be extremely hairy; | |
46 ;; there doesn't seem to be any way to get completing-read to exit on | |
47 ;; an EOL with no substring pending, which is what we'd want to end the loop. | |
48 ;; 2. Search by string in synopsis line? | |
49 ;; 3. Function to check finder-package-info for unknown keywords. | |
50 | |
51 ;;; Code: | |
52 | |
53 (require 'lisp-mnt) | |
54 (condition-case nil | |
55 (require 'finder-inf) | |
56 (t nil)) | |
57 ;; XEmacs addition | |
58 (require 'picture) | |
59 (require 'mode-motion) | |
60 | |
61 (defvar finder-emacs-root-directory | |
62 (file-name-directory (directory-file-name data-directory)) | |
63 "Root directory of current emacs tree.") | |
64 | |
65 (defvar finder-abbreviate-directory-list | |
66 (list finder-emacs-root-directory) | |
67 "*List of directory roots to remove from finder-package-info directory entries. | |
68 The first element in the list is used when expanding relative package | |
69 directories to view or extract information from package source code.") | |
70 | |
71 (defvar finder-file-regexp "\\.el$" | |
72 "Regexp which matches file names but not Emacs Lisp finder keywords.") | |
73 | |
74 ;; Local variable in finder buffer. | |
75 (defvar finder-headmark) | |
76 | |
77 (defvar finder-known-keywords | |
78 `( | |
79 (abbrev . "abbreviation handling, typing shortcuts, macros") | |
80 (bib . "code related to the `bib' bibliography processor") | |
81 (c . "C, C++, and Objective-C language support") | |
82 (calendar . "calendar and time management support") | |
83 (comm . "communications, networking, remote access to files") | |
84 (data . "support for editing files of data") | |
85 (docs . "support for Emacs documentation") | |
86 (dumped . "files preloaded into Emacs") | |
87 (emulations . "emulations of other editors") | |
88 (extensions . "Emacs Lisp language extensions") | |
89 (faces . "support for multiple fonts") | |
90 (frames . "support for Emacs frames and window systems") | |
91 (games . "games, jokes and amusements") | |
92 (hardware . "support for interfacing with exotic hardware") | |
93 (help . "support for on-line help systems") | |
94 (hypermedia . "support for links between text or other media types") | |
95 (i18n . "internationalization and alternate character-set support") | |
96 (internal . "code for Emacs internals, build process, defaults") | |
97 (languages . "specialized modes for editing programming languages") | |
98 (lisp . "Lisp support, including Emacs Lisp") | |
99 (local . "code local to your site") | |
100 (maint . "maintenance aids for the Emacs development group") | |
101 (mail . "modes for electronic-mail handling") | |
102 (matching . "various sorts of searching and matching") | |
103 (mouse . "mouse support") | |
104 ,(when (featurep 'mule) | |
105 (cons 'mule "multi-language extensions")) | |
106 (news . "support for netnews reading and posting") | |
107 (oop . "support for object-oriented programming") | |
108 (outlines . "support for hierarchical outlining") | |
109 (processes . "process, subshell, compilation, and job control support") | |
110 (terminals . "support for terminal types") | |
111 (tex . "code related to the TeX formatter") | |
112 (tools . "programming tools") | |
113 (unix . "front-ends/assistants for, or emulators of, UNIX features") | |
114 (vms . "support code for vms") | |
115 (wp . "word processing") | |
116 )) | |
117 | |
118 (defvar finder-mode-map nil) | |
119 (or finder-mode-map | |
120 (let ((map (make-sparse-keymap))) | |
121 (define-key map " " 'finder-select) | |
122 (define-key map "f" 'finder-select) | |
123 (define-key map "\C-m" 'finder-select) | |
124 ;; XEmacs changes | |
125 (define-key map "e" 'finder-edit) | |
126 (define-key map "v" 'finder-view) | |
127 (define-key map "?" 'finder-summary) | |
128 (define-key map "q" 'finder-exit) | |
129 (define-key map "d" 'finder-list-keywords) | |
130 ;; XEmacs change | |
131 (define-key map [button2] 'finder-mouse-select) | |
132 (setq finder-mode-map map))) | |
133 | |
134 | |
135 ;;; Code for regenerating the keyword list. | |
136 | |
137 (defvar finder-package-info nil | |
138 "Assoc list mapping file names to description & keyword lists.") | |
139 | |
140 (defvar finder-compile-keywords-quiet nil | |
141 "If non-nil finder-compile-keywords will not print any messages.") | |
142 | |
143 (defun finder-compile-keywords (&rest dirs) | |
144 "Regenerate the keywords association list into the file `finder-inf.el'. | |
145 Optional arguments are a list of Emacs Lisp directories to compile from; no | |
146 arguments compiles from `load-path'." | |
147 (save-excursion | |
148 ;; XEmacs change | |
149 (find-file "finder-inf.el") | |
150 (let ((processed nil) | |
151 (directory-abbrev-alist | |
152 (append | |
153 (mapcar (function (lambda (dir) (cons dir ""))) | |
154 finder-abbreviate-directory-list) | |
155 directory-abbrev-alist)) | |
156 (using-load-path)) | |
157 (or dirs (setq dirs load-path)) | |
158 (setq using-load-path (equal dirs load-path)) | |
159 (erase-buffer) | |
160 (insert ";;; finder-inf.el --- keyword-to-package mapping\n") | |
161 (insert ";; Keywords: help\n") | |
162 (insert ";;; Commentary:\n") | |
163 (insert ";; Don't edit this file. It's generated by finder.el\n\n") | |
164 (insert ";;; Code:\n") | |
165 (insert "\n(setq finder-package-info '(\n") | |
166 (mapcar | |
167 (function | |
168 (lambda (d) | |
169 (mapcar | |
170 (function | |
171 (lambda (f) | |
172 (if (not (member f processed)) | |
173 (let (summary keystart keywords) | |
174 (setq processed (cons f processed)) | |
175 (if (not finder-compile-keywords-quiet) | |
176 (message "Processing %s ..." f)) | |
177 (save-excursion | |
178 (set-buffer (get-buffer-create "*finder-scratch*")) | |
179 (buffer-disable-undo (current-buffer)) | |
180 (erase-buffer) | |
181 (insert-file-contents (expand-file-name f d)) | |
182 (setq summary (lm-synopsis) | |
183 keywords (lm-keywords))) | |
184 (if (not summary) | |
185 nil | |
186 (insert (format " (\"%s\"\n " f)) | |
187 (prin1 summary (current-buffer)) | |
188 (insert "\n ") | |
189 (setq keystart (point)) | |
190 (insert (if keywords (format "(%s)" keywords) "nil")) | |
191 (subst-char-in-region keystart (point) ?, ? ) | |
192 (insert "\n ") | |
193 (prin1 (abbreviate-file-name d) (current-buffer)) | |
194 (insert ")\n")))))) | |
195 ;; | |
196 ;; Skip null, non-existent or relative pathnames, e.g. "./", if | |
197 ;; using load-path, so that they do not interfere with a scan of | |
198 ;; library directories only. | |
199 (if (and using-load-path | |
200 (not (and d (file-name-absolute-p d) (file-exists-p d)))) | |
201 nil | |
202 (setq d (file-name-as-directory (or d "."))) | |
203 (directory-files d nil "^[^=].*\\.el$"))))) | |
204 dirs) | |
205 (insert "))\n\n(provide 'finder-inf)\n\n;;; finder-inf.el ends here\n") | |
206 (kill-buffer "*finder-scratch*") | |
207 (eval-current-buffer) ;; So we get the new keyword list immediately | |
208 (basic-save-buffer)))) | |
209 | |
210 (defun finder-compile-keywords-make-dist () | |
211 "Regenerate `finder-inf.el' for the Emacs distribution." | |
212 (finder-compile-keywords default-directory)) | |
213 | |
214 ;;; Now the retrieval code | |
215 | |
216 (defun finder-insert-at-column (column &rest strings) | |
217 "Insert list of STRINGS, at column COLUMN." | |
218 (if (>= (current-column) column) (insert "\n")) | |
219 (move-to-column column) | |
220 (let ((col (current-column))) | |
221 (if (< col column) | |
222 (indent-to column) | |
223 (if (and (/= col column) | |
224 (= (preceding-char) ?\t)) | |
225 (let (indent-tabs-mode) | |
226 (delete-char -1) | |
227 (indent-to col) | |
228 (move-to-column column))))) | |
229 (apply 'insert strings)) | |
230 | |
231 (defun finder-list-keywords () | |
232 "Display descriptions of the keywords in the Finder buffer." | |
233 (interactive) | |
234 (setq buffer-read-only nil) | |
235 (erase-buffer) | |
236 (mapcar | |
237 (lambda (assoc) | |
238 (let ((keyword (car assoc))) | |
239 (insert (symbol-name keyword)) | |
240 (finder-insert-at-column 14 (concat (cdr assoc) "\n")) | |
241 (cons (symbol-name keyword) keyword))) | |
242 finder-known-keywords) | |
243 (goto-char (point-min)) | |
244 (setq finder-headmark (point)) | |
245 (setq buffer-read-only t) | |
246 (set-buffer-modified-p nil) | |
247 ;; XEmacs change | |
248 (if (not (one-window-p)) | |
249 (balance-windows)) | |
250 (finder-summary)) | |
251 | |
252 (defun finder-list-matches (key) | |
253 (setq buffer-read-only nil) | |
254 (erase-buffer) | |
255 (let ((id (intern key))) | |
256 (insert | |
257 "The following packages match the keyword `" key "':\n\n") | |
258 (setq finder-headmark (point)) | |
259 (mapcar | |
260 (lambda (x) | |
261 (if (memq id (car (cdr (cdr x)))) | |
262 (progn | |
263 (insert (car x)) | |
264 (finder-insert-at-column 16 (concat (car (cdr x)) "\n"))))) | |
265 finder-package-info) | |
266 (goto-char (point-min)) | |
267 (forward-line) | |
268 (setq buffer-read-only t) | |
269 (set-buffer-modified-p nil) | |
270 (shrink-window-if-larger-than-buffer) | |
271 (finder-summary))) | |
272 | |
273 ;; Search for a file named FILE the same way `load' would search. | |
274 (defun finder-find-library (file) | |
275 (if (file-name-absolute-p file) | |
276 file | |
277 (let ((dirs load-path) | |
278 found) | |
279 (while (and dirs (not found)) | |
280 (if (file-exists-p (expand-file-name (concat file ".el") (car dirs))) | |
281 (setq found (expand-file-name file (car dirs))) | |
282 (if (file-exists-p (expand-file-name file (car dirs))) | |
283 (setq found (expand-file-name file (car dirs))))) | |
284 (setq dirs (cdr dirs))) | |
285 found))) | |
286 | |
287 (defun finder-commentary (file) | |
288 (interactive) | |
289 (let* ((str (lm-commentary (finder-find-library file)))) | |
290 (if (null str) | |
291 (error "Can't find any Commentary section")) | |
292 (pop-to-buffer "*Finder*") | |
293 ;; XEmacs change | |
294 (setq buffer-read-only nil | |
295 mode-motion-hook 'mode-motion-highlight-line) | |
296 (erase-buffer) | |
297 (insert str) | |
298 (goto-char (point-min)) | |
299 (delete-blank-lines) | |
300 (goto-char (point-max)) | |
301 (delete-blank-lines) | |
302 (goto-char (point-min)) | |
303 (while (re-search-forward "^;+ ?" nil t) | |
304 (replace-match "" nil nil)) | |
305 (goto-char (point-min)) | |
306 (setq buffer-read-only t) | |
307 (set-buffer-modified-p nil) | |
308 (shrink-window-if-larger-than-buffer) | |
309 (finder-summary))) | |
310 | |
311 (defun finder-current-item () | |
312 (if (and finder-headmark (< (point) finder-headmark)) | |
313 (error "No keyword or filename on this line") | |
314 (save-excursion | |
315 (beginning-of-line) | |
316 (current-word)))) | |
317 | |
318 ;; XEmacs change | |
319 (defun finder-edit () | |
320 (interactive) | |
321 (let ((entry (finder-current-item))) | |
322 (if (string-match finder-file-regexp entry) | |
323 (let ((path (finder-find-library entry))) | |
324 (if path | |
325 (find-file-other-window path) | |
326 (error "Can't find Emacs Lisp library: '%s'" entry))) | |
327 ;; a finder keyword | |
328 (error "Finder-edit works on Emacs Lisp libraries only")))) | |
329 | |
330 ;; XEmacs change | |
331 (defun finder-view () | |
332 (interactive) | |
333 (let ((entry (finder-current-item))) | |
334 (if (string-match finder-file-regexp entry) | |
335 (let ((path (finder-find-library entry))) | |
336 (if path | |
337 (view-file-other-window path) | |
338 (error "Can't find Emacs Lisp library: '%s'" entry))) | |
339 ;; a finder keyword | |
340 (error "Finder-view works on Emacs Lisp libraries only")))) | |
341 | |
342 (defun finder-select () | |
343 (interactive) | |
344 (let ((key (finder-current-item))) | |
345 ;; XEmacs change | |
346 (if (string-match finder-file-regexp key) | |
347 (finder-commentary key) | |
348 (finder-list-matches key)))) | |
349 | |
350 ;; XEmacs change | |
351 (defun finder-mouse-select (ev) | |
352 (interactive "e") | |
353 (goto-char (event-point ev)) | |
354 (finder-select)) | |
355 | |
356 (defun finder-by-keyword () | |
357 "Find packages matching a given keyword." | |
358 (interactive) | |
359 (finder-mode) | |
360 (finder-list-keywords)) | |
361 | |
362 (defun finder-mode () | |
363 "Major mode for browsing package documentation. | |
364 \\<finder-mode-map> | |
365 \\[finder-select] more help for the item on the current line | |
366 \\[finder-edit] edit Lisp library in another window | |
367 \\[finder-view] view Lisp library in another window | |
368 \\[finder-exit] exit Finder mode and kill the Finder buffer. | |
369 " | |
370 (interactive) | |
371 (pop-to-buffer "*Finder*") | |
372 ;; XEmacs change | |
373 (setq buffer-read-only nil | |
374 mode-motion-hook 'mode-motion-highlight-line) | |
375 (erase-buffer) | |
376 (use-local-map finder-mode-map) | |
377 (set-syntax-table emacs-lisp-mode-syntax-table) | |
378 (setq mode-name "Finder") | |
379 (setq major-mode 'finder-mode) | |
380 (make-local-variable 'finder-headmark) | |
381 (setq finder-headmark nil)) | |
382 | |
383 (defun finder-summary () | |
384 "Summarize basic Finder commands." | |
385 (interactive) | |
386 (message "%s" | |
387 (substitute-command-keys | |
388 ;; XEmacs change | |
389 "\\<finder-mode-map>\\[finder-select] = select, \\[finder-list-keywords] = keywords, \\[finder-edit] = edit, \\[finder-view] = view, \\[finder-exit] = quit, \\[finder-summary] = help"))) | |
390 | |
391 (defun finder-exit () | |
392 "Exit Finder mode and kill the buffer" | |
393 (interactive) | |
394 ;; XEmacs change | |
395 (or (one-window-p t 0) | |
396 (delete-window)) | |
397 (kill-buffer "*Finder*")) | |
398 | |
399 (provide 'finder) | |
400 | |
401 ;;; finder.el ends here |