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