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