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