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