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