* viper-ex.el: Patch by Samuel Padgett. Copyright papers received.
[emacs.git] / lisp / help.el
blobd47504526d638ae113590312c1cd2b58387bf73a
1 ;;; help.el --- help commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001, 2002
4 ;; Free Software Foundation, Inc.
6 ;; Maintainer: FSF
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)
14 ;; any later version.
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.
26 ;;; Commentary:
28 ;; This code implements GNU Emacs' on-line help system, the one invoked by
29 ;; `M-x help-for-help'.
31 ;;; Code:
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))
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)
41 (defvar help-map (make-sparse-keymap)
42 "Keymap for characters following the Help key.")
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-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)
63 ;; This does not fit the pattern, but it is natural given the C-\ command.
64 (define-key help-map "\C-\\" 'describe-input-method)
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)
73 (define-key help-map "a" 'apropos-command)
75 (define-key help-map "b" 'describe-bindings)
77 (define-key help-map "c" 'describe-key-briefly)
79 (define-key help-map "e" 'view-echo-area-messages)
81 (define-key help-map "f" 'describe-function)
83 (define-key help-map "h" 'view-hello-file)
85 (define-key help-map "i" 'info)
86 (define-key help-map "4i" 'info-other-window)
88 (define-key help-map "k" 'describe-key)
90 (define-key help-map "l" 'view-lossage)
92 (define-key help-map "m" 'describe-mode)
94 (define-key help-map "n" 'view-emacs-news)
96 (define-key help-map "p" 'finder-by-keyword)
97 (autoload 'finder-by-keyword "finder"
98 "Find packages matching a given keyword." t)
100 (define-key help-map "s" 'describe-syntax)
102 (define-key help-map "t" 'help-with-tutorial)
104 (define-key help-map "w" 'where-is)
106 (define-key help-map "v" 'describe-variable)
108 (define-key help-map "q" 'help-quit)
111 (defun help-quit ()
112 "Just exit from the Help command's command loop."
113 (interactive)
114 nil)
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.")
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.")
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))
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."))))))))
171 ;; So keyboard macro definitions are documented correctly
172 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
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.)
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.
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)
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)))))
260 ;;; `User' help functions
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)))
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)))
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)))
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)))
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)
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")
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"))))
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*")))
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))
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)"))
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)))
346 (defun view-lossage ()
347 "Display last 100 input keystrokes.
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)))
367 ;; Key bindings
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.
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)))
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.
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)))))
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)
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)
437 '(mode-line header-line left-margin right-margin))
438 (event-start (aref key 1))
439 (and (consp (aref key 0))
440 (event-start (aref key 0))))))
441 (string-info (and (consp start) (nth 4 start))))
442 (when string-info
443 (let* ((string (car string-info))
444 (pos (cdr string-info))
445 (local-map (and (>= pos 0)
446 (< pos (length string))
447 (or (get-text-property pos 'local-map string)
448 (get-text-property pos 'keymap string)))))
449 (setq defn (and local-map (lookup-key local-map key)))))
450 defn))
452 (defun help-key-description (key untranslated)
453 (let ((string (key-description key)))
454 (if (or (not untranslated) (eq (aref untranslated 0) ?\e))
455 string
456 (let ((otherstring (key-description untranslated)))
457 (if (equal string otherstring)
458 string
459 (format "%s (translated from %s)" string otherstring))))))
461 (defun describe-key-briefly (key &optional insert untranslated)
462 "Print the name of the function KEY invokes. KEY is a string.
463 If INSERT (the prefix arg) is non-nil, insert the message in the buffer.
464 If non-nil UNTRANSLATED is a vector of the untranslated events.
465 It can also be a number in which case the untranslated events from
466 the last key hit are used."
467 (interactive "kDescribe key briefly: \nP\np")
468 (if (numberp untranslated)
469 (setq untranslated (this-single-command-raw-keys)))
470 (save-excursion
471 (let ((modifiers (event-modifiers (aref key 0)))
472 (standard-output (if insert (current-buffer) t))
473 window position)
474 ;; For a mouse button event, go to the button it applies to
475 ;; to get the right key bindings. And go to the right place
476 ;; in case the keymap depends on where you clicked.
477 (if (or (memq 'click modifiers) (memq 'down modifiers)
478 (memq 'drag modifiers))
479 (setq window (posn-window (event-start (aref key 0)))
480 position (posn-point (event-start (aref key 0)))))
481 (if (windowp window)
482 (progn
483 (set-buffer (window-buffer window))
484 (goto-char position)))
485 ;; Ok, now look up the key and name the command.
486 (let ((defn (or (string-key-binding key)
487 (key-binding key)))
488 (key-desc (help-key-description key untranslated)))
489 (if (or (null defn) (integerp defn) (equal defn 'undefined))
490 (princ (format "%s is undefined" key-desc))
491 (princ (format (if (windowp window)
492 "%s at that spot runs the command %s"
493 "%s runs the command %s")
494 key-desc
495 (if (symbolp defn) defn (prin1-to-string defn)))))))))
498 (defun describe-key (key &optional untranslated)
499 "Display documentation of the function invoked by KEY.
500 KEY should be a key sequence--when calling from a program,
501 pass a string or a vector.
502 If non-nil UNTRANSLATED is a vector of the untranslated events.
503 It can also be a number in which case the untranslated events from
504 the last key hit are used."
505 (interactive "kDescribe key: \np")
506 (if (numberp untranslated)
507 (setq untranslated (this-single-command-raw-keys)))
508 (save-excursion
509 (let ((modifiers (event-modifiers (aref key 0)))
510 window position)
511 ;; For a mouse button event, go to the button it applies to
512 ;; to get the right key bindings. And go to the right place
513 ;; in case the keymap depends on where you clicked.
514 (if (or (memq 'click modifiers) (memq 'down modifiers)
515 (memq 'drag modifiers))
516 (setq window (posn-window (event-start (aref key 0)))
517 position (posn-point (event-start (aref key 0)))))
518 (when (windowp window)
519 (set-buffer (window-buffer window))
520 (goto-char position))
521 (let ((defn (or (string-key-binding key) (key-binding key))))
522 (if (or (null defn) (integerp defn) (equal defn 'undefined))
523 (message "%s is undefined" (help-key-description key untranslated))
524 (help-setup-xref (list #'describe-function defn) (interactive-p))
525 (with-output-to-temp-buffer (help-buffer)
526 (princ (help-key-description key untranslated))
527 (if (windowp window)
528 (princ " at that spot"))
529 (princ " runs the command ")
530 (prin1 defn)
531 (princ "\n which is ")
532 (describe-function-1 defn)
533 (print-help-return-message)))))))
536 (defun describe-mode (&optional buffer)
537 "Display documentation of current major mode and minor modes.
538 The major mode description comes first, followed by the minor modes,
539 each on a separate page.
540 For this to work correctly for a minor mode, the mode's indicator variable
541 \(listed in `minor-mode-alist') must also be a function whose documentation
542 describes the minor mode."
543 (interactive)
544 (help-setup-xref (list #'describe-mode (or buffer (current-buffer)))
545 (interactive-p))
546 ;; For the sake of help-do-xref and help-xref-go-back,
547 ;; don't switch buffers before calling `help-buffer'.
548 (with-output-to-temp-buffer (help-buffer)
549 (save-excursion
550 (when buffer (set-buffer buffer))
551 (when minor-mode-alist
552 (princ "The major mode is described first.
553 For minor modes, see following pages.\n\n"))
554 (princ mode-name)
555 (princ " mode:\n")
556 (princ (documentation major-mode))
557 (let ((minor-modes minor-mode-alist))
558 (while minor-modes
559 (let* ((minor-mode (car (car minor-modes)))
560 (indicator (car (cdr (car minor-modes)))))
561 ;; Document a minor mode if it is listed in minor-mode-alist,
562 ;; bound locally in this buffer, non-nil, and has a function
563 ;; definition.
564 (if (and (boundp minor-mode)
565 (symbol-value minor-mode)
566 (fboundp minor-mode))
567 (let ((pretty-minor-mode minor-mode))
568 (if (string-match "\\(-minor\\)?-mode\\'"
569 (symbol-name minor-mode))
570 (setq pretty-minor-mode
571 (capitalize
572 (substring (symbol-name minor-mode)
573 0 (match-beginning 0)))))
574 (while (and indicator (symbolp indicator)
575 (boundp indicator)
576 (not (eq indicator (symbol-value indicator))))
577 (setq indicator (symbol-value indicator)))
578 (princ "\n\f\n")
579 (princ (format "%s minor mode (%s):\n"
580 pretty-minor-mode
581 (if indicator
582 (format "indicator%s" indicator)
583 "no indicator")))
584 (princ (documentation minor-mode)))))
585 (setq minor-modes (cdr minor-modes))))
586 (print-help-return-message))))
589 ;;; Automatic resizing of temporary buffers.
591 (defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2))
592 "*Maximum height of a window displaying a temporary buffer.
593 This is the maximum height (in text lines) which `resize-temp-buffer-window'
594 will give to a window displaying a temporary buffer.
595 It can also be a function which will be called with the object corresponding
596 to the buffer to be displayed as argument and should return an integer
597 positive number."
598 :type '(choice integer function)
599 :group 'help
600 :version "20.4")
602 (define-minor-mode temp-buffer-resize-mode
603 "Toggle the mode which makes windows smaller for temporary buffers.
604 With prefix argument ARG, turn the resizing of windows displaying temporary
605 buffers on if ARG is positive or off otherwise.
606 This makes the window the right height for its contents, but never
607 more than `temp-buffer-max-height' nor less than `window-min-height'.
608 This applies to `help', `apropos' and `completion' buffers, and some others."
609 :global t :group 'help
610 (if temp-buffer-resize-mode
611 ;; `help-make-xrefs' may add a `back' button and thus increase the
612 ;; text size, so `resize-temp-buffer-window' must be run *after* it.
613 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
614 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)))
616 (defun resize-temp-buffer-window ()
617 "Resize the current window to fit its contents.
618 Will not make it higher than `temp-buffer-max-height' nor smaller than
619 `window-min-height'. Do nothing if it is the only window on its frame, if it
620 is not as wide as the frame or if some of the window's contents are scrolled
621 out of view."
622 (unless (or (one-window-p 'nomini)
623 (not (pos-visible-in-window-p (point-min)))
624 (/= (frame-width) (window-width)))
625 (fit-window-to-buffer
626 (selected-window)
627 (if (functionp temp-buffer-max-height)
628 (funcall temp-buffer-max-height (current-buffer))
629 temp-buffer-max-height))))
631 ;; Provide this for the sake of define-minor-mode which generates
632 ;; defcustoms which require 'help'.
633 (provide 'help)
635 ;;; help.el ends here