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