Regenerate.
[emacs.git] / lisp / help-mode.el
blobf931a25509327a89185567773c51efb08234fdc8
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.
6 ;; Maintainer: FSF
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)
14 ;; any later version.
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.
26 ;;; Commentary:
28 ;; Defines `help-mode', which is the mode used by *Help* buffers, and
29 ;; associated support machinery, such as adding hyperlinks, etc.,
31 ;;; Code:
33 (require 'button)
34 (require 'view)
36 (defvar help-mode-map (make-sparse-keymap)
37 "Keymap for help mode.")
39 (set-keymap-parent help-mode-map button-buffer-map)
41 (define-key help-mode-map [mouse-2] 'help-follow-mouse)
42 (define-key help-mode-map "\C-c\C-b" 'help-go-back)
43 (define-key help-mode-map "\C-c\C-c" 'help-follow-symbol)
44 ;; Documentation only, since we use minor-mode-overriding-map-alist.
45 (define-key help-mode-map "\r" 'help-follow)
47 (defvar help-xref-stack nil
48 "A stack of ways by which to return to help buffers after following xrefs.
49 Used by `help-follow' and `help-xref-go-back'.
50 An element looks like (POSITION FUNCTION ARGS...).
51 To use the element, do (apply FUNCTION ARGS) then goto the point.")
52 (put 'help-xref-stack 'permanent-local t)
53 (make-variable-buffer-local 'help-xref-stack)
55 (defvar help-xref-stack-item nil
56 "An item for `help-follow' in this buffer to push onto `help-xref-stack'.
57 The format is (FUNCTION ARGS...).")
58 (put 'help-xref-stack-item 'permanent-local t)
59 (make-variable-buffer-local 'help-xref-stack-item)
61 (setq-default help-xref-stack nil help-xref-stack-item nil)
63 (defcustom help-mode-hook nil
64 "Hook run by `help-mode'."
65 :type 'hook
66 :group 'help)
68 ;; Button types used by help
70 (define-button-type 'help-xref
71 'follow-link t
72 'action #'help-button-action)
74 (defun help-button-action (button)
75 "Call BUTTON's help function."
76 (help-do-xref (button-start button)
77 (button-get button 'help-function)
78 (button-get button 'help-args)))
80 ;; These 6 calls to define-button-type were generated in a dolist
81 ;; loop, but that is bad because it means these button types don't
82 ;; have an easily found definition.
84 (define-button-type 'help-function
85 :supertype 'help-xref
86 'help-function 'describe-function
87 'help-echo (purecopy "mouse-2, RET: describe this function"))
89 (define-button-type 'help-variable
90 :supertype 'help-xref
91 'help-function 'describe-variable
92 'help-echo (purecopy "mouse-2, RET: describe this variable"))
94 (define-button-type 'help-face
95 :supertype 'help-xref
96 'help-function 'describe-face
97 'help-echo (purecopy "mouse-2, RET: describe this face"))
99 (define-button-type 'help-coding-system
100 :supertype 'help-xref
101 'help-function 'describe-coding-system
102 'help-echo (purecopy "mouse-2, RET: describe this coding system"))
104 (define-button-type 'help-input-method
105 :supertype 'help-xref
106 'help-function 'describe-input-method
107 'help-echo (purecopy "mouse-2, RET: describe this input method"))
109 (define-button-type 'help-character-set
110 :supertype 'help-xref
111 'help-function 'describe-character-set
112 'help-echo (purecopy "mouse-2, RET: describe this character set"))
114 ;; make some more ideosyncratic button types
116 (define-button-type 'help-symbol
117 :supertype 'help-xref
118 'help-function #'help-xref-interned
119 'help-echo (purecopy "mouse-2, RET: describe this symbol"))
121 (define-button-type 'help-back
122 :supertype 'help-xref
123 'help-function #'help-xref-go-back
124 'help-echo (purecopy "mouse-2, RET: go back to previous help buffer"))
126 (define-button-type 'help-info
127 :supertype 'help-xref
128 'help-function #'info
129 'help-echo (purecopy "mouse-2, RET: read this Info node"))
131 (define-button-type 'help-url
132 :supertype 'help-xref
133 'help-function #'browse-url
134 'help-echo (purecopy "mouse-2, RET: view this URL in a browser"))
136 (define-button-type 'help-customize-variable
137 :supertype 'help-xref
138 'help-function (lambda (v)
139 (customize-variable v))
140 'help-echo (purecopy "mouse-2, RET: customize variable"))
142 (define-button-type 'help-customize-face
143 :supertype 'help-xref
144 'help-function (lambda (v)
145 (customize-face v))
146 'help-echo (purecopy "mouse-2, RET: customize face"))
148 (define-button-type 'help-function-def
149 :supertype 'help-xref
150 'help-function (lambda (fun file)
151 (require 'find-func)
152 (when (eq file 'C-source)
153 (setq file
154 (help-C-file-name (indirect-function fun) 'fun)))
155 ;; Don't use find-function-noselect because it follows
156 ;; aliases (which fails for built-in functions).
157 (let ((location
158 (find-function-search-for-symbol fun nil file)))
159 (pop-to-buffer (car location))
160 (if (cdr location)
161 (goto-char (cdr location))
162 (message "Unable to find location in file"))))
163 'help-echo (purecopy "mouse-2, RET: find function's definition"))
165 (define-button-type 'help-variable-def
166 :supertype 'help-xref
167 'help-function (lambda (var &optional file)
168 (when (eq file 'C-source)
169 (setq file (help-C-file-name var 'var)))
170 (let ((location (find-variable-noselect var file)))
171 (pop-to-buffer (car location))
172 (if (cdr location)
173 (goto-char (cdr location))
174 (message "Unable to find location in file"))))
175 'help-echo (purecopy "mouse-2, RET: find variable's definition"))
177 (define-button-type 'help-face-def
178 :supertype 'help-xref
179 'help-function (lambda (fun file)
180 (require 'find-func)
181 ;; Don't use find-function-noselect because it follows
182 ;; aliases (which fails for built-in functions).
183 (let ((location
184 (find-function-search-for-symbol fun 'defface file)))
185 (pop-to-buffer (car location))
186 (if (cdr location)
187 (goto-char (cdr location))
188 (message "Unable to find location in file"))))
189 'help-echo (purecopy "mouse-2, RET: find face's definition"))
192 ;;;###autoload
193 (defun help-mode ()
194 "Major mode for viewing help text and navigating references in it.
195 Entry to this mode runs the normal hook `help-mode-hook'.
196 Commands:
197 \\{help-mode-map}"
198 (interactive)
199 (kill-all-local-variables)
200 (use-local-map help-mode-map)
201 (setq mode-name "Help")
202 (setq major-mode 'help-mode)
203 (view-mode)
204 (make-local-variable 'view-no-disable-on-exit)
205 (setq view-no-disable-on-exit t)
206 (setq view-exit-action (lambda (buffer)
207 (or (window-minibuffer-p (selected-window))
208 (one-window-p t)
209 (delete-window))))
210 (run-mode-hooks 'help-mode-hook))
212 ;;;###autoload
213 (defun help-mode-setup ()
214 (help-mode)
215 (setq buffer-read-only nil))
217 ;;;###autoload
218 (defun help-mode-finish ()
219 (let ((entry (assq (selected-window) view-return-to-alist)))
220 (if entry
221 ;; When entering Help mode from the Help window,
222 ;; such as by following a link, preserve the same
223 ;; meaning for the q command.
224 ;; (setcdr entry (cons (selected-window) help-return-method))
226 (setq view-return-to-alist
227 (cons (cons (selected-window) help-return-method)
228 view-return-to-alist))))
229 (when (eq major-mode 'help-mode)
230 ;; View mode's read-only status of existing *Help* buffer is lost
231 ;; by with-output-to-temp-buffer.
232 (toggle-read-only 1)
233 (help-make-xrefs (current-buffer))))
235 ;; Grokking cross-reference information in doc strings and
236 ;; hyperlinking it.
238 ;; This may have some scope for extension and the same or something
239 ;; similar should be done for widget doc strings, which currently use
240 ;; another mechanism.
242 (defvar help-back-label (purecopy "[back]")
243 "Label to use by `help-make-xrefs' for the go-back reference.")
245 (defconst help-xref-symbol-regexp
246 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|" ; Link to var
247 "\\(function\\|command\\)\\|" ; Link to function
248 "\\(face\\)\\|" ; Link to face
249 "\\(symbol\\|program\\|property\\)\\|" ; Don't link
250 "\\(source \\(?:code \\)?\\(?:of\\|for\\)\\)\\)"
251 "[ \t\n]+\\)?"
252 ;; Note starting with word-syntax character:
253 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'"))
254 "Regexp matching doc string references to symbols.
256 The words preceding the quoted symbol can be used in doc strings to
257 distinguish references to variables, functions and symbols.")
259 (defvar help-xref-mule-regexp nil
260 "Regexp matching doc string references to MULE-related keywords.
262 It is usually nil, and is temporarily bound to an appropriate regexp
263 when help commands related to multilingual environment (e.g.,
264 `describe-coding-system') are invoked.")
267 (defconst help-xref-info-regexp
268 (purecopy "\\<[Ii]nfo[ \t\n]+\\(node\\|anchor\\)[ \t\n]+`\\([^']+\\)'")
269 "Regexp matching doc string references to an Info node.")
271 (defconst help-xref-url-regexp
272 (purecopy "\\<[Uu][Rr][Ll][ \t\n]+`\\([^']+\\)'")
273 "Regexp matching doc string references to a URL.")
275 ;;;###autoload
276 (defun help-setup-xref (item interactive-p)
277 "Invoked from commands using the \"*Help*\" buffer to install some xref info.
279 ITEM is a (FUNCTION . ARGS) pair appropriate for recreating the help
280 buffer after following a reference. INTERACTIVE-P is non-nil if the
281 calling command was invoked interactively. In this case the stack of
282 items for help buffer \"back\" buttons is cleared.
284 This should be called very early, before the output buffer is cleared,
285 because we want to record the \"previous\" position of point so we can
286 restore it properly when going back."
287 (with-current-buffer (help-buffer)
288 (when help-xref-stack-item
289 (push (cons (point) help-xref-stack-item) help-xref-stack))
290 (when interactive-p
291 (let ((tail (nthcdr 10 help-xref-stack)))
292 ;; Truncate the stack.
293 (if tail (setcdr tail nil))))
294 (setq help-xref-stack-item item)))
296 (defvar help-xref-following nil
297 "Non-nil when following a help cross-reference.")
299 (defun help-buffer ()
300 (buffer-name ;for with-output-to-temp-buffer
301 (if help-xref-following
302 (current-buffer)
303 (get-buffer-create "*Help*"))))
305 (defvar help-xref-override-view-map
306 (let ((map (make-sparse-keymap)))
307 (set-keymap-parent map view-mode-map)
308 (define-key map "\r" nil)
309 map)
310 "Replacement keymap for `view-mode' in help buffers.")
312 ;;;###autoload
313 (defun help-make-xrefs (&optional buffer)
314 "Parse and hyperlink documentation cross-references in the given BUFFER.
316 Find cross-reference information in a buffer and activate such cross
317 references for selection with `help-follow'. Cross-references have
318 the canonical form `...' and the type of reference may be
319 disambiguated by the preceding word(s) used in
320 `help-xref-symbol-regexp'. Faces only get cross-referenced if
321 preceded or followed by the word `face'. Variables without
322 variable documentation do not get cross-referenced, unless
323 preceded by the word `variable' or `option'.
325 If the variable `help-xref-mule-regexp' is non-nil, find also
326 cross-reference information related to multilingual environment
327 \(e.g., coding-systems). This variable is also used to disambiguate
328 the type of reference as the same way as `help-xref-symbol-regexp'.
330 A special reference `back' is made to return back through a stack of
331 help buffers. Variable `help-back-label' specifies the text for
332 that."
333 (interactive "b")
334 (save-excursion
335 (set-buffer (or buffer (current-buffer)))
336 (goto-char (point-min))
337 ;; Skip the header-type info, though it might be useful to parse
338 ;; it at some stage (e.g. "function in `library'").
339 (forward-paragraph)
340 (let ((old-modified (buffer-modified-p)))
341 (let ((stab (syntax-table))
342 (case-fold-search t)
343 (inhibit-read-only t))
344 (set-syntax-table emacs-lisp-mode-syntax-table)
345 ;; The following should probably be abstracted out.
346 (unwind-protect
347 (progn
348 ;; Info references
349 (save-excursion
350 (while (re-search-forward help-xref-info-regexp nil t)
351 (let ((data (match-string 2)))
352 (save-match-data
353 (unless (string-match "^([^)]+)" data)
354 (setq data (concat "(emacs)" data))))
355 (help-xref-button 2 'help-info data))))
356 ;; URLs
357 (save-excursion
358 (while (re-search-forward help-xref-url-regexp nil t)
359 (let ((data (match-string 1)))
360 (help-xref-button 1 'help-url data))))
361 ;; Mule related keywords. Do this before trying
362 ;; `help-xref-symbol-regexp' because some of Mule
363 ;; keywords have variable or function definitions.
364 (if help-xref-mule-regexp
365 (save-excursion
366 (while (re-search-forward help-xref-mule-regexp nil t)
367 (let* ((data (match-string 7))
368 (sym (intern-soft data)))
369 (cond
370 ((match-string 3) ; coding system
371 (and sym (coding-system-p sym)
372 (help-xref-button 6 'help-coding-system sym)))
373 ((match-string 4) ; input method
374 (and (assoc data input-method-alist)
375 (help-xref-button 7 'help-input-method data)))
376 ((or (match-string 5) (match-string 6)) ; charset
377 (and sym (charsetp sym)
378 (help-xref-button 7 'help-character-set sym)))
379 ((assoc data input-method-alist)
380 (help-xref-button 7 'help-character-set data))
381 ((and sym (coding-system-p sym))
382 (help-xref-button 7 'help-coding-system sym))
383 ((and sym (charsetp sym))
384 (help-xref-button 7 'help-character-set sym)))))))
385 ;; Quoted symbols
386 (save-excursion
387 (while (re-search-forward help-xref-symbol-regexp nil t)
388 (let* ((data (match-string 8))
389 (sym (intern-soft data)))
390 (if sym
391 (cond
392 ((match-string 3) ; `variable' &c
393 (and (or (boundp sym) ; `variable' doesn't ensure
394 ; it's actually bound
395 (get sym 'variable-documentation))
396 (help-xref-button 8 'help-variable sym)))
397 ((match-string 4) ; `function' &c
398 (and (fboundp sym) ; similarly
399 (help-xref-button 8 'help-function sym)))
400 ((match-string 5) ; `face'
401 (and (facep sym)
402 (help-xref-button 8 'help-face sym)))
403 ((match-string 6)) ; nothing for `symbol'
404 ((match-string 7)
405 ;;; this used:
406 ;;; #'(lambda (arg)
407 ;;; (let ((location
408 ;;; (find-function-noselect arg)))
409 ;;; (pop-to-buffer (car location))
410 ;;; (goto-char (cdr location))))
411 (help-xref-button 8 'help-function-def sym))
412 ((and
413 (facep sym)
414 (save-match-data (looking-at "[ \t\n]+face\\W")))
415 (help-xref-button 8 'help-face sym))
416 ((and (or (boundp sym)
417 (get sym 'variable-documentation))
418 (fboundp sym))
419 ;; We can't intuit whether to use the
420 ;; variable or function doc -- supply both.
421 (help-xref-button 8 'help-symbol sym))
422 ((and
423 (or (boundp sym)
424 (get sym 'variable-documentation))
426 (documentation-property
427 sym 'variable-documentation)
428 (condition-case nil
429 (documentation-property
430 (indirect-variable sym)
431 'variable-documentation)
432 (cyclic-variable-indirection nil))))
433 (help-xref-button 8 'help-variable sym))
434 ((fboundp sym)
435 (help-xref-button 8 'help-function sym)))))))
436 ;; An obvious case of a key substitution:
437 (save-excursion
438 (while (re-search-forward
439 ;; Assume command name is only word and symbol
440 ;; characters to get things like `use M-x foo->bar'.
441 ;; Command required to end with word constituent
442 ;; to avoid `.' at end of a sentence.
443 "\\<M-x\\s-+\\(\\sw\\(\\sw\\|\\s_\\)*\\sw\\)" nil t)
444 (let ((sym (intern-soft (match-string 1))))
445 (if (fboundp sym)
446 (help-xref-button 1 'help-function sym)))))
447 ;; Look for commands in whole keymap substitutions:
448 (save-excursion
449 ;; Make sure to find the first keymap.
450 (goto-char (point-min))
451 ;; Find a header and the column at which the command
452 ;; name will be found.
454 ;; If the keymap substitution isn't the last thing in
455 ;; the doc string, and if there is anything on the
456 ;; same line after it, this code won't recognize the end of it.
457 (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n"
458 nil t)
459 (let ((col (- (match-end 1) (match-beginning 1))))
460 (while
461 (and (not (eobp))
462 ;; Stop at a pair of blank lines.
463 (not (looking-at "\n\\s-*\n")))
464 ;; Skip a single blank line.
465 (and (eolp) (forward-line))
466 (end-of-line)
467 (skip-chars-backward "^ \t\n")
468 (if (and (>= (current-column) col)
469 (looking-at "\\(\\sw\\|\\s_\\)+$"))
470 (let ((sym (intern-soft (match-string 0))))
471 (if (fboundp sym)
472 (help-xref-button 0 'help-function sym))))
473 (forward-line))))))
474 (set-syntax-table stab))
475 ;; Delete extraneous newlines at the end of the docstring
476 (goto-char (point-max))
477 (while (and (not (bobp)) (bolp))
478 (delete-char -1))
479 (insert "\n")
480 ;; Make a back-reference in this buffer if appropriate.
481 (when help-xref-stack
482 (insert "\n")
483 (help-insert-xref-button help-back-label 'help-back
484 (current-buffer))
485 (insert "\n")))
486 ;; View mode steals RET from us.
487 (set (make-local-variable 'minor-mode-overriding-map-alist)
488 (list (cons 'view-mode help-xref-override-view-map)))
489 (set-buffer-modified-p old-modified))))
491 ;;;###autoload
492 (defun help-xref-button (match-number type &rest args)
493 "Make a hyperlink for cross-reference text previously matched.
494 MATCH-NUMBER is the subexpression of interest in the last matched
495 regexp. TYPE is the type of button to use. Any remaining arguments are
496 passed to the button's help-function when it is invoked.
497 See `help-make-xrefs'."
498 ;; Don't mung properties we've added specially in some instances.
499 (unless (button-at (match-beginning match-number))
500 (make-text-button (match-beginning match-number)
501 (match-end match-number)
502 'type type 'help-args args)))
504 ;;;###autoload
505 (defun help-insert-xref-button (string type &rest args)
506 "Insert STRING and make a hyperlink from cross-reference text on it.
507 TYPE is the type of button to use. Any remaining arguments are passed
508 to the button's help-function when it is invoked.
509 See `help-make-xrefs'."
510 (unless (button-at (point))
511 (insert-text-button string 'type type 'help-args args)))
513 ;;;###autoload
514 (defun help-xref-on-pp (from to)
515 "Add xrefs for symbols in `pp's output between FROM and TO."
516 (if (> (- to from) 5000) nil
517 (with-syntax-table emacs-lisp-mode-syntax-table
518 (save-excursion
519 (save-restriction
520 (narrow-to-region from to)
521 (goto-char (point-min))
522 (condition-case nil
523 (while (not (eobp))
524 (cond
525 ((looking-at "\"") (forward-sexp 1))
526 ((looking-at "#<") (search-forward ">" nil 'move))
527 ((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)")
528 (let* ((sym (intern-soft (match-string 1)))
529 (type (cond ((fboundp sym) 'help-function)
530 ((or (memq sym '(t nil))
531 (keywordp sym))
532 nil)
533 ((and sym
534 (or (boundp sym)
535 (get sym
536 'variable-documentation)))
537 'help-variable))))
538 (when type (help-xref-button 1 type sym)))
539 (goto-char (match-end 1)))
540 (t (forward-char 1))))
541 (error nil)))))))
544 ;; Additional functions for (re-)creating types of help buffers.
545 (defun help-xref-interned (symbol)
546 "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL.
547 Both variable, function and face documentation are extracted into a single
548 help buffer."
549 (with-current-buffer (help-buffer)
550 ;; Push the previous item on the stack before clobbering the output buffer.
551 (help-setup-xref nil nil)
552 (let ((facedoc (when (facep symbol)
553 ;; Don't record the current entry in the stack.
554 (setq help-xref-stack-item nil)
555 (describe-face symbol)))
556 (fdoc (when (fboundp symbol)
557 ;; Don't record the current entry in the stack.
558 (setq help-xref-stack-item nil)
559 (describe-function symbol)))
560 (sdoc (when (or (boundp symbol)
561 (get symbol 'variable-documentation))
562 ;; Don't record the current entry in the stack.
563 (setq help-xref-stack-item nil)
564 (describe-variable symbol))))
565 (cond
566 (sdoc
567 ;; We now have a help buffer on the variable.
568 ;; Insert the function and face text before it.
569 (when (or fdoc facedoc)
570 (goto-char (point-min))
571 (let ((inhibit-read-only t))
572 (when fdoc
573 (insert fdoc "\n\n")
574 (when facedoc
575 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
576 " is also a " "face." "\n\n")))
577 (when facedoc
578 (insert facedoc "\n\n"))
579 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
580 " is also a " "variable." "\n\n"))
581 ;; Don't record the `describe-variable' item in the stack.
582 (setq help-xref-stack-item nil)
583 (help-setup-xref (list #'help-xref-interned symbol) nil)))
584 (fdoc
585 ;; We now have a help buffer on the function.
586 ;; Insert face text before it.
587 (when facedoc
588 (goto-char (point-max))
589 (let ((inhibit-read-only t))
590 (insert "\n\n" (make-string 30 ?-) "\n\n" (symbol-name symbol)
591 " is also a " "face." "\n\n" facedoc))
592 ;; Don't record the `describe-function' item in the stack.
593 (setq help-xref-stack-item nil)
594 (help-setup-xref (list #'help-xref-interned symbol) nil)))))))
597 ;; Navigation/hyperlinking with xrefs
599 (defun help-xref-go-back (buffer)
600 "From BUFFER, go back to previous help buffer text using `help-xref-stack'."
601 (let (item position method args)
602 (with-current-buffer buffer
603 (when help-xref-stack
604 (setq item (pop help-xref-stack)
605 ;; Clear the current item so that it won't get pushed
606 ;; by the function we're about to call. TODO: We could also
607 ;; push it onto a "forward" stack and add a `forw' button.
608 help-xref-stack-item nil
609 position (car item)
610 method (cadr item)
611 args (cddr item))))
612 (apply method args)
613 (with-current-buffer buffer
614 (if (get-buffer-window buffer)
615 (set-window-point (get-buffer-window buffer) position)
616 (goto-char position)))))
618 (defun help-go-back ()
619 "Go back to previous topic in this help buffer."
620 (interactive)
621 (if help-xref-stack
622 (help-xref-go-back (current-buffer))
623 (error "No previous help buffer")))
625 (defun help-do-xref (pos function args)
626 "Call the help cross-reference function FUNCTION with args ARGS.
627 Things are set up properly so that the resulting help-buffer has
628 a proper [back] button."
629 ;; There is a reference at point. Follow it.
630 (let ((help-xref-following t))
631 (apply function args)))
633 ;; The doc string is meant to explain what buttons do.
634 (defun help-follow-mouse ()
635 "Follow the cross-reference that you click on."
636 (interactive)
637 (error "No cross-reference here"))
639 ;; The doc string is meant to explain what buttons do.
640 (defun help-follow ()
641 "Follow cross-reference at point.
643 For the cross-reference format, see `help-make-xrefs'."
644 (interactive)
645 (error "No cross-reference here"))
647 (defun help-follow-symbol (&optional pos)
648 "In help buffer, show docs for symbol at POS, defaulting to point.
649 Show all docs for that symbol as either a variable, function or face."
650 (interactive "d")
651 (unless pos
652 (setq pos (point)))
653 ;; check if the symbol under point is a function, variable or face
654 (let ((sym
655 (intern
656 (save-excursion
657 (goto-char pos) (skip-syntax-backward "w_")
658 (buffer-substring (point)
659 (progn (skip-syntax-forward "w_")
660 (point)))))))
661 (when (or (boundp sym)
662 (get sym 'variable-documentation)
663 (fboundp sym) (facep sym))
664 (help-do-xref pos #'help-xref-interned (list sym)))))
666 (defun help-insert-string (string)
667 "Insert STRING to the help buffer and install xref info for it.
668 This function can be used to restore the old contents of the help buffer
669 when going back to the previous topic in the xref stack. It is needed
670 in case when it is impossible to recompute the old contents of the
671 help buffer by other means."
672 (setq help-xref-stack-item (list #'help-insert-string string))
673 (with-output-to-temp-buffer (help-buffer)
674 (insert string)))
676 (provide 'help-mode)
678 ;; arch-tag: 850954ae-3725-4cb4-8e91-0bf6d52d6b0b
679 ;;; help-mode.el ends here