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)
713 (help-xref-button 1 #'(lambda (arg)
715 (find-function-noselect arg)))
716 (pop-to-buffer (car location))
717 (goto-char (cdr location))))
719 "mouse-2, RET: find function's definition")))))
720 (if need-close (princ ")"))
723 ;; Handle symbols aliased to other symbols.
724 (setq def (indirect-function def))
725 ;; If definition is a macro, find the function inside it.
726 (if (eq (car-safe def) 'macro)
727 (setq def (cdr def)))
728 (let ((arglist (cond ((byte-code-function-p def)
729 (car (append def nil)))
730 ((eq (car-safe def) 'lambda)
732 ((and (eq (car-safe def) 'autoload)
733 (not (eq (nth 4 def) 'keymap)))
734 (concat "[Arg list not available until "
735 "function definition is loaded.]"))
737 (cond ((listp arglist)
738 (princ (cons (if (symbolp function) function "anonymous")
739 (mapcar (lambda (arg)
740 (if (memq arg '(&optional &rest))
742 (intern (upcase (symbol-name arg)))))
748 (let ((doc (documentation function)))
752 (if (subrp (symbol-function function))
753 (with-current-buffer standard-output
755 ;; Builtins get the calling sequence at the end of
756 ;; the doc string. Move it to the same place as
757 ;; for other functions.
759 ;; In cases where `function' has been fset to a
760 ;; subr we can't search for function's name in
761 ;; the doc string. Kluge round that using the
762 ;; printed representation. The arg list then
763 ;; shows the wrong function name, but that
764 ;; might be a useful hint.
765 (let* ((rep (prin1-to-string def))
767 (string-match " \\([^ ]+\\)>$" rep)
768 (match-string 1 rep))))
769 (if (looking-at (format "(%s[ )]" (regexp-quote name)))
770 (let ((start (point-marker)))
771 (goto-char (point-min))
773 (insert-buffer-substring (current-buffer) start)
775 (delete-region (1- start) (point-max)))
776 (goto-char (point-min))
779 "[Missing arglist. Please make a bug report.]\n")))
780 (goto-char (point-max))))
781 (help-setup-xref (list #'describe-function function)
783 (princ "not documented")))))
785 (defun variable-at-point ()
786 "Return the bound variable symbol found around point.
787 Return 0 if there is no such symbol."
789 (with-syntax-table emacs-lisp-mode-syntax-table
791 (or (not (zerop (skip-syntax-backward "_w")))
792 (eq (char-syntax (following-char)) ?w)
793 (eq (char-syntax (following-char)) ?_)
795 (skip-chars-forward "'")
796 (let ((obj (read (current-buffer))))
797 (or (and (symbolp obj) (boundp obj) obj)
801 (defun help-xref-on-pp (from to)
802 "Add xrefs for symbols in `pp's output between FROM and TO."
803 (let ((ost (syntax-table)))
807 (set-syntax-table emacs-lisp-mode-syntax-table)
808 (narrow-to-region from to)
809 (goto-char (point-min))
812 ((looking-at "\"") (forward-sexp 1))
813 ((looking-at "#<") (search-forward ">" nil 'move))
814 ((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)")
815 (let* ((sym (intern-soft (match-string 1)))
816 (fn (cond ((fboundp sym) #'describe-function)
817 ((or (memq sym '(t nil))
820 ((and sym (boundp sym))
821 #'describe-variable))))
822 (when fn (help-xref-button 1 fn sym)))
823 (goto-char (match-end 1)))
824 (t (forward-char 1))))))
825 (set-syntax-table ost))))
827 (defun describe-variable (variable &optional buffer)
828 "Display the full documentation of VARIABLE (a symbol).
829 Returns the documentation as a string, also.
830 If VARIABLE has a buffer-local value in BUFFER (default to the current buffer),
831 it is displayed along with the global value."
833 (let ((v (variable-at-point))
834 (enable-recursive-minibuffers t)
836 (setq val (completing-read (if (symbolp v)
838 "Describe variable (default %s): " v)
839 "Describe variable: ")
840 obarray 'boundp t nil nil
841 (if (symbolp v) (symbol-name v))))
842 (list (if (equal val "")
844 (unless (bufferp buffer) (setq buffer (current-buffer)))
845 (if (not (symbolp variable))
846 (message "You did not specify a variable")
848 (with-current-buffer buffer
849 (with-output-to-temp-buffer "*Help*"
851 (if (not (boundp variable))
855 (let ((val (symbol-value variable)))
856 (with-current-buffer standard-output
857 (princ "'s value is ")
859 (let ((from (point)))
861 (help-xref-on-pp from (point))))))
863 (if (local-variable-p variable)
865 (princ (format "Local in buffer %s; " (buffer-name)))
866 (if (not (default-boundp variable))
867 (princ "globally void")
868 (let ((val (default-value variable)))
869 (with-current-buffer standard-output
870 (princ "global value is ")
872 ;; Fixme: pp can take an age if you happen to
873 ;; ask for a very large expression. We should
874 ;; probably print it raw once and check it's a
875 ;; sensible size before prettyprinting. -- fx
876 (let ((from (point)))
878 (help-xref-on-pp from (point))))))
881 (with-current-buffer standard-output
882 (if (> (count-lines (point-min) (point-max)) 10)
884 ;; Note that setting the syntax table like below
885 ;; makes forward-sexp move over a `'s' at the end
887 (set-syntax-table emacs-lisp-mode-syntax-table)
888 (goto-char (point-min))
892 (delete-region (point) (progn (end-of-line) (point)))
893 (insert " value is shown below.\n\n")
895 (insert "\n\nValue:"))))))
896 (princ "Documentation:")
898 (let ((doc (documentation-property variable 'variable-documentation)))
899 (princ (or doc "not documented as a variable.")))
900 (help-setup-xref (list #'describe-variable variable (current-buffer))
903 ;; Make a link to customize if this variable can be customized.
904 ;; Note, it is not reliable to test only for a custom-type property
905 ;; because those are only present after the var's definition
907 (if (or (get variable 'custom-type) ; after defcustom
908 (get variable 'custom-loads) ; from loaddefs.el
909 (get variable 'standard-value)) ; from cus-start.el
910 (let ((customize-label "customize"))
913 (princ (concat "You can " customize-label " this variable."))
914 (with-current-buffer "*Help*"
917 (concat "\\(" customize-label "\\)") nil t)
918 (help-xref-button 1 (lambda (v)
920 (pop help-xref-stack))
921 (customize-variable v))
923 "mouse-2, RET: customize variable")))))
924 ;; Make a hyperlink to the library if appropriate. (Don't
925 ;; change the format of the buffer's initial line in case
926 ;; anything expects the current format.)
927 (let ((file-name (symbol-file variable)))
929 (princ "\n\nDefined in `")
932 (with-current-buffer "*Help*"
934 (re-search-backward "`\\([^`']+\\)'" nil t)
938 (find-variable-noselect arg)))
939 (pop-to-buffer (car location))
940 (goto-char (cdr location))))
941 variable "mouse-2, RET: find variable's definition")))))
943 (print-help-return-message)
945 (set-buffer standard-output)
946 ;; Return the text we displayed.
947 (buffer-string)))))))
949 (defun describe-bindings (&optional prefix buffer)
950 "Show a list of all defined keys, and their definitions.
951 We put that list in a buffer, and display the buffer.
953 The optional argument PREFIX, if non-nil, should be a key sequence;
954 then we display only bindings that start with that prefix.
955 The optional argument BUFFER specifies which buffer's bindings
956 to display (default, the current buffer)."
958 (or buffer (setq buffer (current-buffer)))
959 (with-current-buffer buffer
960 (describe-bindings-internal nil prefix))
961 (with-current-buffer "*Help*"
962 (help-setup-xref (list #'describe-bindings prefix buffer)
965 (defun where-is (definition &optional insert)
966 "Print message listing key sequences that invoke the command DEFINITION.
967 Argument is a command definition, usually a symbol with a function definition.
968 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
970 (let ((fn (function-called-at-point))
971 (enable-recursive-minibuffers t)
973 (setq val (completing-read (if fn
974 (format "Where is command (default %s): " fn)
975 "Where is command: ")
976 obarray 'commandp t))
977 (list (if (equal val "")
979 current-prefix-arg)))
980 (let* ((keys (where-is-internal definition overriding-local-map nil nil))
981 (keys1 (mapconcat 'key-description keys ", "))
982 (standard-output (if insert (current-buffer) t)))
984 (if (> (length keys1) 0)
985 (princ (format "%s (%s)" keys1 definition))
986 (princ (format "M-x %s RET" definition)))
987 (if (> (length keys1) 0)
988 (princ (format "%s is on %s" definition keys1))
989 (princ (format "%s is not on any key" definition)))))
992 (defun locate-library (library &optional nosuffix path interactive-call)
993 "Show the precise file name of Emacs library LIBRARY.
994 This command searches the directories in `load-path' like `M-x load-library'
995 to find the file that `M-x load-library RET LIBRARY RET' would load.
996 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
997 to the specified name LIBRARY.
999 If the optional third arg PATH is specified, that list of directories
1000 is used instead of `load-path'.
1002 When called from a program, the file name is normaly returned as a
1003 string. When run interactively, the argument INTERACTIVE-CALL is t,
1004 and the file name is displayed in the echo area."
1005 (interactive (list (read-string "Locate library: ")
1014 (let ((try (expand-file-name (concat library suf) dir)))
1015 (and (file-readable-p try)
1016 (null (file-directory-p try))
1019 (throw 'answer try)))))
1023 ;;; load doesn't handle this yet.
1024 ;;; (let ((basic '(".elc" ".el" ""))
1025 ;;; (compressed '(".Z" ".gz" "")))
1026 ;;; ;; If autocompression mode is on,
1027 ;;; ;; consider all combinations of library suffixes
1028 ;;; ;; and compression suffixes.
1029 ;;; (if (rassq 'jka-compr-handler file-name-handler-alist)
1031 ;;; (mapcar (lambda (compelt)
1032 ;;; (mapcar (lambda (baselt)
1033 ;;; (concat baselt compelt))
1038 (or path load-path)))
1039 (and interactive-call
1041 (message "Library is file %s" result)
1042 (message "No library %s in search path" library)))
1046 ;;; Grokking cross-reference information in doc strings and
1047 ;;; hyperlinking it.
1049 ;; This may have some scope for extension and the same or something
1050 ;; similar should be done for widget doc strings, which currently use
1051 ;; another mechanism.
1053 (defcustom help-highlight-p t
1054 "*If non-nil, `help-make-xrefs' highlight cross-references.
1055 Under a window system it highlights them with face defined by
1056 `help-highlight-face'."
1061 (defcustom help-highlight-face 'underline
1062 "Face used by `help-make-xrefs' to highlight cross-references.
1063 Must be previously-defined."
1068 (defvar help-back-label (purecopy "[back]")
1069 "Label to use by `help-make-xrefs' for the go-back reference.")
1071 (defconst help-xref-symbol-regexp
1072 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|"
1073 "\\(function\\|command\\)\\|"
1075 "\\(symbol\\)\\)\\s-+\\)?"
1076 ;; Note starting with word-syntax character:
1077 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'"))
1078 "Regexp matching doc string references to symbols.
1080 The words preceding the quoted symbol can be used in doc strings to
1081 distinguish references to variables, functions and symbols.")
1083 (defconst help-xref-mule-regexp nil
1084 "Regexp matching doc string references to MULE-related keywords.
1086 It is usually nil, and is temporarily bound to an appropriate regexp
1087 when help commands related to multilingual environment (e.g.,
1088 `describe-coding-system') are invoked.")
1091 (defconst help-xref-info-regexp
1092 (purecopy "\\<[Ii]nfo[ \t\n]+node[ \t\n]+`\\([^']+\\)'")
1093 "Regexp matching doc string references to an Info node.")
1095 (defun help-setup-xref (item interactive-p)
1096 "Invoked from commands using the \"*Help*\" buffer to install some xref info.
1098 ITEM is a (FUNCTION . ARGS) pair appropriate for recreating the help
1099 buffer after following a reference. INTERACTIVE-P is non-nil if the
1100 calling command was invoked interactively. In this case the stack of
1101 items for help buffer \"back\" buttons is cleared."
1103 (setq help-xref-stack nil))
1104 (setq help-xref-stack-item item))
1106 (defvar help-xref-following nil
1107 "Non-nil when following a help cross-reference.")
1109 (defun help-make-xrefs (&optional buffer)
1110 "Parse and hyperlink documentation cross-references in the given BUFFER.
1112 Find cross-reference information in a buffer and, if
1113 `help-highlight-p' is non-nil, highlight it with face defined by
1114 `help-highlight-face'; activate such cross references for selection
1115 with `help-follow'. Cross-references have the canonical form `...'
1116 and the type of reference may be disambiguated by the preceding
1117 word(s) used in `help-xref-symbol-regexp'.
1119 If the variable `help-xref-mule-regexp' is non-nil, find also
1120 cross-reference information related to multilingual environment
1121 \(e.g., coding-systems). This variable is also used to disambiguate
1122 the type of reference as the same way as `help-xref-symbol-regexp'.
1124 A special reference `back' is made to return back through a stack of
1125 help buffers. Variable `help-back-label' specifies the text for
1129 (set-buffer (or buffer (current-buffer)))
1130 (goto-char (point-min))
1131 ;; Skip the header-type info, though it might be useful to parse
1132 ;; it at some stage (e.g. "function in `library'").
1134 (let ((old-modified (buffer-modified-p)))
1135 (let ((stab (syntax-table))
1136 (case-fold-search t)
1137 (inhibit-read-only t))
1138 (set-syntax-table emacs-lisp-mode-syntax-table)
1139 ;; The following should probably be abstracted out.
1144 (while (re-search-forward help-xref-info-regexp nil t)
1145 (let ((data (match-string 1)))
1147 (unless (string-match "^([^)]+)" data)
1148 (setq data (concat "(emacs)" data))))
1149 (help-xref-button 1 #'info data
1150 "mouse-2, RET: read this Info node"))))
1151 ;; Mule related keywords. Do this before trying
1152 ;; `help-xref-symbol-regexp' because some of Mule
1153 ;; keywords have variable or function definitions.
1154 (if help-xref-mule-regexp
1156 (while (re-search-forward help-xref-mule-regexp nil t)
1157 (let* ((data (match-string 7))
1158 (sym (intern-soft data)))
1160 ((match-string 3) ; coding system
1161 (and sym (coding-system-p sym)
1163 7 #'describe-coding-system sym
1164 "mouse-2, RET: describe this coding system")))
1165 ((match-string 4) ; input method
1166 (and (assoc data input-method-alist)
1168 7 #'describe-input-method data
1169 "mouse-2, RET: describe this input method")))
1170 ((or (match-string 5) (match-string 6)) ; charset
1171 (and sym (charsetp sym)
1173 7 #'describe-character-set sym
1174 "mouse-2, RET: describe this character set")))
1175 ((assoc data input-method-alist)
1177 7 #'describe-input-method data
1178 "mouse-2, RET: describe this input method"))
1179 ((and sym (coding-system-p sym))
1181 7 #'describe-coding-system sym
1182 "mouse-2, RET: describe this coding system"))
1183 ((and sym (charsetp sym))
1185 7 #'describe-character-set sym
1186 "mouse-2, RET: describe this character set")))))))
1189 (while (re-search-forward help-xref-symbol-regexp nil t)
1190 (let* ((data (match-string 7))
1191 (sym (intern-soft data)))
1194 ((match-string 3) ; `variable' &c
1195 (and (boundp sym) ; `variable' doesn't ensure
1196 ; it's actually bound
1198 7 #'describe-variable sym
1199 "mouse-2, RET: describe this variable")))
1200 ((match-string 4) ; `function' &c
1201 (and (fboundp sym) ; similarly
1203 7 #'describe-function sym
1204 "mouse-2, RET: describe this function")))
1205 ((match-string 5) ; `face'
1207 (help-xref-button 7 #'describe-face sym
1208 "mouse-2, RET: describe this face")))
1209 ((match-string 6)) ; nothing for symbol
1210 ((and (boundp sym) (fboundp sym))
1211 ;; We can't intuit whether to use the
1212 ;; variable or function doc -- supply both.
1214 7 #'help-xref-interned sym
1215 "mouse-2, RET: describe this symbol"))
1218 7 #'describe-variable sym
1219 "mouse-2, RET: describe this variable"))
1222 7 #'describe-function sym
1223 "mouse-2, RET: describe this function"))
1226 7 #'describe-face sym)))))))
1227 ;; An obvious case of a key substitution:
1229 (while (re-search-forward
1230 ;; Assume command name is only word characters
1231 ;; and dashes to get things like `use M-x foo.'.
1232 "\\<M-x\\s-+\\(\\sw\\(\\sw\\|-\\)+\\)" nil t)
1233 (let ((sym (intern-soft (match-string 1))))
1236 1 #'describe-function sym
1237 "mouse-2, RET: describe this command")))))
1238 ;; Look for commands in whole keymap substitutions:
1240 ;; Make sure to find the first keymap.
1241 (goto-char (point-min))
1242 ;; Find a header and the column at which the command
1243 ;; name will be found.
1244 (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n"
1246 (let ((col (- (match-end 1) (match-beginning 1))))
1248 ;; Ignore single blank lines in table, but not
1249 ;; double ones, which should terminate it.
1250 (and (not (looking-at "\n\\s-*\n"))
1252 (and (eolp) (forward-line))
1254 (skip-chars-backward "^\t\n")
1255 (if (and (>= (current-column) col)
1256 (looking-at "\\(\\sw\\|-\\)+$"))
1257 (let ((sym (intern-soft (match-string 0))))
1260 0 #'describe-function sym
1261 "mouse-2, RET: describe this function"))))
1262 (zerop (forward-line)))))))))
1263 (set-syntax-table stab))
1264 ;; Delete extraneous newlines at the end of the docstring
1265 (goto-char (point-max))
1266 (while (and (not (bobp)) (bolp))
1268 ;; Make a back-reference in this buffer if appropriate.
1269 (when (and help-xref-following help-xref-stack)
1271 (insert "\n\n" help-back-label))
1272 ;; Just to provide the match data:
1273 (looking-at (concat "\n\n\\(" (regexp-quote help-back-label) "\\)"))
1274 (help-xref-button 1 #'help-xref-go-back (current-buffer))))
1275 ;; View mode steals RET from us.
1276 (set (make-local-variable 'minor-mode-overriding-map-alist)
1277 (list (cons 'view-mode
1278 (let ((map (make-sparse-keymap)))
1279 (set-keymap-parent map view-mode-map)
1280 (define-key map "\r" 'help-follow)
1282 (set-buffer-modified-p old-modified))))
1284 (defun help-xref-button (match-number function data &optional help-echo)
1285 "Make a hyperlink for cross-reference text previously matched.
1287 MATCH-NUMBER is the subexpression of interest in the last matched
1288 regexp. FUNCTION is a function to invoke when the button is
1289 activated, applied to DATA. DATA may be a single value or a list.
1290 See `help-make-xrefs'.
1291 If optional arg HELP-ECHO is supplied, it is used as a help string."
1292 ;; Don't mung properties we've added specially in some instances.
1293 (unless (get-text-property (match-beginning match-number) 'help-xref)
1294 (add-text-properties (match-beginning match-number)
1295 (match-end match-number)
1296 (list 'mouse-face 'highlight
1297 'help-xref (cons function
1302 (put-text-property (match-beginning match-number)
1303 (match-end match-number)
1304 'help-echo help-echo))
1305 (if help-highlight-p
1306 (put-text-property (match-beginning match-number)
1307 (match-end match-number)
1308 'face help-highlight-face))))
1310 (defun help-insert-xref-button (string function data &optional help-echo)
1311 "Insert STRING and make a hyperlink from cross-reference text on it.
1313 FUNCTION is a function to invoke when the button is activated, applied
1314 to DATA. DATA may be a single value or a list. See `help-make-xrefs'.
1315 If optional arg HELP-ECHO is supplied, it is used as a help string."
1316 (let ((pos (point)))
1319 (search-forward string)
1320 (help-xref-button 0 function data help-echo)))
1324 ;; Additional functions for (re-)creating types of help buffers.
1325 (defun help-xref-interned (symbol)
1326 "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL.
1328 Both variable and function documentation are extracted into a single
1330 (let ((fdoc (when (fboundp symbol) (describe-function symbol)))
1331 (facedoc (when (facep symbol) (describe-face symbol))))
1332 (when (or (boundp symbol) (not fdoc))
1333 (describe-variable symbol)
1334 ;; We now have a help buffer on the variable. Insert the function
1336 (when (or fdoc facedoc)
1337 (with-current-buffer "*Help*"
1338 (goto-char (point-min))
1339 (let ((inhibit-read-only t))
1341 (insert fdoc "\n\n"))
1343 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
1344 " is also a " "face." "\n\n" facedoc "\n\n"))
1345 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
1346 " is also a " "variable." "\n\n"))
1347 (help-setup-xref (list #'help-xref-interned symbol) nil))))))
1349 (defun help-xref-mode (buffer)
1350 "Do a `describe-mode' for the specified BUFFER."
1355 ;;; Navigation/hyperlinking with xrefs
1357 (defun help-follow-mouse (click)
1358 "Follow the cross-reference that you click on."
1360 (let* ((start (event-start click))
1361 (window (car start))
1362 (pos (car (cdr start))))
1363 (with-current-buffer (window-buffer window)
1364 (help-follow pos))))
1366 (defun help-xref-go-back (buffer)
1367 "From BUFFER, go back to previous help buffer text using `help-xref-stack'."
1368 (let (item position method args)
1369 (with-current-buffer buffer
1370 (when help-xref-stack
1371 (setq help-xref-stack (cdr help-xref-stack)) ; due to help-follow
1372 (setq item (pop help-xref-stack)
1377 ;; We assume that the buffer we just recreated has the saved name,
1378 ;; which might not always be true.
1379 (when (get-buffer (cdr position))
1380 (with-current-buffer (cdr position)
1381 (goto-char (car position))))))
1383 (defun help-go-back ()
1384 "Invoke the [back] button (if any) in the Help mode buffer."
1386 (help-follow (1- (point-max))))
1388 (defun help-follow (&optional pos)
1389 "Follow cross-reference at POS, defaulting to point.
1391 For the cross-reference format, see `help-make-xrefs'."
1396 (or (and (not (= pos (point-max)))
1397 (get-text-property pos 'help-xref))
1398 (and (not (= pos (point-min)))
1399 (get-text-property (1- pos) 'help-xref))
1400 ;; check if the symbol under point is a function or variable
1404 (goto-char pos) (skip-syntax-backward "w_")
1405 (buffer-substring (point)
1406 (progn (skip-syntax-forward "w_")
1408 (when (or (boundp sym) (fboundp sym))
1409 (list #'help-xref-interned sym)))))
1410 (method (car help-data))
1411 (args (cdr help-data)))
1413 (setq help-xref-stack (cons (cons (cons pos (buffer-name))
1414 help-xref-stack-item)
1416 (setq help-xref-stack-item nil)
1417 ;; There is a reference at point. Follow it.
1418 (let ((help-xref-following t))
1419 (apply method args)))))
1421 ;; For tabbing through buffer.
1422 (defun help-next-ref ()
1423 "Find the next help cross-reference in the buffer."
1427 (if (get-text-property (point) 'help-xref) ; move off reference
1428 (goto-char (or (next-single-property-change (point) 'help-xref)
1430 (cond ((setq pos (next-single-property-change (point) 'help-xref))
1431 (if pos (goto-char pos)))
1433 (message "No cross references in the buffer.")
1436 (goto-char (point-min)))))))
1438 (defun help-previous-ref ()
1439 "Find the previous help cross-reference in the buffer."
1443 (if (get-text-property (point) 'help-xref) ; move off reference
1444 (goto-char (or (previous-single-property-change (point) 'help-xref)
1446 (cond ((setq pos (previous-single-property-change (point) 'help-xref))
1447 (if pos (goto-char pos)))
1449 (message "No cross references in the buffer.")
1452 (goto-char (point-max)))))))
1455 ;;; Automatic resizing of temporary buffers.
1457 (defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2))
1458 "*Maximum height of a window displaying a temporary buffer.
1459 This is the maximum height (in text lines) which `resize-temp-buffer-window'
1460 will give to a window displaying a temporary buffer.
1461 It can also be a function which will be called with the object corresponding
1462 to the buffer to be displayed as argument and should return an integer
1464 :type '(choice integer function)
1468 (define-minor-mode temp-buffer-resize-mode
1469 "Toggle the mode which makes windows smaller for temporary buffers.
1470 With prefix argument ARG, turn the resizing of windows displaying temporary
1471 buffers on if ARG is positive or off otherwise.
1472 This makes the window the right height for its contents, but never
1473 more than `temp-buffer-max-height' nor less than `window-min-height'.
1474 This applies to `help', `apropos' and `completion' buffers, and some others."
1475 nil nil nil :global t :group 'help
1476 (if temp-buffer-resize-mode
1477 ;; `help-make-xrefs' may add a `back' button and thus increase the
1478 ;; text size, so `resize-temp-buffer-window' must be run *after* it.
1479 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
1480 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)))
1482 (defun resize-temp-buffer-window ()
1483 "Resize the current window to fit its contents.
1484 Will not make it higher than `temp-buffer-max-height' nor smaller than
1485 `window-min-height'. Do nothing if it is the only window on its frame, if it
1486 is not as wide as the frame or if some of the window's contents are scrolled
1488 (unless (or (one-window-p 'nomini)
1489 (not (pos-visible-in-window-p (point-min)))
1490 (/= (frame-width) (window-width)))
1491 (fit-window-to-buffer
1493 (if (functionp temp-buffer-max-height)
1494 (funcall temp-buffer-max-height (current-buffer))
1495 temp-buffer-max-height))))
1497 ;; `help-manyarg-func-alist' is defined primitively (in doc.c).
1498 ;; New primitives with `MANY' or `UNEVALLED' arglists should be added
1500 ;; The parens and function name are redundant, but it's messy to add
1501 ;; them in `documentation'.
1503 ;; This will find any missing items:
1505 ;; (mapatoms (lambda (x)
1506 ;; (if (and (fboundp x)
1507 ;; (subrp (symbol-function x))
1508 ;; (not (numberp (cdr (subr-arity (symbol-function x)))))
1509 ;; (not (assq x help-manyarg-func-alist)))
1512 (defconst help-manyarg-func-alist
1514 '((list . "(list &rest OBJECTS)")
1515 (vector . "(vector &rest OBJECTS)")
1516 (make-byte-code . "(make-byte-code &rest ELEMENTS)")
1518 . "(call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)")
1519 (call-process-region
1520 . "(call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS)")
1521 (string . "(string &rest CHARACTERS)")
1522 (+ . "(+ &rest NUMBERS-OR-MARKERS)")
1523 (- . "(- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS)")
1524 (* . "(* &rest NUMBERS-OR-MARKERS)")
1525 (/ . "(/ DIVIDEND DIVISOR &rest DIVISORS)")
1526 (max . "(max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS)")
1527 (min . "(min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS)")
1528 (logand . "(logand &rest INTS-OR-MARKERS)")
1529 (logior . "(logior &rest INTS-OR-MARKERS)")
1530 (logxor . "(logxor &rest INTS-OR-MARKERS)")
1532 . "(encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE)")
1533 (insert . "(insert &rest ARGS)")
1534 (insert-and-inherit . "(insert-and-inherit &rest ARGS)")
1535 (insert-before-markers . "(insert-before-markers &rest ARGS)")
1536 (message . "(message STRING &rest ARGUMENTS)")
1537 (message-box . "(message-box STRING &rest ARGUMENTS)")
1538 (message-or-box . "(message-or-box STRING &rest ARGUMENTS)")
1539 (propertize . "(propertize STRING &rest PROPERTIES)")
1540 (format . "(format STRING &rest OBJECTS)")
1541 (apply . "(apply FUNCTION &rest ARGUMENTS)")
1542 (run-hooks . "(run-hooks &rest HOOKS)")
1543 (run-hook-with-args . "(run-hook-with-args HOOK &rest ARGS)")
1544 (run-hook-with-args-until-failure
1545 . "(run-hook-with-args-until-failure HOOK &rest ARGS)")
1546 (run-hook-with-args-until-success
1547 . "(run-hook-with-args-until-success HOOK &rest ARGS)")
1548 (funcall . "(funcall FUNCTION &rest ARGUMENTS)")
1549 (append . "(append &rest SEQUENCES)")
1550 (concat . "(concat &rest SEQUENCES)")
1551 (vconcat . "(vconcat &rest SEQUENCES)")
1552 (nconc . "(nconc &rest LISTS)")
1553 (widget-apply . "(widget-apply WIDGET PROPERTY &rest ARGS)")
1554 (make-hash-table . "(make-hash-table &rest KEYWORD-ARGS)")
1555 (insert-string . "(insert-string &rest ARGS)")
1556 (start-process . "(start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)")
1557 (setq-default . "(setq-default SYMBOL VALUE [SYMBOL VALUE...])")
1558 (save-excursion . "(save-excursion &rest BODY)")
1559 (save-current-buffer . "(save-current-buffer &rest BODY)")
1560 (save-restriction . "(save-restriction &rest BODY)")
1561 (or . "(or CONDITIONS ...)")
1562 (and . "(and CONDITIONS ...)")
1563 (if . "(if COND THEN ELSE...)")
1564 (cond . "(cond CLAUSES...)")
1565 (progn . "(progn BODY ...)")
1566 (prog1 . "(prog1 FIRST BODY...)")
1567 (prog2 . "(prog2 X Y BODY...)")
1568 (setq . "(setq SYM VAL SYM VAL ...)")
1569 (quote . "(quote ARG)")
1570 (function . "(function ARG)")
1571 (defun . "(defun NAME ARGLIST [DOCSTRING] BODY...)")
1572 (defmacro . "(defmacro NAME ARGLIST [DOCSTRING] BODY...)")
1573 (defvar . "(defvar SYMBOL [INITVALUE DOCSTRING])")
1574 (defconst . "(defconst SYMBOL INITVALUE [DOCSTRING])")
1575 (let* . "(let* VARLIST BODY...)")
1576 (let . "(let VARLIST BODY...)")
1577 (while . "(while TEST BODY...)")
1578 (catch . "(catch TAG BODY...)")
1579 (unwind-protect . "(unwind-protect BODYFORM UNWINDFORMS...)")
1580 (condition-case . "(condition-case VAR BODYFORM HANDLERS...)")
1581 (track-mouse . "(track-mouse BODY ...)")
1582 (ml-if . "(ml-if COND THEN ELSE...)")
1583 (ml-provide-prefix-argument . "(ml-provide-prefix-argument ARG1 ARG2)")
1584 (ml-prefix-argument-loop . "(ml-prefix-argument-loop ...)")
1585 (with-output-to-temp-buffer
1586 . "(with-output-to-temp-buffer BUFFNAME BODY ...)")
1587 (save-window-excursion . "(save-window-excursion BODY ...)")
1588 (find-operation-coding-system
1589 . "(find-operation-coding-system OPERATION ARGUMENTS ...)")
1590 (insert-before-markers-and-inherit
1591 . "(insert-before-markers-and-inherit &rest ARGS)"))))
1593 ;; Provide this for the sake of define-minor-mode which generates
1594 ;; defcustoms which require 'help'.
1598 ;;; help.el ends here