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