1 ;;; help.el --- help commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001
4 ;; Free Software Foundation, Inc.
7 ;; Keywords: help, internal
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This code implements GNU Emacs' on-line help system, the one invoked by
29 ;; `M-x help-for-help'.
33 ;; Get the macro make-help-screen when this is compiled,
34 ;; or run interpreted, but not when the compiled code is loaded.
35 (eval-when-compile (require 'help-macro
))
36 (eval-when-compile (require 'view
))
38 (defvar help-map
(make-sparse-keymap)
39 "Keymap for characters following the Help key.")
41 (defvar help-mode-map
(make-sparse-keymap)
42 "Keymap for help mode.")
44 (define-key global-map
(char-to-string help-char
) 'help-command
)
45 (define-key global-map
[help] 'help-command)
46 (define-key global-map [f1] 'help-command)
47 (fset 'help-command help-map)
49 (define-key help-map (char-to-string help-char) 'help-for-help)
50 (define-key help-map [help] 'help-for-help
)
51 (define-key help-map
[f1] 'help-for-help)
52 (define-key help-map "?" 'help-for-help)
54 (define-key help-map "\C-c" 'describe-copying)
55 (define-key help-map "\C-d" 'describe-distribution)
56 (define-key help-map "\C-w" 'describe-no-warranty)
57 (define-key help-map "\C-p" 'describe-project)
58 (define-key help-map "a" 'apropos-command)
60 (define-key help-map "b" 'describe-bindings)
62 (define-key help-map "c" 'describe-key-briefly)
63 (define-key help-map "k" 'describe-key)
65 (define-key help-map "d" 'describe-function)
66 (define-key help-map "f" 'describe-function)
68 (define-key help-map "F" 'view-emacs-FAQ)
70 (define-key help-map "i" 'info)
71 (define-key help-map "4i" 'info-other-window)
72 (define-key help-map "\C-f" 'Info-goto-emacs-command-node)
73 (define-key help-map "\C-k" 'Info-goto-emacs-key-command-node)
74 (define-key help-map "\C-i" 'info-lookup-symbol)
76 (define-key help-map "l" 'view-lossage)
78 (define-key help-map "m" 'describe-mode)
79 (define-key help-map "\C-m" 'view-order-manuals)
81 (define-key help-map "\C-n" 'view-emacs-news)
82 (define-key help-map "n" 'view-emacs-news)
84 (define-key help-map "p" 'finder-by-keyword)
85 (autoload 'finder-by-keyword "finder"
86 "Find packages matching a given keyword." t)
88 (define-key help-map "P" 'view-emacs-problems)
90 (define-key help-map "s" 'describe-syntax)
92 (define-key help-map "t" 'help-with-tutorial)
94 (define-key help-map "w" 'where-is)
96 (define-key help-map "v" 'describe-variable)
98 (define-key help-map "q" 'help-quit)
100 (define-key help-mode-map [mouse-2] 'help-follow-mouse)
101 (define-key help-mode-map "\C-c\C-b" 'help-go-back)
102 (define-key help-mode-map "\C-c\C-c" 'help-follow)
103 (define-key help-mode-map "\t" 'help-next-ref)
104 (define-key help-mode-map [backtab] 'help-previous-ref)
105 (define-key help-mode-map [(shift tab)] 'help-previous-ref)
106 ;; Documentation only, since we use minor-mode-overriding-map-alist.
107 (define-key help-mode-map "\r" 'help-follow)
109 (defvar help-xref-stack nil
110 "A stack of ways by which to return to help buffers after following xrefs.
111 Used by `help-follow' and `help-xref-go-back'.
112 An element looks like (POSITION FUNCTION ARGS...), where POSITION is
113 `(POINT . BUFFER-NAME)'.
114 To use the element, do (apply FUNCTION ARGS) then goto the point in
116 (put 'help-xref-stack 'permanent-local t)
118 (defvar help-xref-stack-item nil
119 "An item for `help-follow' in this buffer to push onto `help-xref-stack'.
120 The format is (FUNCTION ARGS...).")
121 (put 'help-xref-stack-item 'permanent-local t)
123 (setq-default help-xref-stack nil help-xref-stack-item nil)
125 (defcustom help-mode-hook nil
126 "Hook run by `help-mode'."
131 "Major mode for viewing help text and navigating references in it.
132 Entry to this mode runs the normal hook `help-mode-hook'.
136 (kill-all-local-variables)
137 (use-local-map help-mode-map)
138 (setq mode-name "Help")
139 (setq major-mode 'help-mode)
140 (make-local-variable 'font-lock-defaults)
141 (setq font-lock-defaults nil) ; font-lock would defeat xref
143 (make-local-variable 'view-no-disable-on-exit)
144 (setq view-no-disable-on-exit t)
145 (run-hooks 'help-mode-hook))
147 (defun help-mode-setup ()
149 (setq buffer-read-only nil))
151 (add-hook 'temp-buffer-setup-hook 'help-mode-setup)
153 (defun help-mode-finish ()
154 (when (eq major-mode 'help-mode)
155 ;; View mode's read-only status of existing *Help* buffer is lost
156 ;; by with-output-to-temp-buffer.
158 (help-make-xrefs (current-buffer)))
159 (setq view-return-to-alist
160 (list (cons (selected-window) help-return-method))))
162 (add-hook 'temp-buffer-show-hook 'help-mode-finish)
165 "Just exit from the Help command's command loop."
169 (defun help-with-tutorial (&optional arg)
170 "Select the Emacs learn-by-doing tutorial.
171 If there is a tutorial version written in the language
172 of the selected language environment, that version is used.
173 If there's no tutorial in that language, `TUTORIAL' is selected.
174 With arg, you are asked to choose which language."
177 (read-language-name 'tutorial "Language: " "English")
178 (if (get-language-info current-language-environment 'tutorial)
179 current-language-environment
182 (setq filename (get-language-info lang 'tutorial))
183 (setq file (expand-file-name (concat "~/" filename)))
184 (delete-other-windows)
185 (if (get-file-buffer file)
186 (switch-to-buffer (get-file-buffer file))
187 (switch-to-buffer (create-file-buffer file))
188 (setq buffer-file-name file)
189 (setq default-directory (expand-file-name "~/"))
190 (setq buffer-auto-save-file-name nil)
191 (insert-file-contents (expand-file-name filename data-directory))
192 (goto-char (point-min))
193 (search-forward "\n<<")
195 (delete-region (point) (progn (end-of-line) (point)))
196 (let ((n (- (window-height (selected-window))
197 (count-lines (point-min) (point))
201 ;; Some people get confused by the large gap.
203 (insert "[Middle of page left blank for didactic purposes. "
204 "Text continues below]")
205 (newline (- n (/ n 2)))))
206 (goto-char (point-min))
207 (set-buffer-modified-p nil))))
209 (defun string-key-binding (key)
210 "Value is the binding of KEY in a string.
211 If KEY is an event on a string, and that string has a `local-map'
212 or `keymap' property, return the binding of KEY in the string's keymap."
214 (start (when (vectorp key)
215 (if (memq (aref key 0) '(mode-line header-line))
216 (event-start (aref key 1))
217 (and (consp (aref key 0))
218 (event-start (aref key 0))))))
219 (string-info (and (consp start) (nth 4 start))))
221 (let* ((string (car string-info))
222 (pos (cdr string-info))
223 (local-map (and (> pos 0)
224 (< pos (length string))
225 (or (get-text-property pos 'local-map string)
226 (get-text-property pos 'keymap string)))))
227 (setq defn (and local-map (lookup-key local-map key)))))
230 (defun describe-key-briefly (key &optional insert)
231 "Print the name of the function KEY invokes. KEY is a string.
232 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
233 (interactive "kDescribe key briefly: \nP")
235 (let ((modifiers (event-modifiers (aref key 0)))
236 (standard-output (if insert (current-buffer) t))
238 ;; For a mouse button event, go to the button it applies to
239 ;; to get the right key bindings. And go to the right place
240 ;; in case the keymap depends on where you clicked.
241 (if (or (memq 'click modifiers) (memq 'down modifiers)
242 (memq 'drag modifiers))
243 (setq window (posn-window (event-start (aref key 0)))
244 position (posn-point (event-start (aref key 0)))))
247 (set-buffer (window-buffer window))
248 (goto-char position)))
249 ;; Ok, now look up the key and name the command.
250 (let ((defn (or (string-key-binding key)
252 (key-desc (key-description key)))
253 (if (or (null defn) (integerp defn))
254 (princ (format "%s is undefined" key-desc))
255 (princ (format (if insert
258 "%s at that spot runs the command %s"
259 "%s runs the command %s"))
261 (if (symbolp defn) defn (prin1-to-string defn)))))))))
263 (defvar help-return-method nil
264 "What to do to \"exit\" the help buffer.
266 (WINDOW . t) delete the selected window, go to WINDOW.
267 (WINDOW . quit-window) do quit-window, then select WINDOW.
268 (WINDOW BUF START POINT) display BUF at START, POINT, then select WINDOW.")
270 (defun print-help-return-message (&optional function)
271 "Display or return message saying how to restore windows after help command.
272 Computes a message and applies the optional argument FUNCTION to it.
273 If FUNCTION is nil, applies `message' to it, thus printing it."
274 (and (not (get-buffer-window standard-output))
276 (cond ((special-display-p (buffer-name standard-output))
277 (setq help-return-method (cons (selected-window) t))
278 ;; If the help output buffer is a special display buffer,
279 ;; don't say anything about how to get rid of it.
280 ;; First of all, the user will do that with the window
281 ;; manager, not with Emacs.
282 ;; Secondly, the buffer has not been displayed yet,
283 ;; so we don't know whether its frame will be selected.
285 (display-buffer-reuse-frames
286 (setq help-return-method (cons (selected-window)
289 ((not (one-window-p t))
290 (setq help-return-method
291 (cons (selected-window) 'quit-window))
292 "Type \\[switch-to-buffer-other-window] RET to restore the other window.")
294 (setq help-return-method (cons (selected-window) t))
295 "Type \\[delete-other-windows] to remove help window.")
297 (setq help-return-method
298 (list (selected-window) (window-buffer)
299 (window-start) (window-point)))
300 "Type \\[switch-to-buffer] RET to remove help window."))))
301 (funcall (or function 'message)
304 (substitute-command-keys first-message))
305 (if first-message " ")
306 ;; If the help buffer will go in a separate frame,
307 ;; it's no use mentioning a command to scroll, so don't.
308 (if (special-display-p (buffer-name standard-output))
310 (if (same-window-p (buffer-name standard-output))
311 ;; Say how to scroll this window.
312 (substitute-command-keys
313 "\\[scroll-up] to scroll the help.")
314 ;; Say how to scroll some other window.
315 (substitute-command-keys
316 "\\[scroll-other-window] to scroll the help."))))))))
318 (defun describe-key (key)
319 "Display documentation of the function invoked by KEY. KEY is a string."
320 (interactive "kDescribe key: ")
322 (let ((modifiers (event-modifiers (aref key 0)))
324 ;; For a mouse button event, go to the button it applies to
325 ;; to get the right key bindings. And go to the right place
326 ;; in case the keymap depends on where you clicked.
327 (if (or (memq 'click modifiers) (memq 'down modifiers)
328 (memq 'drag modifiers))
329 (setq window (posn-window (event-start (aref key 0)))
330 position (posn-point (event-start (aref key 0)))))
333 (set-buffer (window-buffer window))
334 (goto-char position)))
335 (let ((defn (or (string-key-binding key) (key-binding key))))
336 (if (or (null defn) (integerp defn))
337 (message "%s is undefined" (key-description key))
338 (with-output-to-temp-buffer "*Help*"
339 (princ (key-description key))
341 (princ " at that spot"))
342 (princ " runs the command ")
344 (princ "\n which is ")
345 (describe-function-1 defn nil (interactive-p))
346 (print-help-return-message)))))))
348 (defun describe-mode ()
349 "Display documentation of current major mode and minor modes.
350 The major mode description comes first, followed by the minor modes,
351 each on a separate page.
353 For this to work correctly for a minor mode, the mode's indicator variable
354 \(listed in `minor-mode-alist') must also be a function whose documentation
355 describes the minor mode."
357 (with-output-to-temp-buffer "*Help*"
358 (when minor-mode-alist
359 (princ "The major mode is described first.
360 For minor modes, see following pages.\n\n"))
363 (princ (documentation major-mode))
364 (help-setup-xref (list #'help-xref-mode (current-buffer)) (interactive-p))
365 (let ((minor-modes minor-mode-alist))
367 (let* ((minor-mode (car (car minor-modes)))
368 (indicator (car (cdr (car minor-modes)))))
369 ;; Document a minor mode if it is listed in minor-mode-alist,
370 ;; bound locally in this buffer, non-nil, and has a function
372 (if (and (boundp minor-mode)
373 (symbol-value minor-mode)
374 (fboundp minor-mode))
375 (let ((pretty-minor-mode minor-mode))
376 (if (string-match "-mode$" (symbol-name minor-mode))
377 (setq pretty-minor-mode
379 (substring (symbol-name minor-mode)
380 0 (match-beginning 0)))))
381 (while (and indicator (symbolp indicator)
383 (not (eq indicator (symbol-value indicator))))
384 (setq indicator (symbol-value indicator)))
386 (princ (format "%s minor mode (%s):\n"
389 (format "indicator%s" indicator)
391 (princ (documentation minor-mode)))))
392 (setq minor-modes (cdr minor-modes))))
393 (print-help-return-message)))
395 ;; So keyboard macro definitions are documented correctly
396 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
398 (defun describe-distribution ()
399 "Display info on how to obtain the latest version of GNU Emacs."
402 (expand-file-name "DISTRIB" data-directory)))
404 (defun describe-copying ()
405 "Display info on how you may redistribute copies of GNU Emacs."
408 (expand-file-name "COPYING" data-directory))
409 (goto-char (point-min)))
411 (defun describe-project ()
412 "Display info on the GNU project."
415 (expand-file-name "THE-GNU-PROJECT" data-directory))
416 (goto-char (point-min)))
418 (defun describe-no-warranty ()
419 "Display info on all the kinds of warranty Emacs does NOT have."
422 (let (case-fold-search)
423 (search-forward "NO WARRANTY")
426 (defun describe-prefix-bindings ()
427 "Describe the bindings of the prefix used to reach this command.
428 The prefix described consists of all but the last event
429 of the key sequence that ran this command."
431 (let* ((key (this-command-keys)))
434 (substring key 0 (1- (length key)))
435 (let ((prefix (make-vector (1- (length key)) nil))
437 (while (< i (length prefix))
438 (aset prefix i (aref key i))
441 ;; Make C-h after a prefix, when not specifically bound,
442 ;; run describe-prefix-bindings.
443 (setq prefix-help-command 'describe-prefix-bindings)
445 (defun view-emacs-news (&optional arg)
446 "Display info on recent changes to Emacs.
447 With numeric argument, display information on correspondingly older changes."
449 (let* ((arg (if arg (prefix-numeric-value arg) 0))
450 (file (cond ((eq arg 0) "NEWS")
454 (nreverse (directory-files data-directory
455 nil "^ONEWS\\.[0-9]+$"
458 (find-file-read-only (expand-file-name file data-directory))
459 (error "No such old news"))))
461 (defun view-order-manuals ()
462 "Display the Emacs ORDERS file."
464 (find-file-read-only (expand-file-name "ORDERS" data-directory))
467 (defun view-emacs-FAQ ()
468 "Display the Emacs Frequently Asked Questions (FAQ) file."
470 ;;; (find-file-read-only (expand-file-name "FAQ" data-directory))
473 (defun view-emacs-problems ()
474 "Display info on known problems with Emacs and possible workarounds."
476 (view-file (expand-file-name "PROBLEMS" data-directory)))
478 (defun view-lossage ()
479 "Display last 100 input keystrokes.
481 To record all your input on a file, use `open-dribble-file'."
483 (with-output-to-temp-buffer "*Help*"
484 (princ (mapconcat (function (lambda (key)
485 (if (or (integerp key)
488 (single-key-description key)
489 (prin1-to-string key nil))))
493 (set-buffer standard-output)
494 (goto-char (point-min))
495 (while (progn (move-to-column 50) (not (eobp)))
496 (search-forward " " nil t)
498 (setq help-xref-stack nil
499 help-xref-stack-item nil))
500 (print-help-return-message)))
502 (defalias 'help 'help-for-help)
503 (make-help-screen help-for-help
504 "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:"
505 "You have typed %THIS-KEY%, the help character. Type a Help option:
506 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
508 a command-apropos. Give a substring, and see a list of commands
509 (functions interactively callable) that contain
510 that substring. See also the apropos command.
511 b describe-bindings. Display table of all key bindings.
512 c describe-key-briefly. Type a command key sequence;
513 it prints the function name that sequence runs.
514 C describe-coding-system. This describes either a specific coding system
515 (if you type its name) or the coding systems currently in use
516 (if you type just RET).
517 f describe-function. Type a function name and get documentation of it.
518 C-f Info-goto-emacs-command-node. Type a function name;
519 it takes you to the Info node for that command.
520 i info. The info documentation reader.
521 I describe-input-method. Describe a specific input method (if you type
522 its name) or the current input method (if you type just RET).
523 C-i info-lookup-symbol. Display the definition of a specific symbol
524 as found in the manual for the language this buffer is written in.
525 k describe-key. Type a command key sequence;
526 it displays the full documentation.
527 C-k Info-goto-emacs-key-command-node. Type a command key sequence;
528 it takes you to the Info node for the command bound to that key.
529 l view-lossage. Show last 100 characters you typed.
530 L describe-language-environment. This describes either a
531 specific language environment (if you type its name)
532 or the current language environment (if you type just RET).
533 m describe-mode. Print documentation of current minor modes,
534 and the current major mode, including their special commands.
535 n view-emacs-news. Display news of recent Emacs changes.
536 p finder-by-keyword. Find packages matching a given topic keyword.
537 s describe-syntax. Display contents of syntax table, plus explanations
538 t help-with-tutorial. Select the Emacs learn-by-doing tutorial.
539 v describe-variable. Type name of a variable;
540 it displays the variable's documentation and value.
541 w where-is. Type command name; it prints which keystrokes
544 F Display the frequently asked questions file.
545 h Display the HELLO file which illustrates various scripts.
546 C-c Display Emacs copying permission (General Public License).
547 C-d Display Emacs ordering information.
548 C-n Display news of recent Emacs changes.
549 C-p Display information about the GNU project.
550 C-w Display information on absence of warranty for GNU Emacs."
553 (defun function-called-at-point ()
554 "Return a function around point or else called by the list containing point.
555 If that doesn't give a function, return nil."
556 (with-syntax-table emacs-lisp-mode-syntax-table
557 (or (condition-case ()
559 (or (not (zerop (skip-syntax-backward "_w")))
560 (eq (char-syntax (following-char)) ?w)
561 (eq (char-syntax (following-char)) ?_)
563 (skip-chars-forward "'")
564 (let ((obj (read (current-buffer))))
565 (and (symbolp obj) (fboundp obj) obj)))
570 (narrow-to-region (max (point-min)
571 (- (point) 1000)) (point-max))
572 ;; Move up to surrounding paren, then after the open.
575 ;; If there is space here, this is probably something
576 ;; other than a real Lisp function call, so ignore it.
577 (if (looking-at "[ \t]")
578 (error "Probably not a Lisp function call"))
579 (let ((obj (read (current-buffer))))
580 (and (symbolp obj) (fboundp obj) obj))))
583 (defvar symbol-file-load-history-loaded nil
584 "Non-nil means we have loaded the file `fns-VERSION.el' in `exec-directory'.
585 That file records the part of `load-history' for preloaded files,
586 which is cleared out before dumping to make Emacs smaller.")
588 (defun load-symbol-file-load-history ()
589 "Load the file `fns-VERSION.el' in `exec-directory' if not already done.
590 That file records the part of `load-history' for preloaded files,
591 which is cleared out before dumping to make Emacs smaller."
592 (unless symbol-file-load-history-loaded
593 (load (expand-file-name
594 ;; fns-XX.YY.ZZ.el does not work on DOS filesystem.
595 (if (eq system-type 'ms-dos)
597 (format "fns-%s.el" emacs-version))
599 ;; The file name fns-%s.el already has a .el extension.
601 (setq symbol-file-load-history-loaded t)))
603 (defun symbol-file (function)
604 "Return the input source from which FUNCTION was loaded.
605 The value is normally a string that was passed to `load':
606 either an absolute file name, or a library name
607 \(with no directory name and no `.el' or `.elc' at the end).
608 It can also be nil, if the definition is not associated with any file."
609 (load-symbol-file-load-history)
610 (let ((files load-history)
613 (if (memq function (cdr (car files)))
614 (setq file (car (car files)) files nil))
615 (setq files (cdr files)))
618 (defun describe-function (function)
619 "Display the full documentation of FUNCTION (a symbol)."
621 (let ((fn (function-called-at-point))
622 (enable-recursive-minibuffers t)
624 (setq val (completing-read (if fn
625 (format "Describe function (default %s): " fn)
626 "Describe function: ")
627 obarray 'fboundp t nil nil (symbol-name fn)))
628 (list (if (equal val "")
631 (with-output-to-temp-buffer "*Help*"
633 ;; Use " is " instead of a colon so that
634 ;; it is easier to get out the function name using forward-sexp.
636 (describe-function-1 function nil (interactive-p))
637 (print-help-return-message)
639 (set-buffer standard-output)
640 ;; Return the text we displayed.
642 (message "You didn't specify a function")))
644 (defun describe-function-1 (function parens interactive-p)
645 (let* ((def (if (symbolp function)
646 (symbol-function function)
648 file-name string need-close
649 (beg (if (commandp def) "an interactive " "a ")))
651 (cond ((or (stringp def)
655 (if (eq 'unevalled (cdr (subr-arity def)))
656 (concat beg "special form")
657 (concat beg "built-in function")))
658 ((byte-code-function-p def)
659 (concat beg "compiled Lisp function"))
661 (while (symbolp (symbol-function def))
662 (setq def (symbol-function def)))
663 (format "an alias for `%s'" def))
664 ((eq (car-safe def) 'lambda)
665 (concat beg "Lisp function"))
666 ((eq (car-safe def) 'macro)
668 ((eq (car-safe def) 'mocklisp)
669 "a mocklisp function")
670 ((eq (car-safe def) 'autoload)
671 (setq file-name (nth 1 def))
672 (format "%s autoloaded %s"
673 (if (commandp def) "an interactive" "an")
674 (if (eq (nth 4 def) 'keymap) "keymap"
675 (if (nth 4 def) "Lisp macro" "Lisp function"))
677 ;; perhaps use keymapp here instead
678 ((eq (car-safe def) 'keymap)
680 (elts (cdr-safe def)))
682 (if (char-table-p (car-safe elts))
685 (setq elts (cdr-safe elts)))
690 (when (and parens (not (equal string "")))
694 (with-current-buffer "*Help*"
697 (if (re-search-backward "alias for `\\([^`']+\\)'" nil t)
698 (help-xref-button 1 #'describe-function def
699 "mouse-2, RET: describe this function")))))
701 (setq file-name (symbol-file function)))
705 ;; We used to add .el to the file name,
706 ;; but that's completely wrong when the user used load-file.
709 ;; Make a hyperlink to the library.
710 (with-current-buffer "*Help*"
712 (re-search-backward "`\\([^`']+\\)'" nil t)
717 (let* ((location (find-function-search-for-symbol
718 arg nil (symbol-file arg))))
719 (pop-to-buffer (car location))
720 (goto-char (cdr location))))
722 "mouse-2, RET: find function's definition")))))
723 (if need-close (princ ")"))
726 ;; Handle symbols aliased to other symbols.
727 (setq def (indirect-function def))
728 ;; If definition is a macro, find the function inside it.
729 (if (eq (car-safe def) 'macro)
730 (setq def (cdr def)))
731 (let ((arglist (cond ((byte-code-function-p def)
732 (car (append def nil)))
733 ((eq (car-safe def) 'lambda)
735 ((and (eq (car-safe def) 'autoload)
736 (not (eq (nth 4 def) 'keymap)))
737 (concat "[Arg list not available until "
738 "function definition is loaded.]"))
740 (cond ((listp arglist)
741 (princ (cons (if (symbolp function) function "anonymous")
742 (mapcar (lambda (arg)
743 (if (memq arg '(&optional &rest))
745 (intern (upcase (symbol-name arg)))))
751 (let ((doc (documentation function)))
756 (with-current-buffer standard-output
758 ;; Builtins get the calling sequence at the end of
759 ;; the doc string. Move it to the same place as
760 ;; for other functions.
762 ;; In cases where `function' has been fset to a
763 ;; subr we can't search for function's name in
764 ;; the doc string. Kluge round that using the
765 ;; printed representation. The arg list then
766 ;; shows the wrong function name, but that
767 ;; might be a useful hint.
768 (let* ((rep (prin1-to-string def))
770 (string-match " \\([^ ]+\\)>$" rep)
771 (match-string 1 rep))))
772 (if (looking-at (format "(%s[ )]" (regexp-quote name)))
773 (let ((start (point-marker)))
774 (goto-char (point-min))
776 (insert-buffer-substring (current-buffer) start)
778 (delete-region (1- start) (point-max)))
779 (goto-char (point-min))
782 "[Missing arglist. Please make a bug report.]\n")))
783 (goto-char (point-max))))
784 (help-setup-xref (list #'describe-function function)
786 (princ "not documented")))))
788 (defun variable-at-point ()
789 "Return the bound variable symbol found around point.
790 Return 0 if there is no such symbol."
792 (with-syntax-table emacs-lisp-mode-syntax-table
794 (or (not (zerop (skip-syntax-backward "_w")))
795 (eq (char-syntax (following-char)) ?w)
796 (eq (char-syntax (following-char)) ?_)
798 (skip-chars-forward "'")
799 (let ((obj (read (current-buffer))))
800 (or (and (symbolp obj) (boundp obj) obj)
804 (defun help-xref-on-pp (from to)
805 "Add xrefs for symbols in `pp's output between FROM and TO."
806 (let ((ost (syntax-table)))
810 (set-syntax-table emacs-lisp-mode-syntax-table)
811 (narrow-to-region from to)
812 (goto-char (point-min))
815 ((looking-at "\"") (forward-sexp 1))
816 ((looking-at "#<") (search-forward ">" nil 'move))
817 ((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)")
818 (let* ((sym (intern-soft (match-string 1)))
819 (fn (cond ((fboundp sym) #'describe-function)
820 ((or (memq sym '(t nil))
823 ((and sym (boundp sym))
824 #'describe-variable))))
825 (when fn (help-xref-button 1 fn sym)))
826 (goto-char (match-end 1)))
827 (t (forward-char 1))))))
828 (set-syntax-table ost))))
830 (defun describe-variable (variable &optional buffer)
831 "Display the full documentation of VARIABLE (a symbol).
832 Returns the documentation as a string, also.
833 If VARIABLE has a buffer-local value in BUFFER (default to the current buffer),
834 it is displayed along with the global value."
836 (let ((v (variable-at-point))
837 (enable-recursive-minibuffers t)
839 (setq val (completing-read (if (symbolp v)
841 "Describe variable (default %s): " v)
842 "Describe variable: ")
843 obarray 'boundp t nil nil
844 (if (symbolp v) (symbol-name v))))
845 (list (if (equal val "")
847 (unless (bufferp buffer) (setq buffer (current-buffer)))
848 (if (not (symbolp variable))
849 (message "You did not specify a variable")
851 (with-current-buffer buffer
852 (with-output-to-temp-buffer "*Help*"
854 (if (not (boundp variable))
858 (let ((val (symbol-value variable)))
859 (with-current-buffer standard-output
860 (princ "'s value is ")
862 (let ((from (point)))
864 (help-xref-on-pp from (point))
865 (if (< (point) (+ from 20))
868 (delete-char -1)))))))
870 (if (local-variable-p variable)
872 (princ (format "Local in buffer %s; " (buffer-name)))
873 (if (not (default-boundp variable))
874 (princ "globally void")
875 (let ((val (default-value variable)))
876 (with-current-buffer standard-output
877 (princ "global value is ")
879 ;; Fixme: pp can take an age if you happen to
880 ;; ask for a very large expression. We should
881 ;; probably print it raw once and check it's a
882 ;; sensible size before prettyprinting. -- fx
883 (let ((from (point)))
885 (help-xref-on-pp from (point))
886 (if (< (point) (+ from 20))
889 (delete-char -1)))))))
892 (with-current-buffer standard-output
893 (if (> (count-lines (point-min) (point-max)) 10)
895 ;; Note that setting the syntax table like below
896 ;; makes forward-sexp move over a `'s' at the end
898 (set-syntax-table emacs-lisp-mode-syntax-table)
899 (goto-char (point-min))
903 (delete-region (point) (progn (end-of-line) (point)))
904 (insert " value is shown below.\n\n")
906 (insert "\n\nValue:"))))))
907 (princ "Documentation:")
909 (let ((doc (documentation-property variable 'variable-documentation)))
910 (princ (or doc "not documented as a variable.")))
911 (help-setup-xref (list #'describe-variable variable (current-buffer))
914 ;; Make a link to customize if this variable can be customized.
915 ;; Note, it is not reliable to test only for a custom-type property
916 ;; because those are only present after the var's definition
918 (if (or (get variable 'custom-type) ; after defcustom
919 (get variable 'custom-loads) ; from loaddefs.el
920 (get variable 'standard-value)) ; from cus-start.el
921 (let ((customize-label "customize"))
924 (princ (concat "You can " customize-label " this variable."))
925 (with-current-buffer "*Help*"
928 (concat "\\(" customize-label "\\)") nil t)
929 (help-xref-button 1 (lambda (v)
931 (pop help-xref-stack))
932 (customize-variable v))
934 "mouse-2, RET: customize variable")))))
935 ;; Make a hyperlink to the library if appropriate. (Don't
936 ;; change the format of the buffer's initial line in case
937 ;; anything expects the current format.)
938 (let ((file-name (symbol-file variable)))
940 (princ "\n\nDefined in `")
943 (with-current-buffer "*Help*"
945 (re-search-backward "`\\([^`']+\\)'" nil t)
949 (find-variable-noselect arg)))
950 (pop-to-buffer (car location))
951 (goto-char (cdr location))))
952 variable "mouse-2, RET: find variable's definition")))))
954 (print-help-return-message)
956 (set-buffer standard-output)
957 ;; Return the text we displayed.
958 (buffer-string)))))))
960 (defun describe-bindings (&optional prefix buffer)
961 "Show a list of all defined keys, and their definitions.
962 We put that list in a buffer, and display the buffer.
964 The optional argument PREFIX, if non-nil, should be a key sequence;
965 then we display only bindings that start with that prefix.
966 The optional argument BUFFER specifies which buffer's bindings
967 to display (default, the current buffer)."
969 (or buffer (setq buffer (current-buffer)))
970 (with-current-buffer buffer
971 (describe-bindings-internal nil prefix))
972 (with-current-buffer "*Help*"
973 (help-setup-xref (list #'describe-bindings prefix buffer)
976 (defun where-is (definition &optional insert)
977 "Print message listing key sequences that invoke the command DEFINITION.
978 Argument is a command definition, usually a symbol with a function definition.
979 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
981 (let ((fn (function-called-at-point))
982 (enable-recursive-minibuffers t)
984 (setq val (completing-read (if fn
985 (format "Where is command (default %s): " fn)
986 "Where is command: ")
987 obarray 'commandp t))
988 (list (if (equal val "")
990 current-prefix-arg)))
991 (let* ((keys (where-is-internal definition overriding-local-map nil nil))
992 (keys1 (mapconcat 'key-description keys ", "))
993 (standard-output (if insert (current-buffer) t)))
995 (if (> (length keys1) 0)
996 (princ (format "%s (%s)" keys1 definition))
997 (princ (format "M-x %s RET" definition)))
998 (if (> (length keys1) 0)
999 (princ (format "%s is on %s" definition keys1))
1000 (princ (format "%s is not on any key" definition)))))
1003 (defun locate-library (library &optional nosuffix path interactive-call)
1004 "Show the precise file name of Emacs library LIBRARY.
1005 This command searches the directories in `load-path' like `M-x load-library'
1006 to find the file that `M-x load-library RET LIBRARY RET' would load.
1007 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
1008 to the specified name LIBRARY.
1010 If the optional third arg PATH is specified, that list of directories
1011 is used instead of `load-path'.
1013 When called from a program, the file name is normaly returned as a
1014 string. When run interactively, the argument INTERACTIVE-CALL is t,
1015 and the file name is displayed in the echo area."
1016 (interactive (list (read-string "Locate library: ")
1025 (let ((try (expand-file-name (concat library suf) dir)))
1026 (and (file-readable-p try)
1027 (null (file-directory-p try))
1030 (throw 'answer try)))))
1034 (let ((basic '(".elc" ".el" ""))
1035 (compressed '(".Z" ".gz" "")))
1036 ;; If autocompression mode is on,
1037 ;; consider all combinations of library suffixes
1038 ;; and compression suffixes.
1039 (if (rassq 'jka-compr-handler file-name-handler-alist)
1041 (mapcar (lambda (compelt)
1042 (mapcar (lambda (baselt)
1043 (concat baselt compelt))
1047 (or path load-path)))
1048 (and interactive-call
1050 (message "Library is file %s" result)
1051 (message "No library %s in search path" library)))
1055 ;;; Grokking cross-reference information in doc strings and
1056 ;;; hyperlinking it.
1058 ;; This may have some scope for extension and the same or something
1059 ;; similar should be done for widget doc strings, which currently use
1060 ;; another mechanism.
1062 (defcustom help-highlight-p t
1063 "*If non-nil, `help-make-xrefs' highlight cross-references.
1064 Under a window system it highlights them with face defined by
1065 `help-highlight-face'."
1070 (defcustom help-highlight-face 'underline
1071 "Face used by `help-make-xrefs' to highlight cross-references.
1072 Must be previously-defined."
1077 (defvar help-back-label (purecopy "[back]")
1078 "Label to use by `help-make-xrefs' for the go-back reference.")
1080 (defconst help-xref-symbol-regexp
1081 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|"
1082 "\\(function\\|command\\)\\|"
1085 "\\(source \\(?:code \\)?\\(?:of\\|for\\)\\)\\)\\s-+\\)?"
1086 ;; Note starting with word-syntax character:
1087 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'"))
1088 "Regexp matching doc string references to symbols.
1090 The words preceding the quoted symbol can be used in doc strings to
1091 distinguish references to variables, functions and symbols.")
1093 (defconst help-xref-mule-regexp nil
1094 "Regexp matching doc string references to MULE-related keywords.
1096 It is usually nil, and is temporarily bound to an appropriate regexp
1097 when help commands related to multilingual environment (e.g.,
1098 `describe-coding-system') are invoked.")
1101 (defconst help-xref-info-regexp
1102 (purecopy "\\<[Ii]nfo[ \t\n]+node[ \t\n]+`\\([^']+\\)'")
1103 "Regexp matching doc string references to an Info node.")
1105 (defun help-setup-xref (item interactive-p)
1106 "Invoked from commands using the \"*Help*\" buffer to install some xref info.
1108 ITEM is a (FUNCTION . ARGS) pair appropriate for recreating the help
1109 buffer after following a reference. INTERACTIVE-P is non-nil if the
1110 calling command was invoked interactively. In this case the stack of
1111 items for help buffer \"back\" buttons is cleared."
1113 (setq help-xref-stack nil))
1114 (setq help-xref-stack-item item))
1116 (defvar help-xref-following nil
1117 "Non-nil when following a help cross-reference.")
1119 (defun help-make-xrefs (&optional buffer)
1120 "Parse and hyperlink documentation cross-references in the given BUFFER.
1122 Find cross-reference information in a buffer and, if
1123 `help-highlight-p' is non-nil, highlight it with face defined by
1124 `help-highlight-face'; activate such cross references for selection
1125 with `help-follow'. Cross-references have the canonical form `...'
1126 and the type of reference may be disambiguated by the preceding
1127 word(s) used in `help-xref-symbol-regexp'.
1129 If the variable `help-xref-mule-regexp' is non-nil, find also
1130 cross-reference information related to multilingual environment
1131 \(e.g., coding-systems). This variable is also used to disambiguate
1132 the type of reference as the same way as `help-xref-symbol-regexp'.
1134 A special reference `back' is made to return back through a stack of
1135 help buffers. Variable `help-back-label' specifies the text for
1139 (set-buffer (or buffer (current-buffer)))
1140 (goto-char (point-min))
1141 ;; Skip the header-type info, though it might be useful to parse
1142 ;; it at some stage (e.g. "function in `library'").
1144 (let ((old-modified (buffer-modified-p)))
1145 (let ((stab (syntax-table))
1146 (case-fold-search t)
1147 (inhibit-read-only t))
1148 (set-syntax-table emacs-lisp-mode-syntax-table)
1149 ;; The following should probably be abstracted out.
1154 (while (re-search-forward help-xref-info-regexp nil t)
1155 (let ((data (match-string 1)))
1157 (unless (string-match "^([^)]+)" data)
1158 (setq data (concat "(emacs)" data))))
1159 (help-xref-button 1 #'info data
1160 "mouse-2, RET: read this Info node"))))
1161 ;; Mule related keywords. Do this before trying
1162 ;; `help-xref-symbol-regexp' because some of Mule
1163 ;; keywords have variable or function definitions.
1164 (if help-xref-mule-regexp
1166 (while (re-search-forward help-xref-mule-regexp nil t)
1167 (let* ((data (match-string 7))
1168 (sym (intern-soft data)))
1170 ((match-string 3) ; coding system
1171 (and sym (coding-system-p sym)
1173 7 #'describe-coding-system sym
1174 "mouse-2, RET: describe this coding system")))
1175 ((match-string 4) ; input method
1176 (and (assoc data input-method-alist)
1178 7 #'describe-input-method data
1179 "mouse-2, RET: describe this input method")))
1180 ((or (match-string 5) (match-string 6)) ; charset
1181 (and sym (charsetp sym)
1183 7 #'describe-character-set sym
1184 "mouse-2, RET: describe this character set")))
1185 ((assoc data input-method-alist)
1187 7 #'describe-input-method data
1188 "mouse-2, RET: describe this input method"))
1189 ((and sym (coding-system-p sym))
1191 7 #'describe-coding-system sym
1192 "mouse-2, RET: describe this coding system"))
1193 ((and sym (charsetp sym))
1195 7 #'describe-character-set sym
1196 "mouse-2, RET: describe this character set")))))))
1199 (while (re-search-forward help-xref-symbol-regexp nil t)
1200 (let* ((data (match-string 8))
1201 (sym (intern-soft data)))
1204 ((match-string 3) ; `variable' &c
1205 (and (boundp sym) ; `variable' doesn't ensure
1206 ; it's actually bound
1208 8 #'describe-variable sym
1209 "mouse-2, RET: describe this variable")))
1210 ((match-string 4) ; `function' &c
1211 (and (fboundp sym) ; similarly
1213 8 #'describe-function sym
1214 "mouse-2, RET: describe this function")))
1215 ((match-string 5) ; `face'
1217 (help-xref-button 8 #'describe-face sym
1218 "mouse-2, RET: describe this face")))
1219 ((match-string 6)) ; nothing for `symbol'
1225 (find-function-noselect arg)))
1226 (pop-to-buffer (car location))
1227 (goto-char (cdr location))))
1229 "mouse-2, RET: find function's definition"))
1230 ((and (boundp sym) (fboundp sym))
1231 ;; We can't intuit whether to use the
1232 ;; variable or function doc -- supply both.
1234 8 #'help-xref-interned sym
1235 "mouse-2, RET: describe this symbol"))
1238 8 #'describe-variable sym
1239 "mouse-2, RET: describe this variable"))
1242 8 #'describe-function sym
1243 "mouse-2, RET: describe this function"))
1246 8 #'describe-face sym)))))))
1247 ;; An obvious case of a key substitution:
1249 (while (re-search-forward
1250 ;; Assume command name is only word characters
1251 ;; and dashes to get things like `use M-x foo.'.
1252 "\\<M-x\\s-+\\(\\sw\\(\\sw\\|-\\)+\\)" nil t)
1253 (let ((sym (intern-soft (match-string 1))))
1256 1 #'describe-function sym
1257 "mouse-2, RET: describe this command")))))
1258 ;; Look for commands in whole keymap substitutions:
1260 ;; Make sure to find the first keymap.
1261 (goto-char (point-min))
1262 ;; Find a header and the column at which the command
1263 ;; name will be found.
1264 (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n"
1266 (let ((col (- (match-end 1) (match-beginning 1))))
1268 ;; Ignore single blank lines in table, but not
1269 ;; double ones, which should terminate it.
1270 (and (not (looking-at "\n\\s-*\n"))
1272 (and (eolp) (forward-line))
1274 (skip-chars-backward "^\t\n")
1275 (if (and (>= (current-column) col)
1276 (looking-at "\\(\\sw\\|-\\)+$"))
1277 (let ((sym (intern-soft (match-string 0))))
1280 0 #'describe-function sym
1281 "mouse-2, RET: describe this function"))))
1282 (zerop (forward-line)))))))))
1283 (set-syntax-table stab))
1284 ;; Delete extraneous newlines at the end of the docstring
1285 (goto-char (point-max))
1286 (while (and (not (bobp)) (bolp))
1288 ;; Make a back-reference in this buffer if appropriate.
1289 (when (and help-xref-following help-xref-stack)
1291 (insert "\n\n" help-back-label))
1292 ;; Just to provide the match data:
1293 (looking-at (concat "\n\n\\(" (regexp-quote help-back-label) "\\)"))
1294 (help-xref-button 1 #'help-xref-go-back (current-buffer))))
1295 ;; View mode steals RET from us.
1296 (set (make-local-variable 'minor-mode-overriding-map-alist)
1297 (list (cons 'view-mode
1298 (let ((map (make-sparse-keymap)))
1299 (set-keymap-parent map view-mode-map)
1300 (define-key map "\r" 'help-follow)
1302 (set-buffer-modified-p old-modified))))
1304 (defun help-xref-button (match-number function data &optional help-echo)
1305 "Make a hyperlink for cross-reference text previously matched.
1307 MATCH-NUMBER is the subexpression of interest in the last matched
1308 regexp. FUNCTION is a function to invoke when the button is
1309 activated, applied to DATA. DATA may be a single value or a list.
1310 See `help-make-xrefs'.
1311 If optional arg HELP-ECHO is supplied, it is used as a help string."
1312 ;; Don't mung properties we've added specially in some instances.
1313 (unless (get-text-property (match-beginning match-number) 'help-xref)
1314 (add-text-properties (match-beginning match-number)
1315 (match-end match-number)
1316 (list 'mouse-face 'highlight
1317 'help-xref (cons function
1322 (put-text-property (match-beginning match-number)
1323 (match-end match-number)
1324 'help-echo help-echo))
1325 (if help-highlight-p
1326 (put-text-property (match-beginning match-number)
1327 (match-end match-number)
1328 'face help-highlight-face))))
1330 (defun help-insert-xref-button (string function data &optional help-echo)
1331 "Insert STRING and make a hyperlink from cross-reference text on it.
1333 FUNCTION is a function to invoke when the button is activated, applied
1334 to DATA. DATA may be a single value or a list. See `help-make-xrefs'.
1335 If optional arg HELP-ECHO is supplied, it is used as a help string."
1336 (let ((pos (point)))
1339 (search-forward string)
1340 (help-xref-button 0 function data help-echo)))
1344 ;; Additional functions for (re-)creating types of help buffers.
1345 (defun help-xref-interned (symbol)
1346 "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL.
1348 Both variable and function documentation are extracted into a single
1350 (let ((fdoc (when (fboundp symbol) (describe-function symbol)))
1351 (facedoc (when (facep symbol) (describe-face symbol))))
1352 (when (or (boundp symbol) (not fdoc))
1353 (describe-variable symbol)
1354 ;; We now have a help buffer on the variable. Insert the function
1356 (when (or fdoc facedoc)
1357 (with-current-buffer "*Help*"
1358 (goto-char (point-min))
1359 (let ((inhibit-read-only t))
1361 (insert fdoc "\n\n"))
1363 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
1364 " is also a " "face." "\n\n" facedoc "\n\n"))
1365 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
1366 " is also a " "variable." "\n\n"))
1367 (help-setup-xref (list #'help-xref-interned symbol) nil))))))
1369 (defun help-xref-mode (buffer)
1370 "Do a `describe-mode' for the specified BUFFER."
1375 ;;; Navigation/hyperlinking with xrefs
1377 (defun help-follow-mouse (click)
1378 "Follow the cross-reference that you click on."
1380 (let* ((start (event-start click))
1381 (window (car start))
1382 (pos (car (cdr start))))
1383 (with-current-buffer (window-buffer window)
1384 (help-follow pos))))
1386 (defun help-xref-go-back (buffer)
1387 "From BUFFER, go back to previous help buffer text using `help-xref-stack'."
1388 (let (item position method args)
1389 (with-current-buffer buffer
1390 (when help-xref-stack
1391 (setq help-xref-stack (cdr help-xref-stack)) ; due to help-follow
1392 (setq item (pop help-xref-stack)
1397 ;; We assume that the buffer we just recreated has the saved name,
1398 ;; which might not always be true.
1399 (when (get-buffer (cdr position))
1400 (with-current-buffer (cdr position)
1401 (goto-char (car position))))))
1403 (defun help-go-back ()
1404 "Invoke the [back] button (if any) in the Help mode buffer."
1406 (help-follow (1- (point-max))))
1408 (defun help-follow (&optional pos)
1409 "Follow cross-reference at POS, defaulting to point.
1411 For the cross-reference format, see `help-make-xrefs'."
1416 (or (and (not (= pos (point-max)))
1417 (get-text-property pos 'help-xref))
1418 (and (not (= pos (point-min)))
1419 (get-text-property (1- pos) 'help-xref))
1420 ;; check if the symbol under point is a function or variable
1424 (goto-char pos) (skip-syntax-backward "w_")
1425 (buffer-substring (point)
1426 (progn (skip-syntax-forward "w_")
1428 (when (or (boundp sym) (fboundp sym))
1429 (list #'help-xref-interned sym)))))
1430 (method (car help-data))
1431 (args (cdr help-data)))
1433 (setq help-xref-stack (cons (cons (cons pos (buffer-name))
1434 help-xref-stack-item)
1436 (setq help-xref-stack-item nil)
1437 ;; There is a reference at point. Follow it.
1438 (let ((help-xref-following t))
1439 (apply method args)))))
1441 ;; For tabbing through buffer.
1442 (defun help-next-ref ()
1443 "Find the next help cross-reference in the buffer."
1447 (if (get-text-property (point) 'help-xref) ; move off reference
1448 (goto-char (or (next-single-property-change (point) 'help-xref)
1450 (cond ((setq pos (next-single-property-change (point) 'help-xref))
1451 (if pos (goto-char pos)))
1453 (message "No cross references in the buffer.")
1456 (goto-char (point-min)))))))
1458 (defun help-previous-ref ()
1459 "Find the previous help cross-reference in the buffer."
1463 (if (get-text-property (point) 'help-xref) ; move off reference
1464 (goto-char (or (previous-single-property-change (point) 'help-xref)
1466 (cond ((setq pos (previous-single-property-change (point) 'help-xref))
1467 (if pos (goto-char pos)))
1469 (message "No cross references in the buffer.")
1472 (goto-char (point-max)))))))
1475 ;;; Automatic resizing of temporary buffers.
1477 (defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2))
1478 "*Maximum height of a window displaying a temporary buffer.
1479 This is the maximum height (in text lines) which `resize-temp-buffer-window'
1480 will give to a window displaying a temporary buffer.
1481 It can also be a function which will be called with the object corresponding
1482 to the buffer to be displayed as argument and should return an integer
1484 :type '(choice integer function)
1488 (define-minor-mode temp-buffer-resize-mode
1489 "Toggle the mode which makes windows smaller for temporary buffers.
1490 With prefix argument ARG, turn the resizing of windows displaying temporary
1491 buffers on if ARG is positive or off otherwise.
1492 This makes the window the right height for its contents, but never
1493 more than `temp-buffer-max-height' nor less than `window-min-height'.
1494 This applies to `help', `apropos' and `completion' buffers, and some others."
1495 nil nil nil :global t :group 'help
1496 (if temp-buffer-resize-mode
1497 ;; `help-make-xrefs' may add a `back' button and thus increase the
1498 ;; text size, so `resize-temp-buffer-window' must be run *after* it.
1499 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
1500 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)))
1502 (defun resize-temp-buffer-window ()
1503 "Resize the current window to fit its contents.
1504 Will not make it higher than `temp-buffer-max-height' nor smaller than
1505 `window-min-height'. Do nothing if it is the only window on its frame, if it
1506 is not as wide as the frame or if some of the window's contents are scrolled
1508 (unless (or (one-window-p 'nomini)
1509 (not (pos-visible-in-window-p (point-min)))
1510 (/= (frame-width) (window-width)))
1511 (fit-window-to-buffer
1513 (if (functionp temp-buffer-max-height)
1514 (funcall temp-buffer-max-height (current-buffer))
1515 temp-buffer-max-height))))
1517 ;; `help-manyarg-func-alist' is defined primitively (in doc.c).
1518 ;; New primitives with `MANY' or `UNEVALLED' arglists should be added
1520 ;; The parens and function name are redundant, but it's messy to add
1521 ;; them in `documentation'.
1523 ;; This will find any missing items:
1525 ;; (mapatoms (lambda (x)
1526 ;; (if (and (fboundp x)
1527 ;; (subrp (symbol-function x))
1528 ;; (not (numberp (cdr (subr-arity (symbol-function x)))))
1529 ;; (not (assq x help-manyarg-func-alist)))
1532 (defconst help-manyarg-func-alist
1534 '((list . "(list &rest OBJECTS)")
1535 (vector . "(vector &rest OBJECTS)")
1536 (make-byte-code . "(make-byte-code &rest ELEMENTS)")
1538 . "(call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)")
1539 (call-process-region
1540 . "(call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS)")
1541 (string . "(string &rest CHARACTERS)")
1542 (+ . "(+ &rest NUMBERS-OR-MARKERS)")
1543 (- . "(- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS)")
1544 (* . "(* &rest NUMBERS-OR-MARKERS)")
1545 (/ . "(/ DIVIDEND DIVISOR &rest DIVISORS)")
1546 (max . "(max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS)")
1547 (min . "(min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS)")
1548 (logand . "(logand &rest INTS-OR-MARKERS)")
1549 (logior . "(logior &rest INTS-OR-MARKERS)")
1550 (logxor . "(logxor &rest INTS-OR-MARKERS)")
1552 . "(encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE)")
1553 (insert . "(insert &rest ARGS)")
1554 (insert-and-inherit . "(insert-and-inherit &rest ARGS)")
1555 (insert-before-markers . "(insert-before-markers &rest ARGS)")
1556 (message . "(message STRING &rest ARGUMENTS)")
1557 (message-box . "(message-box STRING &rest ARGUMENTS)")
1558 (message-or-box . "(message-or-box STRING &rest ARGUMENTS)")
1559 (propertize . "(propertize STRING &rest PROPERTIES)")
1560 (format . "(format STRING &rest OBJECTS)")
1561 (apply . "(apply FUNCTION &rest ARGUMENTS)")
1562 (run-hooks . "(run-hooks &rest HOOKS)")
1563 (run-hook-with-args . "(run-hook-with-args HOOK &rest ARGS)")
1564 (run-hook-with-args-until-failure
1565 . "(run-hook-with-args-until-failure HOOK &rest ARGS)")
1566 (run-hook-with-args-until-success
1567 . "(run-hook-with-args-until-success HOOK &rest ARGS)")
1568 (funcall . "(funcall FUNCTION &rest ARGUMENTS)")
1569 (append . "(append &rest SEQUENCES)")
1570 (concat . "(concat &rest SEQUENCES)")
1571 (vconcat . "(vconcat &rest SEQUENCES)")
1572 (nconc . "(nconc &rest LISTS)")
1573 (widget-apply . "(widget-apply WIDGET PROPERTY &rest ARGS)")
1574 (make-hash-table . "(make-hash-table &rest KEYWORD-ARGS)")
1575 (insert-string . "(insert-string &rest ARGS)")
1576 (start-process . "(start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)")
1577 (setq-default . "(setq-default SYMBOL VALUE [SYMBOL VALUE...])")
1578 (save-excursion . "(save-excursion &rest BODY)")
1579 (save-current-buffer . "(save-current-buffer &rest BODY)")
1580 (save-restriction . "(save-restriction &rest BODY)")
1581 (or . "(or CONDITIONS ...)")
1582 (and . "(and CONDITIONS ...)")
1583 (if . "(if COND THEN ELSE...)")
1584 (cond . "(cond CLAUSES...)")
1585 (progn . "(progn BODY ...)")
1586 (prog1 . "(prog1 FIRST BODY...)")
1587 (prog2 . "(prog2 X Y BODY...)")
1588 (setq . "(setq SYM VAL SYM VAL ...)")
1589 (quote . "(quote ARG)")
1590 (function . "(function ARG)")
1591 (defun . "(defun NAME ARGLIST [DOCSTRING] BODY...)")
1592 (defmacro . "(defmacro NAME ARGLIST [DOCSTRING] BODY...)")
1593 (defvar . "(defvar SYMBOL [INITVALUE DOCSTRING])")
1594 (defconst . "(defconst SYMBOL INITVALUE [DOCSTRING])")
1595 (let* . "(let* VARLIST BODY...)")
1596 (let . "(let VARLIST BODY...)")
1597 (while . "(while TEST BODY...)")
1598 (catch . "(catch TAG BODY...)")
1599 (unwind-protect . "(unwind-protect BODYFORM UNWINDFORMS...)")
1600 (condition-case . "(condition-case VAR BODYFORM HANDLERS...)")
1601 (track-mouse . "(track-mouse BODY ...)")
1602 (ml-if . "(ml-if COND THEN ELSE...)")
1603 (ml-provide-prefix-argument . "(ml-provide-prefix-argument ARG1 ARG2)")
1604 (ml-prefix-argument-loop . "(ml-prefix-argument-loop ...)")
1605 (with-output-to-temp-buffer
1606 . "(with-output-to-temp-buffer BUFFNAME BODY ...)")
1607 (save-window-excursion . "(save-window-excursion BODY ...)")
1608 (find-operation-coding-system
1609 . "(find-operation-coding-system OPERATION ARGUMENTS ...)")
1610 (insert-before-markers-and-inherit
1611 . "(insert-before-markers-and-inherit &rest ARGS)"))))
1613 ;; Provide this for the sake of define-minor-mode which generates
1614 ;; defcustoms which require 'help'.
1618 ;;; help.el ends here