]> code.delx.au - gnu-emacs/blob - lisp/help.el
(dired-permission-flags-regexp): New variable.
[gnu-emacs] / lisp / help.el
1 ;;; help.el --- help commands for Emacs
2
3 ;; Copyright (C) 1985, 1986, 1993, 1994 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: help, internal
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; This code implements GNU Emacs' on-line help system, the one invoked by
28 ;;`M-x help-for-help'.
29
30 ;;; Code:
31
32 ;; Get the macro make-help-screen when this is compiled,
33 ;; or run interpreted, but not when the compiled code is loaded.
34 (eval-when-compile (require 'help-macro))
35
36 (defvar help-map (make-sparse-keymap)
37 "Keymap for characters following the Help key.")
38
39 (defvar help-mode-map (make-sparse-keymap)
40 "Keymap for help mode.")
41
42 (define-key global-map (char-to-string help-char) 'help-command)
43 (define-key global-map [help] 'help-command)
44 (define-key global-map [f1] 'help-command)
45 (fset 'help-command help-map)
46
47 (define-key help-map (char-to-string help-char) 'help-for-help)
48 (define-key help-map [help] 'help-for-help)
49 (define-key help-map [f1] 'help-for-help)
50 (define-key help-map "?" 'help-for-help)
51
52 (define-key help-map "\C-c" 'describe-copying)
53 (define-key help-map "\C-d" 'describe-distribution)
54 (define-key help-map "\C-w" 'describe-no-warranty)
55 (define-key help-map "\C-p" 'describe-project)
56 (define-key help-map "a" 'command-apropos)
57
58 (define-key help-map "b" 'describe-bindings)
59
60 (define-key help-map "c" 'describe-key-briefly)
61 (define-key help-map "k" 'describe-key)
62
63 (define-key help-map "d" 'describe-function)
64 (define-key help-map "f" 'describe-function)
65
66 (define-key help-map "F" 'view-emacs-FAQ)
67
68 (define-key help-map "i" 'info)
69 (define-key help-map "\C-f" 'Info-goto-emacs-command-node)
70 (define-key help-map "\C-k" 'Info-goto-emacs-key-command-node)
71 (define-key help-map "\C-i" 'word-help)
72
73 (define-key help-map "l" 'view-lossage)
74
75 (define-key help-map "m" 'describe-mode)
76
77 (define-key help-map "\C-n" 'view-emacs-news)
78 (define-key help-map "n" 'view-emacs-news)
79
80 (define-key help-map "p" 'finder-by-keyword)
81 (autoload 'finder-by-keyword "finder"
82 "Find packages matching a given keyword." t)
83
84 (define-key help-map "s" 'describe-syntax)
85
86 (define-key help-map "t" 'help-with-tutorial)
87
88 (define-key help-map "w" 'where-is)
89
90 (define-key help-map "v" 'describe-variable)
91
92 (define-key help-map "q" 'help-quit)
93
94 (defvar help-font-lock-keywords
95 (eval-when-compile
96 (let ((name-char "[-+a-zA-Z0-9_*]") (sym-char "[-+a-zA-Z0-9_:*]"))
97 (list
98 ;;
99 ;; The symbol itself.
100 (list (concat "\\`\\(" name-char "+\\)\\(\\(:\\)\\|\\('\\)\\)")
101 '(1 (if (match-beginning 3)
102 font-lock-function-name-face
103 font-lock-variable-name-face)))
104 ;;
105 ;; Words inside `' which tend to be symbol names.
106 (list (concat "`\\(" sym-char sym-char "+\\)'")
107 1 'font-lock-reference-face t)
108 ;;
109 ;; CLisp `:' keywords as references.
110 (list (concat "\\<:" sym-char "+\\>") 0 'font-lock-reference-face t))))
111 "Default expressions to highlight in Help mode.")
112
113 (defun help-mode ()
114 "Major mode for viewing help text.
115 Entry to this mode runs the normal hook `help-mode-hook'.
116 Commands:
117 \\{help-mode-map}"
118 (interactive)
119 (kill-all-local-variables)
120 (use-local-map help-mode-map)
121 (setq mode-name "Help")
122 (setq major-mode 'help-mode)
123 (make-local-variable 'font-lock-defaults)
124 (setq font-lock-defaults '(help-font-lock-keywords))
125 (view-mode)
126 (run-hooks 'help-mode-hook))
127
128 (defun help-quit ()
129 (interactive)
130 nil)
131
132 (defun help-with-tutorial ()
133 "Select the Emacs learn-by-doing tutorial."
134 (interactive)
135 (let ((file (expand-file-name "~/TUTORIAL")))
136 (delete-other-windows)
137 (if (get-file-buffer file)
138 (switch-to-buffer (get-file-buffer file))
139 (switch-to-buffer (create-file-buffer file))
140 (setq buffer-file-name file)
141 (setq default-directory (expand-file-name "~/"))
142 (setq buffer-auto-save-file-name nil)
143 (insert-file-contents (expand-file-name "TUTORIAL" data-directory))
144 (goto-char (point-min))
145 (search-forward "\n<<")
146 (beginning-of-line)
147 (delete-region (point) (progn (end-of-line) (point)))
148 (let ((n (- (window-height (selected-window))
149 (count-lines (point-min) (point))
150 6)))
151 (if (< n 12)
152 (newline n)
153 ;; Some people get confused by the large gap.
154 (newline (/ n 2))
155 (insert "[Middle of page left blank for didactic purposes. "
156 "Text continues below]")
157 (newline (- n (/ n 2)))))
158 (goto-char (point-min))
159 (set-buffer-modified-p nil))))
160
161 (defun describe-key-briefly (key)
162 "Print the name of the function KEY invokes. KEY is a string."
163 (interactive "kDescribe key briefly: ")
164 ;; If this key seq ends with a down event, discard the
165 ;; following click or drag event. Otherwise that would
166 ;; erase the message.
167 (let ((type (aref key (1- (length key)))))
168 (if (listp type) (setq type (car type)))
169 (and (symbolp type)
170 (memq 'down (event-modifiers type))
171 (read-event)))
172 (save-excursion
173 (let ((modifiers (event-modifiers (aref key 0)))
174 window position)
175 ;; For a mouse button event, go to the button it applies to
176 ;; to get the right key bindings. And go to the right place
177 ;; in case the keymap depends on where you clicked.
178 (if (or (memq 'click modifiers) (memq 'down modifiers)
179 (memq 'drag modifiers))
180 (setq window (posn-window (event-start (aref key 0)))
181 position (posn-point (event-start (aref key 0)))))
182 (if (windowp window)
183 (progn
184 (set-buffer (window-buffer window))
185 (goto-char position)))
186 ;; Ok, now look up the key and name the command.
187 (let ((defn (key-binding key)))
188 (if (or (null defn) (integerp defn))
189 (message "%s is undefined" (key-description key))
190 (message (if (windowp window)
191 "%s at that spot runs the command %s"
192 "%s runs the command %s")
193 (key-description key)
194 (if (symbolp defn) defn (prin1-to-string defn))))))))
195
196 (defun print-help-return-message (&optional function)
197 "Display or return message saying how to restore windows after help command.
198 Computes a message and applies the optional argument FUNCTION to it.
199 If FUNCTION is nil, applies `message' to it, thus printing it."
200 (and (not (get-buffer-window standard-output))
201 (let ((first-message
202 (cond ((special-display-p (buffer-name standard-output))
203 ;; If the help output buffer is a special display buffer,
204 ;; don't say anything about how to get rid of it.
205 ;; First of all, the user will do that with the window
206 ;; manager, not with Emacs.
207 ;; Secondly, the buffer has not been displayed yet,
208 ;; so we don't know whether its frame will be selected.
209 nil)
210 ((not (one-window-p t))
211 "Type \\[switch-to-buffer-other-window] RET to restore the other window.")
212 (pop-up-windows
213 "Type \\[delete-other-windows] to remove help window.")
214 (t
215 "Type \\[switch-to-buffer] RET to remove help window."))))
216 (funcall (or function 'message)
217 (concat
218 (if first-message
219 (substitute-command-keys first-message)
220 "")
221 (if first-message " " "")
222 ;; If the help buffer will go in a separate frame,
223 ;; it's no use mentioning a command to scroll, so don't.
224 (if (special-display-p (buffer-name standard-output))
225 nil
226 (if (same-window-p (buffer-name standard-output))
227 ;; Say how to scroll this window.
228 (substitute-command-keys
229 "\\[scroll-up] to scroll the help.")
230 ;; Say how to scroll some other window.
231 (substitute-command-keys
232 "\\[scroll-other-window] to scroll the help."))))))))
233
234 (defun describe-key (key)
235 "Display documentation of the function invoked by KEY. KEY is a string."
236 (interactive "kDescribe key: ")
237 ;; If this key seq ends with a down event, discard the
238 ;; following click or drag event. Otherwise that would
239 ;; erase the message.
240 (let ((type (aref key (1- (length key)))))
241 (if (listp type) (setq type (car type)))
242 (and (symbolp type)
243 (memq 'down (event-modifiers type))
244 (read-event)))
245 (save-excursion
246 (let ((modifiers (event-modifiers (aref key 0)))
247 window position)
248 ;; For a mouse button event, go to the button it applies to
249 ;; to get the right key bindings. And go to the right place
250 ;; in case the keymap depends on where you clicked.
251 (if (or (memq 'click modifiers) (memq 'down modifiers)
252 (memq 'drag modifiers))
253 (setq window (posn-window (event-start (aref key 0)))
254 position (posn-point (event-start (aref key 0)))))
255 (if (windowp window)
256 (progn
257 (set-buffer (window-buffer window))
258 (goto-char position)))
259 (let ((defn (key-binding key)))
260 (if (or (null defn) (integerp defn))
261 (message "%s is undefined" (key-description key))
262 (with-output-to-temp-buffer "*Help*"
263 (princ (key-description key))
264 (if (windowp window)
265 (princ " at that spot"))
266 (princ " runs the command ")
267 (prin1 defn)
268 (princ ":\n")
269 (let ((doc (documentation defn)))
270 (if doc
271 (progn (terpri)
272 (princ doc))
273 (princ "not documented")))
274 (save-excursion
275 (set-buffer standard-output)
276 (help-mode))
277 (print-help-return-message)))))))
278
279 (defun describe-mode ()
280 "Display documentation of current major mode and minor modes.
281 For this to work correctly for a minor mode, the mode's indicator variable
282 \(listed in `minor-mode-alist') must also be a function whose documentation
283 describes the minor mode."
284 (interactive)
285 (with-output-to-temp-buffer "*Help*"
286 (let ((minor-modes minor-mode-alist)
287 (first t))
288 (while minor-modes
289 (let* ((minor-mode (car (car minor-modes)))
290 (indicator (car (cdr (car minor-modes)))))
291 ;; Document a minor mode if it is listed in minor-mode-alist,
292 ;; bound locally in this buffer, non-nil, and has a function
293 ;; definition.
294 (if (and (symbol-value minor-mode)
295 (fboundp minor-mode))
296 (let ((pretty-minor-mode minor-mode))
297 (if (string-match "-mode$" (symbol-name minor-mode))
298 (setq pretty-minor-mode
299 (capitalize
300 (substring (symbol-name minor-mode)
301 0 (match-beginning 0)))))
302 (while (and indicator (symbolp indicator))
303 (setq indicator (symbol-value indicator)))
304 (if first
305 (princ "The minor modes are described first,
306 followed by the major mode, which is described on the last page.\n\f\n"))
307 (setq first nil)
308 (princ (format "%s minor mode (%s):\n"
309 pretty-minor-mode
310 (if indicator
311 (format "indicator%s" indicator)
312 "no indicator")))
313 (princ (documentation minor-mode))
314 (princ "\n\f\n"))))
315 (setq minor-modes (cdr minor-modes))))
316 (princ mode-name)
317 (princ " mode:\n")
318 (princ (documentation major-mode))
319 (save-excursion
320 (set-buffer standard-output)
321 (help-mode))
322 (print-help-return-message)))
323
324 ;; So keyboard macro definitions are documented correctly
325 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
326
327 (defun describe-distribution ()
328 "Display info on how to obtain the latest version of GNU Emacs."
329 (interactive)
330 (find-file-read-only
331 (expand-file-name "DISTRIB" data-directory)))
332
333 (defun describe-copying ()
334 "Display info on how you may redistribute copies of GNU Emacs."
335 (interactive)
336 (find-file-read-only
337 (expand-file-name "COPYING" data-directory))
338 (goto-char (point-min)))
339
340 (defun describe-project ()
341 "Display info on the GNU project."
342 (interactive)
343 (find-file-read-only
344 (expand-file-name "GNU" data-directory))
345 (goto-char (point-min)))
346
347 (defun describe-no-warranty ()
348 "Display info on all the kinds of warranty Emacs does NOT have."
349 (interactive)
350 (describe-copying)
351 (let (case-fold-search)
352 (search-forward "NO WARRANTY")
353 (recenter 0)))
354
355 (defun describe-prefix-bindings ()
356 "Describe the bindings of the prefix used to reach this command.
357 The prefix described consists of all but the last event
358 of the key sequence that ran this command."
359 (interactive)
360 (let* ((key (this-command-keys)))
361 (describe-bindings
362 (if (stringp key)
363 (substring key 0 (1- (length key)))
364 (let ((prefix (make-vector (1- (length key)) nil))
365 (i 0))
366 (while (< i (length prefix))
367 (aset prefix i (aref key i))
368 (setq i (1+ i)))
369 prefix)))))
370 ;; Make C-h after a prefix, when not specifically bound,
371 ;; run describe-prefix-bindings.
372 (setq prefix-help-command 'describe-prefix-bindings)
373
374 (defun view-emacs-news ()
375 "Display info on recent changes to Emacs."
376 (interactive)
377 (find-file-read-only (expand-file-name "NEWS" data-directory)))
378
379 (defun view-emacs-FAQ ()
380 "Display the Emacs Frequently Asked Questions (FAQ) file."
381 (interactive)
382 (find-file-read-only (expand-file-name "FAQ" data-directory)))
383
384 (defun view-lossage ()
385 "Display last 100 input keystrokes."
386 (interactive)
387 (with-output-to-temp-buffer "*Help*"
388 (princ (mapconcat (function (lambda (key)
389 (if (or (integerp key)
390 (symbolp key)
391 (listp key))
392 (single-key-description key)
393 (prin1-to-string key nil))))
394 (recent-keys)
395 " "))
396 (save-excursion
397 (set-buffer standard-output)
398 (goto-char (point-min))
399 (while (progn (move-to-column 50) (not (eobp)))
400 (search-forward " " nil t)
401 (insert "\n"))
402 (help-mode))
403 (print-help-return-message)))
404
405 (defalias 'help 'help-for-help)
406 (make-help-screen help-for-help
407 "a b c f C-f i k C-k l m n p s t v w C-c C-d C-n C-w, or ? for more help:"
408 "You have typed \\[help-command], the help character. Type a Help option:
409 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
410
411 a command-apropos. Give a substring, and see a list of commands
412 (functions interactively callable) that contain
413 that substring. See also the apropos command.
414 b describe-bindings. Display table of all key bindings.
415 c describe-key-briefly. Type a command key sequence;
416 it prints the function name that sequence runs.
417 f describe-function. Type a function name and get documentation of it.
418 C-f Info-goto-emacs-command-node. Type a function name;
419 it takes you to the Info node for that command.
420 F view-emacs-FAQ. Shows emacs frequently asked questions file.
421 i info. The info documentation reader.
422 k describe-key. Type a command key sequence;
423 it displays the full documentation.
424 C-k Info-goto-emacs-key-command-node. Type a command key sequence;
425 it takes you to the Info node for the command bound to that key.
426 l view-lossage. Shows last 100 characters you typed.
427 m describe-mode. Print documentation of current major mode,
428 which describes the commands peculiar to it.
429 n view-emacs-news. Shows emacs news file.
430 p finder-by-keyword. Find packages matching a given topic keyword.
431 s describe-syntax. Display contents of syntax table, plus explanations
432 t help-with-tutorial. Select the Emacs learn-by-doing tutorial.
433 v describe-variable. Type name of a variable;
434 it displays the variable's documentation and value.
435 w where-is. Type command name; it prints which keystrokes
436 invoke that command.
437 C-c print Emacs copying permission (General Public License).
438 C-d print Emacs ordering information.
439 C-n print news of recent Emacs changes.
440 C-p print information about the GNU project.
441 C-w print information on absence of warranty for GNU Emacs."
442 help-map)
443
444 ;; Return a function which is called by the list containing point.
445 ;; If that gives no function, return a function whose name is around point.
446 ;; If that doesn't give a function, return nil.
447 (defun function-called-at-point ()
448 (or (condition-case ()
449 (save-excursion
450 (save-restriction
451 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
452 (backward-up-list 1)
453 (forward-char 1)
454 (let (obj)
455 (setq obj (read (current-buffer)))
456 (and (symbolp obj) (fboundp obj) obj))))
457 (error nil))
458 (condition-case ()
459 (let ((stab (syntax-table)))
460 (unwind-protect
461 (save-excursion
462 (set-syntax-table emacs-lisp-mode-syntax-table)
463 (or (not (zerop (skip-syntax-backward "_w")))
464 (eq (char-syntax (following-char)) ?w)
465 (eq (char-syntax (following-char)) ?_)
466 (forward-sexp -1))
467 (skip-chars-forward "'")
468 (let ((obj (read (current-buffer))))
469 (and (symbolp obj) (fboundp obj) obj)))
470 (set-syntax-table stab)))
471 (error nil))))
472
473 (defun describe-function-find-file (function)
474 (let ((files load-history)
475 file functions)
476 (while files
477 (if (memq function (cdr (car files)))
478 (setq file (car (car files)) files nil))
479 (setq files (cdr files)))
480 file))
481
482 (defun describe-function (function)
483 "Display the full documentation of FUNCTION (a symbol)."
484 (interactive
485 (let ((fn (function-called-at-point))
486 (enable-recursive-minibuffers t)
487 val)
488 (setq val (completing-read (if fn
489 (format "Describe function (default %s): " fn)
490 "Describe function: ")
491 obarray 'fboundp t))
492 (list (if (equal val "")
493 fn (intern val)))))
494 (if function
495 (with-output-to-temp-buffer "*Help*"
496 (prin1 function)
497 (princ ": ")
498 (let* ((def (symbol-function function))
499 file-name
500 (beg (if (commandp def) "an interactive " "a ")))
501 (princ (cond ((or (stringp def)
502 (vectorp def))
503 "a keyboard macro")
504 ((subrp def)
505 (concat beg "built-in function"))
506 ((byte-code-function-p def)
507 (concat beg "compiled Lisp function"))
508 ((symbolp def)
509 (format "alias for `%s'" def))
510 ((eq (car-safe def) 'lambda)
511 (concat beg "Lisp function"))
512 ((eq (car-safe def) 'macro)
513 "a Lisp macro")
514 ((eq (car-safe def) 'mocklisp)
515 "a mocklisp function")
516 ((eq (car-safe def) 'autoload)
517 (setq file-name (nth 1 def))
518 (format "%s autoloaded Lisp %s"
519 (if (commandp def) "an interactive" "an")
520 (if (nth 4 def) "macro" "function")
521 ))
522 (t "")))
523 (or file-name
524 (setq file-name (describe-function-find-file function)))
525 (if file-name
526 (progn
527 (princ " in `")
528 ;; We used to add .el to the file name,
529 ;; but that's completely wrong when the user used load-file.
530 (princ file-name)
531 (princ "'")))
532 (princ ".")
533 (terpri)
534 (let ((arglist (cond ((byte-code-function-p def)
535 (car (append def nil)))
536 ((eq (car-safe def) 'lambda)
537 (nth 1 def))
538 (t t))))
539 (if (listp arglist)
540 (progn
541 (princ (cons function
542 (mapcar (lambda (arg)
543 (if (memq arg '(&optional &rest))
544 arg
545 (intern (upcase (symbol-name arg)))))
546 arglist)))
547 (terpri))))
548 (let ((doc (documentation function)))
549 (if doc
550 (progn (terpri)
551 (princ doc))
552 (princ "not documented"))))
553 (print-help-return-message)
554 (save-excursion
555 (set-buffer standard-output)
556 (help-mode)
557 ;; Return the text we displayed.
558 (buffer-string)))
559 (message "You didn't specify a function")))
560
561 ;; We return 0 if we can't find a variable to return.
562 (defun variable-at-point ()
563 (condition-case ()
564 (let ((stab (syntax-table)))
565 (unwind-protect
566 (save-excursion
567 (set-syntax-table emacs-lisp-mode-syntax-table)
568 (or (not (zerop (skip-syntax-backward "_w")))
569 (eq (char-syntax (following-char)) ?w)
570 (eq (char-syntax (following-char)) ?_)
571 (forward-sexp -1))
572 (skip-chars-forward "'")
573 (let ((obj (read (current-buffer))))
574 (or (and (symbolp obj) (boundp obj) obj)
575 0)))
576 (set-syntax-table stab)))
577 (error 0)))
578
579 (defun describe-variable (variable)
580 "Display the full documentation of VARIABLE (a symbol).
581 Returns the documentation as a string, also."
582 (interactive
583 (let ((v (variable-at-point))
584 (enable-recursive-minibuffers t)
585 val)
586 (setq val (completing-read (if (symbolp v)
587 (format "Describe variable (default %s): " v)
588 "Describe variable: ")
589 obarray 'boundp t))
590 (list (if (equal val "")
591 v (intern val)))))
592 (if (symbolp variable)
593 (let (valvoid)
594 (with-output-to-temp-buffer "*Help*"
595 (prin1 variable)
596 (if (not (boundp variable))
597 (progn
598 (princ " is void")
599 (terpri)
600 (setq valvoid t))
601 (princ "'s value is ")
602 (terpri)
603 (pp (symbol-value variable))
604 (terpri))
605 (if (local-variable-p variable)
606 (progn
607 (princ (format "Local in buffer %s; " (buffer-name)))
608 (if (not (default-boundp variable))
609 (princ "globally void")
610 (princ "global value is ")
611 (terpri)
612 (pp (default-value variable)))
613 (terpri)))
614 (terpri)
615 (save-current-buffer
616 (set-buffer standard-output)
617 (if (> (count-lines (point-min) (point-max)) 10)
618 (progn
619 (goto-char (point-min))
620 (if valvoid
621 (forward-line 1)
622 (forward-sexp 1)
623 (delete-region (point) (progn (end-of-line) (point)))
624 (insert "'s value is shown below.\n\n")
625 (save-excursion
626 (insert "\n\nValue:"))))))
627 (princ "Documentation:")
628 (terpri)
629 (let ((doc (documentation-property variable 'variable-documentation)))
630 (princ (or doc "not documented as a variable.")))
631 (print-help-return-message)
632 (save-excursion
633 (set-buffer standard-output)
634 (help-mode)
635 ;; Return the text we displayed.
636 (buffer-string))))
637 (message "You did not specify a variable")))
638
639 (defun where-is (definition)
640 "Print message listing key sequences that invoke specified command.
641 Argument is a command definition, usually a symbol with a function definition."
642 (interactive
643 (let ((fn (function-called-at-point))
644 (enable-recursive-minibuffers t)
645 val)
646 (setq val (completing-read (if fn
647 (format "Where is command (default %s): " fn)
648 "Where is command: ")
649 obarray 'fboundp t))
650 (list (if (equal val "")
651 fn (intern val)))))
652 (let* ((keys (where-is-internal definition overriding-local-map nil nil))
653 (keys1 (mapconcat 'key-description keys ", ")))
654 (if (> (length keys1) 0)
655 (message "%s is on %s" definition keys1)
656 (message "%s is not on any key" definition)))
657 nil)
658
659 (defun locate-library (library &optional nosuffix path interactive-call)
660 "Show the precise file name of Emacs library LIBRARY.
661 This command searches the directories in `load-path' like `M-x load-library'
662 to find the file that `M-x load-library RET LIBRARY RET' would load.
663 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
664 to the specified name LIBRARY.
665
666 If the optional third arg PATH is specified, that list of directories
667 is used instead of `load-path'."
668 (interactive (list (read-string "Locate library: ")
669 nil nil
670 t))
671 (let (result)
672 (catch 'answer
673 (mapcar
674 (lambda (dir)
675 (mapcar
676 (lambda (suf)
677 (let ((try (expand-file-name (concat library suf) dir)))
678 (and (file-readable-p try)
679 (null (file-directory-p try))
680 (progn
681 (setq result try)
682 (throw 'answer try)))))
683 (if nosuffix
684 '("")
685 (let ((basic '(".elc" ".el" ""))
686 (compressed '(".Z" ".gz" "")))
687 ;; If autocompression mode is on,
688 ;; consider all combinations of library suffixes
689 ;; and compression suffixes.
690 (if (rassq 'jka-compr-handler file-name-handler-alist)
691 (apply 'nconc
692 (mapcar (lambda (compelt)
693 (mapcar (lambda (baselt)
694 (concat baselt compelt))
695 basic))
696 compressed))
697 basic)))))
698 (or path load-path)))
699 (and interactive-call
700 (if result
701 (message "Library is file %s" result)
702 (message "No library %s in search path" library)))
703 result))
704
705 ;;; help.el ends here