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