1 ;;; help-mode.el --- `help-mode' used by *Help* buffers
3 ;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001, 2002,
4 ;; 2003, 2004, 2005, 2006, 2007, 2008 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 3, 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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; Defines `help-mode', which is the mode used by *Help* buffers, and
29 ;; associated support machinery, such as adding hyperlinks, etc.,
35 (eval-when-compile (require 'easymenu))
37 (defvar help-mode-map (make-sparse-keymap)
38 "Keymap for help mode.")
40 (set-keymap-parent help-mode-map button-buffer-map)
42 (define-key help-mode-map [mouse-2] 'help-follow-mouse)
43 (define-key help-mode-map "\C-c\C-b" 'help-go-back)
44 (define-key help-mode-map "\C-c\C-f" 'help-go-forward)
45 (define-key help-mode-map "\C-c\C-c" 'help-follow-symbol)
46 ;; Documentation only, since we use minor-mode-overriding-map-alist.
47 (define-key help-mode-map "\r" 'help-follow)
49 (easy-menu-define help-mode-menu help-mode-map
52 ["Show Help for Symbol" help-follow-symbol
53 :help "Show the docs for the symbol at point"]
54 ["Previous Topic" help-go-back
55 :help "Go back to previous topic in this help buffer"]
56 ["Next Topic" help-go-forward
57 :help "Go back to next topic in this help buffer"]
58 ["Move to Previous Button" backward-button
59 :help "Move to the Next Button in the help buffer"]
60 ["Move to Next Button" forward-button
61 :help "Move to the Next Button in the help buffer"]))
63 (defvar help-xref-stack nil
64 "A stack of ways by which to return to help buffers after following xrefs.
65 Used by `help-follow' and `help-xref-go-back'.
66 An element looks like (POSITION FUNCTION ARGS...).
67 To use the element, do (apply FUNCTION ARGS) then goto the point.")
68 (put 'help-xref-stack 'permanent-local t)
69 (make-variable-buffer-local 'help-xref-stack)
71 (defvar help-xref-forward-stack nil
72 "The stack of used to navigate help forwards after using the back button.
73 Used by `help-follow' and `help-xref-go-forward'.
74 An element looks like (POSITION FUNCTION ARGS...).
75 To use the element, do (apply FUNCTION ARGS) then goto the point.")
76 (put 'help-xref-forward-stack 'permanent-local t)
77 (make-variable-buffer-local 'help-xref-forward-stack)
79 (defvar help-xref-stack-item nil
80 "An item for `help-follow' in this buffer to push onto `help-xref-stack'.
81 The format is (FUNCTION ARGS...).")
82 (put 'help-xref-stack-item 'permanent-local t)
83 (make-variable-buffer-local 'help-xref-stack-item)
85 (defvar help-xref-stack-forward-item nil
86 "An item for `help-go-back' to push onto `help-xref-forward-stack'.
87 The format is (FUNCTION ARGS...).")
88 (put 'help-xref-stack-forward-item 'permanent-local t)
89 (make-variable-buffer-local 'help-xref-stack-forward-item)
91 (setq-default help-xref-stack nil help-xref-stack-item nil)
92 (setq-default help-xref-forward-stack nil help-xref-forward-stack-item nil)
94 (defcustom help-mode-hook nil
95 "Hook run by `help-mode'."
99 ;; Button types used by help
101 (define-button-type 'help-xref
103 'action #'help-button-action)
105 (defun help-button-action (button)
106 "Call BUTTON's help function."
107 (help-do-xref (button-start button)
108 (button-get button 'help-function)
109 (button-get button 'help-args)))
111 ;; These 6 calls to define-button-type were generated in a dolist
112 ;; loop, but that is bad because it means these button types don't
113 ;; have an easily found definition.
115 (define-button-type 'help-function
116 :supertype 'help-xref
117 'help-function 'describe-function
118 'help-echo (purecopy "mouse-2, RET: describe this function"))
120 (define-button-type 'help-variable
121 :supertype 'help-xref
122 'help-function 'describe-variable
123 'help-echo (purecopy "mouse-2, RET: describe this variable"))
125 (define-button-type 'help-face
126 :supertype 'help-xref
127 'help-function 'describe-face
128 'help-echo (purecopy "mouse-2, RET: describe this face"))
130 (define-button-type 'help-coding-system
131 :supertype 'help-xref
132 'help-function 'describe-coding-system
133 'help-echo (purecopy "mouse-2, RET: describe this coding system"))
135 (define-button-type 'help-input-method
136 :supertype 'help-xref
137 'help-function 'describe-input-method
138 'help-echo (purecopy "mouse-2, RET: describe this input method"))
140 (define-button-type 'help-character-set
141 :supertype 'help-xref
142 'help-function 'describe-character-set
143 'help-echo (purecopy "mouse-2, RET: describe this character set"))
145 ;; make some more ideosyncratic button types
147 (define-button-type 'help-symbol
148 :supertype 'help-xref
149 'help-function #'help-xref-interned
150 'help-echo (purecopy "mouse-2, RET: describe this symbol"))
152 (define-button-type 'help-back
153 :supertype 'help-xref
154 'help-function #'help-xref-go-back
155 'help-echo (purecopy "mouse-2, RET: go back to previous help buffer"))
157 (define-button-type 'help-forward
158 :supertype 'help-xref
159 'help-function #'help-xref-go-forward
160 'help-echo (purecopy "mouse-2, RET: move forward to next help buffer"))
162 (define-button-type 'help-info
163 :supertype 'help-xref
164 'help-function #'info
165 'help-echo (purecopy "mouse-2, RET: read this Info node"))
167 (define-button-type 'help-url
168 :supertype 'help-xref
169 'help-function #'browse-url
170 'help-echo (purecopy "mouse-2, RET: view this URL in a browser"))
172 (define-button-type 'help-customize-variable
173 :supertype 'help-xref
174 'help-function (lambda (v)
175 (customize-variable v))
176 'help-echo (purecopy "mouse-2, RET: customize variable"))
178 (define-button-type 'help-customize-face
179 :supertype 'help-xref
180 'help-function (lambda (v)
182 'help-echo (purecopy "mouse-2, RET: customize face"))
184 (define-button-type 'help-function-def
185 :supertype 'help-xref
186 'help-function (lambda (fun file)
188 (when (eq file 'C-source)
190 (help-C-file-name (indirect-function fun) 'fun)))
191 ;; Don't use find-function-noselect because it follows
192 ;; aliases (which fails for built-in functions).
194 (find-function-search-for-symbol fun nil file)))
195 (pop-to-buffer (car location))
197 (goto-char (cdr location))
198 (message "Unable to find location in file"))))
199 'help-echo (purecopy "mouse-2, RET: find function's definition"))
201 (define-button-type 'help-variable-def
202 :supertype 'help-xref
203 'help-function (lambda (var &optional file)
204 (when (eq file 'C-source)
205 (setq file (help-C-file-name var 'var)))
206 (let ((location (find-variable-noselect var file)))
207 (pop-to-buffer (car location))
209 (goto-char (cdr location))
210 (message "Unable to find location in file"))))
211 'help-echo (purecopy "mouse-2, RET: find variable's definition"))
213 (define-button-type 'help-face-def
214 :supertype 'help-xref
215 'help-function (lambda (fun file)
217 ;; Don't use find-function-noselect because it follows
218 ;; aliases (which fails for built-in functions).
220 (find-function-search-for-symbol fun 'defface file)))
221 (pop-to-buffer (car location))
223 (goto-char (cdr location))
224 (message "Unable to find location in file"))))
225 'help-echo (purecopy "mouse-2, RET: find face's definition"))
230 "Major mode for viewing help text and navigating references in it.
231 Entry to this mode runs the normal hook `help-mode-hook'.
235 (kill-all-local-variables)
236 (use-local-map help-mode-map)
237 (setq mode-name "Help")
238 (setq major-mode 'help-mode)
241 (set (make-local-variable 'view-no-disable-on-exit) t)
242 ;; With Emacs 22 `view-exit-action' could delete the selected window
243 ;; disregarding whether the help buffer was shown in that window at
244 ;; all. Since `view-exit-action' is called with the help buffer as
245 ;; argument it seems more appropriate to have it work on the buffer
246 ;; only and leave it to `view-mode-exit' to delete any associated
248 (setq view-exit-action
250 ;; Use `with-current-buffer' to make sure that `bury-buffer'
251 ;; also removes BUFFER from the selected window.
252 (with-current-buffer buffer
255 (run-mode-hooks 'help-mode-hook))
258 (defun help-mode-setup ()
260 (setq buffer-read-only nil))
263 (defun help-mode-finish ()
264 (if (eq help-window t)
265 ;; If `help-window' is t, `view-return-to-alist' is handled by
266 ;; `with-help-window'. In this case set `help-window' to the
267 ;; selected window since now is the only moment where we can
268 ;; unambiguously identify it.
269 (setq help-window (selected-window))
270 (let ((entry (assq (selected-window) view-return-to-alist)))
272 ;; When entering Help mode from the Help window,
273 ;; such as by following a link, preserve the same
274 ;; meaning for the q command.
275 ;; (setcdr entry (cons (selected-window) help-return-method))
277 (setq view-return-to-alist
278 (cons (cons (selected-window) help-return-method)
279 view-return-to-alist)))))
281 (when (eq major-mode 'help-mode)
282 ;; View mode's read-only status of existing *Help* buffer is lost
283 ;; by with-output-to-temp-buffer.
285 (help-make-xrefs (current-buffer))))
287 ;; Grokking cross-reference information in doc strings and
290 ;; This may have some scope for extension and the same or something
291 ;; similar should be done for widget doc strings, which currently use
292 ;; another mechanism.
294 (defvar help-back-label (purecopy "[back]")
295 "Label to use by `help-make-xrefs' for the go-back reference.")
297 (defvar help-forward-label (purecopy "[forward]")
298 "Label to use by `help-make-xrefs' for the go-forward reference.")
300 (defconst help-xref-symbol-regexp
301 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|" ; Link to var
302 "\\(function\\|command\\)\\|" ; Link to function
303 "\\(face\\)\\|" ; Link to face
304 "\\(symbol\\|program\\|property\\)\\|" ; Don't link
305 "\\(source \\(?:code \\)?\\(?:of\\|for\\)\\)\\)"
307 ;; Note starting with word-syntax character:
308 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'"))
309 "Regexp matching doc string references to symbols.
311 The words preceding the quoted symbol can be used in doc strings to
312 distinguish references to variables, functions and symbols.")
314 (defvar help-xref-mule-regexp nil
315 "Regexp matching doc string references to MULE-related keywords.
317 It is usually nil, and is temporarily bound to an appropriate regexp
318 when help commands related to multilingual environment (e.g.,
319 `describe-coding-system') are invoked.")
322 (defconst help-xref-info-regexp
323 (purecopy "\\<[Ii]nfo[ \t\n]+\\(node\\|anchor\\)[ \t\n]+`\\([^']+\\)'")
324 "Regexp matching doc string references to an Info node.")
326 (defconst help-xref-url-regexp
327 (purecopy "\\<[Uu][Rr][Ll][ \t\n]+`\\([^']+\\)'")
328 "Regexp matching doc string references to a URL.")
331 (defun help-setup-xref (item interactive-p)
332 "Invoked from commands using the \"*Help*\" buffer to install some xref info.
334 ITEM is a (FUNCTION . ARGS) pair appropriate for recreating the help
335 buffer after following a reference. INTERACTIVE-P is non-nil if the
336 calling command was invoked interactively. In this case the stack of
337 items for help buffer \"back\" buttons is cleared.
339 This should be called very early, before the output buffer is cleared,
340 because we want to record the \"previous\" position of point so we can
341 restore it properly when going back."
342 (with-current-buffer (help-buffer)
343 (when help-xref-stack-item
344 (push (cons (point) help-xref-stack-item) help-xref-stack)
345 (setq help-xref-forward-stack nil))
347 (let ((tail (nthcdr 10 help-xref-stack)))
348 ;; Truncate the stack.
349 (if tail (setcdr tail nil))))
350 (setq help-xref-stack-item item)))
352 (defvar help-xref-following nil
353 "Non-nil when following a help cross-reference.")
356 (defun help-buffer ()
357 (buffer-name ;for with-output-to-temp-buffer
358 (if help-xref-following
360 (get-buffer-create "*Help*"))))
362 (defvar help-xref-override-view-map
363 (let ((map (make-sparse-keymap)))
364 (set-keymap-parent map view-mode-map)
365 (define-key map "\r" nil)
367 "Replacement keymap for `view-mode' in help buffers.")
370 (defun help-make-xrefs (&optional buffer)
371 "Parse and hyperlink documentation cross-references in the given BUFFER.
373 Find cross-reference information in a buffer and activate such cross
374 references for selection with `help-follow'. Cross-references have
375 the canonical form `...' and the type of reference may be
376 disambiguated by the preceding word(s) used in
377 `help-xref-symbol-regexp'. Faces only get cross-referenced if
378 preceded or followed by the word `face'. Variables without
379 variable documentation do not get cross-referenced, unless
380 preceded by the word `variable' or `option'.
382 If the variable `help-xref-mule-regexp' is non-nil, find also
383 cross-reference information related to multilingual environment
384 \(e.g., coding-systems). This variable is also used to disambiguate
385 the type of reference as the same way as `help-xref-symbol-regexp'.
387 A special reference `back' is made to return back through a stack of
388 help buffers. Variable `help-back-label' specifies the text for
392 (set-buffer (or buffer (current-buffer)))
393 (goto-char (point-min))
394 ;; Skip the header-type info, though it might be useful to parse
395 ;; it at some stage (e.g. "function in `library'").
397 (let ((old-modified (buffer-modified-p)))
398 (let ((stab (syntax-table))
400 (inhibit-read-only t))
401 (set-syntax-table emacs-lisp-mode-syntax-table)
402 ;; The following should probably be abstracted out.
407 (while (re-search-forward help-xref-info-regexp nil t)
408 (let ((data (match-string 2)))
410 (unless (string-match "^([^)]+)" data)
411 (setq data (concat "(emacs)" data))))
412 (help-xref-button 2 'help-info data))))
415 (while (re-search-forward help-xref-url-regexp nil t)
416 (let ((data (match-string 1)))
417 (help-xref-button 1 'help-url data))))
418 ;; Mule related keywords. Do this before trying
419 ;; `help-xref-symbol-regexp' because some of Mule
420 ;; keywords have variable or function definitions.
421 (if help-xref-mule-regexp
423 (while (re-search-forward help-xref-mule-regexp nil t)
424 (let* ((data (match-string 7))
425 (sym (intern-soft data)))
427 ((match-string 3) ; coding system
428 (and sym (coding-system-p sym)
429 (help-xref-button 6 'help-coding-system sym)))
430 ((match-string 4) ; input method
431 (and (assoc data input-method-alist)
432 (help-xref-button 7 'help-input-method data)))
433 ((or (match-string 5) (match-string 6)) ; charset
434 (and sym (charsetp sym)
435 (help-xref-button 7 'help-character-set sym)))
436 ((assoc data input-method-alist)
437 (help-xref-button 7 'help-character-set data))
438 ((and sym (coding-system-p sym))
439 (help-xref-button 7 'help-coding-system sym))
440 ((and sym (charsetp sym))
441 (help-xref-button 7 'help-character-set sym)))))))
444 (while (re-search-forward help-xref-symbol-regexp nil t)
445 (let* ((data (match-string 8))
446 (sym (intern-soft data)))
449 ((match-string 3) ; `variable' &c
450 (and (or (boundp sym) ; `variable' doesn't ensure
451 ; it's actually bound
452 (get sym 'variable-documentation))
453 (help-xref-button 8 'help-variable sym)))
454 ((match-string 4) ; `function' &c
455 (and (fboundp sym) ; similarly
456 (help-xref-button 8 'help-function sym)))
457 ((match-string 5) ; `face'
459 (help-xref-button 8 'help-face sym)))
460 ((match-string 6)) ; nothing for `symbol'
465 ;;; (find-function-noselect arg)))
466 ;;; (pop-to-buffer (car location))
467 ;;; (goto-char (cdr location))))
468 (help-xref-button 8 'help-function-def sym))
471 (save-match-data (looking-at "[ \t\n]+face\\W")))
472 (help-xref-button 8 'help-face sym))
473 ((and (or (boundp sym)
474 (get sym 'variable-documentation))
476 ;; We can't intuit whether to use the
477 ;; variable or function doc -- supply both.
478 (help-xref-button 8 'help-symbol sym))
481 (get sym 'variable-documentation))
483 (documentation-property
484 sym 'variable-documentation)
486 (documentation-property
487 (indirect-variable sym)
488 'variable-documentation)
489 (cyclic-variable-indirection nil))))
490 (help-xref-button 8 'help-variable sym))
492 (help-xref-button 8 'help-function sym)))))))
493 ;; An obvious case of a key substitution:
495 (while (re-search-forward
496 ;; Assume command name is only word and symbol
497 ;; characters to get things like `use M-x foo->bar'.
498 ;; Command required to end with word constituent
499 ;; to avoid `.' at end of a sentence.
500 "\\<M-x\\s-+\\(\\sw\\(\\sw\\|\\s_\\)*\\sw\\)" nil t)
501 (let ((sym (intern-soft (match-string 1))))
503 (help-xref-button 1 'help-function sym)))))
504 ;; Look for commands in whole keymap substitutions:
506 ;; Make sure to find the first keymap.
507 (goto-char (point-min))
508 ;; Find a header and the column at which the command
509 ;; name will be found.
511 ;; If the keymap substitution isn't the last thing in
512 ;; the doc string, and if there is anything on the
513 ;; same line after it, this code won't recognize the end of it.
514 (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n"
516 (let ((col (- (match-end 1) (match-beginning 1))))
519 ;; Stop at a pair of blank lines.
520 (not (looking-at "\n\\s-*\n")))
521 ;; Skip a single blank line.
522 (and (eolp) (forward-line))
524 (skip-chars-backward "^ \t\n")
525 (if (and (>= (current-column) col)
526 (looking-at "\\(\\sw\\|\\s_\\)+$"))
527 (let ((sym (intern-soft (match-string 0))))
529 (help-xref-button 0 'help-function sym))))
531 (set-syntax-table stab))
532 ;; Delete extraneous newlines at the end of the docstring
533 (goto-char (point-max))
534 (while (and (not (bobp)) (bolp))
537 (when (or help-xref-stack help-xref-forward-stack)
539 ;; Make a back-reference in this buffer if appropriate.
540 (when help-xref-stack
541 (help-insert-xref-button help-back-label 'help-back
543 ;; Make a forward-reference in this buffer if appropriate.
544 (when help-xref-forward-stack
545 (when help-xref-stack
547 (help-insert-xref-button help-forward-label 'help-forward
549 (when (or help-xref-stack help-xref-forward-stack)
551 ;; View mode steals RET from us.
552 (set (make-local-variable 'minor-mode-overriding-map-alist)
553 (list (cons 'view-mode help-xref-override-view-map)))
554 (set-buffer-modified-p old-modified))))
557 (defun help-xref-button (match-number type &rest args)
558 "Make a hyperlink for cross-reference text previously matched.
559 MATCH-NUMBER is the subexpression of interest in the last matched
560 regexp. TYPE is the type of button to use. Any remaining arguments are
561 passed to the button's help-function when it is invoked.
562 See `help-make-xrefs'."
563 ;; Don't mung properties we've added specially in some instances.
564 (unless (button-at (match-beginning match-number))
565 (make-text-button (match-beginning match-number)
566 (match-end match-number)
567 'type type 'help-args args)))
570 (defun help-insert-xref-button (string type &rest args)
571 "Insert STRING and make a hyperlink from cross-reference text on it.
572 TYPE is the type of button to use. Any remaining arguments are passed
573 to the button's help-function when it is invoked.
574 See `help-make-xrefs'."
575 (unless (button-at (point))
576 (insert-text-button string 'type type 'help-args args)))
579 (defun help-xref-on-pp (from to)
580 "Add xrefs for symbols in `pp's output between FROM and TO."
581 (if (> (- to from) 5000) nil
582 (with-syntax-table emacs-lisp-mode-syntax-table
585 (narrow-to-region from to)
586 (goto-char (point-min))
590 ((looking-at "\"") (forward-sexp 1))
591 ((looking-at "#<") (search-forward ">" nil 'move))
592 ((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)")
593 (let* ((sym (intern-soft (match-string 1)))
594 (type (cond ((fboundp sym) 'help-function)
595 ((or (memq sym '(t nil))
601 'variable-documentation)))
603 (when type (help-xref-button 1 type sym)))
604 (goto-char (match-end 1)))
605 (t (forward-char 1))))
609 ;; Additional functions for (re-)creating types of help buffers.
610 (defun help-xref-interned (symbol)
611 "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL.
612 Both variable, function and face documentation are extracted into a single
614 (with-current-buffer (help-buffer)
615 ;; Push the previous item on the stack before clobbering the output buffer.
616 (help-setup-xref nil nil)
617 (let ((facedoc (when (facep symbol)
618 ;; Don't record the current entry in the stack.
619 (setq help-xref-stack-item nil)
620 (describe-face symbol)))
621 (fdoc (when (fboundp symbol)
622 ;; Don't record the current entry in the stack.
623 (setq help-xref-stack-item nil)
624 (describe-function symbol)))
625 (sdoc (when (or (boundp symbol)
626 (get symbol 'variable-documentation))
627 ;; Don't record the current entry in the stack.
628 (setq help-xref-stack-item nil)
629 (describe-variable symbol))))
632 ;; We now have a help buffer on the variable.
633 ;; Insert the function and face text before it.
634 (when (or fdoc facedoc)
635 (goto-char (point-min))
636 (let ((inhibit-read-only t))
640 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
641 " is also a " "face." "\n\n")))
643 (insert facedoc "\n\n"))
644 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
645 " is also a " "variable." "\n\n"))
646 ;; Don't record the `describe-variable' item in the stack.
647 (setq help-xref-stack-item nil)
648 (help-setup-xref (list #'help-xref-interned symbol) nil)))
650 ;; We now have a help buffer on the function.
651 ;; Insert face text before it.
653 (goto-char (point-max))
654 (let ((inhibit-read-only t))
655 (insert "\n\n" (make-string 30 ?-) "\n\n" (symbol-name symbol)
656 " is also a " "face." "\n\n" facedoc))
657 ;; Don't record the `describe-function' item in the stack.
658 (setq help-xref-stack-item nil)
659 (help-setup-xref (list #'help-xref-interned symbol) nil)))))))
662 ;; Navigation/hyperlinking with xrefs
664 (defun help-xref-go-back (buffer)
665 "From BUFFER, go back to previous help buffer text using `help-xref-stack'."
666 (let (item position method args)
667 (with-current-buffer buffer
668 (push (cons (point) help-xref-stack-item) help-xref-forward-stack)
669 (when help-xref-stack
670 (setq item (pop help-xref-stack)
671 ;; Clear the current item so that it won't get pushed
672 ;; by the function we're about to call. TODO: We could also
673 ;; push it onto a "forward" stack and add a `forw' button.
674 help-xref-stack-item nil
679 (with-current-buffer buffer
680 (if (get-buffer-window buffer)
681 (set-window-point (get-buffer-window buffer) position)
682 (goto-char position)))))
684 (defun help-xref-go-forward (buffer)
685 "From BUFFER, go forward to next help buffer."
686 (let (item position method args)
687 (with-current-buffer buffer
688 (push (cons (point) help-xref-stack-item) help-xref-stack)
689 (when help-xref-forward-stack
690 (setq item (pop help-xref-forward-stack)
691 ;; Clear the current item so that it won't get pushed
692 ;; by the function we're about to call. TODO: We could also
693 ;; push it onto a "forward" stack and add a `forw' button.
694 help-xref-stack-item nil
699 (with-current-buffer buffer
700 (if (get-buffer-window buffer)
701 (set-window-point (get-buffer-window buffer) position)
702 (goto-char position)))))
704 (defun help-go-back ()
705 "Go back to previous topic in this help buffer."
708 (help-xref-go-back (current-buffer))
709 (error "No previous help buffer")))
711 (defun help-go-forward ()
712 "Go back to next topic in this help buffer."
714 (if help-xref-forward-stack
715 (help-xref-go-forward (current-buffer))
716 (error "No next help buffer")))
718 (defun help-do-xref (pos function args)
719 "Call the help cross-reference function FUNCTION with args ARGS.
720 Things are set up properly so that the resulting help-buffer has
721 a proper [back] button."
722 ;; There is a reference at point. Follow it.
723 (let ((help-xref-following t))
724 (apply function args)))
726 ;; The doc string is meant to explain what buttons do.
727 (defun help-follow-mouse ()
728 "Follow the cross-reference that you click on."
730 (error "No cross-reference here"))
732 ;; The doc string is meant to explain what buttons do.
733 (defun help-follow ()
734 "Follow cross-reference at point.
736 For the cross-reference format, see `help-make-xrefs'."
738 (error "No cross-reference here"))
740 (defun help-follow-symbol (&optional pos)
741 "In help buffer, show docs for symbol at POS, defaulting to point.
742 Show all docs for that symbol as either a variable, function or face."
746 ;; check if the symbol under point is a function, variable or face
750 (goto-char pos) (skip-syntax-backward "w_")
751 (buffer-substring (point)
752 (progn (skip-syntax-forward "w_")
754 (when (or (boundp sym)
755 (get sym 'variable-documentation)
756 (fboundp sym) (facep sym))
757 (help-do-xref pos #'help-xref-interned (list sym)))))
759 (defun help-insert-string (string)
760 "Insert STRING to the help buffer and install xref info for it.
761 This function can be used to restore the old contents of the help buffer
762 when going back to the previous topic in the xref stack. It is needed
763 in case when it is impossible to recompute the old contents of the
764 help buffer by other means."
765 (setq help-xref-stack-item (list #'help-insert-string string))
766 (with-output-to-temp-buffer (help-buffer)
771 ;; arch-tag: 850954ae-3725-4cb4-8e91-0bf6d52d6b0b
772 ;;; help-mode.el ends here