(hs-hide-block): Fix message spelling.
[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
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 (let ((doc (documentation defn)))
300 (if doc
301 (progn (terpri)
302 (princ doc))
303 (princ "not documented")))
304 (save-excursion
305 (set-buffer standard-output)
306 (help-mode))
307 (print-help-return-message)))))))
308
309 (defun describe-mode ()
310 "Display documentation of current major mode and minor modes.
311 For this to work correctly for a minor mode, the mode's indicator variable
312 \(listed in `minor-mode-alist') must also be a function whose documentation
313 describes the minor mode."
314 (interactive)
315 (with-output-to-temp-buffer "*Help*"
316 (let ((minor-modes minor-mode-alist)
317 (locals (buffer-local-variables)))
318 (while minor-modes
319 (let* ((minor-mode (car (car minor-modes)))
320 (indicator (car (cdr (car minor-modes))))
321 (local-binding (assq minor-mode locals)))
322 ;; Document a minor mode if it is listed in minor-mode-alist,
323 ;; bound locally in this buffer, non-nil, and has a function
324 ;; definition.
325 (if (and local-binding
326 (cdr local-binding)
327 (fboundp minor-mode))
328 (let ((pretty-minor-mode minor-mode))
329 (if (string-match "-mode$" (symbol-name minor-mode))
330 (setq pretty-minor-mode
331 (capitalize
332 (substring (symbol-name minor-mode)
333 0 (match-beginning 0)))))
334 (while (and indicator (symbolp indicator))
335 (setq indicator (symbol-value indicator)))
336 (princ (format "%s minor mode (indicator%s):\n"
337 pretty-minor-mode indicator))
338 (princ (documentation minor-mode))
339 (princ "\n\n"))))
340 (setq minor-modes (cdr minor-modes))))
341 (princ mode-name)
342 (princ " mode:\n")
343 (princ (documentation major-mode))
344 (save-excursion
345 (set-buffer standard-output)
346 (help-mode))
347 (print-help-return-message)))
348
349 ;; So keyboard macro definitions are documented correctly
350 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
351
352 (defun describe-distribution ()
353 "Display info on how to obtain the latest version of GNU Emacs."
354 (interactive)
355 (find-file-read-only
356 (expand-file-name "DISTRIB" data-directory)))
357
358 (defun describe-copying ()
359 "Display info on how you may redistribute copies of GNU Emacs."
360 (interactive)
361 (find-file-read-only
362 (expand-file-name "COPYING" data-directory))
363 (goto-char (point-min)))
364
365 (defun describe-project ()
366 "Display info on the GNU project."
367 (interactive)
368 (find-file-read-only
369 (expand-file-name "GNU" data-directory))
370 (goto-char (point-min)))
371
372 (defun describe-no-warranty ()
373 "Display info on all the kinds of warranty Emacs does NOT have."
374 (interactive)
375 (describe-copying)
376 (let (case-fold-search)
377 (search-forward "NO WARRANTY")
378 (recenter 0)))
379
380 (defun describe-prefix-bindings ()
381 "Describe the bindings of the prefix used to reach this command.
382 The prefix described consists of all but the last event
383 of the key sequence that ran this command."
384 (interactive)
385 (let* ((key (this-command-keys)))
386 (describe-bindings
387 (if (stringp key)
388 (substring key 0 (1- (length key)))
389 (let ((prefix (make-vector (1- (length key)) nil))
390 (i 0))
391 (while (< i (length prefix))
392 (aset prefix i (aref key i))
393 (setq i (1+ i)))
394 prefix)))))
395 ;; Make C-h after a prefix, when not specifically bound,
396 ;; run describe-prefix-bindings.
397 (setq prefix-help-command 'describe-prefix-bindings)
398
399 (defun view-emacs-news ()
400 "Display info on recent changes to Emacs."
401 (interactive)
402 (find-file-read-only (expand-file-name "NEWS" data-directory)))
403
404 (defun view-emacs-FAQ ()
405 "Display the Emacs Frequently Asked Questions (FAQ) file."
406 (interactive)
407 (find-file-read-only (expand-file-name "FAQ" data-directory)))
408
409 (defun view-lossage ()
410 "Display last 100 input keystrokes."
411 (interactive)
412 (with-output-to-temp-buffer "*Help*"
413 (princ (mapconcat (function (lambda (key)
414 (if (or (integerp key)
415 (symbolp key)
416 (listp key))
417 (single-key-description key)
418 (prin1-to-string key nil))))
419 (recent-keys)
420 " "))
421 (save-excursion
422 (set-buffer standard-output)
423 (goto-char (point-min))
424 (while (progn (move-to-column 50) (not (eobp)))
425 (search-forward " " nil t)
426 (insert "\n"))
427 (help-mode))
428 (print-help-return-message)))
429
430 (defalias 'help 'help-for-help)
431 (make-help-screen help-for-help
432 "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:"
433 "You have typed \\[help-command], the help character. Type a Help option:
434 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
435
436 a command-apropos. Give a substring, and see a list of commands
437 (functions interactively callable) that contain
438 that substring. See also the apropos command.
439 b describe-bindings. Display table of all key bindings.
440 c describe-key-briefly. Type a command key sequence;
441 it prints the function name that sequence runs.
442 f describe-function. Type a function name and get documentation of it.
443 C-f Info-goto-emacs-command-node. Type a function name;
444 it takes you to the Info node for that command.
445 F view-emacs-FAQ. Shows emacs frequently asked questions file.
446 i info. The info documentation reader.
447 k describe-key. Type a command key sequence;
448 it displays the full documentation.
449 C-k Info-goto-emacs-key-command-node. Type a command key sequence;
450 it takes you to the Info node for the command bound to that key.
451 l view-lossage. Shows last 100 characters you typed.
452 m describe-mode. Print documentation of current major mode,
453 which describes the commands peculiar to it.
454 n view-emacs-news. Shows emacs news file.
455 p finder-by-keyword. Find packages matching a given topic keyword.
456 s describe-syntax. Display contents of syntax table, plus explanations
457 t help-with-tutorial. Select the Emacs learn-by-doing tutorial.
458 v describe-variable. Type name of a variable;
459 it displays the variable's documentation and value.
460 w where-is. Type command name; it prints which keystrokes
461 invoke that command.
462 C-c print Emacs copying permission (General Public License).
463 C-d print Emacs ordering information.
464 C-n print news of recent Emacs changes.
465 C-p print information about the GNU project.
466 C-w print information on absence of warranty for GNU Emacs."
467 help-map)
468
469 ;; Return a function which is called by the list containing point.
470 ;; If that gives no function, return a function whose name is around point.
471 ;; If that doesn't give a function, return nil.
472 (defun function-called-at-point ()
473 (or (condition-case ()
474 (save-excursion
475 (save-restriction
476 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
477 (backward-up-list 1)
478 (forward-char 1)
479 (let (obj)
480 (setq obj (read (current-buffer)))
481 (and (symbolp obj) (fboundp obj) obj))))
482 (error nil))
483 (condition-case ()
484 (let ((stab (syntax-table)))
485 (unwind-protect
486 (save-excursion
487 (set-syntax-table emacs-lisp-mode-syntax-table)
488 (or (not (zerop (skip-syntax-backward "_w")))
489 (eq (char-syntax (following-char)) ?w)
490 (eq (char-syntax (following-char)) ?_)
491 (forward-sexp -1))
492 (skip-chars-forward "'")
493 (let ((obj (read (current-buffer))))
494 (and (symbolp obj) (fboundp obj) obj)))
495 (set-syntax-table stab)))
496 (error nil))))
497
498 (defun describe-function-find-file (function)
499 (let ((files load-history)
500 file functions)
501 (while files
502 (if (memq function (cdr (car files)))
503 (setq file (car (car files)) files nil))
504 (setq files (cdr files)))
505 file))
506
507 (defun describe-function (function)
508 "Display the full documentation of FUNCTION (a symbol)."
509 (interactive
510 (let ((fn (function-called-at-point))
511 (enable-recursive-minibuffers t)
512 val)
513 (setq val (completing-read (if fn
514 (format "Describe function (default %s): " fn)
515 "Describe function: ")
516 obarray 'fboundp t))
517 (list (if (equal val "")
518 fn (intern val)))))
519 (with-output-to-temp-buffer "*Help*"
520 (prin1 function)
521 (princ ": ")
522 (let* ((def (symbol-function function))
523 file-name
524 (beg (if (commandp def) "an interactive " "a ")))
525 (princ (cond ((or (stringp def)
526 (vectorp def))
527 "a keyboard macro")
528 ((subrp def)
529 (concat beg "built-in function"))
530 ((byte-code-function-p def)
531 (concat beg "compiled Lisp function"))
532 ((symbolp def)
533 (format "alias for `%s'" def))
534 ((eq (car-safe def) 'lambda)
535 (concat beg "Lisp function"))
536 ((eq (car-safe def) 'macro)
537 "a Lisp macro")
538 ((eq (car-safe def) 'mocklisp)
539 "a mocklisp function")
540 ((eq (car-safe def) 'autoload)
541 (setq file-name (nth 1 def))
542 (format "%s autoloaded Lisp %s"
543 (if (commandp def) "an interactive" "an")
544 (if (nth 4 def) "macro" "function")
545 ))
546 (t "")))
547 (or file-name
548 (setq file-name (describe-function-find-file function)))
549 (if file-name
550 (progn
551 (princ " in `")
552 ;; We used to add .el to the file name,
553 ;; but that's completely wrong when the user used load-file.
554 (princ file-name)
555 (princ "'")))
556 (princ ".")
557 (terpri)
558 (let ((arglist (cond ((byte-code-function-p def)
559 (car (append def nil)))
560 ((eq (car-safe def) 'lambda)
561 (nth 1 def))
562 (t t))))
563 (if (listp arglist)
564 (progn
565 (princ (cons function
566 (mapcar (lambda (arg)
567 (if (memq arg '(&optional &rest))
568 arg
569 (intern (upcase (symbol-name arg)))))
570 arglist)))
571 (terpri))))
572 (let ((doc (documentation function)))
573 (if doc
574 (progn (terpri)
575 (princ doc))
576 (princ "not documented"))))
577 (print-help-return-message)
578 (save-excursion
579 (set-buffer standard-output)
580 (help-mode)
581 ;; Return the text we displayed.
582 (buffer-string))))
583
584 (defun variable-at-point ()
585 (condition-case ()
586 (let ((stab (syntax-table)))
587 (unwind-protect
588 (save-excursion
589 (set-syntax-table emacs-lisp-mode-syntax-table)
590 (or (not (zerop (skip-syntax-backward "_w")))
591 (eq (char-syntax (following-char)) ?w)
592 (eq (char-syntax (following-char)) ?_)
593 (forward-sexp -1))
594 (skip-chars-forward "'")
595 (let ((obj (read (current-buffer))))
596 (and (symbolp obj) (boundp obj) obj)))
597 (set-syntax-table stab)))
598 (error nil)))
599
600 (defun describe-variable (variable)
601 "Display the full documentation of VARIABLE (a symbol).
602 Returns the documentation as a string, also."
603 (interactive
604 (let ((v (variable-at-point))
605 (enable-recursive-minibuffers t)
606 val)
607 (setq val (completing-read (if v
608 (format "Describe variable (default %s): " v)
609 "Describe variable: ")
610 obarray 'boundp t))
611 (list (if (equal val "")
612 v (intern val)))))
613 (with-output-to-temp-buffer "*Help*"
614 (prin1 variable)
615 (if (not (boundp variable))
616 (princ " is void")
617 (princ "'s value is ")
618 (prin1 (symbol-value variable)))
619 (terpri)
620 (if (local-variable-p variable)
621 (progn
622 (princ (format "Local in buffer %s; " (buffer-name)))
623 (if (not (default-boundp variable))
624 (princ "globally void")
625 (princ "global value is ")
626 (prin1 (default-value variable)))
627 (terpri)))
628 (terpri)
629 (princ "Documentation:")
630 (terpri)
631 (let ((doc (documentation-property variable 'variable-documentation)))
632 (princ (or doc "not documented as a variable.")))
633 (print-help-return-message)
634 (save-excursion
635 (set-buffer standard-output)
636 (help-mode)
637 ;; Return the text we displayed.
638 (buffer-string))))
639
640 (defun where-is (definition)
641 "Print message listing key sequences that invoke specified command.
642 Argument is a command definition, usually a symbol with a function definition."
643 (interactive
644 (let ((fn (function-called-at-point))
645 (enable-recursive-minibuffers t)
646 val)
647 (setq val (completing-read (if fn
648 (format "Where is command (default %s): " fn)
649 "Where is command: ")
650 obarray 'fboundp t))
651 (list (if (equal val "")
652 fn (intern val)))))
653 (let* ((keys (where-is-internal definition overriding-local-map nil nil))
654 (keys1 (mapconcat 'key-description keys ", ")))
655 (if (> (length keys1) 0)
656 (message "%s is on %s" definition keys1)
657 (message "%s is not on any key" definition)))
658 nil)
659
660 (defun locate-library (library &optional nosuffix)
661 "Show the full path name of Emacs library LIBRARY.
662 This command searches the directories in `load-path' like `M-x load-library'
663 to find the file that `M-x load-library RET LIBRARY RET' would load.
664 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
665 to the specified name LIBRARY (a la calling `load' instead of `load-library')."
666 (interactive "sLocate library: ")
667 (catch 'answer
668 (mapcar
669 '(lambda (dir)
670 (mapcar
671 '(lambda (suf)
672 (let ((try (expand-file-name (concat library suf) dir)))
673 (and (file-readable-p try)
674 (null (file-directory-p try))
675 (progn
676 (message "Library is file %s" try)
677 (throw 'answer try)))))
678 (if nosuffix '("") '(".elc" ".el" ""))))
679 load-path)
680 (message "No library %s in search path" library)
681 nil))
682
683 ;;; help.el ends here