annotate lisp/help-mode.el @ 39892:ef399b9ffc2b

(2C-mode): Don't use make-local-hook.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 13 Oct 2001 19:12:07 +0000
parents 8f2810b5b5e8
children 296982d27c41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
1 ;;; help-mode.el --- `help-mode' used by *Help* buffers
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
2
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
4 ;; Free Software Foundation, Inc.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
5
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
6 ;; Maintainer: FSF
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
7 ;; Keywords: help, internal
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
8
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
10
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
14 ;; any later version.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
15
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
20
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
25
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
27
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
28 ;; Defines `help-mode', which is the mode used by *Help* buffers, and
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
29 ;; associated support machinery, such as adding hyperlinks, etc.,
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
30
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
31 ;;; Code:
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
32
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
33 (require 'button)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
34 (eval-when-compile (require 'view))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
35
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
36 (defvar help-mode-map (make-sparse-keymap)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
37 "Keymap for help mode.")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
38
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
39 (set-keymap-parent help-mode-map button-buffer-map)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
40
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
41 (define-key help-mode-map [mouse-2] 'help-follow-mouse)
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
42 (define-key help-mode-map "\C-c\C-b" 'help-go-back)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
43 (define-key help-mode-map "\C-c\C-c" 'help-follow)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
44 ;; Documentation only, since we use minor-mode-overriding-map-alist.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
45 (define-key help-mode-map "\r" 'help-follow)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
46
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
47 (defvar help-xref-stack nil
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
48 "A stack of ways by which to return to help buffers after following xrefs.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
49 Used by `help-follow' and `help-xref-go-back'.
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
50 An element looks like (POSITION FUNCTION ARGS...).
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
51 To use the element, do (apply FUNCTION ARGS) then goto the point.")
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
52 (put 'help-xref-stack 'permanent-local t)
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
53 (make-variable-buffer-local 'help-xref-stack)
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
54
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
55 (defvar help-xref-stack-item nil
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
56 "An item for `help-follow' in this buffer to push onto `help-xref-stack'.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
57 The format is (FUNCTION ARGS...).")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
58 (put 'help-xref-stack-item 'permanent-local t)
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
59 (make-variable-buffer-local 'help-xref-stack-item)
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
60
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
61 (setq-default help-xref-stack nil help-xref-stack-item nil)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
62
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
63
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
64
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
65 ;; Button types used by help
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
66
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
67 ;; Make some button types that all use the same naming conventions
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
68 (dolist (help-type '("function" "variable" "face"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
69 "coding-system" "input-method" "character-set"))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
70 (define-button-type (intern (purecopy (concat "help-" help-type)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
71 'help-function (intern (concat "describe-" help-type))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
72 'help-echo (purecopy (concat "mouse-2, RET: describe this " help-type))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
73 'action #'help-button-action))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
74
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
75 ;; make some more ideosyncratic button types
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
76
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
77 (define-button-type 'help-symbol
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
78 'help-function #'help-xref-interned
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
79 'help-echo (purecopy "mouse-2, RET: describe this symbol")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
80 'action #'help-button-action)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
81
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
82 (define-button-type 'help-back
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
83 'help-function #'help-xref-go-back
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
84 'help-echo (purecopy "mouse-2, RET: go back to previous help buffer")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
85 'action #'help-button-action)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
86
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
87 (define-button-type 'help-info
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
88 'help-function #'info
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
89 'help-echo (purecopy"mouse-2, RET: read this Info node")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
90 'action #'help-button-action)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
91
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
92 (define-button-type 'help-customize-variable
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
93 'help-function (lambda (v)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
94 (if help-xref-stack
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
95 (pop help-xref-stack))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
96 (customize-variable v))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
97 'help-echo (purecopy "mouse-2, RET: customize variable")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
98 'action #'help-button-action)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
99
39800
8f2810b5b5e8 (help-customize-face): New button-type.
Miles Bader <miles@gnu.org>
parents: 39787
diff changeset
100 (define-button-type 'help-customize-face
8f2810b5b5e8 (help-customize-face): New button-type.
Miles Bader <miles@gnu.org>
parents: 39787
diff changeset
101 'help-function (lambda (v)
8f2810b5b5e8 (help-customize-face): New button-type.
Miles Bader <miles@gnu.org>
parents: 39787
diff changeset
102 (if help-xref-stack
8f2810b5b5e8 (help-customize-face): New button-type.
Miles Bader <miles@gnu.org>
parents: 39787
diff changeset
103 (pop help-xref-stack))
8f2810b5b5e8 (help-customize-face): New button-type.
Miles Bader <miles@gnu.org>
parents: 39787
diff changeset
104 (customize-face v))
8f2810b5b5e8 (help-customize-face): New button-type.
Miles Bader <miles@gnu.org>
parents: 39787
diff changeset
105 'help-echo (purecopy "mouse-2, RET: customize face")
8f2810b5b5e8 (help-customize-face): New button-type.
Miles Bader <miles@gnu.org>
parents: 39787
diff changeset
106 'action #'help-button-action)
8f2810b5b5e8 (help-customize-face): New button-type.
Miles Bader <miles@gnu.org>
parents: 39787
diff changeset
107
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
108 (define-button-type 'help-function-def
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
109 'help-function (lambda (fun file)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
110 (require 'find-func)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
111 ;; Don't use find-function-noselect because it follows
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
112 ;; aliases (which fails for built-in functions).
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
113 (let* ((location (find-function-search-for-symbol
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
114 fun nil file)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
115 (pop-to-buffer (car location))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
116 (goto-char (cdr location))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
117 'help-echo (purecopy "mouse-2, RET: find function's definition")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
118 'action #'help-button-action)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
119
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
120 (define-button-type 'help-variable-def
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
121 'help-function (lambda (var &optional file)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
122 (let ((location
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
123 (find-variable-noselect var file)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
124 (pop-to-buffer (car location))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
125 (goto-char (cdr location))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
126 'help-echo (purecopy"mouse-2, RET: find variable's definition")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
127 'action #'help-button-action)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
128
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
129 (defun help-button-action (button)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
130 "Call BUTTON's help function."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
131 (help-do-xref (button-start button)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
132 (button-get button 'help-function)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
133 (button-get button 'help-args)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
134
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
135
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
136 ;;;###autoload
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
137 (define-derived-mode help-mode nil "Help"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
138 "Major mode for viewing help text and navigating references in it.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
139 Entry to this mode runs the normal hook `help-mode-hook'.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
140 Commands:
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
141 \\{help-mode-map}"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
142 (setq font-lock-defaults nil) ; font-lock would defeat xref
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
143 (view-mode)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
144 (make-local-variable 'view-no-disable-on-exit)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
145 (setq view-no-disable-on-exit t))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
146
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
147 ;;;###autoload
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
148 (defun help-mode-setup ()
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
149 (help-mode)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
150 (setq buffer-read-only nil))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
151
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
152 ;;;###autoload
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
153 (defun help-mode-finish ()
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
154 (when (eq major-mode 'help-mode)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
155 ;; View mode's read-only status of existing *Help* buffer is lost
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
156 ;; by with-output-to-temp-buffer.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
157 (toggle-read-only 1)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
158 (help-make-xrefs (current-buffer)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
159 (setq view-return-to-alist
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
160 (list (cons (selected-window) help-return-method))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
161
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
162
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
163 ;;; Grokking cross-reference information in doc strings and
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
164 ;;; hyperlinking it.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
165
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
166 ;; This may have some scope for extension and the same or something
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
167 ;; similar should be done for widget doc strings, which currently use
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
168 ;; another mechanism.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
169
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
170 (defcustom help-highlight-p t
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
171 "*If non-nil, `help-make-xrefs' highlight cross-references.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
172 Under a window system it highlights them with face defined by
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
173 `help-highlight-face'."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
174 :group 'help
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
175 :version "20.3"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
176 :type 'boolean)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
177
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
178 (defcustom help-highlight-face 'underline
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
179 "Face used by `help-make-xrefs' to highlight cross-references.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
180 Must be previously-defined."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
181 :group 'help
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
182 :version "20.3"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
183 :type 'face)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
184
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
185 (defvar help-back-label (purecopy "[back]")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
186 "Label to use by `help-make-xrefs' for the go-back reference.")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
187
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
188 (defconst help-xref-symbol-regexp
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
189 (purecopy (concat "\\(\\<\\(\\(variable\\|option\\)\\|"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
190 "\\(function\\|command\\)\\|"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
191 "\\(face\\)\\|"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
192 "\\(symbol\\)\\|"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
193 "\\(source \\(?:code \\)?\\(?:of\\|for\\)\\)\\)\\s-+\\)?"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
194 ;; Note starting with word-syntax character:
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
195 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'"))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
196 "Regexp matching doc string references to symbols.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
197
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
198 The words preceding the quoted symbol can be used in doc strings to
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
199 distinguish references to variables, functions and symbols.")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
200
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
201 (defconst help-xref-mule-regexp nil
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
202 "Regexp matching doc string references to MULE-related keywords.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
203
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
204 It is usually nil, and is temporarily bound to an appropriate regexp
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
205 when help commands related to multilingual environment (e.g.,
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
206 `describe-coding-system') are invoked.")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
207
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
208
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
209 (defconst help-xref-info-regexp
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
210 (purecopy "\\<[Ii]nfo[ \t\n]+node[ \t\n]+`\\([^']+\\)'")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
211 "Regexp matching doc string references to an Info node.")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
212
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
213 ;;;###autoload
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
214 (defun help-setup-xref (item interactive-p)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
215 "Invoked from commands using the \"*Help*\" buffer to install some xref info.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
216
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
217 ITEM is a (FUNCTION . ARGS) pair appropriate for recreating the help
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
218 buffer after following a reference. INTERACTIVE-P is non-nil if the
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
219 calling command was invoked interactively. In this case the stack of
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
220 items for help buffer \"back\" buttons is cleared.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
221
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
222 This should be called very early, before the output buffer is cleared,
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
223 because we want to record the \"previous\" position of point so we can
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
224 restore it properly when going back."
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
225 (with-current-buffer (help-buffer)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
226 (if interactive-p
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
227 ;; Why do we want to prevent the user from going back ?? -stef
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
228 (setq help-xref-stack nil)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
229 (when help-xref-stack-item
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
230 (push (cons (point) help-xref-stack-item) help-xref-stack)))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
231 (setq help-xref-stack-item item)))
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
232
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
233 (defvar help-xref-following nil
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
234 "Non-nil when following a help cross-reference.")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
235
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
236 (defun help-buffer ()
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
237 (unless (equal help-xref-following (eq major-mode 'help-mode))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
238 (debug))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
239 (buffer-name ;for with-output-to-temp-buffer
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
240 (if help-xref-following
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
241 (current-buffer)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
242 (get-buffer-create "*Help*"))))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
243
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
244 ;;;###autoload
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
245 (defun help-make-xrefs (&optional buffer)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
246 "Parse and hyperlink documentation cross-references in the given BUFFER.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
247
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
248 Find cross-reference information in a buffer and, if
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
249 `help-highlight-p' is non-nil, highlight it with face defined by
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
250 `help-highlight-face'; activate such cross references for selection
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
251 with `help-follow'. Cross-references have the canonical form `...'
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
252 and the type of reference may be disambiguated by the preceding
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
253 word(s) used in `help-xref-symbol-regexp'.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
254
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
255 If the variable `help-xref-mule-regexp' is non-nil, find also
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
256 cross-reference information related to multilingual environment
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
257 \(e.g., coding-systems). This variable is also used to disambiguate
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
258 the type of reference as the same way as `help-xref-symbol-regexp'.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
259
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
260 A special reference `back' is made to return back through a stack of
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
261 help buffers. Variable `help-back-label' specifies the text for
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
262 that."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
263 (interactive "b")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
264 (save-excursion
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
265 (set-buffer (or buffer (current-buffer)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
266 (goto-char (point-min))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
267 ;; Skip the header-type info, though it might be useful to parse
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
268 ;; it at some stage (e.g. "function in `library'").
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
269 (forward-paragraph)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
270 (let ((old-modified (buffer-modified-p)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
271 (let ((stab (syntax-table))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
272 (case-fold-search t)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
273 (inhibit-read-only t))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
274 (set-syntax-table emacs-lisp-mode-syntax-table)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
275 ;; The following should probably be abstracted out.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
276 (unwind-protect
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
277 (progn
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
278 ;; Info references
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
279 (save-excursion
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
280 (while (re-search-forward help-xref-info-regexp nil t)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
281 (let ((data (match-string 1)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
282 (save-match-data
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
283 (unless (string-match "^([^)]+)" data)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
284 (setq data (concat "(emacs)" data))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
285 (help-xref-button 1 'help-info data))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
286 ;; Mule related keywords. Do this before trying
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
287 ;; `help-xref-symbol-regexp' because some of Mule
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
288 ;; keywords have variable or function definitions.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
289 (if help-xref-mule-regexp
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
290 (save-excursion
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
291 (while (re-search-forward help-xref-mule-regexp nil t)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
292 (let* ((data (match-string 7))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
293 (sym (intern-soft data)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
294 (cond
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
295 ((match-string 3) ; coding system
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
296 (and sym (coding-system-p sym)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
297 (help-xref-button 6 'help-coding-system sym)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
298 ((match-string 4) ; input method
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
299 (and (assoc data input-method-alist)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
300 (help-xref-button 7 'help-input-method data)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
301 ((or (match-string 5) (match-string 6)) ; charset
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
302 (and sym (charsetp sym)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
303 (help-xref-button 7 'help-character-set sym)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
304 ((assoc data input-method-alist)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
305 (help-xref-button 7 'help-character-set data))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
306 ((and sym (coding-system-p sym))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
307 (help-xref-button 7 'help-coding-system sym))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
308 ((and sym (charsetp sym))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
309 (help-xref-button 7 'help-character-set sym)))))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
310 ;; Quoted symbols
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
311 (save-excursion
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
312 (while (re-search-forward help-xref-symbol-regexp nil t)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
313 (let* ((data (match-string 8))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
314 (sym (intern-soft data)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
315 (if sym
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
316 (cond
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
317 ((match-string 3) ; `variable' &c
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
318 (and (boundp sym) ; `variable' doesn't ensure
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
319 ; it's actually bound
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
320 (help-xref-button 8 'help-variable sym)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
321 ((match-string 4) ; `function' &c
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
322 (and (fboundp sym) ; similarly
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
323 (help-xref-button 8 'help-function sym)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
324 ((match-string 5) ; `face'
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
325 (and (facep sym)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
326 (help-xref-button 8 'help-face sym)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
327 ((match-string 6)) ; nothing for `symbol'
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
328 ((match-string 7)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
329 ;; this used:
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
330 ;; #'(lambda (arg)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
331 ;; (let ((location
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
332 ;; (find-function-noselect arg)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
333 ;; (pop-to-buffer (car location))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
334 ;; (goto-char (cdr location))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
335 (help-xref-button 8 'help-function-def sym))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
336 ((and (boundp sym) (fboundp sym))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
337 ;; We can't intuit whether to use the
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
338 ;; variable or function doc -- supply both.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
339 (help-xref-button 8 'help-symbol sym))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
340 ((boundp sym)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
341 (help-xref-button 8 'help-variable sym))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
342 ((fboundp sym)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
343 (help-xref-button 8 'help-function sym))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
344 ((facep sym)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
345 (help-xref-button 8 'help-face sym)))))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
346 ;; An obvious case of a key substitution:
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
347 (save-excursion
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
348 (while (re-search-forward
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
349 ;; Assume command name is only word characters
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
350 ;; and dashes to get things like `use M-x foo.'.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
351 "\\<M-x\\s-+\\(\\sw\\(\\sw\\|-\\)+\\)" nil t)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
352 (let ((sym (intern-soft (match-string 1))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
353 (if (fboundp sym)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
354 (help-xref-button 1 'help-function sym)))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
355 ;; Look for commands in whole keymap substitutions:
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
356 (save-excursion
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
357 ;; Make sure to find the first keymap.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
358 (goto-char (point-min))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
359 ;; Find a header and the column at which the command
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
360 ;; name will be found.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
361 (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n"
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
362 nil t)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
363 (let ((col (- (match-end 1) (match-beginning 1))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
364 (while
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
365 ;; Ignore single blank lines in table, but not
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
366 ;; double ones, which should terminate it.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
367 (and (not (looking-at "\n\\s-*\n"))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
368 (progn
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
369 (and (eolp) (forward-line))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
370 (end-of-line)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
371 (skip-chars-backward "^\t\n")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
372 (if (and (>= (current-column) col)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
373 (looking-at "\\(\\sw\\|-\\)+$"))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
374 (let ((sym (intern-soft (match-string 0))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
375 (if (fboundp sym)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
376 (help-xref-button 0 'help-function sym))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
377 (zerop (forward-line)))))))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
378 (set-syntax-table stab))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
379 ;; Delete extraneous newlines at the end of the docstring
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
380 (goto-char (point-max))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
381 (while (and (not (bobp)) (bolp))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
382 (delete-char -1))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
383 ;; Make a back-reference in this buffer if appropriate.
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
384 (when help-xref-stack
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
385 (insert "\n\n")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
386 (help-insert-xref-button help-back-label 'help-back
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
387 (current-buffer))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
388 ;; View mode steals RET from us.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
389 (set (make-local-variable 'minor-mode-overriding-map-alist)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
390 (list (cons 'view-mode
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
391 (let ((map (make-sparse-keymap)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
392 (set-keymap-parent map view-mode-map)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
393 (define-key map "\r" 'help-follow)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
394 map))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
395 (set-buffer-modified-p old-modified))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
396
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
397 ;;;###autoload
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
398 (defun help-xref-button (match-number type &rest args)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
399 "Make a hyperlink for cross-reference text previously matched.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
400 MATCH-NUMBER is the subexpression of interest in the last matched
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
401 regexp. TYPE is the type of button to use. Any remaining arguments are
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
402 passed to the button's help-function when it is invoked.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
403 See `help-make-xrefs'."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
404 ;; Don't mung properties we've added specially in some instances.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
405 (unless (button-at (match-beginning match-number))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
406 (make-text-button (match-beginning match-number)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
407 (match-end match-number)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
408 'type type 'help-args args)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
409
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
410 ;;;###autoload
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
411 (defun help-insert-xref-button (string type &rest args)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
412 "Insert STRING and make a hyperlink from cross-reference text on it.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
413 TYPE is the type of button to use. Any remaining arguments are passed
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
414 to the button's help-function when it is invoked.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
415 See `help-make-xrefs'."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
416 (unless (button-at (point))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
417 (insert-text-button string 'type type 'help-args args)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
418
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
419 ;;;###autoload
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
420 (defun help-xref-on-pp (from to)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
421 "Add xrefs for symbols in `pp's output between FROM and TO."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
422 (let ((ost (syntax-table)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
423 (unwind-protect
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
424 (save-excursion
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
425 (save-restriction
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
426 (set-syntax-table emacs-lisp-mode-syntax-table)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
427 (narrow-to-region from to)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
428 (goto-char (point-min))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
429 (while (not (eobp))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
430 (cond
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
431 ((looking-at "\"") (forward-sexp 1))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
432 ((looking-at "#<") (search-forward ">" nil 'move))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
433 ((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
434 (let* ((sym (intern-soft (match-string 1)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
435 (type (cond ((fboundp sym) 'help-function)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
436 ((or (memq sym '(t nil))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
437 (keywordp sym))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
438 nil)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
439 ((and sym (boundp sym))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
440 'help-variable))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
441 (when type (help-xref-button 1 type sym)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
442 (goto-char (match-end 1)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
443 (t (forward-char 1))))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
444 (set-syntax-table ost))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
445
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
446
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
447 ;; Additional functions for (re-)creating types of help buffers.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
448 (defun help-xref-interned (symbol)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
449 "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL.
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
450 Both variable, function and face documentation are extracted into a single
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
451 help buffer."
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
452 (with-current-buffer (help-buffer)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
453 ;; Push the previous item on the stack before clobbering the output buffer.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
454 (help-setup-xref nil nil)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
455 (let ((facedoc (when (facep symbol)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
456 ;; Don't record the current entry in the stack.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
457 (setq help-xref-stack-item nil)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
458 (describe-face symbol)))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
459 (fdoc (when (fboundp symbol)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
460 ;; Don't record the current entry in the stack.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
461 (setq help-xref-stack-item nil)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
462 (describe-function symbol)))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
463 (sdoc (when (boundp symbol)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
464 ;; Don't record the current entry in the stack.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
465 (setq help-xref-stack-item nil)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
466 (describe-variable symbol))))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
467 (cond
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
468 (sdoc
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
469 ;; We now have a help buffer on the variable.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
470 ;; Insert the function and face text before it.
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
471 (when (or fdoc facedoc)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
472 (goto-char (point-min))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
473 (let ((inhibit-read-only t))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
474 (when fdoc
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
475 (insert fdoc "\n\n")
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
476 (when facedoc
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
477 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
478 " is also a " "face." "\n\n")))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
479 (when facedoc
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
480 (insert facedoc "\n\n"))
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
481 (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
482 " is also a " "variable." "\n\n"))
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
483 ;; Don't record the `describe-variable' item in the stack.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
484 (setq help-xref-stack-item nil)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
485 (help-setup-xref (list #'help-xref-interned symbol) nil)))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
486 (fdoc
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
487 ;; We now have a help buffer on the function.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
488 ;; Insert face text before it.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
489 (when facedoc
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
490 (goto-char (point-max))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
491 (let ((inhibit-read-only t))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
492 (insert "\n\n" (make-string 30 ?-) "\n\n" (symbol-name symbol)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
493 " is also a " "face." "\n\n" facedoc))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
494 ;; Don't record the `describe-function' item in the stack.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
495 (setq help-xref-stack-item nil)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
496 (help-setup-xref (list #'help-xref-interned symbol) nil)))))))
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
497
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
498
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
499 ;;; Navigation/hyperlinking with xrefs
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
500
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
501 (defun help-follow-mouse (click)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
502 "Follow the cross-reference that you CLICK on."
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
503 (interactive "e")
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
504 (let* ((start (event-start click))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
505 (window (car start))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
506 (pos (car (cdr start))))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
507 (with-current-buffer (window-buffer window)
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
508 (help-follow pos))))
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
509
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
510 (defun help-xref-go-back (buffer)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
511 "From BUFFER, go back to previous help buffer text using `help-xref-stack'."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
512 (let (item position method args)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
513 (with-current-buffer buffer
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
514 (when help-xref-stack
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
515 (setq item (pop help-xref-stack)
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
516 ;; Clear the current item so that it won't get pushed
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
517 ;; by the function we're about to call. TODO: We could also
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
518 ;; push it onto a "forward" stack and add a `forw' button.
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
519 help-xref-stack-item nil
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
520 position (car item)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
521 method (cadr item)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
522 args (cddr item))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
523 (apply method args)
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
524 ;; FIXME: are we sure we're in the right buffer ?
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
525 (goto-char position)))
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
526
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
527 (defun help-go-back ()
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
528 "Invoke the [back] button (if any) in the Help mode buffer."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
529 (interactive)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
530 (let ((back-button (button-at (1- (point-max)))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
531 (if back-button
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
532 (button-activate back-button)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
533 (error "No [back] button"))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
534
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
535 (defun help-do-xref (pos function args)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
536 "Call the help cross-reference function FUNCTION with args ARGS.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
537 Things are set up properly so that the resulting help-buffer has
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
538 a proper [back] button."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
539 ;; There is a reference at point. Follow it.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
540 (let ((help-xref-following t))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
541 (apply function args)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
542
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
543 (defun help-follow (&optional pos)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
544 "Follow cross-reference at POS, defaulting to point.
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
545
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
546 For the cross-reference format, see `help-make-xrefs'."
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
547 (interactive "d")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
548 (unless pos
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
549 (setq pos (point)))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
550 (unless (push-button pos)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
551 ;; check if the symbol under point is a function or variable
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
552 (let ((sym
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
553 (intern
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
554 (save-excursion
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
555 (goto-char pos) (skip-syntax-backward "w_")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
556 (buffer-substring (point)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
557 (progn (skip-syntax-forward "w_")
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
558 (point)))))))
39787
b44e34df3fa2 (help-buffer): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39727
diff changeset
559 (when (or (boundp sym) (fboundp sym) (facep sym))
39727
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
560 (help-do-xref pos #'help-xref-interned (list sym))))))
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
561
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
562
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
563 (provide 'help-mode)
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
564
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
565 ;;; help-mode.el ends here
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
566
3806fe844742 New file, contents mostly from `help.el'.
Miles Bader <miles@gnu.org>
parents:
diff changeset
567