Fix previous change.
[bpt/emacs.git] / lisp / help.el
CommitLineData
1a06eabd
ER
1;;; help.el --- help commands for Emacs
2
754084bb
GM
3;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001
4;; Free Software Foundation, Inc.
3a801d0c 5
e5167999 6;; Maintainer: FSF
fd7fa35a 7;; Keywords: help, internal
e5167999 8
433ae6f6
RS
9;; This file is part of GNU Emacs.
10
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
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
433ae6f6
RS
14;; any later version.
15
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.
20
21;; You should have received a copy of the GNU General Public License
b578f267
EN
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.
433ae6f6 25
d9ecc911
ER
26;;; Commentary:
27
a1c9f209 28;; This code implements GNU Emacs' on-line help system, the one invoked by
95ac0a6f 29;; `M-x help-for-help'.
d9ecc911 30
e5167999
ER
31;;; Code:
32
8aa3a187
RS
33;; Get the macro make-help-screen when this is compiled,
34;; or run interpreted, but not when the compiled code is loaded.
b1fe9304 35(eval-when-compile (require 'help-macro))
788d62cf
MB
36
37;; This makes `with-output-to-temp-buffer' buffers use `help-mode'.
38(add-hook 'temp-buffer-setup-hook 'help-mode-setup)
39(add-hook 'temp-buffer-show-hook 'help-mode-finish)
41b8542b 40
433ae6f6
RS
41(defvar help-map (make-sparse-keymap)
42 "Keymap for characters following the Help key.")
43
e17d2fd1 44(define-key global-map (char-to-string help-char) 'help-command)
0af3df1c
RS
45(define-key global-map [help] 'help-command)
46(define-key global-map [f1] 'help-command)
433ae6f6
RS
47(fset 'help-command help-map)
48
e17d2fd1 49(define-key help-map (char-to-string help-char) 'help-for-help)
0af3df1c
RS
50(define-key help-map [help] 'help-for-help)
51(define-key help-map [f1] 'help-for-help)
433ae6f6
RS
52(define-key help-map "?" 'help-for-help)
53
54(define-key help-map "\C-c" 'describe-copying)
55(define-key help-map "\C-d" 'describe-distribution)
4f16ea85
RS
56(define-key help-map "\C-e" 'view-emacs-problems)
57(define-key help-map "\C-f" 'view-emacs-FAQ)
58(define-key help-map "\C-h" 'view-hello-file)
59(define-key help-map "\C-m" 'view-order-manuals)
60(define-key help-map "\C-n" 'view-emacs-news)
76766f2d 61(define-key help-map "\C-p" 'describe-project)
4f16ea85
RS
62(define-key help-map "\C-w" 'describe-no-warranty)
63
64;; This does not fit the pattern, but it is natural given the C-\ command.
65(define-key help-map "\C-\\" 'describe-input-method)
66
67(define-key help-map "C" 'describe-coding-system)
68(define-key help-map "F" 'Info-goto-emacs-command-node)
69(define-key help-map "I" 'describe-input-method)
70(define-key help-map "K" 'Info-goto-emacs-key-command-node)
71(define-key help-map "L" 'describe-language-environment)
72(define-key help-map "S" 'info-lookup-symbol)
73
122955bf 74(define-key help-map "a" 'apropos-command)
433ae6f6
RS
75
76(define-key help-map "b" 'describe-bindings)
77
78(define-key help-map "c" 'describe-key-briefly)
433ae6f6 79
4f16ea85
RS
80(define-key help-map "e" 'view-echo-area-messages)
81
433ae6f6
RS
82(define-key help-map "f" 'describe-function)
83
4f16ea85 84(define-key help-map "h" 'view-hello-file)
7ee71cf1 85
433ae6f6 86(define-key help-map "i" 'info)
4b08b7ed 87(define-key help-map "4i" 'info-other-window)
4f16ea85
RS
88
89(define-key help-map "k" 'describe-key)
433ae6f6
RS
90
91(define-key help-map "l" 'view-lossage)
92
93(define-key help-map "m" 'describe-mode)
94
433ae6f6
RS
95(define-key help-map "n" 'view-emacs-news)
96
06b98c51 97(define-key help-map "p" 'finder-by-keyword)
3e9c095d
RS
98(autoload 'finder-by-keyword "finder"
99 "Find packages matching a given keyword." t)
06b98c51 100
433ae6f6
RS
101(define-key help-map "s" 'describe-syntax)
102
103(define-key help-map "t" 'help-with-tutorial)
104
105(define-key help-map "w" 'where-is)
106
107(define-key help-map "v" 'describe-variable)
108
2fc9d9f4
RS
109(define-key help-map "q" 'help-quit)
110
0cf0d828 111\f
2fc9d9f4 112(defun help-quit ()
3120a677 113 "Just exit from the Help command's command loop."
2fc9d9f4
RS
114 (interactive)
115 nil)
116
01364a75
RS
117(defvar help-return-method nil
118 "What to do to \"exit\" the help buffer.
119This is a list
120 (WINDOW . t) delete the selected window, go to WINDOW.
121 (WINDOW . quit-window) do quit-window, then select WINDOW.
122 (WINDOW BUF START POINT) display BUF at START, POINT, then select WINDOW.")
123
433ae6f6
RS
124(defun print-help-return-message (&optional function)
125 "Display or return message saying how to restore windows after help command.
126Computes a message and applies the optional argument FUNCTION to it.
127If FUNCTION is nil, applies `message' to it, thus printing it."
128 (and (not (get-buffer-window standard-output))
d536293f 129 (let ((first-message
a1c9f209 130 (cond ((special-display-p (buffer-name standard-output))
01364a75 131 (setq help-return-method (cons (selected-window) t))
d536293f
RS
132 ;; If the help output buffer is a special display buffer,
133 ;; don't say anything about how to get rid of it.
134 ;; First of all, the user will do that with the window
135 ;; manager, not with Emacs.
136 ;; Secondly, the buffer has not been displayed yet,
137 ;; so we don't know whether its frame will be selected.
d536293f 138 nil)
f3ad2fc8
GM
139 (display-buffer-reuse-frames
140 (setq help-return-method (cons (selected-window)
141 'quit-window))
142 nil)
d536293f 143 ((not (one-window-p t))
01364a75
RS
144 (setq help-return-method
145 (cons (selected-window) 'quit-window))
d536293f
RS
146 "Type \\[switch-to-buffer-other-window] RET to restore the other window.")
147 (pop-up-windows
01364a75 148 (setq help-return-method (cons (selected-window) t))
d536293f
RS
149 "Type \\[delete-other-windows] to remove help window.")
150 (t
01364a75
RS
151 (setq help-return-method
152 (list (selected-window) (window-buffer)
153 (window-start) (window-point)))
d536293f
RS
154 "Type \\[switch-to-buffer] RET to remove help window."))))
155 (funcall (or function 'message)
156 (concat
157 (if first-message
376b2a24
DL
158 (substitute-command-keys first-message))
159 (if first-message " ")
125a8d70
RS
160 ;; If the help buffer will go in a separate frame,
161 ;; it's no use mentioning a command to scroll, so don't.
a1c9f209 162 (if (special-display-p (buffer-name standard-output))
125a8d70 163 nil
a1c9f209 164 (if (same-window-p (buffer-name standard-output))
125a8d70
RS
165 ;; Say how to scroll this window.
166 (substitute-command-keys
167 "\\[scroll-up] to scroll the help.")
168 ;; Say how to scroll some other window.
6e7f5182 169 (substitute-command-keys
125a8d70 170 "\\[scroll-other-window] to scroll the help."))))))))
433ae6f6 171
433ae6f6
RS
172;; So keyboard macro definitions are documented correctly
173(fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
174
788d62cf
MB
175(defalias 'help 'help-for-help)
176(make-help-screen help-for-help
4f16ea85 177 "a b c C e f F C-f i I k C-k l L m p s t v w C-c C-d C-n C-p C-w or ? :"
788d62cf
MB
178 "You have typed %THIS-KEY%, the help character. Type a Help option:
179\(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
180
181a command-apropos. Give a substring, and see a list of commands
182 (functions interactively callable) that contain
183 that substring. See also the apropos command.
184b describe-bindings. Display table of all key bindings.
185c describe-key-briefly. Type a command key sequence;
186 it prints the function name that sequence runs.
187C describe-coding-system. This describes either a specific coding system
188 (if you type its name) or the coding systems currently in use
189 (if you type just RET).
4f16ea85 190e view-echo-area-messages. Show the `*Messages*' buffer.
788d62cf 191f describe-function. Type a function name and get documentation of it.
4f16ea85 192F Info-goto-emacs-command-node. Type a function name;
788d62cf
MB
193 it takes you to the Info node for that command.
194i info. The info documentation reader.
195I describe-input-method. Describe a specific input method (if you type
196 its name) or the current input method (if you type just RET).
788d62cf
MB
197k describe-key. Type a command key sequence;
198 it displays the full documentation.
4f16ea85 199K Info-goto-emacs-key-command-node. Type a command key sequence;
788d62cf
MB
200 it takes you to the Info node for the command bound to that key.
201l view-lossage. Show last 100 characters you typed.
202L describe-language-environment. This describes either a
203 specific language environment (if you type its name)
204 or the current language environment (if you type just RET).
205m describe-mode. Print documentation of current minor modes,
206 and the current major mode, including their special commands.
788d62cf
MB
207p finder-by-keyword. Find packages matching a given topic keyword.
208s describe-syntax. Display contents of syntax table, plus explanations.
4f16ea85
RS
209S info-lookup-symbol. Display the definition of a specific symbol
210 as found in the manual for the language this buffer is written in.
788d62cf
MB
211t help-with-tutorial. Select the Emacs learn-by-doing tutorial.
212v describe-variable. Type name of a variable;
213 it displays the variable's documentation and value.
214w where-is. Type command name; it prints which keystrokes
215 invoke that command.
216
4f16ea85 217C-c Display Emacs copying permission (GNU General Public License).
788d62cf 218C-d Display Emacs ordering information.
4f16ea85
RS
219C-e Display info about Emacs problems.
220C-f Display the Emacs FAQ.
221C-h Display the HELLO file which illustrates various scripts.
222C-m Display how to order printed Emacs manuals.
788d62cf
MB
223C-n Display news of recent Emacs changes.
224C-p Display information about the GNU project.
225C-w Display information on absence of warranty for GNU Emacs."
226 help-map)
227
228\f
229
230(defun function-called-at-point ()
231 "Return a function around point or else called by the list containing point.
232If that doesn't give a function, return nil."
233 (with-syntax-table emacs-lisp-mode-syntax-table
234 (or (condition-case ()
235 (save-excursion
236 (or (not (zerop (skip-syntax-backward "_w")))
237 (eq (char-syntax (following-char)) ?w)
238 (eq (char-syntax (following-char)) ?_)
239 (forward-sexp -1))
240 (skip-chars-forward "'")
241 (let ((obj (read (current-buffer))))
242 (and (symbolp obj) (fboundp obj) obj)))
243 (error nil))
244 (condition-case ()
245 (save-excursion
246 (save-restriction
247 (narrow-to-region (max (point-min)
248 (- (point) 1000)) (point-max))
249 ;; Move up to surrounding paren, then after the open.
250 (backward-up-list 1)
251 (forward-char 1)
252 ;; If there is space here, this is probably something
253 ;; other than a real Lisp function call, so ignore it.
254 (if (looking-at "[ \t]")
255 (error "Probably not a Lisp function call"))
256 (let ((obj (read (current-buffer))))
257 (and (symbolp obj) (fboundp obj) obj))))
258 (error nil)))))
259
260\f
261;;; `User' help functions
262
433ae6f6
RS
263(defun describe-distribution ()
264 "Display info on how to obtain the latest version of GNU Emacs."
265 (interactive)
64f3b7d3 266 (view-find (expand-file-name "DISTRIB" data-directory)))
433ae6f6
RS
267
268(defun describe-copying ()
269 "Display info on how you may redistribute copies of GNU Emacs."
270 (interactive)
64f3b7d3 271 (view-file (expand-file-name "COPYING" data-directory))
433ae6f6
RS
272 (goto-char (point-min)))
273
76766f2d
RS
274(defun describe-project ()
275 "Display info on the GNU project."
276 (interactive)
64f3b7d3 277 (view-file (expand-file-name "THE-GNU-PROJECT" data-directory))
76766f2d
RS
278 (goto-char (point-min)))
279
433ae6f6
RS
280(defun describe-no-warranty ()
281 "Display info on all the kinds of warranty Emacs does NOT have."
282 (interactive)
283 (describe-copying)
284 (let (case-fold-search)
285 (search-forward "NO WARRANTY")
286 (recenter 0)))
287
61c6b658 288(defun describe-prefix-bindings ()
c7cba9cb
RS
289 "Describe the bindings of the prefix used to reach this command.
290The prefix described consists of all but the last event
291of the key sequence that ran this command."
61c6b658 292 (interactive)
ccc06dcc
KH
293 (let* ((key (this-command-keys)))
294 (describe-bindings
295 (if (stringp key)
296 (substring key 0 (1- (length key)))
297 (let ((prefix (make-vector (1- (length key)) nil))
298 (i 0))
299 (while (< i (length prefix))
300 (aset prefix i (aref key i))
301 (setq i (1+ i)))
302 prefix)))))
788d62cf 303;; Make C-h after a prefix, when not specifically bound,
c7cba9cb 304;; run describe-prefix-bindings.
61c6b658
RS
305(setq prefix-help-command 'describe-prefix-bindings)
306
382d018a
RS
307(defun view-emacs-news (&optional arg)
308 "Display info on recent changes to Emacs.
f0753a5f 309With numeric argument, display information on correspondingly older changes."
382d018a 310 (interactive "P")
f0753a5f
GM
311 (let* ((arg (if arg (prefix-numeric-value arg) 0))
312 (file (cond ((eq arg 0) "NEWS")
313 ((eq arg 1) "ONEWS")
314 (t
315 (nth (- arg 2)
316 (nreverse (directory-files data-directory
975f82c9 317 nil "^ONEWS\\.[0-9]+$"
f0753a5f
GM
318 nil)))))))
319 (if file
64f3b7d3 320 (view-file (expand-file-name file data-directory))
f0753a5f 321 (error "No such old news"))))
433ae6f6 322
4f16ea85
RS
323(defun view-echo-area-messages ()
324 "View the log of recent echo-area messages: the `*Messages*' buffer.
325The number of messages retained in that buffer
326is specified by the variable `message-log-max'."
327 (interactive)
328 (switch-to-buffer (get-buffer-create "*Messages*")))
329
754084bb
GM
330(defun view-order-manuals ()
331 "Display the Emacs ORDERS file."
332 (interactive)
64f3b7d3 333 (view-file (expand-file-name "ORDERS" data-directory))
38790755 334 (goto-address))
754084bb 335
7ee71cf1
RS
336(defun view-emacs-FAQ ()
337 "Display the Emacs Frequently Asked Questions (FAQ) file."
338 (interactive)
94ea540b 339 ;; (find-file-read-only (expand-file-name "FAQ" data-directory))
279b772d 340 (info "(efaq)"))
7ee71cf1 341
4cbff657
DL
342(defun view-emacs-problems ()
343 "Display info on known problems with Emacs and possible workarounds."
344 (interactive)
345 (view-file (expand-file-name "PROBLEMS" data-directory)))
346
433ae6f6 347(defun view-lossage ()
50b57199
EZ
348 "Display last 100 input keystrokes.
349
350To record all your input on a file, use `open-dribble-file'."
433ae6f6 351 (interactive)
3e5929af
SM
352 (help-setup-xref (list #'view-lossage) (interactive-p))
353 (with-output-to-temp-buffer (help-buffer)
298a7c8c
RS
354 (princ (mapconcat (function (lambda (key)
355 (if (or (integerp key)
356 (symbolp key)
357 (listp key))
358 (single-key-description key)
359 (prin1-to-string key nil))))
360 (recent-keys)
361 " "))
b0fbf754 362 (with-current-buffer standard-output
433ae6f6
RS
363 (goto-char (point-min))
364 (while (progn (move-to-column 50) (not (eobp)))
365 (search-forward " " nil t)
3e5929af 366 (insert "\n")))
433ae6f6
RS
367 (print-help-return-message)))
368
788d62cf
MB
369\f
370;; Key bindings
433ae6f6 371
4c45295b 372(defun describe-bindings (&optional prefix buffer)
a8ad43aa
RS
373 "Show a list of all defined keys, and their definitions.
374We put that list in a buffer, and display the buffer.
375
376The optional argument PREFIX, if non-nil, should be a key sequence;
4c45295b
KH
377then we display only bindings that start with that prefix.
378The optional argument BUFFER specifies which buffer's bindings
379to display (default, the current buffer)."
3e5929af 380 (interactive)
4c45295b 381 (or buffer (setq buffer (current-buffer)))
3e5929af 382 (help-setup-xref (list #'describe-bindings prefix buffer) (interactive-p))
4c45295b 383 (with-current-buffer buffer
3e5929af 384 (describe-bindings-internal nil prefix)))
a8ad43aa 385
94ea540b
SM
386;; This function used to be in keymap.c.
387(defun describe-bindings-internal (&optional menus prefix)
388 "Show a list of all defined keys, and their definitions.
389We put that list in a buffer, and display the buffer.
390
391The optional argument MENUS, if non-nil, says to mention menu bindings.
392\(Ordinarily these are omitted from the output.)
393The optional argument PREFIX, if non-nil, should be a key sequence;
394then we display only bindings that start with that prefix."
395 (interactive)
396 (let ((buf (current-buffer)))
397 (with-output-to-temp-buffer "*Help*"
398 (with-current-buffer standard-output
399 (describe-buffer-bindings buf prefix menus)))))
400
e88a2c59 401(defun where-is (definition &optional insert)
b2c85790 402 "Print message listing key sequences that invoke the command DEFINITION.
e88a2c59
RS
403Argument is a command definition, usually a symbol with a function definition.
404If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
54c0b967
RS
405 (interactive
406 (let ((fn (function-called-at-point))
788d62cf 407 (enable-recursive-minibuffers t)
54c0b967
RS
408 val)
409 (setq val (completing-read (if fn
410 (format "Where is command (default %s): " fn)
411 "Where is command: ")
d5f65532 412 obarray 'commandp t))
54c0b967 413 (list (if (equal val "")
e88a2c59
RS
414 fn (intern val))
415 current-prefix-arg)))
54c0b967 416 (let* ((keys (where-is-internal definition overriding-local-map nil nil))
e88a2c59
RS
417 (keys1 (mapconcat 'key-description keys ", "))
418 (standard-output (if insert (current-buffer) t)))
419 (if insert
420 (if (> (length keys1) 0)
421 (princ (format "%s (%s)" keys1 definition))
422 (princ (format "M-x %s RET" definition)))
423 (if (> (length keys1) 0)
424 (princ (format "%s is on %s" definition keys1))
425 (princ (format "%s is not on any key" definition)))))
54c0b967
RS
426 nil)
427
788d62cf
MB
428(defun string-key-binding (key)
429 "Value is the binding of KEY in a string.
430If KEY is an event on a string, and that string has a `local-map'
431or `keymap' property, return the binding of KEY in the string's keymap."
432 (let* ((defn nil)
433 (start (when (vectorp key)
434 (if (memq (aref key 0) '(mode-line header-line))
435 (event-start (aref key 1))
436 (and (consp (aref key 0))
437 (event-start (aref key 0))))))
438 (string-info (and (consp start) (nth 4 start))))
439 (when string-info
440 (let* ((string (car string-info))
441 (pos (cdr string-info))
442 (local-map (and (> pos 0)
443 (< pos (length string))
444 (or (get-text-property pos 'local-map string)
445 (get-text-property pos 'keymap string)))))
446 (setq defn (and local-map (lookup-key local-map key)))))
447 defn))
1a06eabd 448
788d62cf
MB
449(defun describe-key-briefly (key &optional insert)
450 "Print the name of the function KEY invokes. KEY is a string.
451If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
452 (interactive "kDescribe key briefly: \nP")
400a1b1f 453 (save-excursion
788d62cf
MB
454 (let ((modifiers (event-modifiers (aref key 0)))
455 (standard-output (if insert (current-buffer) t))
456 window position)
457 ;; For a mouse button event, go to the button it applies to
458 ;; to get the right key bindings. And go to the right place
459 ;; in case the keymap depends on where you clicked.
460 (if (or (memq 'click modifiers) (memq 'down modifiers)
461 (memq 'drag modifiers))
462 (setq window (posn-window (event-start (aref key 0)))
463 position (posn-point (event-start (aref key 0)))))
464 (if (windowp window)
465 (progn
466 (set-buffer (window-buffer window))
467 (goto-char position)))
468 ;; Ok, now look up the key and name the command.
469 (let ((defn (or (string-key-binding key)
470 (key-binding key)))
471 (key-desc (key-description key)))
472 (if (or (null defn) (integerp defn))
473 (princ (format "%s is undefined" key-desc))
474 (princ (format (if insert
475 "`%s' (`%s')"
476 (if (windowp window)
477 "%s at that spot runs the command %s"
478 "%s runs the command %s"))
479 key-desc
480 (if (symbolp defn) defn (prin1-to-string defn)))))))))
96ede6b2 481
788d62cf
MB
482
483(defun describe-key (key)
a0d32c10
RS
484 "Display documentation of the function invoked by KEY.
485KEY should be a key sequence--when calling from a program,
486pass a string or a vector."
788d62cf
MB
487 (interactive "kDescribe key: ")
488 (save-excursion
489 (let ((modifiers (event-modifiers (aref key 0)))
490 window position)
491 ;; For a mouse button event, go to the button it applies to
492 ;; to get the right key bindings. And go to the right place
493 ;; in case the keymap depends on where you clicked.
494 (if (or (memq 'click modifiers) (memq 'down modifiers)
495 (memq 'drag modifiers))
496 (setq window (posn-window (event-start (aref key 0)))
497 position (posn-point (event-start (aref key 0)))))
94ea540b 498 (when (windowp window)
788d62cf 499 (set-buffer (window-buffer window))
94ea540b 500 (goto-char position))
788d62cf
MB
501 (let ((defn (or (string-key-binding key) (key-binding key))))
502 (if (or (null defn) (integerp defn))
503 (message "%s is undefined" (key-description key))
3e5929af
SM
504 (help-setup-xref (list #'describe-function defn) (interactive-p))
505 (with-output-to-temp-buffer (help-buffer)
788d62cf
MB
506 (princ (key-description key))
507 (if (windowp window)
508 (princ " at that spot"))
509 (princ " runs the command ")
510 (prin1 defn)
511 (princ "\n which is ")
3e5929af 512 (describe-function-1 defn)
788d62cf 513 (print-help-return-message)))))))
400a1b1f 514
400a1b1f 515\f
788d62cf
MB
516(defun describe-mode (&optional buffer)
517 "Display documentation of current major mode and minor modes.
518The major mode description comes first, followed by the minor modes,
519each on a separate page.
520For this to work correctly for a minor mode, the mode's indicator variable
521\(listed in `minor-mode-alist') must also be a function whose documentation
522describes the minor mode."
400a1b1f 523 (interactive)
9639be74
RS
524 (help-setup-xref (list #'describe-mode (or buffer (current-buffer)))
525 (interactive-p))
526 ;; For the sake of help-do-xref and help-xref-go-back,
527 ;; don't switch buffers before calling `help-buffer'.
3e5929af 528 (with-output-to-temp-buffer (help-buffer)
9639be74
RS
529 (save-excursion
530 (when buffer (set-buffer buffer))
531 (when minor-mode-alist
532 (princ "The major mode is described first.
788d62cf 533For minor modes, see following pages.\n\n"))
9639be74
RS
534 (princ mode-name)
535 (princ " mode:\n")
536 (princ (documentation major-mode))
537 (let ((minor-modes minor-mode-alist))
538 (while minor-modes
539 (let* ((minor-mode (car (car minor-modes)))
540 (indicator (car (cdr (car minor-modes)))))
541 ;; Document a minor mode if it is listed in minor-mode-alist,
542 ;; bound locally in this buffer, non-nil, and has a function
543 ;; definition.
544 (if (and (boundp minor-mode)
545 (symbol-value minor-mode)
546 (fboundp minor-mode))
547 (let ((pretty-minor-mode minor-mode))
548 (if (string-match "\\(-minor\\)?-mode\\'"
549 (symbol-name minor-mode))
550 (setq pretty-minor-mode
551 (capitalize
552 (substring (symbol-name minor-mode)
553 0 (match-beginning 0)))))
554 (while (and indicator (symbolp indicator)
555 (boundp indicator)
556 (not (eq indicator (symbol-value indicator))))
557 (setq indicator (symbol-value indicator)))
558 (princ "\n\f\n")
559 (princ (format "%s minor mode (%s):\n"
560 pretty-minor-mode
561 (if indicator
562 (format "indicator%s" indicator)
563 "no indicator")))
564 (princ (documentation minor-mode)))))
565 (setq minor-modes (cdr minor-modes))))
566 (print-help-return-message))))
400a1b1f 567
48ce3c22
RS
568\f
569;;; Automatic resizing of temporary buffers.
570
4483ddc5 571(defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2))
48ce3c22
RS
572 "*Maximum height of a window displaying a temporary buffer.
573This is the maximum height (in text lines) which `resize-temp-buffer-window'
574will give to a window displaying a temporary buffer.
575It can also be a function which will be called with the object corresponding
576to the buffer to be displayed as argument and should return an integer
577positive number."
578 :type '(choice integer function)
579 :group 'help
580 :version "20.4")
581
4e1ede6c
SM
582(define-minor-mode temp-buffer-resize-mode
583 "Toggle the mode which makes windows smaller for temporary buffers.
48ce3c22
RS
584With prefix argument ARG, turn the resizing of windows displaying temporary
585buffers on if ARG is positive or off otherwise.
4e1ede6c
SM
586This makes the window the right height for its contents, but never
587more than `temp-buffer-max-height' nor less than `window-min-height'.
588This applies to `help', `apropos' and `completion' buffers, and some others."
b0fbf754 589 :global t :group 'help
4e1ede6c 590 (if temp-buffer-resize-mode
57f43907 591 ;; `help-make-xrefs' may add a `back' button and thus increase the
4e1ede6c
SM
592 ;; text size, so `resize-temp-buffer-window' must be run *after* it.
593 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
8304a3bb 594 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)))
48ce3c22
RS
595
596(defun resize-temp-buffer-window ()
597 "Resize the current window to fit its contents.
4483ddc5 598Will not make it higher than `temp-buffer-max-height' nor smaller than
b2c85790 599`window-min-height'. Do nothing if it is the only window on its frame, if it
48ce3c22
RS
600is not as wide as the frame or if some of the window's contents are scrolled
601out of view."
602 (unless (or (one-window-p 'nomini)
603 (not (pos-visible-in-window-p (point-min)))
604 (/= (frame-width) (window-width)))
d9c30bdf
MB
605 (fit-window-to-buffer
606 (selected-window)
607 (if (functionp temp-buffer-max-height)
608 (funcall temp-buffer-max-height (current-buffer))
609 temp-buffer-max-height))))
48ce3c22 610
5fbeea74
GM
611;; Provide this for the sake of define-minor-mode which generates
612;; defcustoms which require 'help'.
5fbeea74
GM
613(provide 'help)
614
1a06eabd 615;;; help.el ends here