660
|
1 ;;; help.el --- help commands for Emacs
|
|
2
|
21371
|
3 ;; Copyright (C) 1985, 1986, 1993, 1994, 1998 Free Software Foundation, Inc.
|
846
|
4
|
807
|
5 ;; Maintainer: FSF
|
811
|
6 ;; Keywords: help, internal
|
807
|
7
|
409
|
8 ;; This file is part of GNU Emacs.
|
|
9
|
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
807
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
409
|
13 ;; any later version.
|
|
14
|
|
15 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
14169
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
409
|
24
|
2315
|
25 ;;; Commentary:
|
|
26
|
16391
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
27 ;; This code implements GNU Emacs' on-line help system, the one invoked by
|
2315
|
28 ;;`M-x help-for-help'.
|
|
29
|
807
|
30 ;;; Code:
|
|
31
|
2312
|
32 ;; Get the macro make-help-screen when this is compiled,
|
|
33 ;; or run interpreted, but not when the compiled code is loaded.
|
2697
|
34 (eval-when-compile (require 'help-macro))
|
2237
|
35
|
409
|
36 (defvar help-map (make-sparse-keymap)
|
|
37 "Keymap for characters following the Help key.")
|
|
38
|
9833
|
39 (defvar help-mode-map (make-sparse-keymap)
|
|
40 "Keymap for help mode.")
|
|
41
|
919
|
42 (define-key global-map (char-to-string help-char) 'help-command)
|
12424
|
43 (define-key global-map [help] 'help-command)
|
|
44 (define-key global-map [f1] 'help-command)
|
409
|
45 (fset 'help-command help-map)
|
|
46
|
919
|
47 (define-key help-map (char-to-string help-char) 'help-for-help)
|
12424
|
48 (define-key help-map [help] 'help-for-help)
|
|
49 (define-key help-map [f1] 'help-for-help)
|
409
|
50 (define-key help-map "?" 'help-for-help)
|
|
51
|
|
52 (define-key help-map "\C-c" 'describe-copying)
|
|
53 (define-key help-map "\C-d" 'describe-distribution)
|
|
54 (define-key help-map "\C-w" 'describe-no-warranty)
|
5025
|
55 (define-key help-map "\C-p" 'describe-project)
|
17200
|
56 (define-key help-map "a" 'apropos-command)
|
409
|
57
|
|
58 (define-key help-map "b" 'describe-bindings)
|
|
59
|
|
60 (define-key help-map "c" 'describe-key-briefly)
|
|
61 (define-key help-map "k" 'describe-key)
|
|
62
|
|
63 (define-key help-map "d" 'describe-function)
|
|
64 (define-key help-map "f" 'describe-function)
|
|
65
|
10923
|
66 (define-key help-map "F" 'view-emacs-FAQ)
|
|
67
|
409
|
68 (define-key help-map "i" 'info)
|
22470
|
69 (define-key help-map "4i" 'info-other-window)
|
732
|
70 (define-key help-map "\C-f" 'Info-goto-emacs-command-node)
|
|
71 (define-key help-map "\C-k" 'Info-goto-emacs-key-command-node)
|
18293
|
72 (define-key help-map "\C-i" 'info-lookup-symbol)
|
409
|
73
|
|
74 (define-key help-map "l" 'view-lossage)
|
|
75
|
|
76 (define-key help-map "m" 'describe-mode)
|
|
77
|
|
78 (define-key help-map "\C-n" 'view-emacs-news)
|
|
79 (define-key help-map "n" 'view-emacs-news)
|
|
80
|
2134
b275e1b50542
Added autoload, binding and menu line for new finder feature (P).
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
81 (define-key help-map "p" 'finder-by-keyword)
|
7978
|
82 (autoload 'finder-by-keyword "finder"
|
|
83 "Find packages matching a given keyword." t)
|
2134
b275e1b50542
Added autoload, binding and menu line for new finder feature (P).
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
84
|
409
|
85 (define-key help-map "s" 'describe-syntax)
|
|
86
|
|
87 (define-key help-map "t" 'help-with-tutorial)
|
|
88
|
|
89 (define-key help-map "w" 'where-is)
|
|
90
|
|
91 (define-key help-map "v" 'describe-variable)
|
|
92
|
6580
|
93 (define-key help-map "q" 'help-quit)
|
|
94
|
21371
|
95 (define-key help-mode-map [mouse-2] 'help-follow-mouse)
|
|
96 (define-key help-mode-map "\C-c\C-b" 'help-go-back)
|
|
97 (define-key help-mode-map "\C-c\C-c" 'help-follow)
|
|
98 (define-key help-mode-map "\t" 'help-next-ref)
|
|
99 (define-key help-mode-map [backtab] 'help-previous-ref)
|
21708
|
100 (define-key help-mode-map [(shift tab)] 'help-previous-ref)
|
21371
|
101 ;; Documentation only, since we use minor-mode-overriding-map-alist.
|
|
102 (define-key help-mode-map "\r" 'help-follow)
|
|
103
|
|
104 ;; Font-locking is incompatible with the new xref stuff.
|
|
105 ;(defvar help-font-lock-keywords
|
|
106 ; (eval-when-compile
|
|
107 ; (let ((name-char "[-+a-zA-Z0-9_*]") (sym-char "[-+a-zA-Z0-9_:*]"))
|
|
108 ; (list
|
|
109 ; ;;
|
|
110 ; ;; The symbol itself.
|
|
111 ; (list (concat "\\`\\(" name-char "+\\)\\(\\(:\\)\\|\\('\\)\\)")
|
|
112 ; '(1 (if (match-beginning 3)
|
|
113 ; font-lock-function-name-face
|
|
114 ; font-lock-variable-name-face)))
|
|
115 ; ;;
|
|
116 ; ;; Words inside `' which tend to be symbol names.
|
|
117 ; (list (concat "`\\(" sym-char sym-char "+\\)'")
|
|
118 ; 1 'font-lock-constant-face t)
|
|
119 ; ;;
|
|
120 ; ;; CLisp `:' keywords as references.
|
|
121 ; (list (concat "\\<:" sym-char "+\\>") 0 'font-lock-builtin-face t))))
|
|
122 ; "Default expressions to highlight in Help mode.")
|
|
123
|
|
124 (defvar help-xref-stack nil
|
|
125 "A stack of ways by which to return to help buffers after following xrefs.
|
22325
|
126 Used by `help-follow' and `help-xref-go-back'.
|
|
127 An element looks like (POSITION FUNCTION ARGS...).
|
|
128 To use the element, do (apply FUNCTION ARGS) then (goto-char POSITION).")
|
21371
|
129 (put 'help-xref-stack 'permanent-local t)
|
|
130
|
|
131 (defvar help-xref-stack-item nil
|
22325
|
132 "An item for `help-follow' in this buffer to push onto `help-xref-stack'.
|
|
133 The format is (FUNCTION ARGS...).")
|
21371
|
134 (put 'help-xref-stack-item 'permanent-local t)
|
|
135
|
|
136 (setq-default help-xref-stack nil help-xref-stack-item nil)
|
12816
|
137
|
9833
|
138 (defun help-mode ()
|
21371
|
139 "Major mode for viewing help text and navigating references in it.
|
9833
|
140 Entry to this mode runs the normal hook `help-mode-hook'.
|
|
141 Commands:
|
|
142 \\{help-mode-map}"
|
|
143 (interactive)
|
|
144 (kill-all-local-variables)
|
|
145 (use-local-map help-mode-map)
|
|
146 (setq mode-name "Help")
|
|
147 (setq major-mode 'help-mode)
|
12816
|
148 (make-local-variable 'font-lock-defaults)
|
21371
|
149 (setq font-lock-defaults nil) ; font-lock would defeat xref
|
13079
|
150 (view-mode)
|
19228
|
151 (make-local-variable 'view-no-disable-on-exit)
|
|
152 (setq view-no-disable-on-exit t)
|
21371
|
153 ;; `help-make-xrefs' would be run here if not invoked from
|
|
154 ;; `help-mode-maybe'.
|
9833
|
155 (run-hooks 'help-mode-hook))
|
|
156
|
20060
|
157 (defun help-mode-maybe ()
|
|
158 (if (eq major-mode 'fundamental-mode)
|
21188
|
159 (help-mode))
|
21371
|
160 (when (eq major-mode 'help-mode)
|
|
161 ;; View mode's read-only status of existing *Help* buffer is lost
|
|
162 ;; by with-output-to-temp-buffer.
|
|
163 (toggle-read-only 1)
|
|
164 (help-make-xrefs (current-buffer)))
|
21188
|
165 (setq view-return-to-alist
|
|
166 (list (cons (selected-window) help-return-method))))
|
20060
|
167
|
|
168 (add-hook 'temp-buffer-show-hook 'help-mode-maybe)
|
|
169
|
6580
|
170 (defun help-quit ()
|
23333
|
171 "Just exit from the Help command's command loop."
|
6580
|
172 (interactive)
|
|
173 nil)
|
|
174
|
17005
|
175 (defun help-with-tutorial (&optional arg)
|
|
176 "Select the Emacs learn-by-doing tutorial.
|
19423
|
177 If there is a tutorial version written in the language
|
19576
|
178 of the selected language environment, that version is used.
|
19423
|
179 If there's no tutorial in that language, `TUTORIAL' is selected.
|
20286
|
180 With arg, you are asked to choose which language."
|
17005
|
181 (interactive "P")
|
21440
|
182 (let ((lang (if arg
|
|
183 (read-language-name 'tutorial "Language: " "English")
|
|
184 (if (get-language-info current-language-environment 'tutorial)
|
|
185 current-language-environment
|
21587
|
186 "English")))
|
|
187 file filename)
|
21440
|
188 (setq filename (get-language-info lang 'tutorial))
|
17756
|
189 (setq file (expand-file-name (concat "~/" filename)))
|
409
|
190 (delete-other-windows)
|
|
191 (if (get-file-buffer file)
|
|
192 (switch-to-buffer (get-file-buffer file))
|
|
193 (switch-to-buffer (create-file-buffer file))
|
|
194 (setq buffer-file-name file)
|
|
195 (setq default-directory (expand-file-name "~/"))
|
755
|
196 (setq buffer-auto-save-file-name nil)
|
17005
|
197 (insert-file-contents (expand-file-name filename data-directory))
|
409
|
198 (goto-char (point-min))
|
|
199 (search-forward "\n<<")
|
|
200 (beginning-of-line)
|
|
201 (delete-region (point) (progn (end-of-line) (point)))
|
6419
|
202 (let ((n (- (window-height (selected-window))
|
409
|
203 (count-lines (point-min) (point))
|
6419
|
204 6)))
|
6433
|
205 (if (< n 12)
|
6419
|
206 (newline n)
|
|
207 ;; Some people get confused by the large gap.
|
|
208 (newline (/ n 2))
|
|
209 (insert "[Middle of page left blank for didactic purposes. "
|
|
210 "Text continues below]")
|
|
211 (newline (- n (/ n 2)))))
|
409
|
212 (goto-char (point-min))
|
|
213 (set-buffer-modified-p nil))))
|
|
214
|
17917
|
215 (defun describe-key-briefly (key &optional insert)
|
|
216 "Print the name of the function KEY invokes. KEY is a string.
|
|
217 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
|
|
218 (interactive "kDescribe key briefly: \nP")
|
13293
|
219 (save-excursion
|
|
220 (let ((modifiers (event-modifiers (aref key 0)))
|
17917
|
221 (standard-output (if insert (current-buffer) t))
|
13293
|
222 window position)
|
|
223 ;; For a mouse button event, go to the button it applies to
|
|
224 ;; to get the right key bindings. And go to the right place
|
|
225 ;; in case the keymap depends on where you clicked.
|
|
226 (if (or (memq 'click modifiers) (memq 'down modifiers)
|
|
227 (memq 'drag modifiers))
|
|
228 (setq window (posn-window (event-start (aref key 0)))
|
|
229 position (posn-point (event-start (aref key 0)))))
|
|
230 (if (windowp window)
|
|
231 (progn
|
|
232 (set-buffer (window-buffer window))
|
|
233 (goto-char position)))
|
|
234 ;; Ok, now look up the key and name the command.
|
17917
|
235 (let ((defn (key-binding key))
|
|
236 (key-desc (key-description key)))
|
13293
|
237 (if (or (null defn) (integerp defn))
|
17917
|
238 (princ (format "%s is undefined" key-desc))
|
|
239 (princ (format (if insert
|
22060
|
240 "`%s' (`%s')"
|
17917
|
241 (if (windowp window)
|
|
242 "%s at that spot runs the command %s"
|
|
243 "%s runs the command %s"))
|
|
244 key-desc
|
|
245 (if (symbolp defn) defn (prin1-to-string defn)))))))))
|
409
|
246
|
21188
|
247 (defvar help-return-method nil
|
|
248 "What to do to \"exit\" the help buffer.
|
|
249 This is a list
|
|
250 (WINDOW . t) delete the selected window, go to WINDOW.
|
|
251 (WINDOW . quit-window) do quit-window, then select WINDOW.
|
|
252 (WINDOW BUF START POINT) display BUF at START, POINT, then select WINDOW.")
|
|
253
|
409
|
254 (defun print-help-return-message (&optional function)
|
|
255 "Display or return message saying how to restore windows after help command.
|
|
256 Computes a message and applies the optional argument FUNCTION to it.
|
|
257 If FUNCTION is nil, applies `message' to it, thus printing it."
|
|
258 (and (not (get-buffer-window standard-output))
|
8259
|
259 (let ((first-message
|
16391
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
260 (cond ((special-display-p (buffer-name standard-output))
|
21188
|
261 (setq help-return-method (cons (selected-window) t))
|
8259
|
262 ;; If the help output buffer is a special display buffer,
|
|
263 ;; don't say anything about how to get rid of it.
|
|
264 ;; First of all, the user will do that with the window
|
|
265 ;; manager, not with Emacs.
|
|
266 ;; Secondly, the buffer has not been displayed yet,
|
|
267 ;; so we don't know whether its frame will be selected.
|
|
268 nil)
|
|
269 ((not (one-window-p t))
|
21188
|
270 (setq help-return-method
|
|
271 (cons (selected-window) 'quit-window))
|
8259
|
272 "Type \\[switch-to-buffer-other-window] RET to restore the other window.")
|
|
273 (pop-up-windows
|
21188
|
274 (setq help-return-method (cons (selected-window) t))
|
8259
|
275 "Type \\[delete-other-windows] to remove help window.")
|
|
276 (t
|
21188
|
277 (setq help-return-method
|
|
278 (list (selected-window) (window-buffer)
|
|
279 (window-start) (window-point)))
|
8259
|
280 "Type \\[switch-to-buffer] RET to remove help window."))))
|
|
281 (funcall (or function 'message)
|
|
282 (concat
|
|
283 (if first-message
|
|
284 (substitute-command-keys first-message)
|
|
285 "")
|
|
286 (if first-message " " "")
|
11524
|
287 ;; If the help buffer will go in a separate frame,
|
|
288 ;; it's no use mentioning a command to scroll, so don't.
|
16391
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
289 (if (special-display-p (buffer-name standard-output))
|
11524
|
290 nil
|
16391
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
291 (if (same-window-p (buffer-name standard-output))
|
11524
|
292 ;; Say how to scroll this window.
|
|
293 (substitute-command-keys
|
|
294 "\\[scroll-up] to scroll the help.")
|
|
295 ;; Say how to scroll some other window.
|
11428
|
296 (substitute-command-keys
|
11524
|
297 "\\[scroll-other-window] to scroll the help."))))))))
|
409
|
298
|
|
299 (defun describe-key (key)
|
|
300 "Display documentation of the function invoked by KEY. KEY is a string."
|
|
301 (interactive "kDescribe key: ")
|
13293
|
302 (save-excursion
|
|
303 (let ((modifiers (event-modifiers (aref key 0)))
|
|
304 window position)
|
|
305 ;; For a mouse button event, go to the button it applies to
|
|
306 ;; to get the right key bindings. And go to the right place
|
|
307 ;; in case the keymap depends on where you clicked.
|
|
308 (if (or (memq 'click modifiers) (memq 'down modifiers)
|
|
309 (memq 'drag modifiers))
|
|
310 (setq window (posn-window (event-start (aref key 0)))
|
|
311 position (posn-point (event-start (aref key 0)))))
|
|
312 (if (windowp window)
|
|
313 (progn
|
|
314 (set-buffer (window-buffer window))
|
|
315 (goto-char position)))
|
|
316 (let ((defn (key-binding key)))
|
|
317 (if (or (null defn) (integerp defn))
|
|
318 (message "%s is undefined" (key-description key))
|
|
319 (with-output-to-temp-buffer "*Help*"
|
|
320 (princ (key-description key))
|
|
321 (if (windowp window)
|
|
322 (princ " at that spot"))
|
|
323 (princ " runs the command ")
|
|
324 (prin1 defn)
|
21491
|
325 (princ "\n which is ")
|
|
326 (describe-function-1 defn nil)
|
13293
|
327 (print-help-return-message)))))))
|
409
|
328
|
6902
|
329 (defun describe-mode ()
|
|
330 "Display documentation of current major mode and minor modes.
|
409
|
331 For this to work correctly for a minor mode, the mode's indicator variable
|
3980
|
332 \(listed in `minor-mode-alist') must also be a function whose documentation
|
409
|
333 describes the minor mode."
|
6903
|
334 (interactive)
|
409
|
335 (with-output-to-temp-buffer "*Help*"
|
6903
|
336 (let ((minor-modes minor-mode-alist)
|
16694
|
337 (first t))
|
6903
|
338 (while minor-modes
|
|
339 (let* ((minor-mode (car (car minor-modes)))
|
16694
|
340 (indicator (car (cdr (car minor-modes)))))
|
6903
|
341 ;; Document a minor mode if it is listed in minor-mode-alist,
|
|
342 ;; bound locally in this buffer, non-nil, and has a function
|
|
343 ;; definition.
|
16694
|
344 (if (and (symbol-value minor-mode)
|
6903
|
345 (fboundp minor-mode))
|
|
346 (let ((pretty-minor-mode minor-mode))
|
|
347 (if (string-match "-mode$" (symbol-name minor-mode))
|
|
348 (setq pretty-minor-mode
|
|
349 (capitalize
|
|
350 (substring (symbol-name minor-mode)
|
|
351 0 (match-beginning 0)))))
|
|
352 (while (and indicator (symbolp indicator))
|
|
353 (setq indicator (symbol-value indicator)))
|
15783
|
354 (if first
|
|
355 (princ "The minor modes are described first,
|
|
356 followed by the major mode, which is described on the last page.\n\f\n"))
|
|
357 (setq first nil)
|
14832
|
358 (princ (format "%s minor mode (%s):\n"
|
|
359 pretty-minor-mode
|
|
360 (if indicator
|
|
361 (format "indicator%s" indicator)
|
|
362 "no indicator")))
|
6903
|
363 (princ (documentation minor-mode))
|
15783
|
364 (princ "\n\f\n"))))
|
6903
|
365 (setq minor-modes (cdr minor-modes))))
|
409
|
366 (princ mode-name)
|
6902
|
367 (princ " mode:\n")
|
409
|
368 (princ (documentation major-mode))
|
22325
|
369 (help-setup-xref (list #'help-xref-mode (current-buffer)) (interactive-p))
|
409
|
370 (print-help-return-message)))
|
|
371
|
|
372 ;; So keyboard macro definitions are documented correctly
|
|
373 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
|
|
374
|
|
375 (defun describe-distribution ()
|
|
376 "Display info on how to obtain the latest version of GNU Emacs."
|
|
377 (interactive)
|
|
378 (find-file-read-only
|
444
|
379 (expand-file-name "DISTRIB" data-directory)))
|
409
|
380
|
|
381 (defun describe-copying ()
|
|
382 "Display info on how you may redistribute copies of GNU Emacs."
|
|
383 (interactive)
|
|
384 (find-file-read-only
|
444
|
385 (expand-file-name "COPYING" data-directory))
|
409
|
386 (goto-char (point-min)))
|
|
387
|
5025
|
388 (defun describe-project ()
|
|
389 "Display info on the GNU project."
|
|
390 (interactive)
|
|
391 (find-file-read-only
|
|
392 (expand-file-name "GNU" data-directory))
|
|
393 (goto-char (point-min)))
|
|
394
|
409
|
395 (defun describe-no-warranty ()
|
|
396 "Display info on all the kinds of warranty Emacs does NOT have."
|
|
397 (interactive)
|
|
398 (describe-copying)
|
|
399 (let (case-fold-search)
|
|
400 (search-forward "NO WARRANTY")
|
|
401 (recenter 0)))
|
|
402
|
3980
|
403 (defun describe-prefix-bindings ()
|
3982
|
404 "Describe the bindings of the prefix used to reach this command.
|
|
405 The prefix described consists of all but the last event
|
|
406 of the key sequence that ran this command."
|
3980
|
407 (interactive)
|
11890
|
408 (let* ((key (this-command-keys)))
|
|
409 (describe-bindings
|
|
410 (if (stringp key)
|
|
411 (substring key 0 (1- (length key)))
|
|
412 (let ((prefix (make-vector (1- (length key)) nil))
|
|
413 (i 0))
|
|
414 (while (< i (length prefix))
|
|
415 (aset prefix i (aref key i))
|
|
416 (setq i (1+ i)))
|
|
417 prefix)))))
|
3982
|
418 ;; Make C-h after a prefix, when not specifically bound,
|
|
419 ;; run describe-prefix-bindings.
|
3980
|
420 (setq prefix-help-command 'describe-prefix-bindings)
|
|
421
|
21210
|
422 (defun view-emacs-news (&optional arg)
|
|
423 "Display info on recent changes to Emacs.
|
|
424 With numeric argument display information on correspondingly older changes."
|
|
425 (interactive "P")
|
|
426 (let* ((arg (if arg (prefix-numeric-value arg) 0)))
|
|
427 (find-file-read-only
|
|
428 (expand-file-name (concat (make-string arg ?O) "NEWS")
|
|
429 data-directory))))
|
409
|
430
|
10923
|
431 (defun view-emacs-FAQ ()
|
|
432 "Display the Emacs Frequently Asked Questions (FAQ) file."
|
|
433 (interactive)
|
|
434 (find-file-read-only (expand-file-name "FAQ" data-directory)))
|
|
435
|
409
|
436 (defun view-lossage ()
|
|
437 "Display last 100 input keystrokes."
|
|
438 (interactive)
|
|
439 (with-output-to-temp-buffer "*Help*"
|
8504
|
440 (princ (mapconcat (function (lambda (key)
|
|
441 (if (or (integerp key)
|
|
442 (symbolp key)
|
|
443 (listp key))
|
|
444 (single-key-description key)
|
|
445 (prin1-to-string key nil))))
|
|
446 (recent-keys)
|
|
447 " "))
|
409
|
448 (save-excursion
|
|
449 (set-buffer standard-output)
|
|
450 (goto-char (point-min))
|
|
451 (while (progn (move-to-column 50) (not (eobp)))
|
|
452 (search-forward " " nil t)
|
21973
|
453 (insert "\n"))
|
|
454 (setq help-xref-stack nil
|
|
455 help-xref-stack-item nil))
|
409
|
456 (print-help-return-message)))
|
|
457
|
6580
|
458 (defalias 'help 'help-for-help)
|
2237
|
459 (make-help-screen help-for-help
|
18632
|
460 "a b c C f F C-f i I k C-k l L m n p s t v w C-c C-d C-n C-p C-w; ? for help:"
|
23332
|
461 "You have typed %THIS-KEY%, the help character. Type a Help option:
|
10479
|
462 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
|
409
|
463
|
4467
|
464 a command-apropos. Give a substring, and see a list of commands
|
|
465 (functions interactively callable) that contain
|
|
466 that substring. See also the apropos command.
|
2638
|
467 b describe-bindings. Display table of all key bindings.
|
|
468 c describe-key-briefly. Type a command key sequence;
|
4467
|
469 it prints the function name that sequence runs.
|
18632
|
470 C describe-coding-system. This describes either a specific coding system
|
|
471 (if you type its name) or the coding systems currently in use
|
|
472 (if you type just RET).
|
2638
|
473 f describe-function. Type a function name and get documentation of it.
|
4467
|
474 C-f Info-goto-emacs-command-node. Type a function name;
|
|
475 it takes you to the Info node for that command.
|
2638
|
476 i info. The info documentation reader.
|
18632
|
477 I describe-input-method. Describe a specific input method (if you type
|
|
478 its name) or the current input method (if you type just RET).
|
2638
|
479 k describe-key. Type a command key sequence;
|
4467
|
480 it displays the full documentation.
|
|
481 C-k Info-goto-emacs-key-command-node. Type a command key sequence;
|
|
482 it takes you to the Info node for the command bound to that key.
|
2638
|
483 l view-lossage. Shows last 100 characters you typed.
|
18632
|
484 L describe-language-environment. This describes either the a
|
|
485 specific language environment (if you type its name)
|
|
486 or the current language environment (if you type just RET).
|
20250
|
487 m describe-mode. Print documentation of current minor modes,
|
|
488 and the current major mode, including their special commands.
|
2638
|
489 n view-emacs-news. Shows emacs news file.
|
|
490 p finder-by-keyword. Find packages matching a given topic keyword.
|
|
491 s describe-syntax. Display contents of syntax table, plus explanations
|
|
492 t help-with-tutorial. Select the Emacs learn-by-doing tutorial.
|
|
493 v describe-variable. Type name of a variable;
|
4467
|
494 it displays the variable's documentation and value.
|
2638
|
495 w where-is. Type command name; it prints which keystrokes
|
4467
|
496 invoke that command.
|
18632
|
497
|
|
498 F Display the frequently asked questions file.
|
|
499 h Display the HELLO file which illustrates various scripts.
|
|
500 C-c Display Emacs copying permission (General Public License).
|
|
501 C-d Display Emacs ordering information.
|
|
502 C-n Display news of recent Emacs changes.
|
|
503 C-p Display information about the GNU project.
|
|
504 C-w Display information on absence of warranty for GNU Emacs."
|
2237
|
505 help-map)
|
409
|
506
|
|
507 ;; Return a function which is called by the list containing point.
|
|
508 ;; If that gives no function, return a function whose name is around point.
|
|
509 ;; If that doesn't give a function, return nil.
|
|
510 (defun function-called-at-point ()
|
20077
|
511 (let ((stab (syntax-table)))
|
|
512 (set-syntax-table emacs-lisp-mode-syntax-table)
|
|
513 (unwind-protect
|
|
514 (or (condition-case ()
|
13209
|
515 (save-excursion
|
20077
|
516 (save-restriction
|
|
517 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
|
|
518 ;; Move up to surrounding paren, then after the open.
|
|
519 (backward-up-list 1)
|
|
520 (forward-char 1)
|
|
521 ;; If there is space here, this is probably something
|
|
522 ;; other than a real Lisp function call, so ignore it.
|
|
523 (if (looking-at "[ \t]")
|
|
524 (error "Probably not a Lisp function call"))
|
|
525 (let (obj)
|
|
526 (setq obj (read (current-buffer)))
|
|
527 (and (symbolp obj) (fboundp obj) obj))))
|
|
528 (error nil))
|
|
529 (condition-case ()
|
|
530 (save-excursion
|
13209
|
531 (or (not (zerop (skip-syntax-backward "_w")))
|
|
532 (eq (char-syntax (following-char)) ?w)
|
|
533 (eq (char-syntax (following-char)) ?_)
|
|
534 (forward-sexp -1))
|
|
535 (skip-chars-forward "'")
|
|
536 (let ((obj (read (current-buffer))))
|
|
537 (and (symbolp obj) (fboundp obj) obj)))
|
20077
|
538 (error nil)))
|
|
539 (set-syntax-table stab))))
|
409
|
540
|
9639
|
541 (defun describe-function-find-file (function)
|
|
542 (let ((files load-history)
|
|
543 file functions)
|
|
544 (while files
|
|
545 (if (memq function (cdr (car files)))
|
|
546 (setq file (car (car files)) files nil))
|
|
547 (setq files (cdr files)))
|
|
548 file))
|
|
549
|
409
|
550 (defun describe-function (function)
|
|
551 "Display the full documentation of FUNCTION (a symbol)."
|
|
552 (interactive
|
|
553 (let ((fn (function-called-at-point))
|
|
554 (enable-recursive-minibuffers t)
|
|
555 val)
|
|
556 (setq val (completing-read (if fn
|
|
557 (format "Describe function (default %s): " fn)
|
|
558 "Describe function: ")
|
20069
|
559 obarray 'fboundp t nil nil (symbol-name fn)))
|
409
|
560 (list (if (equal val "")
|
|
561 fn (intern val)))))
|
16439
|
562 (if function
|
|
563 (with-output-to-temp-buffer "*Help*"
|
|
564 (prin1 function)
|
19124
|
565 ;; Use " is " instead of a colon so that
|
|
566 ;; it is easier to get out the function name using forward-sexp.
|
|
567 (princ " is ")
|
21491
|
568 (describe-function-1 function nil)
|
16439
|
569 (print-help-return-message)
|
|
570 (save-excursion
|
|
571 (set-buffer standard-output)
|
|
572 ;; Return the text we displayed.
|
|
573 (buffer-string)))
|
|
574 (message "You didn't specify a function")))
|
409
|
575
|
21491
|
576 (defun describe-function-1 (function parens)
|
|
577 (let* ((def (symbol-function function))
|
|
578 file-name string need-close
|
|
579 (beg (if (commandp def) "an interactive " "a ")))
|
|
580 (setq string
|
|
581 (cond ((or (stringp def)
|
|
582 (vectorp def))
|
|
583 "a keyboard macro")
|
|
584 ((subrp def)
|
|
585 (concat beg "built-in function"))
|
|
586 ((byte-code-function-p def)
|
|
587 (concat beg "compiled Lisp function"))
|
|
588 ((symbolp def)
|
22973
|
589 (while (symbolp (symbol-function def))
|
|
590 (setq def (symbol-function def)))
|
21491
|
591 (format "alias for `%s'" def))
|
|
592 ((eq (car-safe def) 'lambda)
|
|
593 (concat beg "Lisp function"))
|
|
594 ((eq (car-safe def) 'macro)
|
|
595 "a Lisp macro")
|
|
596 ((eq (car-safe def) 'mocklisp)
|
|
597 "a mocklisp function")
|
|
598 ((eq (car-safe def) 'autoload)
|
|
599 (setq file-name (nth 1 def))
|
|
600 (format "%s autoloaded Lisp %s"
|
|
601 (if (commandp def) "an interactive" "an")
|
|
602 (if (nth 4 def) "macro" "function")
|
|
603 ))
|
|
604 (t "")))
|
|
605 (when (and parens (not (equal string "")))
|
|
606 (setq need-close t)
|
|
607 (princ "("))
|
|
608 (princ string)
|
|
609 (or file-name
|
|
610 (setq file-name (describe-function-find-file function)))
|
|
611 (if file-name
|
|
612 (progn
|
|
613 (princ " in `")
|
|
614 ;; We used to add .el to the file name,
|
|
615 ;; but that's completely wrong when the user used load-file.
|
|
616 (princ file-name)
|
21695
|
617 (princ "'")
|
|
618 ;; Make a hyperlink to the library.
|
|
619 (with-current-buffer "*Help*"
|
|
620 (save-excursion
|
|
621 (re-search-backward "`\\([^`']+\\)'" nil t)
|
21972
9c71660c0a8d
(describe-function-1): Use find-function-noselect instead of find-function.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
622 (help-xref-button 1 #'(lambda (arg)
|
9c71660c0a8d
(describe-function-1): Use find-function-noselect instead of find-function.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
623 (let ((location
|
9c71660c0a8d
(describe-function-1): Use find-function-noselect instead of find-function.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
624 (find-function-noselect arg)))
|
22850
e7684a1dd417
(describe-function-1): Fix the code that uses find-function-noselect.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
625 (pop-to-buffer (car location))
|
e7684a1dd417
(describe-function-1): Fix the code that uses find-function-noselect.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
626 (goto-char (cdr location))))
|
21972
9c71660c0a8d
(describe-function-1): Use find-function-noselect instead of find-function.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
627 function)))))
|
21491
|
628 (if need-close (princ ")"))
|
|
629 (princ ".")
|
|
630 (terpri)
|
22973
|
631 ;; Handle symbols aliased to other symbols.
|
|
632 (setq def (indirect-function def))
|
|
633 ;; If definition is a macro, find the function inside it.
|
|
634 (if (eq (car-safe def) 'macro)
|
|
635 (setq def (cdr def)))
|
|
636 (let ((arglist (cond ((byte-code-function-p def)
|
|
637 (car (append def nil)))
|
|
638 ((eq (car-safe def) 'lambda)
|
|
639 (nth 1 def))
|
|
640 (t t))))
|
21491
|
641 (if (listp arglist)
|
|
642 (progn
|
|
643 (princ (cons function
|
|
644 (mapcar (lambda (arg)
|
|
645 (if (memq arg '(&optional &rest))
|
|
646 arg
|
|
647 (intern (upcase (symbol-name arg)))))
|
|
648 arglist)))
|
|
649 (terpri))))
|
|
650 (let ((doc (documentation function)))
|
|
651 (if doc
|
|
652 (progn (terpri)
|
|
653 (princ doc)
|
22325
|
654 (help-setup-xref (list #'describe-function function) (interactive-p)))
|
21491
|
655 (princ "not documented")))))
|
|
656
|
16439
|
657 ;; We return 0 if we can't find a variable to return.
|
409
|
658 (defun variable-at-point ()
|
|
659 (condition-case ()
|
13209
|
660 (let ((stab (syntax-table)))
|
|
661 (unwind-protect
|
|
662 (save-excursion
|
|
663 (set-syntax-table emacs-lisp-mode-syntax-table)
|
|
664 (or (not (zerop (skip-syntax-backward "_w")))
|
|
665 (eq (char-syntax (following-char)) ?w)
|
|
666 (eq (char-syntax (following-char)) ?_)
|
|
667 (forward-sexp -1))
|
|
668 (skip-chars-forward "'")
|
|
669 (let ((obj (read (current-buffer))))
|
16439
|
670 (or (and (symbolp obj) (boundp obj) obj)
|
|
671 0)))
|
13209
|
672 (set-syntax-table stab)))
|
16439
|
673 (error 0)))
|
409
|
674
|
|
675 (defun describe-variable (variable)
|
|
676 "Display the full documentation of VARIABLE (a symbol).
|
|
677 Returns the documentation as a string, also."
|
|
678 (interactive
|
|
679 (let ((v (variable-at-point))
|
|
680 (enable-recursive-minibuffers t)
|
|
681 val)
|
16439
|
682 (setq val (completing-read (if (symbolp v)
|
409
|
683 (format "Describe variable (default %s): " v)
|
|
684 "Describe variable: ")
|
20290
|
685 obarray 'boundp t nil nil
|
|
686 (if (symbolp v) (symbol-name v))))
|
409
|
687 (list (if (equal val "")
|
|
688 v (intern val)))))
|
16439
|
689 (if (symbolp variable)
|
16557
|
690 (let (valvoid)
|
|
691 (with-output-to-temp-buffer "*Help*"
|
|
692 (prin1 variable)
|
|
693 (if (not (boundp variable))
|
|
694 (progn
|
|
695 (princ " is void")
|
|
696 (terpri)
|
|
697 (setq valvoid t))
|
|
698 (princ "'s value is ")
|
|
699 (terpri)
|
|
700 (pp (symbol-value variable))
|
|
701 (terpri))
|
|
702 (if (local-variable-p variable)
|
|
703 (progn
|
|
704 (princ (format "Local in buffer %s; " (buffer-name)))
|
|
705 (if (not (default-boundp variable))
|
|
706 (princ "globally void")
|
|
707 (princ "global value is ")
|
|
708 (terpri)
|
|
709 (pp (default-value variable)))
|
|
710 (terpri)))
|
|
711 (terpri)
|
|
712 (save-current-buffer
|
|
713 (set-buffer standard-output)
|
|
714 (if (> (count-lines (point-min) (point-max)) 10)
|
|
715 (progn
|
|
716 (goto-char (point-min))
|
|
717 (if valvoid
|
|
718 (forward-line 1)
|
|
719 (forward-sexp 1)
|
|
720 (delete-region (point) (progn (end-of-line) (point)))
|
|
721 (insert "'s value is shown below.\n\n")
|
|
722 (save-excursion
|
|
723 (insert "\n\nValue:"))))))
|
|
724 (princ "Documentation:")
|
|
725 (terpri)
|
|
726 (let ((doc (documentation-property variable 'variable-documentation)))
|
|
727 (princ (or doc "not documented as a variable.")))
|
22325
|
728 (help-setup-xref (list #'describe-variable variable) (interactive-p))
|
22234
|
729
|
|
730 ;; Make a link to customize if this variable can be customized.
|
22407
|
731 ;; Note, it is not reliable to test for a custom-type property
|
|
732 ;; because those are only present after the var's definition
|
|
733 ;; has been loaded.
|
|
734 (if (user-variable-p variable)
|
22234
|
735 (let ((customize-label "customize"))
|
|
736 (terpri)
|
|
737 (terpri)
|
|
738 (princ (concat "You can " customize-label " this variable."))
|
|
739 (with-current-buffer "*Help*"
|
|
740 (save-excursion
|
|
741 (re-search-backward
|
|
742 (concat "\\(" customize-label "\\)") nil t)
|
|
743 (help-xref-button 1 #'(lambda (v)
|
|
744 (customize-variable v)) variable)
|
|
745 ))))
|
23591
|
746 ;; Make a hyperlink to the library if appropriate. (Don't
|
|
747 ;; change the format of the buffer's initial line in case
|
|
748 ;; anything expects the current format.)
|
|
749 (let ((file-name (describe-function-find-file variable)))
|
|
750 (when file-name
|
|
751 (princ "\n\nDefined in `")
|
|
752 (princ file-name)
|
|
753 (princ "'.")
|
|
754 (with-current-buffer "*Help*"
|
|
755 (save-excursion
|
|
756 (re-search-backward "`\\([^`']+\\)'" nil t)
|
|
757 (help-xref-button 1 (lambda (arg)
|
|
758 (let ((location
|
|
759 (find-variable-noselect arg)))
|
|
760 (pop-to-buffer (car location))
|
|
761 (goto-char (cdr location))))
|
|
762 variable)))))
|
22234
|
763
|
16557
|
764 (print-help-return-message)
|
|
765 (save-excursion
|
|
766 (set-buffer standard-output)
|
|
767 ;; Return the text we displayed.
|
|
768 (buffer-string))))
|
16439
|
769 (message "You did not specify a variable")))
|
409
|
770
|
22325
|
771 (defun describe-bindings (&optional prefix buffer)
|
20848
|
772 "Show a list of all defined keys, and their definitions.
|
|
773 We put that list in a buffer, and display the buffer.
|
|
774
|
|
775 The optional argument PREFIX, if non-nil, should be a key sequence;
|
22325
|
776 then we display only bindings that start with that prefix.
|
|
777 The optional argument BUFFER specifies which buffer's bindings
|
|
778 to display (default, the current buffer)."
|
20882
|
779 (interactive "P")
|
22325
|
780 (or buffer (setq buffer (current-buffer)))
|
|
781 (with-current-buffer buffer
|
|
782 (describe-bindings-internal nil prefix))
|
21973
|
783 (with-current-buffer "*Help*"
|
22325
|
784 (help-setup-xref (list #'describe-bindings prefix buffer)
|
|
785 (interactive-p))))
|
20848
|
786
|
17917
|
787 (defun where-is (definition &optional insert)
|
6476
|
788 "Print message listing key sequences that invoke specified command.
|
17917
|
789 Argument is a command definition, usually a symbol with a function definition.
|
|
790 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
|
6476
|
791 (interactive
|
|
792 (let ((fn (function-called-at-point))
|
|
793 (enable-recursive-minibuffers t)
|
|
794 val)
|
|
795 (setq val (completing-read (if fn
|
|
796 (format "Where is command (default %s): " fn)
|
|
797 "Where is command: ")
|
|
798 obarray 'fboundp t))
|
|
799 (list (if (equal val "")
|
17917
|
800 fn (intern val))
|
|
801 current-prefix-arg)))
|
6476
|
802 (let* ((keys (where-is-internal definition overriding-local-map nil nil))
|
17917
|
803 (keys1 (mapconcat 'key-description keys ", "))
|
|
804 (standard-output (if insert (current-buffer) t)))
|
|
805 (if insert
|
|
806 (if (> (length keys1) 0)
|
|
807 (princ (format "%s (%s)" keys1 definition))
|
|
808 (princ (format "M-x %s RET" definition)))
|
|
809 (if (> (length keys1) 0)
|
|
810 (princ (format "%s is on %s" definition keys1))
|
|
811 (princ (format "%s is not on any key" definition)))))
|
6476
|
812 nil)
|
|
813
|
16273
|
814 (defun locate-library (library &optional nosuffix path interactive-call)
|
16063
|
815 "Show the precise file name of Emacs library LIBRARY.
|
409
|
816 This command searches the directories in `load-path' like `M-x load-library'
|
|
817 to find the file that `M-x load-library RET LIBRARY RET' would load.
|
|
818 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
|
16064
|
819 to the specified name LIBRARY.
|
|
820
|
|
821 If the optional third arg PATH is specified, that list of directories
|
|
822 is used instead of `load-path'."
|
16273
|
823 (interactive (list (read-string "Locate library: ")
|
|
824 nil nil
|
|
825 t))
|
20176
|
826 (let (result)
|
16273
|
827 (catch 'answer
|
|
828 (mapcar
|
16391
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
829 (lambda (dir)
|
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
830 (mapcar
|
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
831 (lambda (suf)
|
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
832 (let ((try (expand-file-name (concat library suf) dir)))
|
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
833 (and (file-readable-p try)
|
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
834 (null (file-directory-p try))
|
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
835 (progn
|
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
836 (setq result try)
|
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
837 (throw 'answer try)))))
|
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
838 (if nosuffix
|
5d64d742ccbb
(print-help-return-message): Use new functions `special-display-p' and
Erik Naggum <erik@naggum.no>
diff
changeset
|
839 '("")
|
20176
|
840 '(".elc" ".el" "")
|
|
841 ;;; load doesn't handle this yet.
|
|
842 ;;; (let ((basic '(".elc" ".el" ""))
|
|
843 ;;; (compressed '(".Z" ".gz" "")))
|
|
844 ;;; ;; If autocompression mode is on,
|
|
845 ;;; ;; consider all combinations of library suffixes
|
|
846 ;;; ;; and compression suffixes.
|
|
847 ;;; (if (rassq 'jka-compr-handler file-name-handler-alist)
|
|
848 ;;; (apply 'nconc
|
|
849 ;;; (mapcar (lambda (compelt)
|
|
850 ;;; (mapcar (lambda (baselt)
|
|
851 ;;; (concat baselt compelt))
|
|
852 ;;; basic))
|
|
853 ;;; compressed))
|
|
854 ;;; basic))
|
|
855 )))
|
16273
|
856 (or path load-path)))
|
|
857 (and interactive-call
|
|
858 (if result
|
|
859 (message "Library is file %s" result)
|
|
860 (message "No library %s in search path" library)))
|
|
861 result))
|
660
|
862
|
21371
|
863
|
|
864 ;;; Grokking cross-reference information in doc strings and
|
|
865 ;;; hyperlinking it.
|
|
866
|
|
867 ;; This may have some scope for extension and the same or something
|
|
868 ;; similar should be done for widget doc strings, which currently use
|
|
869 ;; another mechanism.
|
|
870
|
|
871 (defcustom help-highlight-p t
|
|
872 "*If non-nil, `help-make-xrefs' highlight cross-references.
|
|
873 Under a window system it highlights them with face defined by
|
|
874 `help-highlight-face'. On a character terminal highlighted
|
|
875 references look like cross-references in info mode."
|
|
876 :group 'help
|
|
877 :version "20.3"
|
|
878 :type 'boolean)
|
|
879
|
|
880 (defcustom help-highlight-face 'underline
|
|
881 "Face used by `help-make-xrefs' to highlight cross-references.
|
|
882 Must be previously-defined."
|
|
883 :group 'help
|
|
884 :version "20.3"
|
21698
|
885 :type 'face)
|
21371
|
886
|
|
887 (defvar help-back-label "[back]"
|
|
888 "Label to use by `help-make-xrefs' for the go-back reference.")
|
|
889
|
|
890 (defvar help-xref-symbol-regexp
|
|
891 (concat "\\(\\<\\(\\(variable\\|option\\)\\|"
|
|
892 "\\(function\\|command\\)\\|"
|
|
893 "\\(symbol\\)\\)\\s-+\\)?"
|
|
894 ;; Note starting with word-syntax character:
|
|
895 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'")
|
|
896 "Regexp matching doc string references to symbols.
|
|
897
|
|
898 The words preceding the quoted symbol can be used in doc strings to
|
|
899 distinguish references to variables, functions and symbols.")
|
|
900
|
|
901 (defvar help-xref-info-regexp
|
|
902 "\\<info\\s-+node\\s-`\\([^']+\\)'"
|
|
903 "Regexp matching doc string references to an Info node.")
|
|
904
|
|
905 (defun help-setup-xref (item interactive-p)
|
|
906 "Invoked from commands using the \"*Help*\" buffer to install some xref info.
|
|
907
|
22325
|
908 ITEM is a (FUNCTION . ARGS) pair appropriate for recreating the help
|
21371
|
909 buffer after following a reference. INTERACTIVE-P is non-nil if the
|
|
910 calling command was invoked interactively. In this case the stack of
|
|
911 items for help buffer \"back\" buttons is cleared."
|
|
912 (if interactive-p
|
|
913 (setq help-xref-stack nil))
|
|
914 (setq help-xref-stack-item item))
|
|
915
|
|
916 (defun help-make-xrefs (&optional buffer)
|
|
917 "Parse and hyperlink documentation cross-references in the given BUFFER.
|
|
918
|
|
919 Find cross-reference information in a buffer and, if
|
|
920 `help-highlight-p' is non-nil, highlight it with face defined by
|
|
921 `help-highlight-face'; activate such cross references for selection
|
|
922 with `help-follow'. Cross-references have the canonical form `...'
|
|
923 and the type of reference may be disambiguated by the preceding
|
|
924 word(s) used in `help-xref-symbol-regexp'.
|
|
925
|
|
926 A special reference `back' is made to return back through a stack of
|
|
927 help buffers. Variable `help-back-label' specifies the text for
|
|
928 that."
|
|
929 (interactive "b")
|
|
930 (save-excursion
|
|
931 (set-buffer (or buffer (current-buffer)))
|
|
932 (goto-char (point-min))
|
|
933 ;; Skip the header-type info, though it might be useful to parse
|
|
934 ;; it at some stage (e.g. "function in `library'").
|
|
935 (forward-paragraph)
|
|
936 (let ((old-modified (buffer-modified-p)))
|
|
937 (let ((stab (syntax-table))
|
|
938 (case-fold-search t)
|
|
939 (inhibit-read-only t))
|
|
940 (set-syntax-table emacs-lisp-mode-syntax-table)
|
|
941 ;; The following should probably be abstracted out.
|
|
942 (unwind-protect
|
|
943 (progn
|
|
944 ;; Quoted symbols
|
|
945 (save-excursion
|
|
946 (while (re-search-forward help-xref-symbol-regexp nil t)
|
|
947 (let* ((data (match-string 6))
|
|
948 (sym (intern-soft data)))
|
|
949 (if sym
|
|
950 (cond
|
|
951 ((match-string 3) ; `variable' &c
|
|
952 (and (boundp sym) ; `variable' doesn't ensure
|
|
953 ; it's actually bound
|
|
954 (help-xref-button 6 #'describe-variable sym)))
|
|
955 ((match-string 4) ; `function' &c
|
|
956 (and (fboundp sym) ; similarly
|
|
957 (help-xref-button 6 #'describe-function sym)))
|
|
958 ((match-string 5)) ; nothing for symbol
|
|
959 ((and (boundp sym) (fboundp sym))
|
|
960 ;; We can't intuit whether to use the
|
|
961 ;; variable or function doc -- supply both.
|
|
962 (help-xref-button 6 #'help-xref-interned sym))
|
|
963 ((boundp sym)
|
|
964 (help-xref-button 6 #'describe-variable sym))
|
|
965 ((fboundp sym)
|
|
966 (help-xref-button 6 #'describe-function sym)))))))
|
|
967 ;; Info references
|
|
968 (save-excursion
|
|
969 (while (re-search-forward help-xref-info-regexp nil t)
|
23291
|
970 (help-xref-button 1 #'Info-goto-node (match-string 1))))
|
21371
|
971 ;; An obvious case of a key substitution:
|
|
972 (save-excursion
|
|
973 (while (re-search-forward
|
|
974 "\\<M-x\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)" nil t)
|
|
975 (let ((sym (intern-soft (match-string 1))))
|
|
976 (if (fboundp sym)
|
21385
|
977 (help-xref-button 1 #'describe-function sym)))))
|
|
978 ;; Look for commands in whole keymap substitutions:
|
|
979 (save-excursion
|
22417
|
980 ;; Make sure to find the first keymap.
|
|
981 (goto-char (point-min))
|
21385
|
982 ;; Find a header and the column at which the command
|
|
983 ;; name will be found.
|
|
984 (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n"
|
|
985 nil t)
|
|
986 (let ((col (- (match-end 1) (match-beginning 1))))
|
|
987 (while
|
|
988 ;; Ignore single blank lines in table, but not
|
|
989 ;; double ones, which should terminate it.
|
|
990 (and (looking-at "^\n?[^\n]")
|
|
991 (progn
|
|
992 (if (and (> (move-to-column col) 0)
|
|
993 (looking-at "\\(\\sw\\|\\s_\\)+$"))
|
|
994 ;;
|
|
995 (let ((sym (intern-soft (match-string 0))))
|
|
996 (if (fboundp sym)
|
|
997 (help-xref-button
|
|
998 0 #'describe-function sym))))
|
|
999 t)
|
|
1000 (zerop (forward-line))
|
|
1001 (move-to-column 0)))))))
|
21371
|
1002 (set-syntax-table stab))
|
|
1003 ;; Make a back-reference in this buffer if appropriate.
|
|
1004 (when help-xref-stack
|
|
1005 (goto-char (point-max))
|
|
1006 (save-excursion
|
|
1007 (insert "\n\n" help-back-label))
|
|
1008 ;; Just to provide the match data:
|
|
1009 (looking-at (concat "\n\n\\(" (regexp-quote help-back-label) "\\)"))
|
21973
|
1010 (help-xref-button 1 #'help-xref-go-back (current-buffer))))
|
21371
|
1011 ;; View mode steals RET from us.
|
|
1012 (set (make-local-variable 'minor-mode-overriding-map-alist)
|
|
1013 (list (cons 'view-mode
|
|
1014 (let ((map (make-sparse-keymap)))
|
21385
|
1015 (set-keymap-parent map view-mode-map)
|
21371
|
1016 (define-key map "\r" 'help-follow)
|
|
1017 map))))
|
|
1018 (set-buffer-modified-p old-modified))))
|
|
1019
|
|
1020 (defun help-xref-button (match-number function data)
|
|
1021 "Make a hyperlink for cross-reference text previously matched.
|
|
1022
|
|
1023 MATCH-NUMBER is the subexpression of interest in the last matched
|
|
1024 regexp. FUNCTION is a function to invoke when the button is
|
|
1025 activated, applied to DATA. DATA may be a single value or a list.
|
|
1026 See `help-make-xrefs'."
|
21385
|
1027 (add-text-properties (match-beginning match-number)
|
21371
|
1028 (match-end match-number)
|
21385
|
1029 (list 'mouse-face 'highlight
|
21371
|
1030 'help-xref (cons function
|
|
1031 (if (listp data)
|
|
1032 data
|
|
1033 (list data)))))
|
21385
|
1034 (if help-highlight-p
|
|
1035 (put-text-property (match-beginning match-number)
|
|
1036 (match-end match-number)
|
|
1037 'face help-highlight-face)))
|
21371
|
1038
|
|
1039
|
|
1040 ;; Additional functions for (re-)creating types of help buffers.
|
|
1041 (defun help-xref-interned (symbol)
|
|
1042 "Follow a hyperlink which appeared to be an arbitrary interned SYMBOL.
|
|
1043
|
|
1044 Both variable and function documentation are extracted into a single
|
|
1045 help buffer."
|
|
1046 (let ((fdoc (describe-function symbol)))
|
|
1047 (describe-variable symbol)
|
|
1048 ;; We now have a help buffer on the variable. Insert the function
|
|
1049 ;; text after it.
|
|
1050 (goto-char (point-max))
|
23216
|
1051 (let ((inhibit-read-only t))
|
|
1052 (insert "\n\n" fdoc)))
|
21371
|
1053 (goto-char (point-min))
|
22325
|
1054 (help-setup-xref (list #'help-xref-interned symbol) nil))
|
21371
|
1055
|
|
1056 (defun help-xref-mode (buffer)
|
|
1057 "Do a `describe-mode' for the specified BUFFER."
|
|
1058 (save-excursion
|
|
1059 (set-buffer buffer)
|
|
1060 (describe-mode)))
|
|
1061
|
|
1062 ;;; Navigation/hyperlinking with xrefs
|
|
1063
|
|
1064 (defun help-follow-mouse (click)
|
|
1065 "Follow the cross-reference that you click on."
|
|
1066 (interactive "e")
|
22417
|
1067 (let* ((start (event-start click))
|
|
1068 (window (car start))
|
|
1069 (pos (car (cdr start))))
|
|
1070 (with-current-buffer (window-buffer window)
|
21371
|
1071 (help-follow pos))))
|
|
1072
|
21973
|
1073 (defun help-xref-go-back (buffer)
|
|
1074 "Go back to the previous help buffer text using info on `help-xref-stack'."
|
21371
|
1075 (interactive)
|
22325
|
1076 (let (item position method args)
|
21973
|
1077 (with-current-buffer buffer
|
|
1078 (when help-xref-stack
|
|
1079 (setq help-xref-stack (cdr help-xref-stack)) ; due to help-follow
|
|
1080 (setq item (car help-xref-stack)
|
22325
|
1081 position (car item)
|
|
1082 method (cadr item)
|
|
1083 args (cddr item))
|
21973
|
1084 (setq help-xref-stack (cdr help-xref-stack))))
|
22325
|
1085 (apply method args)
|
|
1086 (goto-char position)))
|
21371
|
1087
|
|
1088 (defun help-go-back ()
|
|
1089 (interactive)
|
|
1090 (help-follow (1- (point-max))))
|
|
1091
|
|
1092 (defun help-follow (&optional pos)
|
|
1093 "Follow cross-reference at POS, defaulting to point.
|
|
1094
|
|
1095 For the cross-reference format, see `help-make-xrefs'."
|
|
1096 (interactive "d")
|
22325
|
1097 (let* ((help-data (or (and (not (= pos (point-max)))
|
|
1098 (get-text-property pos 'help-xref))
|
|
1099 (and (not (= pos (point-min)))
|
|
1100 (get-text-property (1- pos) 'help-xref))))
|
21371
|
1101 (method (car help-data))
|
|
1102 (args (cdr help-data)))
|
22325
|
1103 (setq help-xref-stack (cons (cons (point) help-xref-stack-item)
|
|
1104 help-xref-stack))
|
21371
|
1105 (setq help-xref-stack-item nil)
|
|
1106 (when help-data
|
|
1107 ;; There is a reference at point. Follow it.
|
|
1108 (apply method args))))
|
|
1109
|
|
1110 ;; For tabbing through buffer.
|
|
1111 (defun help-next-ref ()
|
|
1112 "Find the next help cross-reference in the buffer."
|
|
1113 (interactive)
|
|
1114 (let (pos)
|
|
1115 (while (not pos)
|
|
1116 (if (get-text-property (point) 'help-xref) ; move off reference
|
21385
|
1117 (goto-char (or (next-single-property-change (point) 'help-xref)
|
|
1118 (point))))
|
21371
|
1119 (cond ((setq pos (next-single-property-change (point) 'help-xref))
|
|
1120 (if pos (goto-char pos)))
|
|
1121 ((bobp)
|
|
1122 (message "No cross references in the buffer.")
|
|
1123 (setq pos t))
|
|
1124 (t ; be circular
|
|
1125 (goto-char (point-min)))))))
|
|
1126
|
|
1127 (defun help-previous-ref ()
|
|
1128 "Find the previous help cross-reference in the buffer."
|
|
1129 (interactive)
|
|
1130 (let (pos)
|
|
1131 (while (not pos)
|
|
1132 (if (get-text-property (point) 'help-xref) ; move off reference
|
|
1133 (goto-char (or (previous-single-property-change (point) 'help-xref)
|
|
1134 (point))))
|
|
1135 (cond ((setq pos (previous-single-property-change (point) 'help-xref))
|
|
1136 (if pos (goto-char pos)))
|
|
1137 ((bobp)
|
|
1138 (message "No cross references in the buffer.")
|
|
1139 (setq pos t))
|
|
1140 (t ; be circular
|
|
1141 (goto-char (point-max)))))))
|
|
1142
|
660
|
1143 ;;; help.el ends here
|