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