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