Rename eww-download-path to eww-download-directory.
[emacs.git] / lisp / help.el
blobf732cf385cda04520ce10c261a428afd7a26a8bf
1 ;;; help.el --- help commands for Emacs
3 ;; Copyright (C) 1985-1986, 1993-1994, 1998-2014 Free Software
4 ;; Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: help, internal
8 ;; Package: emacs
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; This code implements GNU Emacs's on-line help system, the one invoked by
28 ;; `M-x help-for-help'.
30 ;;; Code:
32 ;; Get the macro make-help-screen when this is compiled,
33 ;; or run interpreted, but not when the compiled code is loaded.
34 (eval-when-compile (require 'help-macro))
36 ;; This makes `with-output-to-temp-buffer' buffers use `help-mode'.
37 (add-hook 'temp-buffer-setup-hook 'help-mode-setup)
38 (add-hook 'temp-buffer-show-hook 'help-mode-finish)
40 ;; `help-window-point-marker' is a marker you can move to a valid
41 ;; position of the buffer shown in the help window in order to override
42 ;; the standard positioning mechanism (`point-min') chosen by
43 ;; `with-output-to-temp-buffer' and `with-temp-buffer-window'.
44 ;; `with-help-window' has this point nowhere before exiting. Currently
45 ;; used by `view-lossage' to assert that the last keystrokes are always
46 ;; visible.
47 (defvar help-window-point-marker (make-marker)
48 "Marker to override default `window-point' in help windows.")
50 (defvar help-map
51 (let ((map (make-sparse-keymap)))
52 (define-key map (char-to-string help-char) 'help-for-help)
53 (define-key map [help] 'help-for-help)
54 (define-key map [f1] 'help-for-help)
55 (define-key map "." 'display-local-help)
56 (define-key map "?" 'help-for-help)
58 (define-key map "\C-a" 'about-emacs)
59 (define-key map "\C-c" 'describe-copying)
60 (define-key map "\C-d" 'view-emacs-debugging)
61 (define-key map "\C-e" 'view-external-packages)
62 (define-key map "\C-f" 'view-emacs-FAQ)
63 (define-key map "\C-m" 'view-order-manuals)
64 (define-key map "\C-n" 'view-emacs-news)
65 (define-key map "\C-o" 'describe-distribution)
66 (define-key map "\C-p" 'view-emacs-problems)
67 (define-key map "\C-t" 'view-emacs-todo)
68 (define-key map "\C-w" 'describe-no-warranty)
70 ;; This does not fit the pattern, but it is natural given the C-\ command.
71 (define-key map "\C-\\" 'describe-input-method)
73 (define-key map "C" 'describe-coding-system)
74 (define-key map "F" 'Info-goto-emacs-command-node)
75 (define-key map "I" 'describe-input-method)
76 (define-key map "K" 'Info-goto-emacs-key-command-node)
77 (define-key map "L" 'describe-language-environment)
78 (define-key map "S" 'info-lookup-symbol)
80 (define-key map "a" 'apropos-command)
81 (define-key map "b" 'describe-bindings)
82 (define-key map "c" 'describe-key-briefly)
83 (define-key map "d" 'apropos-documentation)
84 (define-key map "e" 'view-echo-area-messages)
85 (define-key map "f" 'describe-function)
86 (define-key map "g" 'describe-gnu-project)
87 (define-key map "h" 'view-hello-file)
89 (define-key map "i" 'info)
90 (define-key map "4i" 'info-other-window)
92 (define-key map "k" 'describe-key)
93 (define-key map "l" 'view-lossage)
94 (define-key map "m" 'describe-mode)
95 (define-key map "n" 'view-emacs-news)
96 (define-key map "p" 'finder-by-keyword)
97 (define-key map "P" 'describe-package)
98 (define-key map "r" 'info-emacs-manual)
99 (define-key map "s" 'describe-syntax)
100 (define-key map "t" 'help-with-tutorial)
101 (define-key map "w" 'where-is)
102 (define-key map "v" 'describe-variable)
103 (define-key map "q" 'help-quit)
104 map)
105 "Keymap for characters following the Help key.")
107 (define-key global-map (char-to-string help-char) 'help-command)
108 (define-key global-map [help] 'help-command)
109 (define-key global-map [f1] 'help-command)
110 (fset 'help-command help-map)
112 ;; insert-button makes the action nil if it is not store somewhere
113 (defvar help-button-cache nil)
116 (defun help-quit ()
117 "Just exit from the Help command's command loop."
118 (interactive)
119 nil)
121 (defvar help-return-method nil
122 "What to do to \"exit\" the help buffer.
123 This is a list
124 (WINDOW . t) delete the selected window (and possibly its frame,
125 see `quit-window'), go to WINDOW.
126 (WINDOW . quit-window) do quit-window, then select WINDOW.
127 (WINDOW BUF START POINT) display BUF at START, POINT, then select WINDOW.")
129 (define-obsolete-function-alias 'print-help-return-message 'help-print-return-message "23.2")
130 (defun help-print-return-message (&optional function)
131 "Display or return message saying how to restore windows after help command.
132 This function assumes that `standard-output' is the help buffer.
133 It computes a message, and applies the optional argument FUNCTION to it.
134 If FUNCTION is nil, it applies `message', thus displaying the message.
135 In addition, this function sets up `help-return-method', which see, that
136 specifies what to do when the user exits the help buffer."
137 (and (not (get-buffer-window standard-output))
138 (let ((first-message
139 (cond ((or
140 pop-up-frames
141 (special-display-p (buffer-name standard-output)))
142 (setq help-return-method (cons (selected-window) t))
143 ;; If the help output buffer is a special display buffer,
144 ;; don't say anything about how to get rid of it.
145 ;; First of all, the user will do that with the window
146 ;; manager, not with Emacs.
147 ;; Secondly, the buffer has not been displayed yet,
148 ;; so we don't know whether its frame will be selected.
149 nil)
150 ((not (one-window-p t))
151 (setq help-return-method
152 (cons (selected-window) 'quit-window))
153 "Type \\[display-buffer] RET to restore the other window.")
154 (pop-up-windows
155 (setq help-return-method (cons (selected-window) t))
156 "Type \\[delete-other-windows] to remove help window.")
158 (setq help-return-method
159 (list (selected-window) (window-buffer)
160 (window-start) (window-point)))
161 "Type \\[switch-to-buffer] RET to remove help window."))))
162 (funcall (or function 'message)
163 (concat
164 (if first-message
165 (substitute-command-keys first-message))
166 (if first-message " ")
167 ;; If the help buffer will go in a separate frame,
168 ;; it's no use mentioning a command to scroll, so don't.
169 (if (or pop-up-windows
170 (special-display-p (buffer-name standard-output)))
172 (if (same-window-p (buffer-name standard-output))
173 ;; Say how to scroll this window.
174 (substitute-command-keys
175 "\\[scroll-up] to scroll the help.")
176 ;; Say how to scroll some other window.
177 (substitute-command-keys
178 "\\[scroll-other-window] to scroll the help."))))))))
180 ;; So keyboard macro definitions are documented correctly
181 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
183 (defalias 'help 'help-for-help-internal)
184 ;; find-function can find this.
185 (defalias 'help-for-help 'help-for-help-internal)
186 ;; It can't find this, but nobody will look.
187 (make-help-screen help-for-help-internal
188 (purecopy "Type a help option: [abcCdefFgiIkKlLmnprstvw.] C-[cdefmnoptw] or ?")
189 ;; Don't purecopy this one, because it's not evaluated (it's
190 ;; directly used as a docstring in a function definition, so it'll
191 ;; be moved to the DOC file anyway: no need for purecopying it).
192 "You have typed %THIS-KEY%, the help character. Type a Help option:
193 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
195 a PATTERN Show commands whose name matches the PATTERN (a list of words
196 or a regexp). See also the `apropos' command.
197 b Display all key bindings.
198 c KEYS Display the command name run by the given key sequence.
199 C CODING Describe the given coding system, or RET for current ones.
200 d PATTERN Show a list of functions, variables, and other items whose
201 documentation matches the PATTERN (a list of words or a regexp).
202 e Go to the *Messages* buffer which logs echo-area messages.
203 f FUNCTION Display documentation for the given function.
204 F COMMAND Show the on-line manual's section that describes the command.
205 g Display information about the GNU project.
206 h Display the HELLO file which illustrates various scripts.
207 i Start the Info documentation reader: read on-line manuals.
208 I METHOD Describe a specific input method, or RET for current.
209 k KEYS Display the full documentation for the key sequence.
210 K KEYS Show the on-line manual's section for the command bound to KEYS.
211 l Show last 300 input keystrokes (lossage).
212 L LANG-ENV Describes a specific language environment, or RET for current.
213 m Display documentation of current minor modes and current major mode,
214 including their special commands.
215 n Display news of recent Emacs changes.
216 p TOPIC Find packages matching a given topic keyword.
217 r Display the Emacs manual in Info mode.
218 s Display contents of current syntax table, plus explanations.
219 S SYMBOL Show the section for the given symbol in the on-line manual
220 for the programming language used in this buffer.
221 t Start the Emacs learn-by-doing tutorial.
222 v VARIABLE Display the given variable's documentation and value.
223 w COMMAND Display which keystrokes invoke the given command (where-is).
224 . Display any available local help at point in the echo area.
226 C-a Information about Emacs.
227 C-c Emacs copying permission (GNU General Public License).
228 C-d Instructions for debugging GNU Emacs.
229 C-e External packages and information about Emacs.
230 C-f Emacs FAQ.
231 C-m How to order printed Emacs manuals.
232 C-n News of recent Emacs changes.
233 C-o Emacs ordering and distribution information.
234 C-p Info about known Emacs problems.
235 C-t Emacs TODO list.
236 C-w Information on absence of warranty for GNU Emacs."
237 help-map)
241 (defun function-called-at-point ()
242 "Return a function around point or else called by the list containing point.
243 If that doesn't give a function, return nil."
244 (with-syntax-table emacs-lisp-mode-syntax-table
245 (or (condition-case ()
246 (save-excursion
247 (or (not (zerop (skip-syntax-backward "_w")))
248 (eq (char-syntax (following-char)) ?w)
249 (eq (char-syntax (following-char)) ?_)
250 (forward-sexp -1))
251 (skip-chars-forward "'")
252 (let ((obj (read (current-buffer))))
253 (and (symbolp obj) (fboundp obj) obj)))
254 (error nil))
255 (condition-case ()
256 (save-excursion
257 (save-restriction
258 (narrow-to-region (max (point-min)
259 (- (point) 1000)) (point-max))
260 ;; Move up to surrounding paren, then after the open.
261 (backward-up-list 1)
262 (forward-char 1)
263 ;; If there is space here, this is probably something
264 ;; other than a real Lisp function call, so ignore it.
265 (if (looking-at "[ \t]")
266 (error "Probably not a Lisp function call"))
267 (let ((obj (read (current-buffer))))
268 (and (symbolp obj) (fboundp obj) obj))))
269 (error nil))
270 (let* ((str (find-tag-default))
271 (sym (if str (intern-soft str))))
272 (if (and sym (fboundp sym))
274 (save-match-data
275 (when (and str (string-match "\\`\\W*\\(.*?\\)\\W*\\'" str))
276 (setq sym (intern-soft (match-string 1 str)))
277 (and (fboundp sym) sym))))))))
280 ;;; `User' help functions
282 (defun view-help-file (file &optional dir)
283 (view-file (expand-file-name file (or dir data-directory)))
284 (goto-address-mode 1)
285 (goto-char (point-min)))
287 (defun describe-distribution ()
288 "Display info on how to obtain the latest version of GNU Emacs."
289 (interactive)
290 (view-help-file "DISTRIB"))
292 (defun describe-copying ()
293 "Display info on how you may redistribute copies of GNU Emacs."
294 (interactive)
295 (view-help-file "COPYING"))
297 (defun describe-gnu-project ()
298 "Display info on the GNU project."
299 (interactive)
300 (view-help-file "THE-GNU-PROJECT"))
302 (define-obsolete-function-alias 'describe-project 'describe-gnu-project "22.2")
304 (defun describe-no-warranty ()
305 "Display info on all the kinds of warranty Emacs does NOT have."
306 (interactive)
307 (describe-copying)
308 (let (case-fold-search)
309 (search-forward "Disclaimer of Warranty")
310 (forward-line 0)
311 (recenter 0)))
313 (defun describe-prefix-bindings ()
314 "Describe the bindings of the prefix used to reach this command.
315 The prefix described consists of all but the last event
316 of the key sequence that ran this command."
317 (interactive)
318 (let ((key (this-command-keys)))
319 (describe-bindings
320 (if (stringp key)
321 (substring key 0 (1- (length key)))
322 (let ((prefix (make-vector (1- (length key)) nil))
323 (i 0))
324 (while (< i (length prefix))
325 (aset prefix i (aref key i))
326 (setq i (1+ i)))
327 prefix)))))
328 ;; Make C-h after a prefix, when not specifically bound,
329 ;; run describe-prefix-bindings.
330 (setq prefix-help-command 'describe-prefix-bindings)
332 (defun view-emacs-news (&optional version)
333 "Display info on recent changes to Emacs.
334 With argument, display info only for the selected version."
335 (interactive "P")
336 (unless version
337 (setq version emacs-major-version))
338 (when (consp version)
339 (let* ((all-versions
340 (let (res)
341 (mapc
342 (lambda (file)
343 (with-temp-buffer
344 (insert-file-contents
345 (expand-file-name file data-directory))
346 (while (re-search-forward
347 (if (member file '("NEWS.18" "NEWS.1-17"))
348 "Changes in \\(?:Emacs\\|version\\)?[ \t]*\\([0-9]+\\(?:\\.[0-9]+\\)?\\)"
349 "^\* [^0-9\n]*\\([0-9]+\\.[0-9]+\\)") nil t)
350 (setq res (cons (match-string-no-properties 1) res)))))
351 (cons "NEWS"
352 (directory-files data-directory nil
353 "^NEWS\\.[0-9][-0-9]*$" nil)))
354 (sort (delete-dups res) (lambda (a b) (string< b a)))))
355 (current (car all-versions)))
356 (setq version (completing-read
357 (format "Read NEWS for the version (default %s): " current)
358 all-versions nil nil nil nil current))
359 (if (integerp (string-to-number version))
360 (setq version (string-to-number version))
361 (unless (or (member version all-versions)
362 (<= (string-to-number version) (string-to-number current)))
363 (error "No news about version %s" version)))))
364 (when (integerp version)
365 (cond ((<= version 12)
366 (setq version (format "1.%d" version)))
367 ((<= version 18)
368 (setq version (format "%d" version)))
369 ((> version emacs-major-version)
370 (error "No news about Emacs %d (yet)" version))))
371 (let* ((vn (if (stringp version)
372 (string-to-number version)
373 version))
374 (file (cond
375 ((>= vn emacs-major-version) "NEWS")
376 ((< vn 18) "NEWS.1-17")
377 (t (format "NEWS.%d" vn))))
378 res)
379 (view-file (expand-file-name file data-directory))
380 (widen)
381 (goto-char (point-min))
382 (when (stringp version)
383 (when (re-search-forward
384 (concat (if (< vn 19)
385 "Changes in Emacs[ \t]*"
386 "^\* [^0-9\n]*") version "$")
387 nil t)
388 (beginning-of-line)
389 (narrow-to-region
390 (point)
391 (save-excursion
392 (while (and (setq res
393 (re-search-forward
394 (if (< vn 19)
395 "Changes in \\(?:Emacs\\|version\\)?[ \t]*\\([0-9]+\\(?:\\.[0-9]+\\)?\\)"
396 "^\* [^0-9\n]*\\([0-9]+\\.[0-9]+\\)") nil t))
397 (equal (match-string-no-properties 1) version)))
398 (or res (goto-char (point-max)))
399 (beginning-of-line)
400 (point)))))))
402 (defun view-emacs-todo (&optional _arg)
403 "Display the Emacs TODO list."
404 (interactive "P")
405 (view-help-file "TODO"))
407 (define-obsolete-function-alias 'view-todo 'view-emacs-todo "22.2")
410 (defun view-echo-area-messages ()
411 "View the log of recent echo-area messages: the `*Messages*' buffer.
412 The number of messages retained in that buffer
413 is specified by the variable `message-log-max'."
414 (interactive)
415 (with-current-buffer (messages-buffer)
416 (goto-char (point-max))
417 (display-buffer (current-buffer))))
419 (defun view-order-manuals ()
420 "Display information on how to buy printed copies of Emacs manuals."
421 (interactive)
422 ;; (view-help-file "ORDERS")
423 (info "(emacs)Printed Books"))
425 (defun view-emacs-FAQ ()
426 "Display the Emacs Frequently Asked Questions (FAQ) file."
427 (interactive)
428 ;; (find-file-read-only (expand-file-name "FAQ" data-directory))
429 (info "(efaq)"))
431 (defun view-emacs-problems ()
432 "Display info on known problems with Emacs and possible workarounds."
433 (interactive)
434 (view-help-file "PROBLEMS"))
436 (defun view-emacs-debugging ()
437 "Display info on how to debug Emacs problems."
438 (interactive)
439 (view-help-file "DEBUG"))
441 ;; This used to visit MORE.STUFF; maybe it should just be removed.
442 (defun view-external-packages ()
443 "Display info on where to get more Emacs packages."
444 (interactive)
445 (info "(efaq)Packages that do not come with Emacs"))
447 (defun view-lossage ()
448 "Display last 300 input keystrokes.
450 To record all your input on a file, use `open-dribble-file'."
451 (interactive)
452 (help-setup-xref (list #'view-lossage)
453 (called-interactively-p 'interactive))
454 (with-help-window (help-buffer)
455 (princ (mapconcat (lambda (key)
456 (if (or (integerp key) (symbolp key) (listp key))
457 (single-key-description key)
458 (prin1-to-string key nil)))
459 (recent-keys)
460 " "))
461 (with-current-buffer standard-output
462 (goto-char (point-min))
463 (while (progn (move-to-column 50) (not (eobp)))
464 (when (search-forward " " nil t)
465 (delete-char -1))
466 (insert "\n"))
467 ;; jidanni wants to see the last keystrokes immediately.
468 (set-marker help-window-point-marker (point)))))
471 ;; Key bindings
473 (defun describe-bindings (&optional prefix buffer)
474 "Show a list of all defined keys, and their definitions.
475 We put that list in a buffer, and display the buffer.
477 The optional argument PREFIX, if non-nil, should be a key sequence;
478 then we display only bindings that start with that prefix.
479 The optional argument BUFFER specifies which buffer's bindings
480 to display (default, the current buffer). BUFFER can be a buffer
481 or a buffer name."
482 (interactive)
483 (or buffer (setq buffer (current-buffer)))
484 (help-setup-xref (list #'describe-bindings prefix buffer)
485 (called-interactively-p 'interactive))
486 (with-current-buffer buffer
487 (describe-bindings-internal nil prefix)))
489 ;; This function used to be in keymap.c.
490 (defun describe-bindings-internal (&optional menus prefix)
491 "Show a list of all defined keys, and their definitions.
492 We put that list in a buffer, and display the buffer.
494 The optional argument MENUS, if non-nil, says to mention menu bindings.
495 \(Ordinarily these are omitted from the output.)
496 The optional argument PREFIX, if non-nil, should be a key sequence;
497 then we display only bindings that start with that prefix."
498 (let ((buf (current-buffer)))
499 (with-help-window (help-buffer)
500 (describe-buffer-bindings buf prefix menus))))
502 (defun where-is (definition &optional insert)
503 "Print message listing key sequences that invoke the command DEFINITION.
504 Argument is a command definition, usually a symbol with a function definition.
505 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
506 (interactive
507 (let ((fn (function-called-at-point))
508 (enable-recursive-minibuffers t)
509 val)
510 (setq val (completing-read
511 (if fn
512 (format "Where is command (default %s): " fn)
513 "Where is command: ")
514 obarray 'commandp t))
515 (list (if (equal val "") fn (intern val)) current-prefix-arg)))
516 (unless definition (error "No command"))
517 (let ((func (indirect-function definition))
518 (defs nil)
519 (standard-output (if insert (current-buffer) standard-output)))
520 ;; In DEFS, find all symbols that are aliases for DEFINITION.
521 (mapatoms (lambda (symbol)
522 (and (fboundp symbol)
523 (not (eq symbol definition))
524 (eq func (condition-case ()
525 (indirect-function symbol)
526 (error symbol)))
527 (push symbol defs))))
528 ;; Look at all the symbols--first DEFINITION,
529 ;; then its aliases.
530 (dolist (symbol (cons definition defs))
531 (let* ((remapped (command-remapping symbol))
532 (keys (where-is-internal
533 symbol overriding-local-map nil nil remapped))
534 (keys (mapconcat 'key-description keys ", "))
535 string)
536 (setq string
537 (if insert
538 (if (> (length keys) 0)
539 (if remapped
540 (format "%s (%s) (remapped from %s)"
541 keys remapped symbol)
542 (format "%s (%s)" keys symbol))
543 (format "M-x %s RET" symbol))
544 (if (> (length keys) 0)
545 (if remapped
546 (format "%s is remapped to %s which is on %s"
547 symbol remapped keys)
548 (format "%s is on %s" symbol keys))
549 ;; If this is the command the user asked about,
550 ;; and it is not on any key, say so.
551 ;; For other symbols, its aliases, say nothing
552 ;; about them unless they are on keys.
553 (if (eq symbol definition)
554 (format "%s is not on any key" symbol)))))
555 (when string
556 (unless (eq symbol definition)
557 (princ ";\n its alias "))
558 (princ string)))))
559 nil)
561 (defun help-key-description (key untranslated)
562 (let ((string (key-description key)))
563 (if (or (not untranslated)
564 (and (eq (aref untranslated 0) ?\e) (not (eq (aref key 0) ?\e))))
565 string
566 (let ((otherstring (key-description untranslated)))
567 (if (equal string otherstring)
568 string
569 (format "%s (translated from %s)" string otherstring))))))
571 (defun describe-key-briefly (&optional key insert untranslated)
572 "Print the name of the function KEY invokes. KEY is a string.
573 If INSERT (the prefix arg) is non-nil, insert the message in the buffer.
574 If non-nil, UNTRANSLATED is a vector of the untranslated events.
575 It can also be a number in which case the untranslated events from
576 the last key hit are used.
578 If KEY is a menu item or a tool-bar button that is disabled, this command
579 temporarily enables it to allow getting help on disabled items and buttons."
580 (interactive
581 (let ((enable-disabled-menus-and-buttons t)
582 (cursor-in-echo-area t)
583 saved-yank-menu)
584 (unwind-protect
585 (let (key)
586 ;; If yank-menu is empty, populate it temporarily, so that
587 ;; "Select and Paste" menu can generate a complete event.
588 (when (null (cdr yank-menu))
589 (setq saved-yank-menu (copy-sequence yank-menu))
590 (menu-bar-update-yank-menu "(any string)" nil))
591 (setq key (read-key-sequence "Describe key (or click or menu item): "))
592 ;; Clear the echo area message (Bug#7014).
593 (message nil)
594 ;; If KEY is a down-event, read and discard the
595 ;; corresponding up-event. Note that there are also
596 ;; down-events on scroll bars and mode lines: the actual
597 ;; event then is in the second element of the vector.
598 (and (vectorp key)
599 (let ((last-idx (1- (length key))))
600 (and (eventp (aref key last-idx))
601 (memq 'down (event-modifiers (aref key last-idx)))))
602 (read-event))
603 (list
605 (if current-prefix-arg (prefix-numeric-value current-prefix-arg))
607 ;; Put yank-menu back as it was, if we changed it.
608 (when saved-yank-menu
609 (setq yank-menu (copy-sequence saved-yank-menu))
610 (fset 'yank-menu (cons 'keymap yank-menu))))))
611 (if (numberp untranslated)
612 (setq untranslated (this-single-command-raw-keys)))
613 (let* ((event (if (and (symbolp (aref key 0))
614 (> (length key) 1)
615 (consp (aref key 1)))
616 (aref key 1)
617 (aref key 0)))
618 (modifiers (event-modifiers event))
619 (standard-output (if insert (current-buffer) standard-output))
620 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
621 (memq 'drag modifiers)) " at that spot" ""))
622 (defn (key-binding key t))
623 key-desc)
624 ;; Handle the case where we faked an entry in "Select and Paste" menu.
625 (if (and (eq defn nil)
626 (stringp (aref key (1- (length key))))
627 (eq (key-binding (substring key 0 -1)) 'yank-menu))
628 (setq defn 'menu-bar-select-yank))
629 ;; Don't bother user with strings from (e.g.) the select-paste menu.
630 (if (stringp (aref key (1- (length key))))
631 (aset key (1- (length key)) "(any string)"))
632 (if (and (> (length untranslated) 0)
633 (stringp (aref untranslated (1- (length untranslated)))))
634 (aset untranslated (1- (length untranslated)) "(any string)"))
635 ;; Now describe the key, perhaps as changed.
636 (setq key-desc (help-key-description key untranslated))
637 (if (or (null defn) (integerp defn) (equal defn 'undefined))
638 (princ (format "%s%s is undefined" key-desc mouse-msg))
639 (princ (format "%s%s runs the command %S" key-desc mouse-msg defn)))))
641 (defun describe-key (&optional key untranslated up-event)
642 "Display documentation of the function invoked by KEY.
643 KEY can be any kind of a key sequence; it can include keyboard events,
644 mouse events, and/or menu events. When calling from a program,
645 pass KEY as a string or a vector.
647 If non-nil, UNTRANSLATED is a vector of the corresponding untranslated events.
648 It can also be a number, in which case the untranslated events from
649 the last key sequence entered are used.
650 UP-EVENT is the up-event that was discarded by reading KEY, or nil.
652 If KEY is a menu item or a tool-bar button that is disabled, this command
653 temporarily enables it to allow getting help on disabled items and buttons."
654 (interactive
655 (let ((enable-disabled-menus-and-buttons t)
656 (cursor-in-echo-area t)
657 saved-yank-menu)
658 (unwind-protect
659 (let (key)
660 ;; If yank-menu is empty, populate it temporarily, so that
661 ;; "Select and Paste" menu can generate a complete event.
662 (when (null (cdr yank-menu))
663 (setq saved-yank-menu (copy-sequence yank-menu))
664 (menu-bar-update-yank-menu "(any string)" nil))
665 (setq key (read-key-sequence "Describe key (or click or menu item): "))
666 (list
668 (prefix-numeric-value current-prefix-arg)
669 ;; If KEY is a down-event, read and include the
670 ;; corresponding up-event. Note that there are also
671 ;; down-events on scroll bars and mode lines: the actual
672 ;; event then is in the second element of the vector.
673 (and (vectorp key)
674 (let ((last-idx (1- (length key))))
675 (and (eventp (aref key last-idx))
676 (memq 'down (event-modifiers (aref key last-idx)))))
677 (or (and (eventp (aref key 0))
678 (memq 'down (event-modifiers (aref key 0)))
679 ;; However, for the C-down-mouse-2 popup
680 ;; menu, there is no subsequent up-event. In
681 ;; this case, the up-event is the next
682 ;; element in the supplied vector.
683 (= (length key) 1))
684 (and (> (length key) 1)
685 (eventp (aref key 1))
686 (memq 'down (event-modifiers (aref key 1)))))
687 (read-event))))
688 ;; Put yank-menu back as it was, if we changed it.
689 (when saved-yank-menu
690 (setq yank-menu (copy-sequence saved-yank-menu))
691 (fset 'yank-menu (cons 'keymap yank-menu))))))
692 (if (numberp untranslated)
693 (setq untranslated (this-single-command-raw-keys)))
694 (let* ((event (aref key (if (and (symbolp (aref key 0))
695 (> (length key) 1)
696 (consp (aref key 1)))
698 0)))
699 (modifiers (event-modifiers event))
700 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
701 (memq 'drag modifiers)) " at that spot" ""))
702 (defn (key-binding key t))
703 defn-up defn-up-tricky ev-type
704 mouse-1-remapped mouse-1-tricky)
706 ;; Handle the case where we faked an entry in "Select and Paste" menu.
707 (when (and (eq defn nil)
708 (stringp (aref key (1- (length key))))
709 (eq (key-binding (substring key 0 -1)) 'yank-menu))
710 (setq defn 'menu-bar-select-yank))
711 (if (or (null defn) (integerp defn) (equal defn 'undefined))
712 (message "%s%s is undefined"
713 (help-key-description key untranslated) mouse-msg)
714 (help-setup-xref (list #'describe-function defn)
715 (called-interactively-p 'interactive))
716 ;; Don't bother user with strings from (e.g.) the select-paste menu.
717 (when (stringp (aref key (1- (length key))))
718 (aset key (1- (length key)) "(any string)"))
719 (when (and untranslated
720 (stringp (aref untranslated (1- (length untranslated)))))
721 (aset untranslated (1- (length untranslated))
722 "(any string)"))
723 ;; Need to do this before erasing *Help* buffer in case event
724 ;; is a mouse click in an existing *Help* buffer.
725 (when up-event
726 (setq ev-type (event-basic-type up-event))
727 (let ((sequence (vector up-event)))
728 (when (and (eq ev-type 'mouse-1)
729 mouse-1-click-follows-link
730 (not (eq mouse-1-click-follows-link 'double))
731 (setq mouse-1-remapped
732 (mouse-on-link-p (event-start up-event))))
733 (setq mouse-1-tricky (and (integerp mouse-1-click-follows-link)
734 (> mouse-1-click-follows-link 0)))
735 (cond ((stringp mouse-1-remapped)
736 (setq sequence mouse-1-remapped))
737 ((vectorp mouse-1-remapped)
738 (setcar up-event (elt mouse-1-remapped 0)))
739 (t (setcar up-event 'mouse-2))))
740 (setq defn-up (key-binding sequence nil nil (event-start up-event)))
741 (when mouse-1-tricky
742 (setq sequence (vector up-event))
743 (aset sequence 0 'mouse-1)
744 (setq defn-up-tricky (key-binding sequence nil nil (event-start up-event))))))
745 (with-help-window (help-buffer)
746 (princ (help-key-description key untranslated))
747 (princ (format "\
748 %s runs the command %S, which is "
749 mouse-msg defn))
750 (describe-function-1 defn)
751 (when up-event
752 (unless (or (null defn-up)
753 (integerp defn-up)
754 (equal defn-up 'undefined))
755 (princ (format "
757 ----------------- up-event %s----------------
759 %s%s%s runs the command %S, which is "
760 (if mouse-1-tricky "(short click) " "")
761 (key-description (vector up-event))
762 mouse-msg
763 (if mouse-1-remapped
764 " is remapped to <mouse-2>, which" "")
765 defn-up))
766 (describe-function-1 defn-up))
767 (unless (or (null defn-up-tricky)
768 (integerp defn-up-tricky)
769 (eq defn-up-tricky 'undefined))
770 (princ (format "
772 ----------------- up-event (long click) ----------------
774 Pressing <%S>%s for longer than %d milli-seconds
775 runs the command %S, which is "
776 ev-type mouse-msg
777 mouse-1-click-follows-link
778 defn-up-tricky))
779 (describe-function-1 defn-up-tricky)))))))
781 (defun describe-mode (&optional buffer)
782 "Display documentation of current major mode and minor modes.
783 A brief summary of the minor modes comes first, followed by the
784 major mode description. This is followed by detailed
785 descriptions of the minor modes, each on a separate page.
787 For this to work correctly for a minor mode, the mode's indicator
788 variable \(listed in `minor-mode-alist') must also be a function
789 whose documentation describes the minor mode.
791 If called from Lisp with a non-nil BUFFER argument, display
792 documentation for the major and minor modes of that buffer."
793 (interactive "@")
794 (unless buffer (setq buffer (current-buffer)))
795 (help-setup-xref (list #'describe-mode buffer)
796 (called-interactively-p 'interactive))
797 ;; For the sake of help-do-xref and help-xref-go-back,
798 ;; don't switch buffers before calling `help-buffer'.
799 (with-help-window (help-buffer)
800 (with-current-buffer buffer
801 (let (minor-modes)
802 ;; Older packages do not register in minor-mode-list but only in
803 ;; minor-mode-alist.
804 (dolist (x minor-mode-alist)
805 (setq x (car x))
806 (unless (memq x minor-mode-list)
807 (push x minor-mode-list)))
808 ;; Find enabled minor mode we will want to mention.
809 (dolist (mode minor-mode-list)
810 ;; Document a minor mode if it is listed in minor-mode-alist,
811 ;; non-nil, and has a function definition.
812 (let ((fmode (or (get mode :minor-mode-function) mode)))
813 (and (boundp mode) (symbol-value mode)
814 (fboundp fmode)
815 (let ((pretty-minor-mode
816 (if (string-match "\\(\\(-minor\\)?-mode\\)?\\'"
817 (symbol-name fmode))
818 (capitalize
819 (substring (symbol-name fmode)
820 0 (match-beginning 0)))
821 fmode)))
822 (push (list fmode pretty-minor-mode
823 (format-mode-line (assq mode minor-mode-alist)))
824 minor-modes)))))
825 (setq minor-modes
826 (sort minor-modes
827 (lambda (a b) (string-lessp (cadr a) (cadr b)))))
828 (when minor-modes
829 (princ "Enabled minor modes:\n")
830 (make-local-variable 'help-button-cache)
831 (with-current-buffer standard-output
832 (dolist (mode minor-modes)
833 (let ((mode-function (nth 0 mode))
834 (pretty-minor-mode (nth 1 mode))
835 (indicator (nth 2 mode)))
836 (add-text-properties 0 (length pretty-minor-mode)
837 '(face bold) pretty-minor-mode)
838 (save-excursion
839 (goto-char (point-max))
840 (princ "\n\f\n")
841 (push (point-marker) help-button-cache)
842 ;; Document the minor modes fully.
843 (insert pretty-minor-mode)
844 (princ (format " minor mode (%s):\n"
845 (if (zerop (length indicator))
846 "no indicator"
847 (format "indicator%s"
848 indicator))))
849 (princ (documentation mode-function)))
850 (insert-button pretty-minor-mode
851 'action (car help-button-cache)
852 'follow-link t
853 'help-echo "mouse-2, RET: show full information")
854 (newline)))
855 (forward-line -1)
856 (fill-paragraph nil)
857 (forward-line 1))
859 (princ "\n(Information about these minor modes follows the major mode info.)\n\n"))
860 ;; Document the major mode.
861 (let ((mode mode-name))
862 (with-current-buffer standard-output
863 (let ((start (point)))
864 (insert (format-mode-line mode nil nil buffer))
865 (add-text-properties start (point) '(face bold)))))
866 (princ " mode")
867 (let* ((mode major-mode)
868 (file-name (find-lisp-object-file-name mode nil)))
869 (when file-name
870 (princ (concat " defined in `" (file-name-nondirectory file-name) "'"))
871 ;; Make a hyperlink to the library.
872 (with-current-buffer standard-output
873 (save-excursion
874 (re-search-backward "`\\([^`']+\\)'" nil t)
875 (help-xref-button 1 'help-function-def mode file-name)))))
876 (princ ":\n")
877 (princ (documentation major-mode)))))
878 ;; For the sake of IELM and maybe others
879 nil)
882 (defun describe-minor-mode (minor-mode)
883 "Display documentation of a minor mode given as MINOR-MODE.
884 MINOR-MODE can be a minor mode symbol or a minor mode indicator string
885 appeared on the mode-line."
886 (interactive (list (completing-read
887 "Minor mode: "
888 (nconc
889 (describe-minor-mode-completion-table-for-symbol)
890 (describe-minor-mode-completion-table-for-indicator)
891 ))))
892 (if (symbolp minor-mode)
893 (setq minor-mode (symbol-name minor-mode)))
894 (let ((symbols (describe-minor-mode-completion-table-for-symbol))
895 (indicators (describe-minor-mode-completion-table-for-indicator)))
896 (cond
897 ((member minor-mode symbols)
898 (describe-minor-mode-from-symbol (intern minor-mode)))
899 ((member minor-mode indicators)
900 (describe-minor-mode-from-indicator minor-mode))
902 (error "No such minor mode: %s" minor-mode)))))
904 ;; symbol
905 (defun describe-minor-mode-completion-table-for-symbol ()
906 ;; In order to list up all minor modes, minor-mode-list
907 ;; is used here instead of minor-mode-alist.
908 (delq nil (mapcar 'symbol-name minor-mode-list)))
910 (defun describe-minor-mode-from-symbol (symbol)
911 "Display documentation of a minor mode given as a symbol, SYMBOL"
912 (interactive (list (intern (completing-read
913 "Minor mode symbol: "
914 (describe-minor-mode-completion-table-for-symbol)))))
915 (if (fboundp symbol)
916 (describe-function symbol)
917 (describe-variable symbol)))
919 ;; indicator
920 (defun describe-minor-mode-completion-table-for-indicator ()
921 (delq nil
922 (mapcar (lambda (x)
923 (let ((i (format-mode-line x)))
924 ;; remove first space if existed
925 (cond
926 ((= 0 (length i))
927 nil)
928 ((eq (aref i 0) ?\s)
929 (substring i 1))
931 i))))
932 minor-mode-alist)))
934 (defun describe-minor-mode-from-indicator (indicator)
935 "Display documentation of a minor mode specified by INDICATOR.
936 If you call this function interactively, you can give indicator which
937 is currently activated with completion."
938 (interactive (list
939 (completing-read
940 "Minor mode indicator: "
941 (describe-minor-mode-completion-table-for-indicator))))
942 (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))
943 (if minor-mode
944 (describe-minor-mode-from-symbol minor-mode)
945 (error "Cannot find minor mode for `%s'" indicator))))
947 (defun lookup-minor-mode-from-indicator (indicator)
948 "Return a minor mode symbol from its indicator on the mode line."
949 ;; remove first space if existed
950 (if (and (< 0 (length indicator))
951 (eq (aref indicator 0) ?\s))
952 (setq indicator (substring indicator 1)))
953 (let ((minor-modes minor-mode-alist)
954 result)
955 (while minor-modes
956 (let* ((minor-mode (car (car minor-modes)))
957 (anindicator (format-mode-line
958 (car (cdr (car minor-modes))))))
959 ;; remove first space if existed
960 (if (and (stringp anindicator)
961 (> (length anindicator) 0)
962 (eq (aref anindicator 0) ?\s))
963 (setq anindicator (substring anindicator 1)))
964 (if (equal indicator anindicator)
965 (setq result minor-mode
966 minor-modes nil)
967 (setq minor-modes (cdr minor-modes)))))
968 result))
970 ;;; Automatic resizing of temporary buffers.
971 (defcustom temp-buffer-max-height
972 (lambda (buffer)
973 (if (eq (selected-window) (frame-root-window))
974 (/ (x-display-pixel-height) (frame-char-height) 2)
975 (/ (- (frame-height) 2) 2)))
976 "Maximum height of a window displaying a temporary buffer.
977 This is effective only when Temp Buffer Resize mode is enabled.
978 The value is the maximum height (in lines) which
979 `resize-temp-buffer-window' will give to a window displaying a
980 temporary buffer. It can also be a function to be called to
981 choose the height for such a buffer. It gets one argument, the
982 buffer, and should return a positive integer. At the time the
983 function is called, the window to be resized is selected."
984 :type '(choice integer function)
985 :group 'help
986 :version "24.3")
988 (defcustom temp-buffer-max-width
989 (lambda (buffer)
990 (if (eq (selected-window) (frame-root-window))
991 (/ (x-display-pixel-width) (frame-char-width) 2)
992 (/ (- (frame-width) 2) 2)))
993 "Maximum width of a window displaying a temporary buffer.
994 This is effective only when Temp Buffer Resize mode is enabled.
995 The value is the maximum width (in columns) which
996 `resize-temp-buffer-window' will give to a window displaying a
997 temporary buffer. It can also be a function to be called to
998 choose the width for such a buffer. It gets one argument, the
999 buffer, and should return a positive integer. At the time the
1000 function is called, the window to be resized is selected."
1001 :type '(choice integer function)
1002 :group 'help
1003 :version "24.4")
1005 (define-minor-mode temp-buffer-resize-mode
1006 "Toggle auto-resizing temporary buffer windows (Temp Buffer Resize Mode).
1007 With a prefix argument ARG, enable Temp Buffer Resize mode if ARG
1008 is positive, and disable it otherwise. If called from Lisp,
1009 enable the mode if ARG is omitted or nil.
1011 When Temp Buffer Resize mode is enabled, the windows in which we
1012 show a temporary buffer are automatically resized in height to
1013 fit the buffer's contents, but never more than
1014 `temp-buffer-max-height' nor less than `window-min-height'.
1016 A window is resized only if it has been specially created for the
1017 buffer. Windows that have shown another buffer before are not
1018 resized. A frame is resized only if `fit-frame-to-buffer' is
1019 non-nil.
1021 This mode is used by `help', `apropos' and `completion' buffers,
1022 and some others."
1023 :global t :group 'help
1024 (if temp-buffer-resize-mode
1025 ;; `help-make-xrefs' may add a `back' button and thus increase the
1026 ;; text size, so `resize-temp-buffer-window' must be run *after* it.
1027 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
1028 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)))
1030 (defun resize-temp-buffer-window (&optional window)
1031 "Resize WINDOW to fit its contents.
1032 WINDOW must be a live window and defaults to the selected one.
1033 Do not resize if WINDOW was not created by `display-buffer'.
1035 If WINDOW is part of a vertical combination, restrain its new
1036 size by `temp-buffer-max-height' and do not resize if its minimum
1037 accessible position is scrolled out of view. If WINDOW is part
1038 of a horizontal combination, restrain its new size by
1039 `temp-buffer-max-width'. In both cases, the value of the option
1040 `fit-window-to-buffer-horizontally' can inhibit resizing.
1042 If WINDOW is the root window of its frame, resize the frame
1043 provided `fit-frame-to-buffer' is non-nil."
1044 (setq window (window-normalize-window window t))
1045 (let ((height (if (functionp temp-buffer-max-height)
1046 (with-selected-window window
1047 (funcall temp-buffer-max-height (window-buffer)))
1048 temp-buffer-max-height))
1049 (width (if (functionp temp-buffer-max-width)
1050 (with-selected-window window
1051 (funcall temp-buffer-max-width (window-buffer)))
1052 temp-buffer-max-width))
1053 (quit-cadr (cadr (window-parameter window 'quit-restore))))
1054 ;; Resize WINDOW iff it was made by `display-buffer'.
1055 (when (or (and (eq quit-cadr 'window)
1056 (or (and (window-combined-p window)
1057 (not (eq fit-window-to-buffer-horizontally
1058 'only))
1059 (pos-visible-in-window-p (point-min) window))
1060 (and (window-combined-p window t)
1061 fit-window-to-buffer-horizontally)))
1062 (and (eq quit-cadr 'frame)
1063 fit-frame-to-buffer
1064 (eq window (frame-root-window window))))
1065 (fit-window-to-buffer window height nil width))))
1067 ;;; Help windows.
1068 (defcustom help-window-select 'other
1069 "Non-nil means select help window for viewing.
1070 Choices are:
1071 never (nil) Select help window only if there is no other window
1072 on its frame.
1073 other Select help window unless the selected window is the
1074 only other window on the help window's frame.
1075 always (t) Always select the help window.
1077 This option has effect if and only if the help window was created
1078 by `with-help-window'"
1079 :type '(choice (const :tag "never (nil)" nil)
1080 (const :tag "other" other)
1081 (const :tag "always (t)" t))
1082 :group 'help
1083 :version "23.1")
1085 (defcustom help-enable-auto-load t
1086 "Whether Help commands can perform autoloading.
1087 If non-nil, whenever \\[describe-function] is called for an
1088 autoloaded function whose docstring contains any key substitution
1089 construct (see `substitute-command-keys'), the library is loaded,
1090 so that the documentation can show the right key bindings."
1091 :type 'boolean
1092 :group 'help
1093 :version "24.3")
1095 (defun help-window-display-message (quit-part window &optional scroll)
1096 "Display message telling how to quit and scroll help window.
1097 QUIT-PART is a string telling how to quit the help window WINDOW.
1098 Optional argument SCROLL non-nil means tell how to scroll WINDOW.
1099 SCROLL equal `other' means tell how to scroll the \"other\"
1100 window."
1101 (let ((scroll-part
1102 (cond
1103 ;; If we don't have QUIT-PART we probably reuse a window
1104 ;; showing the same buffer so we don't show any message.
1105 ((not quit-part) nil)
1106 ((pos-visible-in-window-p
1107 (with-current-buffer (window-buffer window)
1108 (point-max)) window t)
1109 ;; Buffer end is at least partially visible, no need to talk
1110 ;; about scrolling.
1111 ".")
1112 ((eq scroll 'other)
1113 ", \\[scroll-other-window] to scroll help.")
1114 (scroll ", \\[scroll-up] to scroll help."))))
1115 (message "%s"
1116 (substitute-command-keys (concat quit-part scroll-part)))))
1118 (defun help-window-setup (window &optional value)
1119 "Set up help window WINDOW for `with-help-window'.
1120 WINDOW is the window used for displaying the help buffer.
1121 Return VALUE."
1122 (let* ((help-buffer (when (window-live-p window)
1123 (window-buffer window)))
1124 (help-setup (when (window-live-p window)
1125 (car (window-parameter window 'quit-restore)))))
1126 (when help-buffer
1127 ;; Handle `help-window-point-marker'.
1128 (when (eq (marker-buffer help-window-point-marker) help-buffer)
1129 (set-window-point window help-window-point-marker)
1130 ;; Reset `help-window-point-marker'.
1131 (set-marker help-window-point-marker nil))
1133 (cond
1134 ((or (eq window (selected-window))
1135 (and (or (eq help-window-select t)
1136 (eq help-setup 'frame)
1137 (and (eq help-window-select 'other)
1138 (eq (window-frame window) (selected-frame))
1139 (> (length (window-list nil 'no-mini)) 2)))
1140 (select-window window)))
1141 ;; The help window is or gets selected ...
1142 (help-window-display-message
1143 (cond
1144 ((eq help-setup 'window)
1145 ;; ... and is new, ...
1146 "Type \"q\" to delete help window")
1147 ((eq help-setup 'frame)
1148 "Type \"q\" to quit the help frame")
1149 ((eq help-setup 'other)
1150 ;; ... or displayed some other buffer before.
1151 "Type \"q\" to restore previous buffer"))
1152 window t))
1153 ((and (eq (window-frame window) (selected-frame))
1154 (= (length (window-list nil 'no-mini)) 2))
1155 ;; There are two windows on the help window's frame and the
1156 ;; other one is the selected one.
1157 (help-window-display-message
1158 (cond
1159 ((eq help-setup 'window)
1160 "Type \\[delete-other-windows] to delete the help window")
1161 ((eq help-setup 'other)
1162 "Type \"q\" in help window to restore its previous buffer"))
1163 window 'other))
1165 ;; The help window is not selected ...
1166 (help-window-display-message
1167 (cond
1168 ((eq help-setup 'window)
1169 ;; ... and is new, ...
1170 "Type \"q\" in help window to delete it")
1171 ((eq help-setup 'other)
1172 ;; ... or displayed some other buffer before.
1173 "Type \"q\" in help window to restore previous buffer"))
1174 window))))
1175 ;; Return VALUE.
1176 value))
1178 ;; `with-help-window' is a wrapper for `with-temp-buffer-window'
1179 ;; providing the following additional twists:
1181 ;; (1) It puts the buffer in `help-mode' (via `help-mode-setup') and
1182 ;; adds cross references (via `help-mode-finish').
1184 ;; (2) It issues a message telling how to scroll and quit the help
1185 ;; window (via `help-window-setup').
1187 ;; (3) An option (customizable via `help-window-select') to select the
1188 ;; help window automatically.
1190 ;; (4) A marker (`help-window-point-marker') to move point in the help
1191 ;; window to an arbitrary buffer position.
1193 ;; Note: It's usually always wrong to use `help-print-return-message' in
1194 ;; the body of `with-help-window'.
1195 (defmacro with-help-window (buffer-name &rest body)
1196 "Display buffer with name BUFFER-NAME in a help window evaluating BODY.
1197 Select help window if the current value of the user option
1198 `help-window-select' says so. Return last value in BODY."
1199 (declare (indent 1) (debug t))
1200 `(progn
1201 ;; Make `help-window-point-marker' point nowhere. The only place
1202 ;; where this should be set to a buffer position is within BODY.
1203 (set-marker help-window-point-marker nil)
1204 (let ((temp-buffer-window-setup-hook
1205 (cons 'help-mode-setup temp-buffer-window-setup-hook))
1206 (temp-buffer-window-show-hook
1207 (cons 'help-mode-finish temp-buffer-window-show-hook)))
1208 (with-temp-buffer-window
1209 ,buffer-name nil 'help-window-setup (progn ,@body)))))
1211 ;; Called from C, on encountering `help-char' when reading a char.
1212 ;; Don't print to *Help*; that would clobber Help history.
1213 (defun help-form-show ()
1214 "Display the output of a non-nil `help-form'."
1215 (let ((msg (eval help-form)))
1216 (if (stringp msg)
1217 (with-output-to-temp-buffer " *Char Help*"
1218 (princ msg)))))
1220 (provide 'help)
1222 ;;; help.el ends here