1 ;;; help.el --- help commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2004
4 ;; Free Software Foundation, Inc.
7 ;; Keywords: help, internal
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This code implements GNU Emacs' on-line help system, the one invoked by
29 ;; `M-x help-for-help'.
33 ;; Get the macro make-help-screen when this is compiled,
34 ;; or run interpreted, but not when the compiled code is loaded.
35 (eval-when-compile (require 'help-macro))
37 ;; This makes `with-output-to-temp-buffer' buffers use `help-mode'.
38 (add-hook 'temp-buffer-setup-hook 'help-mode-setup)
39 (add-hook 'temp-buffer-show-hook 'help-mode-finish)
41 (defvar help-map (make-sparse-keymap)
42 "Keymap for characters following the Help key.")
44 (define-key global-map (char-to-string help-char) 'help-command)
45 (define-key global-map [help] 'help-command)
46 (define-key global-map [f1] 'help-command)
47 (fset 'help-command help-map)
49 (define-key help-map (char-to-string help-char) 'help-for-help)
50 (define-key help-map [help] 'help-for-help)
51 (define-key help-map [f1] 'help-for-help)
52 (define-key help-map "." 'display-local-help)
53 (define-key help-map "?" 'help-for-help)
55 (define-key help-map "\C-c" 'describe-copying)
56 (define-key help-map "\C-d" 'describe-distribution)
57 (define-key help-map "\C-e" 'view-emacs-problems)
58 (define-key help-map "\C-f" 'view-emacs-FAQ)
59 (define-key help-map "\C-m" 'view-order-manuals)
60 (define-key help-map "\C-n" 'view-emacs-news)
61 (define-key help-map "\C-p" 'describe-project)
62 (define-key help-map "\C-t" 'view-todo)
63 (define-key help-map "\C-w" 'describe-no-warranty)
65 ;; This does not fit the pattern, but it is natural given the C-\ command.
66 (define-key help-map "\C-\\" 'describe-input-method)
68 (define-key help-map "C" 'describe-coding-system)
69 (define-key help-map "F" 'Info-goto-emacs-command-node)
70 (define-key help-map "I" 'describe-input-method)
71 (define-key help-map "K" 'Info-goto-emacs-key-command-node)
72 (define-key help-map "L" 'describe-language-environment)
73 (define-key help-map "S" 'info-lookup-symbol)
75 (define-key help-map "a" 'apropos-command)
77 (define-key help-map "b" 'describe-bindings)
79 (define-key help-map "c" 'describe-key-briefly)
81 (define-key help-map "e" 'view-echo-area-messages)
83 (define-key help-map "f" 'describe-function)
85 (define-key help-map "h" 'view-hello-file)
87 (define-key help-map "i" 'info)
88 (define-key help-map "4i" 'info-other-window)
90 (define-key help-map "k" 'describe-key)
92 (define-key help-map "l" 'view-lossage)
94 (define-key help-map "m" 'describe-mode)
96 (define-key help-map "n" 'view-emacs-news)
98 (define-key help-map "p" 'finder-by-keyword)
99 (autoload 'finder-by-keyword "finder"
100 "Find packages matching a given keyword." t)
102 (define-key help-map "r" 'info-emacs-manual)
104 (define-key help-map "s" 'describe-syntax)
106 (define-key help-map "t" 'help-with-tutorial)
108 (define-key help-map "w" 'where-is)
110 (define-key help-map "v" 'describe-variable)
112 (define-key help-map "q" 'help-quit)
114 ;; insert-button makes the action nil if it is not store somewhere
115 (defvar help-button-cache nil)
119 "Just exit from the Help command's command loop."
123 (defvar help-return-method nil
124 "What to do to \"exit\" the help buffer.
126 (WINDOW . t) delete the selected window, go to WINDOW.
127 (WINDOW . quit-window) do quit-window, then select WINDOW.
128 (WINDOW BUF START POINT) display BUF at START, POINT, then select WINDOW.")
130 (defun print-help-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 (and (not (get-buffer-window standard-output))
137 (cond ((special-display-p (buffer-name standard-output))
138 (setq help-return-method (cons (selected-window) t))
139 ;; If the help output buffer is a special display buffer,
140 ;; don't say anything about how to get rid of it.
141 ;; First of all, the user will do that with the window
142 ;; manager, not with Emacs.
143 ;; Secondly, the buffer has not been displayed yet,
144 ;; so we don't know whether its frame will be selected.
146 (display-buffer-reuse-frames
147 (setq help-return-method (cons (selected-window)
150 ((not (one-window-p t))
151 (setq help-return-method
152 (cons (selected-window) 'quit-window))
153 "Type \\[switch-to-buffer-other-window] RET to restore the other window.")
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)
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 (special-display-p (buffer-name standard-output))
171 (if (same-window-p (buffer-name standard-output))
172 ;; Say how to scroll this window.
173 (substitute-command-keys
174 "\\[scroll-up] to scroll the help.")
175 ;; Say how to scroll some other window.
176 (substitute-command-keys
177 "\\[scroll-other-window] to scroll the help."))))))))
179 ;; So keyboard macro definitions are documented correctly
180 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
182 (defalias 'help 'help-for-help)
183 (make-help-screen help-for-help
184 "a b c C e f F i I k C-k l L m p s t v w C-c C-d C-f C-n C-p C-t C-w . or ? :"
185 "You have typed %THIS-KEY%, the help character. Type a Help option:
186 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
188 a command-apropos. Give a substring, and see a list of commands
189 (functions that are interactively callable) that contain
190 that substring. See also the apropos command.
191 b describe-bindings. Display table of all key bindings.
192 c describe-key-briefly. Type a command key sequence;
193 it prints the function name that sequence runs.
194 C describe-coding-system. This describes either a specific coding system
195 (if you type its name) or the coding systems currently in use
196 (if you type just RET).
197 e view-echo-area-messages. Show the buffer where the echo-area messages
199 f describe-function. Type a function name and get its documentation.
200 F Info-goto-emacs-command-node. Type a function name;
201 it takes you to the on-line manual's section that describes
203 h Display the HELLO file which illustrates various scripts.
204 i info. The Info documentation reader: read on-line manuals.
205 I describe-input-method. Describe a specific input method (if you type
206 its name) or the current input method (if you type just RET).
207 k describe-key. Type a command key sequence;
208 it displays the full documentation for that key sequence.
209 K Info-goto-emacs-key-command-node. Type a command key sequence;
210 it takes you to the on-line manual's section that describes
211 the command bound to that key.
212 l view-lossage. Show last 100 characters you typed.
213 L describe-language-environment. This describes either a
214 specific language environment (if you type its name)
215 or the current language environment (if you type just RET).
216 m describe-mode. Display documentation of current minor modes,
217 and the current major mode, including their special commands.
218 n view-emacs-news. Display news of recent Emacs changes.
219 p finder-by-keyword. Find packages matching a given topic keyword.
220 s describe-syntax. Display contents of syntax table, plus explanations.
221 S info-lookup-symbol. Display the definition of a specific symbol
222 as found in the manual for the language this buffer is written in.
223 t help-with-tutorial. Select the Emacs learn-by-doing tutorial.
224 v describe-variable. Type name of a variable;
225 it displays the variable's documentation and value.
226 w where-is. Type command name; it prints which keystrokes
228 . display-local-help. Display any available local help at point
231 C-c Display Emacs copying permission (GNU General Public License).
232 C-d Display Emacs ordering information.
233 C-e Display info about Emacs problems.
234 C-f Display the Emacs FAQ.
235 C-m Display how to order printed Emacs manuals.
236 C-n Display news of recent Emacs changes.
237 C-p Display information about the GNU project.
238 C-t Display the Emacs TODO list.
239 C-w Display information on absence of warranty for GNU Emacs."
244 (defun function-called-at-point ()
245 "Return a function around point or else called by the list containing point.
246 If that doesn't give a function, return nil."
247 (or (with-syntax-table emacs-lisp-mode-syntax-table
248 (or (condition-case ()
250 (or (not (zerop (skip-syntax-backward "_w")))
251 (eq (char-syntax (following-char)) ?w)
252 (eq (char-syntax (following-char)) ?_)
254 (skip-chars-forward "'")
255 (let ((obj (read (current-buffer))))
256 (and (symbolp obj) (fboundp obj) obj)))
261 (narrow-to-region (max (point-min)
262 (- (point) 1000)) (point-max))
263 ;; Move up to surrounding paren, then after the open.
266 ;; If there is space here, this is probably something
267 ;; other than a real Lisp function call, so ignore it.
268 (if (looking-at "[ \t]")
269 (error "Probably not a Lisp function call"))
270 (let ((obj (read (current-buffer))))
271 (and (symbolp obj) (fboundp obj) obj))))
273 (let* ((str (find-tag-default))
274 (sym (if str (intern-soft str))))
275 (if (and sym (fboundp sym))
278 (when (and str (string-match "\\`\\W*\\(.*?\\)\\W*\\'" str))
279 (setq sym (intern-soft (match-string 1 str)))
280 (and (fboundp sym) sym)))))))
283 ;;; `User' help functions
285 (defun describe-distribution ()
286 "Display info on how to obtain the latest version of GNU Emacs."
288 (view-file (expand-file-name "DISTRIB" data-directory)))
290 (defun describe-copying ()
291 "Display info on how you may redistribute copies of GNU Emacs."
293 (view-file (expand-file-name "COPYING" data-directory))
294 (goto-char (point-min)))
296 (defun describe-project ()
297 "Display info on the GNU project."
299 (view-file (expand-file-name "THE-GNU-PROJECT" data-directory))
300 (goto-char (point-min)))
302 (defun describe-no-warranty ()
303 "Display info on all the kinds of warranty Emacs does NOT have."
306 (let (case-fold-search)
307 (search-forward "NO WARRANTY")
310 (defun describe-prefix-bindings ()
311 "Describe the bindings of the prefix used to reach this command.
312 The prefix described consists of all but the last event
313 of the key sequence that ran this command."
315 (let* ((key (this-command-keys)))
318 (substring key 0 (1- (length key)))
319 (let ((prefix (make-vector (1- (length key)) nil))
321 (while (< i (length prefix))
322 (aset prefix i (aref key i))
325 ;; Make C-h after a prefix, when not specifically bound,
326 ;; run describe-prefix-bindings.
327 (setq prefix-help-command 'describe-prefix-bindings)
329 (defun view-emacs-news (&optional arg)
330 "Display info on recent changes to Emacs.
331 With argument, display info only for the selected version."
334 (view-file (expand-file-name "NEWS" data-directory))
342 (insert-file-contents
343 (expand-file-name file data-directory))
345 (while (re-search-forward
346 (if (string-match "^ONEWS\\.[0-9]+$" file)
347 "Changes in \\(?:Emacs\\|version\\)?[ \t]*\\([0-9]+\\(?:\\.[0-9]+\\)?\\)"
348 "^\* [^0-9\n]*\\([0-9]+\\.[0-9]+\\)") nil t)
349 (setq res (cons (list (match-string-no-properties 1)
352 (append '("NEWS" "ONEWS")
353 (directory-files data-directory nil
354 "^ONEWS\\.[0-9]+$" nil)))))
356 (string< (car b) (car a)))))
358 (version (completing-read
359 (format "Read NEWS for the version (default %s): " current)
360 (mapcar 'car map) nil nil nil nil current))
361 (file (cadr (assoc version map)))
364 (error "No news is good news")
365 (view-file (expand-file-name file data-directory))
367 (goto-char (point-min))
368 (when (re-search-forward
369 (concat (if (string-match "^ONEWS\\.[0-9]+$" file)
370 "Changes in \\(?:Emacs\\|version\\)?[ \t]*"
371 "^\* [^0-9\n]*") version)
377 (while (and (setq res
379 (if (string-match "^ONEWS\\.[0-9]+$" file)
380 "Changes in \\(?:Emacs\\|version\\)?[ \t]*\\([0-9]+\\(?:\\.[0-9]+\\)?\\)"
381 "^\* [^0-9\n]*\\([0-9]+\\.[0-9]+\\)") nil t))
382 (equal (match-string-no-properties 1) version)))
383 (or res (goto-char (point-max)))
387 (defun view-todo (&optional arg)
388 "Display the Emacs TODO list."
390 (view-file (expand-file-name "TODO" data-directory)))
392 (defun view-echo-area-messages ()
393 "View the log of recent echo-area messages: the `*Messages*' buffer.
394 The number of messages retained in that buffer
395 is specified by the variable `message-log-max'."
397 (switch-to-buffer (get-buffer-create "*Messages*")))
399 (defun view-order-manuals ()
400 "Display the Emacs ORDERS file."
402 (view-file (expand-file-name "ORDERS" data-directory))
405 (defun view-emacs-FAQ ()
406 "Display the Emacs Frequently Asked Questions (FAQ) file."
408 ;; (find-file-read-only (expand-file-name "FAQ" data-directory))
411 (defun view-emacs-problems ()
412 "Display info on known problems with Emacs and possible workarounds."
414 (view-file (expand-file-name "PROBLEMS" data-directory)))
416 (defun view-lossage ()
417 "Display last 100 input keystrokes.
419 To record all your input on a file, use `open-dribble-file'."
421 (help-setup-xref (list #'view-lossage) (interactive-p))
422 (with-output-to-temp-buffer (help-buffer)
423 (princ (mapconcat (lambda (key)
424 (if (or (integerp key) (symbolp key) (listp key))
425 (single-key-description key)
426 (prin1-to-string key nil)))
429 (with-current-buffer standard-output
430 (goto-char (point-min))
431 (while (progn (move-to-column 50) (not (eobp)))
432 (search-forward " " nil t)
434 (print-help-return-message)))
439 (defun describe-bindings (&optional prefix buffer)
440 "Show a list of all defined keys, and their definitions.
441 We put that list in a buffer, and display the buffer.
443 The optional argument PREFIX, if non-nil, should be a key sequence;
444 then we display only bindings that start with that prefix.
445 The optional argument BUFFER specifies which buffer's bindings
446 to display (default, the current buffer). BUFFER can be a buffer
449 (or buffer (setq buffer (current-buffer)))
450 (help-setup-xref (list #'describe-bindings prefix buffer) (interactive-p))
451 (with-current-buffer buffer
452 (describe-bindings-internal nil prefix)))
454 ;; This function used to be in keymap.c.
455 (defun describe-bindings-internal (&optional menus prefix)
456 "Show a list of all defined keys, and their definitions.
457 We put that list in a buffer, and display the buffer.
459 The optional argument MENUS, if non-nil, says to mention menu bindings.
460 \(Ordinarily these are omitted from the output.)
461 The optional argument PREFIX, if non-nil, should be a key sequence;
462 then we display only bindings that start with that prefix."
464 (let ((buf (current-buffer)))
465 (with-output-to-temp-buffer "*Help*"
466 (with-current-buffer standard-output
467 (describe-buffer-bindings buf prefix menus)))))
469 (defun where-is (definition &optional insert)
470 "Print message listing key sequences that invoke the command DEFINITION.
471 Argument is a command definition, usually a symbol with a function definition.
472 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
474 (let ((fn (function-called-at-point))
475 (enable-recursive-minibuffers t)
477 (setq val (completing-read
479 (format "Where is command (default %s): " fn)
480 "Where is command: ")
481 obarray 'commandp t))
482 (list (if (equal val "") fn (intern val)) current-prefix-arg)))
483 (let ((func (indirect-function definition))
485 (standard-output (if insert (current-buffer) t)))
486 (mapatoms (lambda (symbol)
487 (and (fboundp symbol)
488 (not (eq symbol definition))
489 (eq func (condition-case ()
490 (indirect-function symbol)
492 (push symbol defs))))
495 (let* ((remapped (command-remapping symbol))
496 (keys (where-is-internal
497 symbol overriding-local-map nil nil remapped))
498 (keys (mapconcat 'key-description keys ", ")))
500 (if (> (length keys) 0)
502 (format "%s (%s) (remapped from %s)"
503 keys remapped symbol)
504 (format "%s (%s)" keys symbol))
505 (format "M-x %s RET" symbol))
506 (if (> (length keys) 0)
508 (format "%s is remapped to %s which is on %s"
509 definition symbol keys)
510 (format "%s is on %s" symbol keys))
511 (format "%s is not on any key" symbol)))))
512 (cons definition defs)
516 (defun string-key-binding (key)
517 "Value is the binding of KEY in a string.
518 If KEY is an event on a string, and that string has a `local-map'
519 or `keymap' property, return the binding of KEY in the string's keymap."
521 (start (when (vectorp key)
522 (if (memq (aref key 0)
523 '(mode-line header-line left-margin right-margin))
524 (event-start (aref key 1))
525 (and (consp (aref key 0))
526 (event-start (aref key 0))))))
527 (string-info (and (consp start) (nth 4 start))))
529 (let* ((string (car string-info))
530 (pos (cdr string-info))
531 (local-map (and (>= pos 0)
532 (< pos (length string))
533 (or (get-text-property pos 'local-map string)
534 (get-text-property pos 'keymap string)))))
535 (setq defn (and local-map (lookup-key local-map key)))))
538 (defun help-key-description (key untranslated)
539 (let ((string (key-description key)))
540 (if (or (not untranslated)
541 (and (eq (aref untranslated 0) ?\e) (not (eq (aref key 0) ?\e))))
543 (let ((otherstring (key-description untranslated)))
544 (if (equal string otherstring)
546 (format "%s (translated from %s)" string otherstring))))))
548 (defun describe-key-briefly (key &optional insert untranslated)
549 "Print the name of the function KEY invokes. KEY is a string.
550 If INSERT (the prefix arg) is non-nil, insert the message in the buffer.
551 If non-nil UNTRANSLATED is a vector of the untranslated events.
552 It can also be a number in which case the untranslated events from
553 the last key hit are used."
554 (interactive "kDescribe key briefly: \nP\np")
555 (if (numberp untranslated)
556 (setq untranslated (this-single-command-raw-keys)))
558 (let ((modifiers (event-modifiers (aref key 0)))
559 (standard-output (if insert (current-buffer) t))
561 ;; For a mouse button event, go to the button it applies to
562 ;; to get the right key bindings. And go to the right place
563 ;; in case the keymap depends on where you clicked.
564 (if (or (memq 'click modifiers) (memq 'down modifiers)
565 (memq 'drag modifiers))
566 (setq window (posn-window (event-start (aref key 0)))
567 position (posn-point (event-start (aref key 0)))))
570 (set-buffer (window-buffer window))
571 (goto-char position)))
572 ;; Ok, now look up the key and name the command.
573 (let ((defn (or (string-key-binding key)
575 (key-desc (help-key-description key untranslated)))
576 (if (or (null defn) (integerp defn) (equal defn 'undefined))
577 (princ (format "%s is undefined" key-desc))
578 (princ (format (if (windowp window)
579 "%s at that spot runs the command %s"
580 "%s runs the command %s")
582 (if (symbolp defn) defn (prin1-to-string defn)))))))))
585 (defun describe-key (key &optional untranslated up-event)
586 "Display documentation of the function invoked by KEY.
587 KEY should be a key sequence--when calling from a program,
588 pass a string or a vector.
589 If non-nil UNTRANSLATED is a vector of the untranslated events.
590 It can also be a number in which case the untranslated events from
591 the last key hit are used."
592 (interactive "kDescribe key: \np\nU")
593 (if (numberp untranslated)
594 (setq untranslated (this-single-command-raw-keys)))
596 (let ((modifiers (event-modifiers (aref key 0)))
598 ;; For a mouse button event, go to the button it applies to
599 ;; to get the right key bindings. And go to the right place
600 ;; in case the keymap depends on where you clicked.
601 (if (or (memq 'click modifiers) (memq 'down modifiers)
602 (memq 'drag modifiers))
603 (setq window (posn-window (event-start (aref key 0)))
604 position (posn-point (event-start (aref key 0)))))
605 (when (windowp window)
606 (set-buffer (window-buffer window))
607 (goto-char position))
608 (let ((defn (or (string-key-binding key) (key-binding key))))
609 (if (or (null defn) (integerp defn) (equal defn 'undefined))
610 (message "%s is undefined" (help-key-description key untranslated))
611 (help-setup-xref (list #'describe-function defn) (interactive-p))
612 (with-output-to-temp-buffer (help-buffer)
613 (princ (help-key-description key untranslated))
615 (princ " at that spot"))
616 (princ " runs the command ")
618 (princ "\n which is ")
619 (describe-function-1 defn)
621 (let ((ev (aref up-event 0))
622 (descr (key-description up-event))
623 (hdr "\n\n-------------- up event ---------------\n\n")
625 mouse-1-tricky mouse-1-remapped)
626 (when (and (consp ev)
627 (eq (car ev) 'mouse-1)
629 mouse-1-click-follows-link
630 (not (eq mouse-1-click-follows-link 'double))
631 (with-current-buffer (window-buffer window)
632 (mouse-on-link-p (posn-point (event-start ev)))))
633 (setq mouse-1-tricky (integerp mouse-1-click-follows-link)
634 mouse-1-remapped (or (not mouse-1-tricky)
635 (> mouse-1-click-follows-link 0)))
637 (setcar ev 'mouse-2)))
638 (setq defn (or (string-key-binding up-event) (key-binding up-event)))
639 (unless (or (null defn) (integerp defn) (equal defn 'undefined))
640 (princ (if mouse-1-tricky
641 "\n\n----------------- up-event (short click) ----------------\n\n"
646 (princ " at that spot"))
648 (princ " is remapped to <mouse-2>\n which" ))
649 (princ " runs the command ")
651 (princ "\n which is ")
652 (describe-function-1 defn))
655 (if (> mouse-1-click-follows-link 0) 'mouse-1 'mouse-2))
656 (setq defn (or (string-key-binding up-event) (key-binding up-event)))
657 (unless (or (null defn) (integerp defn) (equal defn 'undefined))
659 "\n\n----------------- up-event (long click) ----------------\n\n"))
663 (princ " at that spot"))
664 (princ (format " for longer than %d milli-seconds\n"
665 (abs mouse-1-click-follows-link)))
666 (if (not mouse-1-remapped)
667 (princ " remaps it to <mouse-2> which" ))
668 (princ " runs the command ")
670 (princ "\n which is ")
671 (describe-function-1 defn))))
672 (print-help-return-message))))))))
675 (defun describe-mode (&optional buffer)
676 "Display documentation of current major mode and minor modes.
677 A brief summary of the minor modes comes first, followed by the
678 major mode description. This is followed by detailed
679 descriptions of the minor modes, each on a separate page.
681 For this to work correctly for a minor mode, the mode's indicator
682 variable \(listed in `minor-mode-alist') must also be a function
683 whose documentation describes the minor mode."
685 (help-setup-xref (list #'describe-mode (or buffer (current-buffer)))
687 ;; For the sake of help-do-xref and help-xref-go-back,
688 ;; don't switch buffers before calling `help-buffer'.
689 (with-output-to-temp-buffer (help-buffer)
691 (when buffer (set-buffer buffer))
693 ;; Find enabled minor mode we will want to mention.
694 (dolist (mode minor-mode-list)
695 ;; Document a minor mode if it is listed in minor-mode-alist,
696 ;; non-nil, and has a function definition.
697 (and (boundp mode) (symbol-value mode)
699 (let ((pretty-minor-mode mode)
701 (if (string-match "\\(-minor\\)?-mode\\'"
703 (setq pretty-minor-mode
705 (substring (symbol-name mode)
706 0 (match-beginning 0)))))
707 (setq indicator (cadr (assq mode minor-mode-alist)))
708 (while (and indicator (symbolp indicator)
710 (not (eq indicator (symbol-value indicator))))
711 (setq indicator (symbol-value indicator)))
712 (push (list pretty-minor-mode mode indicator)
714 (if auto-fill-function
715 ;; copy pure string so we can add face property to it below.
716 (push (list (copy-sequence "Auto Fill") 'auto-fill-mode " Fill")
720 (lambda (a b) (string-lessp (car a) (car b)))))
722 (princ "Summary of minor modes:\n")
723 (make-local-variable 'help-button-cache)
724 (with-current-buffer standard-output
725 (dolist (mode minor-modes)
726 (let ((pretty-minor-mode (nth 0 mode))
727 (mode-function (nth 1 mode))
728 (indicator (nth 2 mode)))
729 (add-text-properties 0 (length pretty-minor-mode)
730 '(face bold) pretty-minor-mode)
732 (goto-char (point-max))
734 (push (point-marker) help-button-cache)
735 ;; Document the minor modes fully.
736 (insert pretty-minor-mode)
737 (princ (format " minor mode (%s):\n"
739 (format "indicator%s" indicator)
741 (princ (documentation mode-function)))
743 (insert-button pretty-minor-mode
744 'action (car help-button-cache)
746 'help-echo "mouse-2, RET: show full information")
747 (princ (format " minor mode (%s):\n"
749 (format "indicator%s" indicator)
751 (princ "\n(Full information about these minor modes
752 follows the description of the major mode.)\n\n"))
753 ;; Document the major mode.
754 (let ((mode mode-name))
755 (with-current-buffer standard-output
757 (add-text-properties (- (point) (length mode)) (point) '(face bold))))
759 (princ (documentation major-mode)))
760 (print-help-return-message))))
763 (defun describe-minor-mode (minor-mode)
764 "Display documentation of a minor mode given as MINOR-MODE.
765 MINOR-MODE can be a minor mode symbol or a minor mode indicator string
766 appeared on the mode-line."
767 (interactive (list (completing-read
770 (describe-minor-mode-completion-table-for-symbol)
771 (describe-minor-mode-completion-table-for-indicator)
773 (if (symbolp minor-mode)
774 (setq minor-mode (symbol-name minor-mode)))
775 (let ((symbols (describe-minor-mode-completion-table-for-symbol))
776 (indicators (describe-minor-mode-completion-table-for-indicator)))
778 ((member minor-mode symbols)
779 (describe-minor-mode-from-symbol (intern minor-mode)))
780 ((member minor-mode indicators)
781 (describe-minor-mode-from-indicator minor-mode))
783 (error "No such minor mode: %s" minor-mode)))))
786 (defun describe-minor-mode-completion-table-for-symbol ()
787 ;; In order to list up all minor modes, minor-mode-list
788 ;; is used here instead of minor-mode-alist.
789 (delq nil (mapcar 'symbol-name minor-mode-list)))
790 (defun describe-minor-mode-from-symbol (symbol)
791 "Display documentation of a minor mode given as a symbol, SYMBOL"
792 (interactive (list (intern (completing-read
793 "Minor mode symbol: "
794 (describe-minor-mode-completion-table-for-symbol)))))
796 (describe-function symbol)
797 (describe-variable symbol)))
800 (defun describe-minor-mode-completion-table-for-indicator ()
803 (let ((i (format-mode-line x)))
804 ;; remove first space if existed
813 (defun describe-minor-mode-from-indicator (indicator)
814 "Display documentation of a minor mode specified by INDICATOR.
815 If you call this function interactively, you can give indicator which
816 is currently activated with completion."
819 "Minor mode indicator: "
820 (describe-minor-mode-completion-table-for-indicator))))
821 (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))
823 (describe-minor-mode-from-symbol minor-mode)
824 (error "Cannot find minor mode for `%s'" indicator))))
826 (defun lookup-minor-mode-from-indicator (indicator)
827 "Return a minor mode symbol from its indicator on the modeline."
828 ;; remove first space if existed
829 (if (and (< 0 (length indicator))
830 (eq (aref indicator 0) ?\ ))
831 (setq indicator (substring indicator 1)))
832 (let ((minor-modes minor-mode-alist)
835 (let* ((minor-mode (car (car minor-modes)))
836 (anindicator (format-mode-line
837 (car (cdr (car minor-modes))))))
838 ;; remove first space if existed
839 (if (and (stringp anindicator)
840 (> (length anindicator) 0)
841 (eq (aref anindicator 0) ?\ ))
842 (setq anindicator (substring anindicator 1)))
843 (if (equal indicator anindicator)
844 (setq result minor-mode
846 (setq minor-modes (cdr minor-modes)))))
850 ;;; Automatic resizing of temporary buffers.
852 (defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2))
853 "*Maximum height of a window displaying a temporary buffer.
854 This is the maximum height (in text lines) which `resize-temp-buffer-window'
855 will give to a window displaying a temporary buffer.
856 It can also be a function which will be called with the object corresponding
857 to the buffer to be displayed as argument and should return an integer
859 :type '(choice integer function)
863 (define-minor-mode temp-buffer-resize-mode
864 "Toggle the mode which makes windows smaller for temporary buffers.
865 With prefix argument ARG, turn the resizing of windows displaying temporary
866 buffers on if ARG is positive or off otherwise.
867 This makes the window the right height for its contents, but never
868 more than `temp-buffer-max-height' nor less than `window-min-height'.
869 This applies to `help', `apropos' and `completion' buffers, and some others."
870 :global t :group 'help
871 (if temp-buffer-resize-mode
872 ;; `help-make-xrefs' may add a `back' button and thus increase the
873 ;; text size, so `resize-temp-buffer-window' must be run *after* it.
874 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
875 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)))
877 (defun resize-temp-buffer-window ()
878 "Resize the current window to fit its contents.
879 Will not make it higher than `temp-buffer-max-height' nor smaller than
880 `window-min-height'. Do nothing if it is the only window on its frame, if it
881 is not as wide as the frame or if some of the window's contents are scrolled
883 (unless (or (one-window-p 'nomini)
884 (not (pos-visible-in-window-p (point-min)))
885 (/= (frame-width) (window-width)))
886 (fit-window-to-buffer
888 (if (functionp temp-buffer-max-height)
889 (funcall temp-buffer-max-height (current-buffer))
890 temp-buffer-max-height))))
892 ;; Provide this for the sake of define-minor-mode which generates
893 ;; defcustoms which require 'help'.
896 ;;; arch-tag: cf427352-27e9-49b7-9a6f-741ebab02423
897 ;;; help.el ends here