Pacify GCC when configuring with --enable-gcc-warnings.
[emacs.git] / lisp / help.el
blobf00accc370c40142395f48fb1f83ef4f13f26f5e
1 ;;; help.el --- help commands for Emacs
3 ;; Copyright (C) 1985-1986, 1993-1994, 1998-2014 Free Software
4 ;; Foundation, Inc.
6 ;; Maintainer: emacs-devel@gnu.org
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 P PACKAGE Describe the given Emacs Lisp package.
218 r Display the Emacs manual in Info mode.
219 s Display contents of current syntax table, plus explanations.
220 S SYMBOL Show the section for the given symbol in the on-line manual
221 for the programming language used in this buffer.
222 t Start the Emacs learn-by-doing tutorial.
223 v VARIABLE Display the given variable's documentation and value.
224 w COMMAND Display which keystrokes invoke the given command (where-is).
225 . Display any available local help at point in the echo area.
227 C-a Information about Emacs.
228 C-c Emacs copying permission (GNU General Public License).
229 C-d Instructions for debugging GNU Emacs.
230 C-e External packages and information about Emacs.
231 C-f Emacs FAQ.
232 C-m How to order printed Emacs manuals.
233 C-n News of recent Emacs changes.
234 C-o Emacs ordering and distribution information.
235 C-p Info about known Emacs problems.
236 C-t Emacs TODO list.
237 C-w Information on absence of warranty for GNU Emacs."
238 help-map)
242 (defun function-called-at-point ()
243 "Return a function around point or else called by the list containing point.
244 If that doesn't give a function, return nil."
245 (with-syntax-table emacs-lisp-mode-syntax-table
246 (or (condition-case ()
247 (save-excursion
248 (or (not (zerop (skip-syntax-backward "_w")))
249 (eq (char-syntax (following-char)) ?w)
250 (eq (char-syntax (following-char)) ?_)
251 (forward-sexp -1))
252 (skip-chars-forward "'")
253 (let ((obj (read (current-buffer))))
254 (and (symbolp obj) (fboundp obj) obj)))
255 (error nil))
256 (condition-case ()
257 (save-excursion
258 (save-restriction
259 (narrow-to-region (max (point-min)
260 (- (point) 1000)) (point-max))
261 ;; Move up to surrounding paren, then after the open.
262 (backward-up-list 1)
263 (forward-char 1)
264 ;; If there is space here, this is probably something
265 ;; other than a real Lisp function call, so ignore it.
266 (if (looking-at "[ \t]")
267 (error "Probably not a Lisp function call"))
268 (let ((obj (read (current-buffer))))
269 (and (symbolp obj) (fboundp obj) obj))))
270 (error nil))
271 (let* ((str (find-tag-default))
272 (sym (if str (intern-soft str))))
273 (if (and sym (fboundp sym))
275 (save-match-data
276 (when (and str (string-match "\\`\\W*\\(.*?\\)\\W*\\'" str))
277 (setq sym (intern-soft (match-string 1 str)))
278 (and (fboundp sym) sym))))))))
281 ;;; `User' help functions
283 (defun view-help-file (file &optional dir)
284 (view-file (expand-file-name file (or dir data-directory)))
285 (goto-address-mode 1)
286 (goto-char (point-min)))
288 (defun describe-distribution ()
289 "Display info on how to obtain the latest version of GNU Emacs."
290 (interactive)
291 (view-help-file "DISTRIB"))
293 (defun describe-copying ()
294 "Display info on how you may redistribute copies of GNU Emacs."
295 (interactive)
296 (view-help-file "COPYING"))
298 (defun describe-gnu-project ()
299 "Display info on the GNU project."
300 (interactive)
301 (view-help-file "THE-GNU-PROJECT"))
303 (define-obsolete-function-alias 'describe-project 'describe-gnu-project "22.2")
305 (defun describe-no-warranty ()
306 "Display info on all the kinds of warranty Emacs does NOT have."
307 (interactive)
308 (describe-copying)
309 (let (case-fold-search)
310 (search-forward "Disclaimer of Warranty")
311 (forward-line 0)
312 (recenter 0)))
314 (defun describe-prefix-bindings ()
315 "Describe the bindings of the prefix used to reach this command.
316 The prefix described consists of all but the last event
317 of the key sequence that ran this command."
318 (interactive)
319 (let ((key (this-command-keys)))
320 (describe-bindings
321 (if (stringp key)
322 (substring key 0 (1- (length key)))
323 (let ((prefix (make-vector (1- (length key)) nil))
324 (i 0))
325 (while (< i (length prefix))
326 (aset prefix i (aref key i))
327 (setq i (1+ i)))
328 prefix)))))
329 ;; Make C-h after a prefix, when not specifically bound,
330 ;; run describe-prefix-bindings.
331 (setq prefix-help-command 'describe-prefix-bindings)
333 (defun view-emacs-news (&optional version)
334 "Display info on recent changes to Emacs.
335 With argument, display info only for the selected version."
336 (interactive "P")
337 (unless version
338 (setq version emacs-major-version))
339 (when (consp version)
340 (let* ((all-versions
341 (let (res)
342 (mapc
343 (lambda (file)
344 (with-temp-buffer
345 (insert-file-contents
346 (expand-file-name file data-directory))
347 (while (re-search-forward
348 (if (member file '("NEWS.18" "NEWS.1-17"))
349 "Changes in \\(?:Emacs\\|version\\)?[ \t]*\\([0-9]+\\(?:\\.[0-9]+\\)?\\)"
350 "^\* [^0-9\n]*\\([0-9]+\\.[0-9]+\\)") nil t)
351 (setq res (cons (match-string-no-properties 1) res)))))
352 (cons "NEWS"
353 (directory-files data-directory nil
354 "^NEWS\\.[0-9][-0-9]*$" nil)))
355 (sort (delete-dups res) (lambda (a b) (string< b a)))))
356 (current (car all-versions)))
357 (setq version (completing-read
358 (format "Read NEWS for the version (default %s): " current)
359 all-versions nil nil nil nil current))
360 (if (integerp (string-to-number version))
361 (setq version (string-to-number version))
362 (unless (or (member version all-versions)
363 (<= (string-to-number version) (string-to-number current)))
364 (error "No news about version %s" version)))))
365 (when (integerp version)
366 (cond ((<= version 12)
367 (setq version (format "1.%d" version)))
368 ((<= version 18)
369 (setq version (format "%d" version)))
370 ((> version emacs-major-version)
371 (error "No news about Emacs %d (yet)" version))))
372 (let* ((vn (if (stringp version)
373 (string-to-number version)
374 version))
375 (file (cond
376 ((>= vn emacs-major-version) "NEWS")
377 ((< vn 18) "NEWS.1-17")
378 (t (format "NEWS.%d" vn))))
379 res)
380 (view-file (expand-file-name file data-directory))
381 (widen)
382 (goto-char (point-min))
383 (when (stringp version)
384 (when (re-search-forward
385 (concat (if (< vn 19)
386 "Changes in Emacs[ \t]*"
387 "^\* [^0-9\n]*") version "$")
388 nil t)
389 (beginning-of-line)
390 (narrow-to-region
391 (point)
392 (save-excursion
393 (while (and (setq res
394 (re-search-forward
395 (if (< vn 19)
396 "Changes in \\(?:Emacs\\|version\\)?[ \t]*\\([0-9]+\\(?:\\.[0-9]+\\)?\\)"
397 "^\* [^0-9\n]*\\([0-9]+\\.[0-9]+\\)") nil t))
398 (equal (match-string-no-properties 1) version)))
399 (or res (goto-char (point-max)))
400 (beginning-of-line)
401 (point)))))))
403 (defun view-emacs-todo (&optional _arg)
404 "Display the Emacs TODO list."
405 (interactive "P")
406 (view-help-file "TODO"))
408 (define-obsolete-function-alias 'view-todo 'view-emacs-todo "22.2")
411 (defun view-echo-area-messages ()
412 "View the log of recent echo-area messages: the `*Messages*' buffer.
413 The number of messages retained in that buffer
414 is specified by the variable `message-log-max'."
415 (interactive)
416 (with-current-buffer (messages-buffer)
417 (goto-char (point-max))
418 (display-buffer (current-buffer))))
420 (defun view-order-manuals ()
421 "Display information on how to buy printed copies of Emacs manuals."
422 (interactive)
423 ;; (view-help-file "ORDERS")
424 (info "(emacs)Printed Books"))
426 (defun view-emacs-FAQ ()
427 "Display the Emacs Frequently Asked Questions (FAQ) file."
428 (interactive)
429 ;; (find-file-read-only (expand-file-name "FAQ" data-directory))
430 (info "(efaq)"))
432 (defun view-emacs-problems ()
433 "Display info on known problems with Emacs and possible workarounds."
434 (interactive)
435 (view-help-file "PROBLEMS"))
437 (defun view-emacs-debugging ()
438 "Display info on how to debug Emacs problems."
439 (interactive)
440 (view-help-file "DEBUG"))
442 ;; This used to visit MORE.STUFF; maybe it should just be removed.
443 (defun view-external-packages ()
444 "Display info on where to get more Emacs packages."
445 (interactive)
446 (info "(efaq)Packages that do not come with Emacs"))
448 (defun view-lossage ()
449 "Display last 300 input keystrokes.
451 To record all your input on a file, use `open-dribble-file'."
452 (interactive)
453 (help-setup-xref (list #'view-lossage)
454 (called-interactively-p 'interactive))
455 (with-help-window (help-buffer)
456 (princ (mapconcat (lambda (key)
457 (if (or (integerp key) (symbolp key) (listp key))
458 (single-key-description key)
459 (prin1-to-string key nil)))
460 (recent-keys)
461 " "))
462 (with-current-buffer standard-output
463 (goto-char (point-min))
464 (while (progn (move-to-column 50) (not (eobp)))
465 (when (search-forward " " nil t)
466 (delete-char -1))
467 (insert "\n"))
468 ;; jidanni wants to see the last keystrokes immediately.
469 (set-marker help-window-point-marker (point)))))
472 ;; Key bindings
474 (defun describe-bindings (&optional prefix buffer)
475 "Display a buffer showing a list of all defined keys, and their definitions.
476 The keys are displayed in order of precedence.
478 The optional argument PREFIX, if non-nil, should be a key sequence;
479 then we display only bindings that start with that prefix.
480 The optional argument BUFFER specifies which buffer's bindings
481 to display (default, the current buffer). BUFFER can be a buffer
482 or a buffer name."
483 (interactive)
484 (or buffer (setq buffer (current-buffer)))
485 (help-setup-xref (list #'describe-bindings prefix buffer)
486 (called-interactively-p 'interactive))
487 (with-current-buffer buffer
488 (describe-bindings-internal nil prefix)))
490 ;; This function used to be in keymap.c.
491 (defun describe-bindings-internal (&optional menus prefix)
492 "Show a list of all defined keys, and their definitions.
493 We put that list in a buffer, and display the buffer.
495 The optional argument MENUS, if non-nil, says to mention menu bindings.
496 \(Ordinarily these are omitted from the output.)
497 The optional argument PREFIX, if non-nil, should be a key sequence;
498 then we display only bindings that start with that prefix."
499 (let ((buf (current-buffer)))
500 (with-help-window (help-buffer)
501 (describe-buffer-bindings buf prefix menus))))
503 (defun where-is (definition &optional insert)
504 "Print message listing key sequences that invoke the command DEFINITION.
505 Argument is a command definition, usually a symbol with a function definition.
506 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
507 (interactive
508 (let ((fn (function-called-at-point))
509 (enable-recursive-minibuffers t)
510 val)
511 (setq val (completing-read
512 (if fn
513 (format "Where is command (default %s): " fn)
514 "Where is command: ")
515 obarray 'commandp t))
516 (list (if (equal val "") fn (intern val)) current-prefix-arg)))
517 (unless definition (error "No command"))
518 (let ((func (indirect-function definition))
519 (defs nil)
520 (standard-output (if insert (current-buffer) standard-output)))
521 ;; In DEFS, find all symbols that are aliases for DEFINITION.
522 (mapatoms (lambda (symbol)
523 (and (fboundp symbol)
524 (not (eq symbol definition))
525 (eq func (condition-case ()
526 (indirect-function symbol)
527 (error symbol)))
528 (push symbol defs))))
529 ;; Look at all the symbols--first DEFINITION,
530 ;; then its aliases.
531 (dolist (symbol (cons definition defs))
532 (let* ((remapped (command-remapping symbol))
533 (keys (where-is-internal
534 symbol overriding-local-map nil nil remapped))
535 (keys (mapconcat 'key-description keys ", "))
536 string)
537 (setq string
538 (if insert
539 (if (> (length keys) 0)
540 (if remapped
541 (format "%s (%s) (remapped from %s)"
542 keys remapped symbol)
543 (format "%s (%s)" keys symbol))
544 (format "M-x %s RET" symbol))
545 (if (> (length keys) 0)
546 (if remapped
547 (format "%s is remapped to %s which is on %s"
548 symbol remapped keys)
549 (format "%s is on %s" symbol keys))
550 ;; If this is the command the user asked about,
551 ;; and it is not on any key, say so.
552 ;; For other symbols, its aliases, say nothing
553 ;; about them unless they are on keys.
554 (if (eq symbol definition)
555 (format "%s is not on any key" symbol)))))
556 (when string
557 (unless (eq symbol definition)
558 (princ ";\n its alias "))
559 (princ string)))))
560 nil)
562 (defun help-key-description (key untranslated)
563 (let ((string (key-description key)))
564 (if (or (not untranslated)
565 (and (eq (aref untranslated 0) ?\e) (not (eq (aref key 0) ?\e))))
566 string
567 (let ((otherstring (key-description untranslated)))
568 (if (equal string otherstring)
569 string
570 (format "%s (translated from %s)" string otherstring))))))
572 (defun describe-key-briefly (&optional key insert untranslated)
573 "Print the name of the function KEY invokes. KEY is a string.
574 If INSERT (the prefix arg) is non-nil, insert the message in the buffer.
575 If non-nil, UNTRANSLATED is a vector of the untranslated events.
576 It can also be a number in which case the untranslated events from
577 the last key hit are used.
579 If KEY is a menu item or a tool-bar button that is disabled, this command
580 temporarily enables it to allow getting help on disabled items and buttons."
581 (interactive
582 (let ((enable-disabled-menus-and-buttons t)
583 (cursor-in-echo-area t)
584 saved-yank-menu)
585 (unwind-protect
586 (let (key)
587 ;; If yank-menu is empty, populate it temporarily, so that
588 ;; "Select and Paste" menu can generate a complete event.
589 (when (null (cdr yank-menu))
590 (setq saved-yank-menu (copy-sequence yank-menu))
591 (menu-bar-update-yank-menu "(any string)" nil))
592 (setq key (read-key-sequence "Describe key (or click or menu item): "))
593 ;; Clear the echo area message (Bug#7014).
594 (message nil)
595 ;; If KEY is a down-event, read and discard the
596 ;; corresponding up-event. Note that there are also
597 ;; down-events on scroll bars and mode lines: the actual
598 ;; event then is in the second element of the vector.
599 (and (vectorp key)
600 (let ((last-idx (1- (length key))))
601 (and (eventp (aref key last-idx))
602 (memq 'down (event-modifiers (aref key last-idx)))))
603 (read-event))
604 (list
606 (if current-prefix-arg (prefix-numeric-value current-prefix-arg))
608 ;; Put yank-menu back as it was, if we changed it.
609 (when saved-yank-menu
610 (setq yank-menu (copy-sequence saved-yank-menu))
611 (fset 'yank-menu (cons 'keymap yank-menu))))))
612 (if (numberp untranslated)
613 (setq untranslated (this-single-command-raw-keys)))
614 (let* ((event (if (and (symbolp (aref key 0))
615 (> (length key) 1)
616 (consp (aref key 1)))
617 (aref key 1)
618 (aref key 0)))
619 (modifiers (event-modifiers event))
620 (standard-output (if insert (current-buffer) standard-output))
621 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
622 (memq 'drag modifiers)) " at that spot" ""))
623 (defn (key-binding key t))
624 key-desc)
625 ;; Handle the case where we faked an entry in "Select and Paste" menu.
626 (if (and (eq defn nil)
627 (stringp (aref key (1- (length key))))
628 (eq (key-binding (substring key 0 -1)) 'yank-menu))
629 (setq defn 'menu-bar-select-yank))
630 ;; Don't bother user with strings from (e.g.) the select-paste menu.
631 (if (stringp (aref key (1- (length key))))
632 (aset key (1- (length key)) "(any string)"))
633 (if (and (> (length untranslated) 0)
634 (stringp (aref untranslated (1- (length untranslated)))))
635 (aset untranslated (1- (length untranslated)) "(any string)"))
636 ;; Now describe the key, perhaps as changed.
637 (setq key-desc (help-key-description key untranslated))
638 (if (or (null defn) (integerp defn) (equal defn 'undefined))
639 (princ (format "%s%s is undefined" key-desc mouse-msg))
640 (princ (format "%s%s runs the command %S" key-desc mouse-msg defn)))))
642 (defun describe-key (&optional key untranslated up-event)
643 "Display documentation of the function invoked by KEY.
644 KEY can be any kind of a key sequence; it can include keyboard events,
645 mouse events, and/or menu events. When calling from a program,
646 pass KEY as a string or a vector.
648 If non-nil, UNTRANSLATED is a vector of the corresponding untranslated events.
649 It can also be a number, in which case the untranslated events from
650 the last key sequence entered are used.
651 UP-EVENT is the up-event that was discarded by reading KEY, or nil.
653 If KEY is a menu item or a tool-bar button that is disabled, this command
654 temporarily enables it to allow getting help on disabled items and buttons."
655 (interactive
656 (let ((enable-disabled-menus-and-buttons t)
657 (cursor-in-echo-area t)
658 saved-yank-menu)
659 (unwind-protect
660 (let (key)
661 ;; If yank-menu is empty, populate it temporarily, so that
662 ;; "Select and Paste" menu can generate a complete event.
663 (when (null (cdr yank-menu))
664 (setq saved-yank-menu (copy-sequence yank-menu))
665 (menu-bar-update-yank-menu "(any string)" nil))
666 (setq key (read-key-sequence "Describe key (or click or menu item): "))
667 (list
669 (prefix-numeric-value current-prefix-arg)
670 ;; If KEY is a down-event, read and include the
671 ;; corresponding up-event. Note that there are also
672 ;; down-events on scroll bars and mode lines: the actual
673 ;; event then is in the second element of the vector.
674 (and (vectorp key)
675 (let ((last-idx (1- (length key))))
676 (and (eventp (aref key last-idx))
677 (memq 'down (event-modifiers (aref key last-idx)))))
678 (or (and (eventp (aref key 0))
679 (memq 'down (event-modifiers (aref key 0)))
680 ;; However, for the C-down-mouse-2 popup
681 ;; menu, there is no subsequent up-event. In
682 ;; this case, the up-event is the next
683 ;; element in the supplied vector.
684 (= (length key) 1))
685 (and (> (length key) 1)
686 (eventp (aref key 1))
687 (memq 'down (event-modifiers (aref key 1)))))
688 (read-event))))
689 ;; Put yank-menu back as it was, if we changed it.
690 (when saved-yank-menu
691 (setq yank-menu (copy-sequence saved-yank-menu))
692 (fset 'yank-menu (cons 'keymap yank-menu))))))
693 (if (numberp untranslated)
694 (setq untranslated (this-single-command-raw-keys)))
695 (let* ((event (aref key (if (and (symbolp (aref key 0))
696 (> (length key) 1)
697 (consp (aref key 1)))
699 0)))
700 (modifiers (event-modifiers event))
701 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
702 (memq 'drag modifiers)) " at that spot" ""))
703 (defn (key-binding key t))
704 defn-up defn-up-tricky ev-type
705 mouse-1-remapped mouse-1-tricky)
707 ;; Handle the case where we faked an entry in "Select and Paste" menu.
708 (when (and (eq defn nil)
709 (stringp (aref key (1- (length key))))
710 (eq (key-binding (substring key 0 -1)) 'yank-menu))
711 (setq defn 'menu-bar-select-yank))
712 (if (or (null defn) (integerp defn) (equal defn 'undefined))
713 (message "%s%s is undefined"
714 (help-key-description key untranslated) mouse-msg)
715 (help-setup-xref (list #'describe-function defn)
716 (called-interactively-p 'interactive))
717 ;; Don't bother user with strings from (e.g.) the select-paste menu.
718 (when (stringp (aref key (1- (length key))))
719 (aset key (1- (length key)) "(any string)"))
720 (when (and untranslated
721 (stringp (aref untranslated (1- (length untranslated)))))
722 (aset untranslated (1- (length untranslated))
723 "(any string)"))
724 ;; Need to do this before erasing *Help* buffer in case event
725 ;; is a mouse click in an existing *Help* buffer.
726 (when up-event
727 (setq ev-type (event-basic-type up-event))
728 (let ((sequence (vector up-event)))
729 (when (and (eq ev-type 'mouse-1)
730 mouse-1-click-follows-link
731 (not (eq mouse-1-click-follows-link 'double))
732 (setq mouse-1-remapped
733 (mouse-on-link-p (event-start up-event))))
734 (setq mouse-1-tricky (and (integerp mouse-1-click-follows-link)
735 (> mouse-1-click-follows-link 0)))
736 (cond ((stringp mouse-1-remapped)
737 (setq sequence mouse-1-remapped))
738 ((vectorp mouse-1-remapped)
739 (setcar up-event (elt mouse-1-remapped 0)))
740 (t (setcar up-event 'mouse-2))))
741 (setq defn-up (key-binding sequence nil nil (event-start up-event)))
742 (when mouse-1-tricky
743 (setq sequence (vector up-event))
744 (aset sequence 0 'mouse-1)
745 (setq defn-up-tricky (key-binding sequence nil nil (event-start up-event))))))
746 (with-help-window (help-buffer)
747 (princ (help-key-description key untranslated))
748 (princ (format "\
749 %s runs the command %S, which is "
750 mouse-msg defn))
751 (describe-function-1 defn)
752 (when up-event
753 (unless (or (null defn-up)
754 (integerp defn-up)
755 (equal defn-up 'undefined))
756 (princ (format "
758 ----------------- up-event %s----------------
760 %s%s%s runs the command %S, which is "
761 (if mouse-1-tricky "(short click) " "")
762 (key-description (vector up-event))
763 mouse-msg
764 (if mouse-1-remapped
765 " is remapped to <mouse-2>, which" "")
766 defn-up))
767 (describe-function-1 defn-up))
768 (unless (or (null defn-up-tricky)
769 (integerp defn-up-tricky)
770 (eq defn-up-tricky 'undefined))
771 (princ (format "
773 ----------------- up-event (long click) ----------------
775 Pressing <%S>%s for longer than %d milli-seconds
776 runs the command %S, which is "
777 ev-type mouse-msg
778 mouse-1-click-follows-link
779 defn-up-tricky))
780 (describe-function-1 defn-up-tricky)))))))
782 (defun describe-mode (&optional buffer)
783 "Display documentation of current major mode and minor modes.
784 A brief summary of the minor modes comes first, followed by the
785 major mode description. This is followed by detailed
786 descriptions of the minor modes, each on a separate page.
788 For this to work correctly for a minor mode, the mode's indicator
789 variable \(listed in `minor-mode-alist') must also be a function
790 whose documentation describes the minor mode.
792 If called from Lisp with a non-nil BUFFER argument, display
793 documentation for the major and minor modes of that buffer."
794 (interactive "@")
795 (unless buffer (setq buffer (current-buffer)))
796 (help-setup-xref (list #'describe-mode buffer)
797 (called-interactively-p 'interactive))
798 ;; For the sake of help-do-xref and help-xref-go-back,
799 ;; don't switch buffers before calling `help-buffer'.
800 (with-help-window (help-buffer)
801 (with-current-buffer buffer
802 (let (minor-modes)
803 ;; Older packages do not register in minor-mode-list but only in
804 ;; minor-mode-alist.
805 (dolist (x minor-mode-alist)
806 (setq x (car x))
807 (unless (memq x minor-mode-list)
808 (push x minor-mode-list)))
809 ;; Find enabled minor mode we will want to mention.
810 (dolist (mode minor-mode-list)
811 ;; Document a minor mode if it is listed in minor-mode-alist,
812 ;; non-nil, and has a function definition.
813 (let ((fmode (or (get mode :minor-mode-function) mode)))
814 (and (boundp mode) (symbol-value mode)
815 (fboundp fmode)
816 (let ((pretty-minor-mode
817 (if (string-match "\\(\\(-minor\\)?-mode\\)?\\'"
818 (symbol-name fmode))
819 (capitalize
820 (substring (symbol-name fmode)
821 0 (match-beginning 0)))
822 fmode)))
823 (push (list fmode pretty-minor-mode
824 (format-mode-line (assq mode minor-mode-alist)))
825 minor-modes)))))
826 (setq minor-modes
827 (sort minor-modes
828 (lambda (a b) (string-lessp (cadr a) (cadr b)))))
829 (when minor-modes
830 (princ "Enabled minor modes:\n")
831 (make-local-variable 'help-button-cache)
832 (with-current-buffer standard-output
833 (dolist (mode minor-modes)
834 (let ((mode-function (nth 0 mode))
835 (pretty-minor-mode (nth 1 mode))
836 (indicator (nth 2 mode)))
837 (add-text-properties 0 (length pretty-minor-mode)
838 '(face bold) pretty-minor-mode)
839 (save-excursion
840 (goto-char (point-max))
841 (princ "\n\f\n")
842 (push (point-marker) help-button-cache)
843 ;; Document the minor modes fully.
844 (insert pretty-minor-mode)
845 (princ (format " minor mode (%s):\n"
846 (if (zerop (length indicator))
847 "no indicator"
848 (format "indicator%s"
849 indicator))))
850 (princ (documentation mode-function)))
851 (insert-button pretty-minor-mode
852 'action (car help-button-cache)
853 'follow-link t
854 'help-echo "mouse-2, RET: show full information")
855 (newline)))
856 (forward-line -1)
857 (fill-paragraph nil)
858 (forward-line 1))
860 (princ "\n(Information about these minor modes follows the major mode info.)\n\n"))
861 ;; Document the major mode.
862 (let ((mode mode-name))
863 (with-current-buffer standard-output
864 (let ((start (point)))
865 (insert (format-mode-line mode nil nil buffer))
866 (add-text-properties start (point) '(face bold)))))
867 (princ " mode")
868 (let* ((mode major-mode)
869 (file-name (find-lisp-object-file-name mode nil)))
870 (when file-name
871 (princ (concat " defined in `" (file-name-nondirectory file-name) "'"))
872 ;; Make a hyperlink to the library.
873 (with-current-buffer standard-output
874 (save-excursion
875 (re-search-backward "`\\([^`']+\\)'" nil t)
876 (help-xref-button 1 'help-function-def mode file-name)))))
877 (princ ":\n")
878 (princ (documentation major-mode)))))
879 ;; For the sake of IELM and maybe others
880 nil)
883 (defun describe-minor-mode (minor-mode)
884 "Display documentation of a minor mode given as MINOR-MODE.
885 MINOR-MODE can be a minor mode symbol or a minor mode indicator string
886 appeared on the mode-line."
887 (interactive (list (completing-read
888 "Minor mode: "
889 (nconc
890 (describe-minor-mode-completion-table-for-symbol)
891 (describe-minor-mode-completion-table-for-indicator)
892 ))))
893 (if (symbolp minor-mode)
894 (setq minor-mode (symbol-name minor-mode)))
895 (let ((symbols (describe-minor-mode-completion-table-for-symbol))
896 (indicators (describe-minor-mode-completion-table-for-indicator)))
897 (cond
898 ((member minor-mode symbols)
899 (describe-minor-mode-from-symbol (intern minor-mode)))
900 ((member minor-mode indicators)
901 (describe-minor-mode-from-indicator minor-mode))
903 (error "No such minor mode: %s" minor-mode)))))
905 ;; symbol
906 (defun describe-minor-mode-completion-table-for-symbol ()
907 ;; In order to list up all minor modes, minor-mode-list
908 ;; is used here instead of minor-mode-alist.
909 (delq nil (mapcar 'symbol-name minor-mode-list)))
911 (defun describe-minor-mode-from-symbol (symbol)
912 "Display documentation of a minor mode given as a symbol, SYMBOL"
913 (interactive (list (intern (completing-read
914 "Minor mode symbol: "
915 (describe-minor-mode-completion-table-for-symbol)))))
916 (if (fboundp symbol)
917 (describe-function symbol)
918 (describe-variable symbol)))
920 ;; indicator
921 (defun describe-minor-mode-completion-table-for-indicator ()
922 (delq nil
923 (mapcar (lambda (x)
924 (let ((i (format-mode-line x)))
925 ;; remove first space if existed
926 (cond
927 ((= 0 (length i))
928 nil)
929 ((eq (aref i 0) ?\s)
930 (substring i 1))
932 i))))
933 minor-mode-alist)))
935 (defun describe-minor-mode-from-indicator (indicator)
936 "Display documentation of a minor mode specified by INDICATOR.
937 If you call this function interactively, you can give indicator which
938 is currently activated with completion."
939 (interactive (list
940 (completing-read
941 "Minor mode indicator: "
942 (describe-minor-mode-completion-table-for-indicator))))
943 (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))
944 (if minor-mode
945 (describe-minor-mode-from-symbol minor-mode)
946 (error "Cannot find minor mode for `%s'" indicator))))
948 (defun lookup-minor-mode-from-indicator (indicator)
949 "Return a minor mode symbol from its indicator on the mode line."
950 ;; remove first space if existed
951 (if (and (< 0 (length indicator))
952 (eq (aref indicator 0) ?\s))
953 (setq indicator (substring indicator 1)))
954 (let ((minor-modes minor-mode-alist)
955 result)
956 (while minor-modes
957 (let* ((minor-mode (car (car minor-modes)))
958 (anindicator (format-mode-line
959 (car (cdr (car minor-modes))))))
960 ;; remove first space if existed
961 (if (and (stringp anindicator)
962 (> (length anindicator) 0)
963 (eq (aref anindicator 0) ?\s))
964 (setq anindicator (substring anindicator 1)))
965 (if (equal indicator anindicator)
966 (setq result minor-mode
967 minor-modes nil)
968 (setq minor-modes (cdr minor-modes)))))
969 result))
971 ;;; Automatic resizing of temporary buffers.
972 (defcustom temp-buffer-max-height
973 (lambda (buffer)
974 (if (eq (selected-window) (frame-root-window))
975 (/ (x-display-pixel-height) (frame-char-height) 2)
976 (/ (- (frame-height) 2) 2)))
977 "Maximum height of a window displaying a temporary buffer.
978 This is effective only when Temp Buffer Resize mode is enabled.
979 The value is the maximum height (in lines) which
980 `resize-temp-buffer-window' will give to a window displaying a
981 temporary buffer. It can also be a function to be called to
982 choose the height for such a buffer. It gets one argument, the
983 buffer, and should return a positive integer. At the time the
984 function is called, the window to be resized is selected."
985 :type '(choice integer function)
986 :group 'help
987 :version "24.3")
989 (defcustom temp-buffer-max-width
990 (lambda (buffer)
991 (if (eq (selected-window) (frame-root-window))
992 (/ (x-display-pixel-width) (frame-char-width) 2)
993 (/ (- (frame-width) 2) 2)))
994 "Maximum width of a window displaying a temporary buffer.
995 This is effective only when Temp Buffer Resize mode is enabled.
996 The value is the maximum width (in columns) which
997 `resize-temp-buffer-window' will give to a window displaying a
998 temporary buffer. It can also be a function to be called to
999 choose the width for such a buffer. It gets one argument, the
1000 buffer, and should return a positive integer. At the time the
1001 function is called, the window to be resized is selected."
1002 :type '(choice integer function)
1003 :group 'help
1004 :version "24.4")
1006 (define-minor-mode temp-buffer-resize-mode
1007 "Toggle auto-resizing temporary buffer windows (Temp Buffer Resize Mode).
1008 With a prefix argument ARG, enable Temp Buffer Resize mode if ARG
1009 is positive, and disable it otherwise. If called from Lisp,
1010 enable the mode if ARG is omitted or nil.
1012 When Temp Buffer Resize mode is enabled, the windows in which we
1013 show a temporary buffer are automatically resized in height to
1014 fit the buffer's contents, but never more than
1015 `temp-buffer-max-height' nor less than `window-min-height'.
1017 A window is resized only if it has been specially created for the
1018 buffer. Windows that have shown another buffer before are not
1019 resized. A frame is resized only if `fit-frame-to-buffer' is
1020 non-nil.
1022 This mode is used by `help', `apropos' and `completion' buffers,
1023 and some others."
1024 :global t :group 'help
1025 (if temp-buffer-resize-mode
1026 ;; `help-make-xrefs' may add a `back' button and thus increase the
1027 ;; text size, so `resize-temp-buffer-window' must be run *after* it.
1028 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
1029 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)))
1031 (defun resize-temp-buffer-window (&optional window)
1032 "Resize WINDOW to fit its contents.
1033 WINDOW must be a live window and defaults to the selected one.
1034 Do not resize if WINDOW was not created by `display-buffer'.
1036 If WINDOW is part of a vertical combination, restrain its new
1037 size by `temp-buffer-max-height' and do not resize if its minimum
1038 accessible position is scrolled out of view. If WINDOW is part
1039 of a horizontal combination, restrain its new size by
1040 `temp-buffer-max-width'. In both cases, the value of the option
1041 `fit-window-to-buffer-horizontally' can inhibit resizing.
1043 If WINDOW is the root window of its frame, resize the frame
1044 provided `fit-frame-to-buffer' is non-nil."
1045 (setq window (window-normalize-window window t))
1046 (let ((height (if (functionp temp-buffer-max-height)
1047 (with-selected-window window
1048 (funcall temp-buffer-max-height (window-buffer)))
1049 temp-buffer-max-height))
1050 (width (if (functionp temp-buffer-max-width)
1051 (with-selected-window window
1052 (funcall temp-buffer-max-width (window-buffer)))
1053 temp-buffer-max-width))
1054 (quit-cadr (cadr (window-parameter window 'quit-restore))))
1055 ;; Resize WINDOW iff it was made by `display-buffer'.
1056 (when (or (and (eq quit-cadr 'window)
1057 (or (and (window-combined-p window)
1058 (not (eq fit-window-to-buffer-horizontally
1059 'only))
1060 (pos-visible-in-window-p (point-min) window))
1061 (and (window-combined-p window t)
1062 fit-window-to-buffer-horizontally)))
1063 (and (eq quit-cadr 'frame)
1064 fit-frame-to-buffer
1065 (eq window (frame-root-window window))))
1066 (fit-window-to-buffer window height nil width))))
1068 ;;; Help windows.
1069 (defcustom help-window-select 'other
1070 "Non-nil means select help window for viewing.
1071 Choices are:
1072 never (nil) Select help window only if there is no other window
1073 on its frame.
1074 other Select help window unless the selected window is the
1075 only other window on the help window's frame.
1076 always (t) Always select the help window.
1078 This option has effect if and only if the help window was created
1079 by `with-help-window'"
1080 :type '(choice (const :tag "never (nil)" nil)
1081 (const :tag "other" other)
1082 (const :tag "always (t)" t))
1083 :group 'help
1084 :version "23.1")
1086 (defcustom help-enable-auto-load t
1087 "Whether Help commands can perform autoloading.
1088 If non-nil, whenever \\[describe-function] is called for an
1089 autoloaded function whose docstring contains any key substitution
1090 construct (see `substitute-command-keys'), the library is loaded,
1091 so that the documentation can show the right key bindings."
1092 :type 'boolean
1093 :group 'help
1094 :version "24.3")
1096 (defun help-window-display-message (quit-part window &optional scroll)
1097 "Display message telling how to quit and scroll help window.
1098 QUIT-PART is a string telling how to quit the help window WINDOW.
1099 Optional argument SCROLL non-nil means tell how to scroll WINDOW.
1100 SCROLL equal `other' means tell how to scroll the \"other\"
1101 window."
1102 (let ((scroll-part
1103 (cond
1104 ;; If we don't have QUIT-PART we probably reuse a window
1105 ;; showing the same buffer so we don't show any message.
1106 ((not quit-part) nil)
1107 ((pos-visible-in-window-p
1108 (with-current-buffer (window-buffer window)
1109 (point-max)) window t)
1110 ;; Buffer end is at least partially visible, no need to talk
1111 ;; about scrolling.
1112 ".")
1113 ((eq scroll 'other)
1114 ", \\[scroll-other-window] to scroll help.")
1115 (scroll ", \\[scroll-up] to scroll help."))))
1116 (message "%s"
1117 (substitute-command-keys (concat quit-part scroll-part)))))
1119 (defun help-window-setup (window &optional value)
1120 "Set up help window WINDOW for `with-help-window'.
1121 WINDOW is the window used for displaying the help buffer.
1122 Return VALUE."
1123 (let* ((help-buffer (when (window-live-p window)
1124 (window-buffer window)))
1125 (help-setup (when (window-live-p window)
1126 (car (window-parameter window 'quit-restore)))))
1127 (when help-buffer
1128 ;; Handle `help-window-point-marker'.
1129 (when (eq (marker-buffer help-window-point-marker) help-buffer)
1130 (set-window-point window help-window-point-marker)
1131 ;; Reset `help-window-point-marker'.
1132 (set-marker help-window-point-marker nil))
1134 (cond
1135 ((or (eq window (selected-window))
1136 (and (or (eq help-window-select t)
1137 (eq help-setup 'frame)
1138 (and (eq help-window-select 'other)
1139 (eq (window-frame window) (selected-frame))
1140 (> (length (window-list nil 'no-mini)) 2)))
1141 (select-window window)))
1142 ;; The help window is or gets selected ...
1143 (help-window-display-message
1144 (cond
1145 ((eq help-setup 'window)
1146 ;; ... and is new, ...
1147 "Type \"q\" to delete help window")
1148 ((eq help-setup 'frame)
1149 "Type \"q\" to quit the help frame")
1150 ((eq help-setup 'other)
1151 ;; ... or displayed some other buffer before.
1152 "Type \"q\" to restore previous buffer"))
1153 window t))
1154 ((and (eq (window-frame window) (selected-frame))
1155 (= (length (window-list nil 'no-mini)) 2))
1156 ;; There are two windows on the help window's frame and the
1157 ;; other one is the selected one.
1158 (help-window-display-message
1159 (cond
1160 ((eq help-setup 'window)
1161 "Type \\[delete-other-windows] to delete the help window")
1162 ((eq help-setup 'other)
1163 "Type \"q\" in help window to restore its previous buffer"))
1164 window 'other))
1166 ;; The help window is not selected ...
1167 (help-window-display-message
1168 (cond
1169 ((eq help-setup 'window)
1170 ;; ... and is new, ...
1171 "Type \"q\" in help window to delete it")
1172 ((eq help-setup 'other)
1173 ;; ... or displayed some other buffer before.
1174 "Type \"q\" in help window to restore previous buffer"))
1175 window))))
1176 ;; Return VALUE.
1177 value))
1179 ;; `with-help-window' is a wrapper for `with-temp-buffer-window'
1180 ;; providing the following additional twists:
1182 ;; (1) It puts the buffer in `help-mode' (via `help-mode-setup') and
1183 ;; adds cross references (via `help-mode-finish').
1185 ;; (2) It issues a message telling how to scroll and quit the help
1186 ;; window (via `help-window-setup').
1188 ;; (3) An option (customizable via `help-window-select') to select the
1189 ;; help window automatically.
1191 ;; (4) A marker (`help-window-point-marker') to move point in the help
1192 ;; window to an arbitrary buffer position.
1194 ;; Note: It's usually always wrong to use `help-print-return-message' in
1195 ;; the body of `with-help-window'.
1196 (defmacro with-help-window (buffer-name &rest body)
1197 "Display buffer with name BUFFER-NAME in a help window evaluating BODY.
1198 Select help window if the current value of the user option
1199 `help-window-select' says so. Return last value in BODY."
1200 (declare (indent 1) (debug t))
1201 `(progn
1202 ;; Make `help-window-point-marker' point nowhere. The only place
1203 ;; where this should be set to a buffer position is within BODY.
1204 (set-marker help-window-point-marker nil)
1205 (let ((temp-buffer-window-setup-hook
1206 (cons 'help-mode-setup temp-buffer-window-setup-hook))
1207 (temp-buffer-window-show-hook
1208 (cons 'help-mode-finish temp-buffer-window-show-hook)))
1209 (with-temp-buffer-window
1210 ,buffer-name nil 'help-window-setup (progn ,@body)))))
1212 ;; Called from C, on encountering `help-char' when reading a char.
1213 ;; Don't print to *Help*; that would clobber Help history.
1214 (defun help-form-show ()
1215 "Display the output of a non-nil `help-form'."
1216 (let ((msg (eval help-form)))
1217 (if (stringp msg)
1218 (with-output-to-temp-buffer " *Char Help*"
1219 (princ msg)))))
1221 (provide 'help)
1223 ;;; help.el ends here