Comment change.
[emacs.git] / lisp / help.el
blob42fd5d29112249b7cc34f46c79a66ebce1e5ce8f
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" 'info-lookup-symbol)
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 C f F C-f i I k C-k l L m n p s t v w C-c C-d C-n C-p C-w; ? for 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 C describe-coding-system. This describes either a specific coding system
433 (if you type its name) or the coding systems currently in use
434 (if you type just RET).
435 f describe-function. Type a function name and get documentation of it.
436 C-f Info-goto-emacs-command-node. Type a function name;
437 it takes you to the Info node for that command.
438 i info. The info documentation reader.
439 I describe-input-method. Describe a specific input method (if you type
440 its name) or the current input method (if you type just RET).
441 k describe-key. Type a command key sequence;
442 it displays the full documentation.
443 C-k Info-goto-emacs-key-command-node. Type a command key sequence;
444 it takes you to the Info node for the command bound to that key.
445 l view-lossage. Shows last 100 characters you typed.
446 L describe-language-environment. This describes either the a
447 specific language environment (if you type its name)
448 or the current language environment (if you type just RET).
449 m describe-mode. Print documentation of current major mode,
450 which describes the commands peculiar to it.
451 n view-emacs-news. Shows emacs news file.
452 p finder-by-keyword. Find packages matching a given topic keyword.
453 s describe-syntax. Display contents of syntax table, plus explanations
454 t help-with-tutorial. Select the Emacs learn-by-doing tutorial.
455 v describe-variable. Type name of a variable;
456 it displays the variable's documentation and value.
457 w where-is. Type command name; it prints which keystrokes
458 invoke that command.
460 F Display the frequently asked questions file.
461 h Display the HELLO file which illustrates various scripts.
462 C-c Display Emacs copying permission (General Public License).
463 C-d Display Emacs ordering information.
464 C-n Display news of recent Emacs changes.
465 C-p Display information about the GNU project.
466 C-w Display information on absence of warranty for GNU Emacs."
467 help-map)
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))))
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))
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 (if function
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")
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))
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 (message "You didn't specify a function")))
586 ;; We return 0 if we can't find a variable to return.
587 (defun variable-at-point ()
588 (condition-case ()
589 (let ((stab (syntax-table)))
590 (unwind-protect
591 (save-excursion
592 (set-syntax-table emacs-lisp-mode-syntax-table)
593 (or (not (zerop (skip-syntax-backward "_w")))
594 (eq (char-syntax (following-char)) ?w)
595 (eq (char-syntax (following-char)) ?_)
596 (forward-sexp -1))
597 (skip-chars-forward "'")
598 (let ((obj (read (current-buffer))))
599 (or (and (symbolp obj) (boundp obj) obj)
600 0)))
601 (set-syntax-table stab)))
602 (error 0)))
604 (defun describe-variable (variable)
605 "Display the full documentation of VARIABLE (a symbol).
606 Returns the documentation as a string, also."
607 (interactive
608 (let ((v (variable-at-point))
609 (enable-recursive-minibuffers t)
610 val)
611 (setq val (completing-read (if (symbolp v)
612 (format "Describe variable (default %s): " v)
613 "Describe variable: ")
614 obarray 'boundp t))
615 (list (if (equal val "")
616 v (intern val)))))
617 (if (symbolp variable)
618 (let (valvoid)
619 (with-output-to-temp-buffer "*Help*"
620 (prin1 variable)
621 (if (not (boundp variable))
622 (progn
623 (princ " is void")
624 (terpri)
625 (setq valvoid t))
626 (princ "'s value is ")
627 (terpri)
628 (pp (symbol-value variable))
629 (terpri))
630 (if (local-variable-p variable)
631 (progn
632 (princ (format "Local in buffer %s; " (buffer-name)))
633 (if (not (default-boundp variable))
634 (princ "globally void")
635 (princ "global value is ")
636 (terpri)
637 (pp (default-value variable)))
638 (terpri)))
639 (terpri)
640 (save-current-buffer
641 (set-buffer standard-output)
642 (if (> (count-lines (point-min) (point-max)) 10)
643 (progn
644 (goto-char (point-min))
645 (if valvoid
646 (forward-line 1)
647 (forward-sexp 1)
648 (delete-region (point) (progn (end-of-line) (point)))
649 (insert "'s value is shown below.\n\n")
650 (save-excursion
651 (insert "\n\nValue:"))))))
652 (princ "Documentation:")
653 (terpri)
654 (let ((doc (documentation-property variable 'variable-documentation)))
655 (princ (or doc "not documented as a variable.")))
656 (print-help-return-message)
657 (save-excursion
658 (set-buffer standard-output)
659 (help-mode)
660 ;; Return the text we displayed.
661 (buffer-string))))
662 (message "You did not specify a variable")))
664 (defun where-is (definition &optional insert)
665 "Print message listing key sequences that invoke specified command.
666 Argument is a command definition, usually a symbol with a function definition.
667 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
668 (interactive
669 (let ((fn (function-called-at-point))
670 (enable-recursive-minibuffers t)
671 val)
672 (setq val (completing-read (if fn
673 (format "Where is command (default %s): " fn)
674 "Where is command: ")
675 obarray 'fboundp t))
676 (list (if (equal val "")
677 fn (intern val))
678 current-prefix-arg)))
679 (let* ((keys (where-is-internal definition overriding-local-map nil nil))
680 (keys1 (mapconcat 'key-description keys ", "))
681 (standard-output (if insert (current-buffer) t)))
682 (if insert
683 (if (> (length keys1) 0)
684 (princ (format "%s (%s)" keys1 definition))
685 (princ (format "M-x %s RET" definition)))
686 (if (> (length keys1) 0)
687 (princ (format "%s is on %s" definition keys1))
688 (princ (format "%s is not on any key" definition)))))
689 nil)
691 (defun locate-library (library &optional nosuffix path interactive-call)
692 "Show the precise file name of Emacs library LIBRARY.
693 This command searches the directories in `load-path' like `M-x load-library'
694 to find the file that `M-x load-library RET LIBRARY RET' would load.
695 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
696 to the specified name LIBRARY.
698 If the optional third arg PATH is specified, that list of directories
699 is used instead of `load-path'."
700 (interactive (list (read-string "Locate library: ")
701 nil nil
703 (let (result)
704 (catch 'answer
705 (mapcar
706 (lambda (dir)
707 (mapcar
708 (lambda (suf)
709 (let ((try (expand-file-name (concat library suf) dir)))
710 (and (file-readable-p try)
711 (null (file-directory-p try))
712 (progn
713 (setq result try)
714 (throw 'answer try)))))
715 (if nosuffix
716 '("")
717 (let ((basic '(".elc" ".el" ""))
718 (compressed '(".Z" ".gz" "")))
719 ;; If autocompression mode is on,
720 ;; consider all combinations of library suffixes
721 ;; and compression suffixes.
722 (if (rassq 'jka-compr-handler file-name-handler-alist)
723 (apply 'nconc
724 (mapcar (lambda (compelt)
725 (mapcar (lambda (baselt)
726 (concat baselt compelt))
727 basic))
728 compressed))
729 basic)))))
730 (or path load-path)))
731 (and interactive-call
732 (if result
733 (message "Library is file %s" result)
734 (message "No library %s in search path" library)))
735 result))
737 ;;; help.el ends here