Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / help.el
blobe80d2d8590553c8d6b8c1dd521ab1d796f50538a
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 the Emacs ORDERS file."
421 (interactive)
422 (view-help-file "ORDERS"))
424 (defun view-emacs-FAQ ()
425 "Display the Emacs Frequently Asked Questions (FAQ) file."
426 (interactive)
427 ;; (find-file-read-only (expand-file-name "FAQ" data-directory))
428 (info "(efaq)"))
430 (defun view-emacs-problems ()
431 "Display info on known problems with Emacs and possible workarounds."
432 (interactive)
433 (view-help-file "PROBLEMS"))
435 (defun view-emacs-debugging ()
436 "Display info on how to debug Emacs problems."
437 (interactive)
438 (view-help-file "DEBUG"))
440 (defun view-external-packages ()
441 "Display external packages and information about Emacs."
442 (interactive)
443 (view-help-file "MORE.STUFF"))
445 (defun view-lossage ()
446 "Display last 300 input keystrokes.
448 To record all your input on a file, use `open-dribble-file'."
449 (interactive)
450 (help-setup-xref (list #'view-lossage)
451 (called-interactively-p 'interactive))
452 (with-help-window (help-buffer)
453 (princ (mapconcat (lambda (key)
454 (if (or (integerp key) (symbolp key) (listp key))
455 (single-key-description key)
456 (prin1-to-string key nil)))
457 (recent-keys)
458 " "))
459 (with-current-buffer standard-output
460 (goto-char (point-min))
461 (while (progn (move-to-column 50) (not (eobp)))
462 (when (search-forward " " nil t)
463 (delete-char -1))
464 (insert "\n"))
465 ;; jidanni wants to see the last keystrokes immediately.
466 (set-marker help-window-point-marker (point)))))
469 ;; Key bindings
471 (defun describe-bindings (&optional prefix buffer)
472 "Show a list of all defined keys, and their definitions.
473 We put that list in a buffer, and display the buffer.
475 The optional argument PREFIX, if non-nil, should be a key sequence;
476 then we display only bindings that start with that prefix.
477 The optional argument BUFFER specifies which buffer's bindings
478 to display (default, the current buffer). BUFFER can be a buffer
479 or a buffer name."
480 (interactive)
481 (or buffer (setq buffer (current-buffer)))
482 (help-setup-xref (list #'describe-bindings prefix buffer)
483 (called-interactively-p 'interactive))
484 (with-current-buffer buffer
485 (describe-bindings-internal nil prefix)))
487 ;; This function used to be in keymap.c.
488 (defun describe-bindings-internal (&optional menus prefix)
489 "Show a list of all defined keys, and their definitions.
490 We put that list in a buffer, and display the buffer.
492 The optional argument MENUS, if non-nil, says to mention menu bindings.
493 \(Ordinarily these are omitted from the output.)
494 The optional argument PREFIX, if non-nil, should be a key sequence;
495 then we display only bindings that start with that prefix."
496 (let ((buf (current-buffer)))
497 (with-help-window (help-buffer)
498 (describe-buffer-bindings buf prefix menus))))
500 (defun where-is (definition &optional insert)
501 "Print message listing key sequences that invoke the command DEFINITION.
502 Argument is a command definition, usually a symbol with a function definition.
503 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
504 (interactive
505 (let ((fn (function-called-at-point))
506 (enable-recursive-minibuffers t)
507 val)
508 (setq val (completing-read
509 (if fn
510 (format "Where is command (default %s): " fn)
511 "Where is command: ")
512 obarray 'commandp t))
513 (list (if (equal val "") fn (intern val)) current-prefix-arg)))
514 (unless definition (error "No command"))
515 (let ((func (indirect-function definition))
516 (defs nil)
517 (standard-output (if insert (current-buffer) standard-output)))
518 ;; In DEFS, find all symbols that are aliases for DEFINITION.
519 (mapatoms (lambda (symbol)
520 (and (fboundp symbol)
521 (not (eq symbol definition))
522 (eq func (condition-case ()
523 (indirect-function symbol)
524 (error symbol)))
525 (push symbol defs))))
526 ;; Look at all the symbols--first DEFINITION,
527 ;; then its aliases.
528 (dolist (symbol (cons definition defs))
529 (let* ((remapped (command-remapping symbol))
530 (keys (where-is-internal
531 symbol overriding-local-map nil nil remapped))
532 (keys (mapconcat 'key-description keys ", "))
533 string)
534 (setq string
535 (if insert
536 (if (> (length keys) 0)
537 (if remapped
538 (format "%s (%s) (remapped from %s)"
539 keys remapped symbol)
540 (format "%s (%s)" keys symbol))
541 (format "M-x %s RET" symbol))
542 (if (> (length keys) 0)
543 (if remapped
544 (format "%s is remapped to %s which is on %s"
545 symbol remapped keys)
546 (format "%s is on %s" symbol keys))
547 ;; If this is the command the user asked about,
548 ;; and it is not on any key, say so.
549 ;; For other symbols, its aliases, say nothing
550 ;; about them unless they are on keys.
551 (if (eq symbol definition)
552 (format "%s is not on any key" symbol)))))
553 (when string
554 (unless (eq symbol definition)
555 (princ ";\n its alias "))
556 (princ string)))))
557 nil)
559 (defun help-key-description (key untranslated)
560 (let ((string (key-description key)))
561 (if (or (not untranslated)
562 (and (eq (aref untranslated 0) ?\e) (not (eq (aref key 0) ?\e))))
563 string
564 (let ((otherstring (key-description untranslated)))
565 (if (equal string otherstring)
566 string
567 (format "%s (translated from %s)" string otherstring))))))
569 (defun describe-key-briefly (&optional key insert untranslated)
570 "Print the name of the function KEY invokes. KEY is a string.
571 If INSERT (the prefix arg) is non-nil, insert the message in the buffer.
572 If non-nil, UNTRANSLATED is a vector of the untranslated events.
573 It can also be a number in which case the untranslated events from
574 the last key hit are used.
576 If KEY is a menu item or a tool-bar button that is disabled, this command
577 temporarily enables it to allow getting help on disabled items and buttons."
578 (interactive
579 (let ((enable-disabled-menus-and-buttons t)
580 (cursor-in-echo-area t)
581 saved-yank-menu)
582 (unwind-protect
583 (let (key)
584 ;; If yank-menu is empty, populate it temporarily, so that
585 ;; "Select and Paste" menu can generate a complete event.
586 (when (null (cdr yank-menu))
587 (setq saved-yank-menu (copy-sequence yank-menu))
588 (menu-bar-update-yank-menu "(any string)" nil))
589 (setq key (read-key-sequence "Describe key (or click or menu item): "))
590 ;; Clear the echo area message (Bug#7014).
591 (message nil)
592 ;; If KEY is a down-event, read and discard the
593 ;; corresponding up-event. Note that there are also
594 ;; down-events on scroll bars and mode lines: the actual
595 ;; event then is in the second element of the vector.
596 (and (vectorp key)
597 (let ((last-idx (1- (length key))))
598 (and (eventp (aref key last-idx))
599 (memq 'down (event-modifiers (aref key last-idx)))))
600 (read-event))
601 (list
603 (if current-prefix-arg (prefix-numeric-value current-prefix-arg))
605 ;; Put yank-menu back as it was, if we changed it.
606 (when saved-yank-menu
607 (setq yank-menu (copy-sequence saved-yank-menu))
608 (fset 'yank-menu (cons 'keymap yank-menu))))))
609 (if (numberp untranslated)
610 (setq untranslated (this-single-command-raw-keys)))
611 (let* ((event (if (and (symbolp (aref key 0))
612 (> (length key) 1)
613 (consp (aref key 1)))
614 (aref key 1)
615 (aref key 0)))
616 (modifiers (event-modifiers event))
617 (standard-output (if insert (current-buffer) standard-output))
618 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
619 (memq 'drag modifiers)) " at that spot" ""))
620 (defn (key-binding key t))
621 key-desc)
622 ;; Handle the case where we faked an entry in "Select and Paste" menu.
623 (if (and (eq defn nil)
624 (stringp (aref key (1- (length key))))
625 (eq (key-binding (substring key 0 -1)) 'yank-menu))
626 (setq defn 'menu-bar-select-yank))
627 ;; Don't bother user with strings from (e.g.) the select-paste menu.
628 (if (stringp (aref key (1- (length key))))
629 (aset key (1- (length key)) "(any string)"))
630 (if (and (> (length untranslated) 0)
631 (stringp (aref untranslated (1- (length untranslated)))))
632 (aset untranslated (1- (length untranslated)) "(any string)"))
633 ;; Now describe the key, perhaps as changed.
634 (setq key-desc (help-key-description key untranslated))
635 (if (or (null defn) (integerp defn) (equal defn 'undefined))
636 (princ (format "%s%s is undefined" key-desc mouse-msg))
637 (princ (format "%s%s runs the command %S" key-desc mouse-msg defn)))))
639 (defun describe-key (&optional key untranslated up-event)
640 "Display documentation of the function invoked by KEY.
641 KEY can be any kind of a key sequence; it can include keyboard events,
642 mouse events, and/or menu events. When calling from a program,
643 pass KEY as a string or a vector.
645 If non-nil, UNTRANSLATED is a vector of the corresponding untranslated events.
646 It can also be a number, in which case the untranslated events from
647 the last key sequence entered are used.
648 UP-EVENT is the up-event that was discarded by reading KEY, or nil.
650 If KEY is a menu item or a tool-bar button that is disabled, this command
651 temporarily enables it to allow getting help on disabled items and buttons."
652 (interactive
653 (let ((enable-disabled-menus-and-buttons t)
654 (cursor-in-echo-area t)
655 saved-yank-menu)
656 (unwind-protect
657 (let (key)
658 ;; If yank-menu is empty, populate it temporarily, so that
659 ;; "Select and Paste" menu can generate a complete event.
660 (when (null (cdr yank-menu))
661 (setq saved-yank-menu (copy-sequence yank-menu))
662 (menu-bar-update-yank-menu "(any string)" nil))
663 (setq key (read-key-sequence "Describe key (or click or menu item): "))
664 (list
666 (prefix-numeric-value current-prefix-arg)
667 ;; If KEY is a down-event, read and include the
668 ;; corresponding up-event. Note that there are also
669 ;; down-events on scroll bars and mode lines: the actual
670 ;; event then is in the second element of the vector.
671 (and (vectorp key)
672 (let ((last-idx (1- (length key))))
673 (and (eventp (aref key last-idx))
674 (memq 'down (event-modifiers (aref key last-idx)))))
675 (or (and (eventp (aref key 0))
676 (memq 'down (event-modifiers (aref key 0)))
677 ;; However, for the C-down-mouse-2 popup
678 ;; menu, there is no subsequent up-event. In
679 ;; this case, the up-event is the next
680 ;; element in the supplied vector.
681 (= (length key) 1))
682 (and (> (length key) 1)
683 (eventp (aref key 1))
684 (memq 'down (event-modifiers (aref key 1)))))
685 (read-event))))
686 ;; Put yank-menu back as it was, if we changed it.
687 (when saved-yank-menu
688 (setq yank-menu (copy-sequence saved-yank-menu))
689 (fset 'yank-menu (cons 'keymap yank-menu))))))
690 (if (numberp untranslated)
691 (setq untranslated (this-single-command-raw-keys)))
692 (let* ((event (aref key (if (and (symbolp (aref key 0))
693 (> (length key) 1)
694 (consp (aref key 1)))
696 0)))
697 (modifiers (event-modifiers event))
698 (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
699 (memq 'drag modifiers)) " at that spot" ""))
700 (defn (key-binding key t))
701 defn-up defn-up-tricky ev-type
702 mouse-1-remapped mouse-1-tricky)
704 ;; Handle the case where we faked an entry in "Select and Paste" menu.
705 (when (and (eq defn nil)
706 (stringp (aref key (1- (length key))))
707 (eq (key-binding (substring key 0 -1)) 'yank-menu))
708 (setq defn 'menu-bar-select-yank))
709 (if (or (null defn) (integerp defn) (equal defn 'undefined))
710 (message "%s%s is undefined"
711 (help-key-description key untranslated) mouse-msg)
712 (help-setup-xref (list #'describe-function defn)
713 (called-interactively-p 'interactive))
714 ;; Don't bother user with strings from (e.g.) the select-paste menu.
715 (when (stringp (aref key (1- (length key))))
716 (aset key (1- (length key)) "(any string)"))
717 (when (and untranslated
718 (stringp (aref untranslated (1- (length untranslated)))))
719 (aset untranslated (1- (length untranslated))
720 "(any string)"))
721 ;; Need to do this before erasing *Help* buffer in case event
722 ;; is a mouse click in an existing *Help* buffer.
723 (when up-event
724 (setq ev-type (event-basic-type up-event))
725 (let ((sequence (vector up-event)))
726 (when (and (eq ev-type 'mouse-1)
727 mouse-1-click-follows-link
728 (not (eq mouse-1-click-follows-link 'double))
729 (setq mouse-1-remapped
730 (mouse-on-link-p (event-start up-event))))
731 (setq mouse-1-tricky (and (integerp mouse-1-click-follows-link)
732 (> mouse-1-click-follows-link 0)))
733 (cond ((stringp mouse-1-remapped)
734 (setq sequence mouse-1-remapped))
735 ((vectorp mouse-1-remapped)
736 (setcar up-event (elt mouse-1-remapped 0)))
737 (t (setcar up-event 'mouse-2))))
738 (setq defn-up (key-binding sequence nil nil (event-start up-event)))
739 (when mouse-1-tricky
740 (setq sequence (vector up-event))
741 (aset sequence 0 'mouse-1)
742 (setq defn-up-tricky (key-binding sequence nil nil (event-start up-event))))))
743 (with-help-window (help-buffer)
744 (princ (help-key-description key untranslated))
745 (princ (format "\
746 %s runs the command %S, which is "
747 mouse-msg defn))
748 (describe-function-1 defn)
749 (when up-event
750 (unless (or (null defn-up)
751 (integerp defn-up)
752 (equal defn-up 'undefined))
753 (princ (format "
755 ----------------- up-event %s----------------
757 %s%s%s runs the command %S, which is "
758 (if mouse-1-tricky "(short click) " "")
759 (key-description (vector up-event))
760 mouse-msg
761 (if mouse-1-remapped
762 " is remapped to <mouse-2>, which" "")
763 defn-up))
764 (describe-function-1 defn-up))
765 (unless (or (null defn-up-tricky)
766 (integerp defn-up-tricky)
767 (eq defn-up-tricky 'undefined))
768 (princ (format "
770 ----------------- up-event (long click) ----------------
772 Pressing <%S>%s for longer than %d milli-seconds
773 runs the command %S, which is "
774 ev-type mouse-msg
775 mouse-1-click-follows-link
776 defn-up-tricky))
777 (describe-function-1 defn-up-tricky)))))))
779 (defun describe-mode (&optional buffer)
780 "Display documentation of current major mode and minor modes.
781 A brief summary of the minor modes comes first, followed by the
782 major mode description. This is followed by detailed
783 descriptions of the minor modes, each on a separate page.
785 For this to work correctly for a minor mode, the mode's indicator
786 variable \(listed in `minor-mode-alist') must also be a function
787 whose documentation describes the minor mode.
789 If called from Lisp with a non-nil BUFFER argument, display
790 documentation for the major and minor modes of that buffer."
791 (interactive "@")
792 (unless buffer (setq buffer (current-buffer)))
793 (help-setup-xref (list #'describe-mode buffer)
794 (called-interactively-p 'interactive))
795 ;; For the sake of help-do-xref and help-xref-go-back,
796 ;; don't switch buffers before calling `help-buffer'.
797 (with-help-window (help-buffer)
798 (with-current-buffer buffer
799 (let (minor-modes)
800 ;; Older packages do not register in minor-mode-list but only in
801 ;; minor-mode-alist.
802 (dolist (x minor-mode-alist)
803 (setq x (car x))
804 (unless (memq x minor-mode-list)
805 (push x minor-mode-list)))
806 ;; Find enabled minor mode we will want to mention.
807 (dolist (mode minor-mode-list)
808 ;; Document a minor mode if it is listed in minor-mode-alist,
809 ;; non-nil, and has a function definition.
810 (let ((fmode (or (get mode :minor-mode-function) mode)))
811 (and (boundp mode) (symbol-value mode)
812 (fboundp fmode)
813 (let ((pretty-minor-mode
814 (if (string-match "\\(\\(-minor\\)?-mode\\)?\\'"
815 (symbol-name fmode))
816 (capitalize
817 (substring (symbol-name fmode)
818 0 (match-beginning 0)))
819 fmode)))
820 (push (list fmode pretty-minor-mode
821 (format-mode-line (assq mode minor-mode-alist)))
822 minor-modes)))))
823 (setq minor-modes
824 (sort minor-modes
825 (lambda (a b) (string-lessp (cadr a) (cadr b)))))
826 (when minor-modes
827 (princ "Enabled minor modes:\n")
828 (make-local-variable 'help-button-cache)
829 (with-current-buffer standard-output
830 (dolist (mode minor-modes)
831 (let ((mode-function (nth 0 mode))
832 (pretty-minor-mode (nth 1 mode))
833 (indicator (nth 2 mode)))
834 (add-text-properties 0 (length pretty-minor-mode)
835 '(face bold) pretty-minor-mode)
836 (save-excursion
837 (goto-char (point-max))
838 (princ "\n\f\n")
839 (push (point-marker) help-button-cache)
840 ;; Document the minor modes fully.
841 (insert pretty-minor-mode)
842 (princ (format " minor mode (%s):\n"
843 (if (zerop (length indicator))
844 "no indicator"
845 (format "indicator%s"
846 indicator))))
847 (princ (documentation mode-function)))
848 (insert-button pretty-minor-mode
849 'action (car help-button-cache)
850 'follow-link t
851 'help-echo "mouse-2, RET: show full information")
852 (newline)))
853 (forward-line -1)
854 (fill-paragraph nil)
855 (forward-line 1))
857 (princ "\n(Information about these minor modes follows the major mode info.)\n\n"))
858 ;; Document the major mode.
859 (let ((mode mode-name))
860 (with-current-buffer standard-output
861 (let ((start (point)))
862 (insert (format-mode-line mode nil nil buffer))
863 (add-text-properties start (point) '(face bold)))))
864 (princ " mode")
865 (let* ((mode major-mode)
866 (file-name (find-lisp-object-file-name mode nil)))
867 (when file-name
868 (princ (concat " defined in `" (file-name-nondirectory file-name) "'"))
869 ;; Make a hyperlink to the library.
870 (with-current-buffer standard-output
871 (save-excursion
872 (re-search-backward "`\\([^`']+\\)'" nil t)
873 (help-xref-button 1 'help-function-def mode file-name)))))
874 (princ ":\n")
875 (princ (documentation major-mode)))))
876 ;; For the sake of IELM and maybe others
877 nil)
880 (defun describe-minor-mode (minor-mode)
881 "Display documentation of a minor mode given as MINOR-MODE.
882 MINOR-MODE can be a minor mode symbol or a minor mode indicator string
883 appeared on the mode-line."
884 (interactive (list (completing-read
885 "Minor mode: "
886 (nconc
887 (describe-minor-mode-completion-table-for-symbol)
888 (describe-minor-mode-completion-table-for-indicator)
889 ))))
890 (if (symbolp minor-mode)
891 (setq minor-mode (symbol-name minor-mode)))
892 (let ((symbols (describe-minor-mode-completion-table-for-symbol))
893 (indicators (describe-minor-mode-completion-table-for-indicator)))
894 (cond
895 ((member minor-mode symbols)
896 (describe-minor-mode-from-symbol (intern minor-mode)))
897 ((member minor-mode indicators)
898 (describe-minor-mode-from-indicator minor-mode))
900 (error "No such minor mode: %s" minor-mode)))))
902 ;; symbol
903 (defun describe-minor-mode-completion-table-for-symbol ()
904 ;; In order to list up all minor modes, minor-mode-list
905 ;; is used here instead of minor-mode-alist.
906 (delq nil (mapcar 'symbol-name minor-mode-list)))
908 (defun describe-minor-mode-from-symbol (symbol)
909 "Display documentation of a minor mode given as a symbol, SYMBOL"
910 (interactive (list (intern (completing-read
911 "Minor mode symbol: "
912 (describe-minor-mode-completion-table-for-symbol)))))
913 (if (fboundp symbol)
914 (describe-function symbol)
915 (describe-variable symbol)))
917 ;; indicator
918 (defun describe-minor-mode-completion-table-for-indicator ()
919 (delq nil
920 (mapcar (lambda (x)
921 (let ((i (format-mode-line x)))
922 ;; remove first space if existed
923 (cond
924 ((= 0 (length i))
925 nil)
926 ((eq (aref i 0) ?\s)
927 (substring i 1))
929 i))))
930 minor-mode-alist)))
932 (defun describe-minor-mode-from-indicator (indicator)
933 "Display documentation of a minor mode specified by INDICATOR.
934 If you call this function interactively, you can give indicator which
935 is currently activated with completion."
936 (interactive (list
937 (completing-read
938 "Minor mode indicator: "
939 (describe-minor-mode-completion-table-for-indicator))))
940 (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))
941 (if minor-mode
942 (describe-minor-mode-from-symbol minor-mode)
943 (error "Cannot find minor mode for `%s'" indicator))))
945 (defun lookup-minor-mode-from-indicator (indicator)
946 "Return a minor mode symbol from its indicator on the mode line."
947 ;; remove first space if existed
948 (if (and (< 0 (length indicator))
949 (eq (aref indicator 0) ?\s))
950 (setq indicator (substring indicator 1)))
951 (let ((minor-modes minor-mode-alist)
952 result)
953 (while minor-modes
954 (let* ((minor-mode (car (car minor-modes)))
955 (anindicator (format-mode-line
956 (car (cdr (car minor-modes))))))
957 ;; remove first space if existed
958 (if (and (stringp anindicator)
959 (> (length anindicator) 0)
960 (eq (aref anindicator 0) ?\s))
961 (setq anindicator (substring anindicator 1)))
962 (if (equal indicator anindicator)
963 (setq result minor-mode
964 minor-modes nil)
965 (setq minor-modes (cdr minor-modes)))))
966 result))
968 ;;; Automatic resizing of temporary buffers.
969 (defcustom temp-buffer-max-height
970 (lambda (buffer)
971 (if (eq (selected-window) (frame-root-window))
972 (/ (x-display-pixel-height) (frame-char-height) 2)
973 (/ (- (frame-height) 2) 2)))
974 "Maximum height of a window displaying a temporary buffer.
975 This is effective only when Temp Buffer Resize mode is enabled.
976 The value is the maximum height (in lines) which
977 `resize-temp-buffer-window' will give to a window displaying a
978 temporary buffer. It can also be a function to be called to
979 choose the height for such a buffer. It gets one argument, the
980 buffer, and should return a positive integer. At the time the
981 function is called, the window to be resized is selected."
982 :type '(choice integer function)
983 :group 'help
984 :version "24.3")
986 (defcustom temp-buffer-max-width
987 (lambda (buffer)
988 (if (eq (selected-window) (frame-root-window))
989 (/ (x-display-pixel-width) (frame-char-width) 2)
990 (/ (- (frame-width) 2) 2)))
991 "Maximum width of a window displaying a temporary buffer.
992 This is effective only when Temp Buffer Resize mode is enabled.
993 The value is the maximum width (in columns) which
994 `resize-temp-buffer-window' will give to a window displaying a
995 temporary buffer. It can also be a function to be called to
996 choose the width for such a buffer. It gets one argument, the
997 buffer, and should return a positive integer. At the time the
998 function is called, the window to be resized is selected."
999 :type '(choice integer function)
1000 :group 'help
1001 :version "24.4")
1003 (define-minor-mode temp-buffer-resize-mode
1004 "Toggle auto-resizing temporary buffer windows (Temp Buffer Resize Mode).
1005 With a prefix argument ARG, enable Temp Buffer Resize mode if ARG
1006 is positive, and disable it otherwise. If called from Lisp,
1007 enable the mode if ARG is omitted or nil.
1009 When Temp Buffer Resize mode is enabled, the windows in which we
1010 show a temporary buffer are automatically resized in height to
1011 fit the buffer's contents, but never more than
1012 `temp-buffer-max-height' nor less than `window-min-height'.
1014 A window is resized only if it has been specially created for the
1015 buffer. Windows that have shown another buffer before are not
1016 resized. A frame is resized only if `fit-frame-to-buffer' is
1017 non-nil.
1019 This mode is used by `help', `apropos' and `completion' buffers,
1020 and some others."
1021 :global t :group 'help
1022 (if temp-buffer-resize-mode
1023 ;; `help-make-xrefs' may add a `back' button and thus increase the
1024 ;; text size, so `resize-temp-buffer-window' must be run *after* it.
1025 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
1026 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)))
1028 (defun resize-temp-buffer-window (&optional window)
1029 "Resize WINDOW to fit its contents.
1030 WINDOW must be a live window and defaults to the selected one.
1031 Do not resize if WINDOW was not created by `display-buffer'.
1033 If WINDOW is part of a vertical combination, restrain its new
1034 size by `temp-buffer-max-height' and do not resize if its minimum
1035 accessible position is scrolled out of view. If WINDOW is part
1036 of a horizontal combination, restrain its new size by
1037 `temp-buffer-max-width'. In both cases, the value of the option
1038 `fit-window-to-buffer-horizontally' can inhibit resizing.
1040 If WINDOW is the root window of its frame, resize the frame
1041 provided `fit-frame-to-buffer' is non-nil."
1042 (setq window (window-normalize-window window t))
1043 (let ((height (if (functionp temp-buffer-max-height)
1044 (with-selected-window window
1045 (funcall temp-buffer-max-height (window-buffer)))
1046 temp-buffer-max-height))
1047 (width (if (functionp temp-buffer-max-width)
1048 (with-selected-window window
1049 (funcall temp-buffer-max-width (window-buffer)))
1050 temp-buffer-max-width))
1051 (quit-cadr (cadr (window-parameter window 'quit-restore))))
1052 ;; Resize WINDOW iff it was made by `display-buffer'.
1053 (when (or (and (eq quit-cadr 'window)
1054 (or (and (window-combined-p window)
1055 (not (eq fit-window-to-buffer-horizontally
1056 'only))
1057 (pos-visible-in-window-p (point-min) window))
1058 (and (window-combined-p window t)
1059 fit-window-to-buffer-horizontally)))
1060 (and (eq quit-cadr 'frame)
1061 fit-frame-to-buffer
1062 (eq window (frame-root-window window))))
1063 (fit-window-to-buffer window height nil width))))
1065 ;;; Help windows.
1066 (defcustom help-window-select 'other
1067 "Non-nil means select help window for viewing.
1068 Choices are:
1069 never (nil) Select help window only if there is no other window
1070 on its frame.
1071 other Select help window unless the selected window is the
1072 only other window on the help window's frame.
1073 always (t) Always select the help window.
1075 This option has effect if and only if the help window was created
1076 by `with-help-window'"
1077 :type '(choice (const :tag "never (nil)" nil)
1078 (const :tag "other" other)
1079 (const :tag "always (t)" t))
1080 :group 'help
1081 :version "23.1")
1083 (defcustom help-enable-auto-load t
1084 "Whether Help commands can perform autoloading.
1085 If non-nil, whenever \\[describe-function] is called for an
1086 autoloaded function whose docstring contains any key substitution
1087 construct (see `substitute-command-keys'), the library is loaded,
1088 so that the documentation can show the right key bindings."
1089 :type 'boolean
1090 :group 'help
1091 :version "24.3")
1093 (defun help-window-display-message (quit-part window &optional scroll)
1094 "Display message telling how to quit and scroll help window.
1095 QUIT-PART is a string telling how to quit the help window WINDOW.
1096 Optional argument SCROLL non-nil means tell how to scroll WINDOW.
1097 SCROLL equal `other' means tell how to scroll the \"other\"
1098 window."
1099 (let ((scroll-part
1100 (cond
1101 ;; If we don't have QUIT-PART we probably reuse a window
1102 ;; showing the same buffer so we don't show any message.
1103 ((not quit-part) nil)
1104 ((pos-visible-in-window-p
1105 (with-current-buffer (window-buffer window)
1106 (point-max)) window t)
1107 ;; Buffer end is at least partially visible, no need to talk
1108 ;; about scrolling.
1109 ".")
1110 ((eq scroll 'other)
1111 ", \\[scroll-other-window] to scroll help.")
1112 (scroll ", \\[scroll-up] to scroll help."))))
1113 (message "%s"
1114 (substitute-command-keys (concat quit-part scroll-part)))))
1116 (defun help-window-setup (window &optional value)
1117 "Set up help window WINDOW for `with-help-window'.
1118 WINDOW is the window used for displaying the help buffer.
1119 Return VALUE."
1120 (let* ((help-buffer (when (window-live-p window)
1121 (window-buffer window)))
1122 (help-setup (when (window-live-p window)
1123 (car (window-parameter window 'quit-restore)))))
1124 (when help-buffer
1125 ;; Handle `help-window-point-marker'.
1126 (when (eq (marker-buffer help-window-point-marker) help-buffer)
1127 (set-window-point window help-window-point-marker)
1128 ;; Reset `help-window-point-marker'.
1129 (set-marker help-window-point-marker nil))
1131 (cond
1132 ((or (eq window (selected-window))
1133 (and (or (eq help-window-select t)
1134 (eq help-setup 'frame)
1135 (and (eq help-window-select 'other)
1136 (eq (window-frame window) (selected-frame))
1137 (> (length (window-list nil 'no-mini)) 2)))
1138 (select-window window)))
1139 ;; The help window is or gets selected ...
1140 (help-window-display-message
1141 (cond
1142 ((eq help-setup 'window)
1143 ;; ... and is new, ...
1144 "Type \"q\" to delete help window")
1145 ((eq help-setup 'frame)
1146 "Type \"q\" to quit the help frame")
1147 ((eq help-setup 'other)
1148 ;; ... or displayed some other buffer before.
1149 "Type \"q\" to restore previous buffer"))
1150 window t))
1151 ((and (eq (window-frame window) (selected-frame))
1152 (= (length (window-list nil 'no-mini)) 2))
1153 ;; There are two windows on the help window's frame and the
1154 ;; other one is the selected one.
1155 (help-window-display-message
1156 (cond
1157 ((eq help-setup 'window)
1158 "Type \\[delete-other-windows] to delete the help window")
1159 ((eq help-setup 'other)
1160 "Type \"q\" in help window to restore its previous buffer"))
1161 window 'other))
1163 ;; The help window is not selected ...
1164 (help-window-display-message
1165 (cond
1166 ((eq help-setup 'window)
1167 ;; ... and is new, ...
1168 "Type \"q\" in help window to delete it")
1169 ((eq help-setup 'other)
1170 ;; ... or displayed some other buffer before.
1171 "Type \"q\" in help window to restore previous buffer"))
1172 window))))
1173 ;; Return VALUE.
1174 value))
1176 ;; `with-help-window' is a wrapper for `with-temp-buffer-window'
1177 ;; providing the following additional twists:
1179 ;; (1) It puts the buffer in `help-mode' (via `help-mode-setup') and
1180 ;; adds cross references (via `help-mode-finish').
1182 ;; (2) It issues a message telling how to scroll and quit the help
1183 ;; window (via `help-window-setup').
1185 ;; (3) An option (customizable via `help-window-select') to select the
1186 ;; help window automatically.
1188 ;; (4) A marker (`help-window-point-marker') to move point in the help
1189 ;; window to an arbitrary buffer position.
1191 ;; Note: It's usually always wrong to use `help-print-return-message' in
1192 ;; the body of `with-help-window'.
1193 (defmacro with-help-window (buffer-name &rest body)
1194 "Display buffer with name BUFFER-NAME in a help window evaluating BODY.
1195 Select help window if the current value of the user option
1196 `help-window-select' says so. Return last value in BODY."
1197 (declare (indent 1) (debug t))
1198 `(progn
1199 ;; Make `help-window-point-marker' point nowhere. The only place
1200 ;; where this should be set to a buffer position is within BODY.
1201 (set-marker help-window-point-marker nil)
1202 (let ((temp-buffer-window-setup-hook
1203 (cons 'help-mode-setup temp-buffer-window-setup-hook))
1204 (temp-buffer-window-show-hook
1205 (cons 'help-mode-finish temp-buffer-window-show-hook)))
1206 (with-temp-buffer-window
1207 ,buffer-name nil 'help-window-setup (progn ,@body)))))
1209 ;; Called from C, on encountering `help-char' when reading a char.
1210 ;; Don't print to *Help*; that would clobber Help history.
1211 (defun help-form-show ()
1212 "Display the output of a non-nil `help-form'."
1213 (let ((msg (eval help-form)))
1214 (if (stringp msg)
1215 (with-output-to-temp-buffer " *Char Help*"
1216 (princ msg)))))
1218 (provide 'help)
1220 ;;; help.el ends here