Commit | Line | Data |
---|---|---|
1a06eabd ER |
1 | ;;; help.el --- help commands for Emacs |
2 | ||
d733c5ec | 3 | ;; Copyright (C) 1985, 1986, 1993, 1994 Free Software Foundation, Inc. |
3a801d0c | 4 | |
e5167999 | 5 | ;; Maintainer: FSF |
fd7fa35a | 6 | ;; Keywords: help, internal |
e5167999 | 7 | |
433ae6f6 RS |
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 | |
e5167999 | 12 | ;; the Free Software Foundation; either version 2, or (at your option) |
433ae6f6 RS |
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 | |
21 | ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | ||
d9ecc911 ER |
24 | ;;; Commentary: |
25 | ||
26 | ;; This code implements GNU Emac's on-line help system, the one invoked by | |
27 | ;;`M-x help-for-help'. | |
28 | ||
e5167999 ER |
29 | ;;; Code: |
30 | ||
8aa3a187 RS |
31 | ;; Get the macro make-help-screen when this is compiled, |
32 | ;; or run interpreted, but not when the compiled code is loaded. | |
b1fe9304 | 33 | (eval-when-compile (require 'help-macro)) |
41b8542b | 34 | |
433ae6f6 RS |
35 | (defvar help-map (make-sparse-keymap) |
36 | "Keymap for characters following the Help key.") | |
37 | ||
afaa65e4 KH |
38 | (defvar help-mode-map (make-sparse-keymap) |
39 | "Keymap for help mode.") | |
40 | ||
e17d2fd1 | 41 | (define-key global-map (char-to-string help-char) 'help-command) |
433ae6f6 RS |
42 | (fset 'help-command help-map) |
43 | ||
e17d2fd1 | 44 | (define-key help-map (char-to-string help-char) 'help-for-help) |
433ae6f6 RS |
45 | (define-key help-map "?" 'help-for-help) |
46 | ||
47 | (define-key help-map "\C-c" 'describe-copying) | |
48 | (define-key help-map "\C-d" 'describe-distribution) | |
49 | (define-key help-map "\C-w" 'describe-no-warranty) | |
76766f2d | 50 | (define-key help-map "\C-p" 'describe-project) |
433ae6f6 RS |
51 | (define-key help-map "a" 'command-apropos) |
52 | ||
53 | (define-key help-map "b" 'describe-bindings) | |
54 | ||
55 | (define-key help-map "c" 'describe-key-briefly) | |
56 | (define-key help-map "k" 'describe-key) | |
57 | ||
58 | (define-key help-map "d" 'describe-function) | |
59 | (define-key help-map "f" 'describe-function) | |
60 | ||
7ee71cf1 RS |
61 | (define-key help-map "F" 'view-emacs-FAQ) |
62 | ||
433ae6f6 | 63 | (define-key help-map "i" 'info) |
e5d77022 JB |
64 | (define-key help-map "\C-f" 'Info-goto-emacs-command-node) |
65 | (define-key help-map "\C-k" 'Info-goto-emacs-key-command-node) | |
433ae6f6 RS |
66 | |
67 | (define-key help-map "l" 'view-lossage) | |
68 | ||
69 | (define-key help-map "m" 'describe-mode) | |
70 | ||
71 | (define-key help-map "\C-n" 'view-emacs-news) | |
72 | (define-key help-map "n" 'view-emacs-news) | |
73 | ||
06b98c51 | 74 | (define-key help-map "p" 'finder-by-keyword) |
3e9c095d RS |
75 | (autoload 'finder-by-keyword "finder" |
76 | "Find packages matching a given keyword." t) | |
06b98c51 | 77 | |
433ae6f6 RS |
78 | (define-key help-map "s" 'describe-syntax) |
79 | ||
80 | (define-key help-map "t" 'help-with-tutorial) | |
81 | ||
82 | (define-key help-map "w" 'where-is) | |
83 | ||
84 | (define-key help-map "v" 'describe-variable) | |
85 | ||
2fc9d9f4 RS |
86 | (define-key help-map "q" 'help-quit) |
87 | ||
afaa65e4 KH |
88 | (defun help-mode () |
89 | "Major mode for viewing help text. | |
90 | Entry to this mode runs the normal hook `help-mode-hook'. | |
91 | Commands: | |
92 | \\{help-mode-map}" | |
93 | (interactive) | |
94 | (kill-all-local-variables) | |
95 | (use-local-map help-mode-map) | |
96 | (setq mode-name "Help") | |
97 | (setq major-mode 'help-mode) | |
98 | (run-hooks 'help-mode-hook)) | |
99 | ||
2fc9d9f4 RS |
100 | (defun help-quit () |
101 | (interactive) | |
102 | nil) | |
103 | ||
433ae6f6 RS |
104 | (defun help-with-tutorial () |
105 | "Select the Emacs learn-by-doing tutorial." | |
106 | (interactive) | |
107 | (let ((file (expand-file-name "~/TUTORIAL"))) | |
108 | (delete-other-windows) | |
109 | (if (get-file-buffer file) | |
110 | (switch-to-buffer (get-file-buffer file)) | |
111 | (switch-to-buffer (create-file-buffer file)) | |
112 | (setq buffer-file-name file) | |
113 | (setq default-directory (expand-file-name "~/")) | |
79058860 | 114 | (setq buffer-auto-save-file-name nil) |
1e6dacf6 | 115 | (insert-file-contents (expand-file-name "TUTORIAL" data-directory)) |
433ae6f6 RS |
116 | (goto-char (point-min)) |
117 | (search-forward "\n<<") | |
118 | (beginning-of-line) | |
119 | (delete-region (point) (progn (end-of-line) (point))) | |
857a1de6 | 120 | (let ((n (- (window-height (selected-window)) |
433ae6f6 | 121 | (count-lines (point-min) (point)) |
857a1de6 | 122 | 6))) |
d0da2301 | 123 | (if (< n 12) |
857a1de6 KH |
124 | (newline n) |
125 | ;; Some people get confused by the large gap. | |
126 | (newline (/ n 2)) | |
127 | (insert "[Middle of page left blank for didactic purposes. " | |
128 | "Text continues below]") | |
129 | (newline (- n (/ n 2))))) | |
433ae6f6 RS |
130 | (goto-char (point-min)) |
131 | (set-buffer-modified-p nil)))) | |
132 | ||
133 | (defun describe-key-briefly (key) | |
134 | "Print the name of the function KEY invokes. KEY is a string." | |
135 | (interactive "kDescribe key briefly: ") | |
5f296b78 RS |
136 | ;; If this key seq ends with a down event, discard the |
137 | ;; following click or drag event. Otherwise that would | |
138 | ;; erase the message. | |
139 | (let ((type (aref key (1- (length key))))) | |
140 | (if (listp type) (setq type (car type))) | |
141 | (and (symbolp type) | |
142 | (memq 'down (event-modifiers type)) | |
fca4b775 | 143 | (read-event))) |
433ae6f6 RS |
144 | (let ((defn (key-binding key))) |
145 | (if (or (null defn) (integerp defn)) | |
146 | (message "%s is undefined" (key-description key)) | |
147 | (message "%s runs the command %s" | |
148 | (key-description key) | |
149 | (if (symbolp defn) defn (prin1-to-string defn)))))) | |
150 | ||
151 | (defun print-help-return-message (&optional function) | |
152 | "Display or return message saying how to restore windows after help command. | |
153 | Computes a message and applies the optional argument FUNCTION to it. | |
154 | If FUNCTION is nil, applies `message' to it, thus printing it." | |
155 | (and (not (get-buffer-window standard-output)) | |
d536293f RS |
156 | (let ((first-message |
157 | (cond ((or (member (buffer-name standard-output) | |
158 | special-display-buffer-names) | |
34b0ef48 RS |
159 | (assoc (buffer-name standard-output) |
160 | special-display-buffer-names) | |
d536293f RS |
161 | (let (found |
162 | (tail special-display-regexps) | |
163 | (name (buffer-name standard-output))) | |
164 | (while (and tail (not found)) | |
afaa65e4 | 165 | (if (or (and (consp (car tail)) |
34b0ef48 RS |
166 | (string-match (car (car tail)) name)) |
167 | (and (stringp (car tail)) | |
168 | (string-match (car tail) name))) | |
d536293f RS |
169 | (setq found t)) |
170 | (setq tail (cdr tail))) | |
171 | found)) | |
172 | ;; If the help output buffer is a special display buffer, | |
173 | ;; don't say anything about how to get rid of it. | |
174 | ;; First of all, the user will do that with the window | |
175 | ;; manager, not with Emacs. | |
176 | ;; Secondly, the buffer has not been displayed yet, | |
177 | ;; so we don't know whether its frame will be selected. | |
178 | ;; Even the message about scrolling the help | |
179 | ;; might be wrong, but it seems worth showing it anyway. | |
180 | nil) | |
181 | ((not (one-window-p t)) | |
182 | "Type \\[switch-to-buffer-other-window] RET to restore the other window.") | |
183 | (pop-up-windows | |
184 | "Type \\[delete-other-windows] to remove help window.") | |
185 | (t | |
186 | "Type \\[switch-to-buffer] RET to remove help window.")))) | |
187 | (funcall (or function 'message) | |
188 | (concat | |
189 | (if first-message | |
190 | (substitute-command-keys first-message) | |
191 | "") | |
192 | (if first-message " " "") | |
125a8d70 RS |
193 | ;; If the help buffer will go in a separate frame, |
194 | ;; it's no use mentioning a command to scroll, so don't. | |
6e7f5182 | 195 | (if (or (member (buffer-name standard-output) |
125a8d70 | 196 | special-display-buffer-names) |
6e7f5182 RS |
197 | (memq t (mapcar '(lambda (elt) |
198 | (string-match elt (buffer-name standard-output))) | |
125a8d70 RS |
199 | special-display-regexps))) |
200 | nil | |
201 | (if (or (member (buffer-name standard-output) | |
202 | same-window-buffer-names) | |
203 | (memq t (mapcar '(lambda (elt) | |
204 | (string-match elt (buffer-name standard-output))) | |
205 | same-window-regexps))) | |
206 | ;; Say how to scroll this window. | |
207 | (substitute-command-keys | |
208 | "\\[scroll-up] to scroll the help.") | |
209 | ;; Say how to scroll some other window. | |
6e7f5182 | 210 | (substitute-command-keys |
125a8d70 | 211 | "\\[scroll-other-window] to scroll the help.")))))))) |
433ae6f6 RS |
212 | |
213 | (defun describe-key (key) | |
214 | "Display documentation of the function invoked by KEY. KEY is a string." | |
215 | (interactive "kDescribe key: ") | |
5f296b78 RS |
216 | ;; If this key seq ends with a down event, discard the |
217 | ;; following click or drag event. Otherwise that would | |
218 | ;; erase the message. | |
219 | (let ((type (aref key (1- (length key))))) | |
220 | (if (listp type) (setq type (car type))) | |
221 | (and (symbolp type) | |
222 | (memq 'down (event-modifiers type)) | |
223 | (read-event))) | |
433ae6f6 RS |
224 | (let ((defn (key-binding key))) |
225 | (if (or (null defn) (integerp defn)) | |
226 | (message "%s is undefined" (key-description key)) | |
227 | (with-output-to-temp-buffer "*Help*" | |
228 | (prin1 defn) | |
229 | (princ ":\n") | |
230 | (if (documentation defn) | |
231 | (princ (documentation defn)) | |
232 | (princ "not documented")) | |
c46bbd92 KH |
233 | (save-excursion |
234 | (set-buffer standard-output) | |
235 | (help-mode)) | |
433ae6f6 RS |
236 | (print-help-return-message))))) |
237 | ||
ad023904 RS |
238 | (defun describe-mode () |
239 | "Display documentation of current major mode and minor modes. | |
433ae6f6 | 240 | For this to work correctly for a minor mode, the mode's indicator variable |
61c6b658 | 241 | \(listed in `minor-mode-alist') must also be a function whose documentation |
433ae6f6 | 242 | describes the minor mode." |
7192540b | 243 | (interactive) |
433ae6f6 | 244 | (with-output-to-temp-buffer "*Help*" |
7192540b RS |
245 | (let ((minor-modes minor-mode-alist) |
246 | (locals (buffer-local-variables))) | |
247 | (while minor-modes | |
248 | (let* ((minor-mode (car (car minor-modes))) | |
249 | (indicator (car (cdr (car minor-modes)))) | |
250 | (local-binding (assq minor-mode locals))) | |
251 | ;; Document a minor mode if it is listed in minor-mode-alist, | |
252 | ;; bound locally in this buffer, non-nil, and has a function | |
253 | ;; definition. | |
254 | (if (and local-binding | |
255 | (cdr local-binding) | |
256 | (fboundp minor-mode)) | |
257 | (let ((pretty-minor-mode minor-mode)) | |
258 | (if (string-match "-mode$" (symbol-name minor-mode)) | |
259 | (setq pretty-minor-mode | |
260 | (capitalize | |
261 | (substring (symbol-name minor-mode) | |
262 | 0 (match-beginning 0))))) | |
263 | (while (and indicator (symbolp indicator)) | |
264 | (setq indicator (symbol-value indicator))) | |
265 | (princ (format "%s minor mode (indicator%s):\n" | |
266 | pretty-minor-mode indicator)) | |
267 | (princ (documentation minor-mode)) | |
268 | (princ "\n\n")))) | |
269 | (setq minor-modes (cdr minor-modes)))) | |
433ae6f6 | 270 | (princ mode-name) |
ad023904 | 271 | (princ " mode:\n") |
433ae6f6 | 272 | (princ (documentation major-mode)) |
c46bbd92 KH |
273 | (save-excursion |
274 | (set-buffer standard-output) | |
275 | (help-mode)) | |
433ae6f6 RS |
276 | (print-help-return-message))) |
277 | ||
278 | ;; So keyboard macro definitions are documented correctly | |
279 | (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro)) | |
280 | ||
281 | (defun describe-distribution () | |
282 | "Display info on how to obtain the latest version of GNU Emacs." | |
283 | (interactive) | |
284 | (find-file-read-only | |
1e6dacf6 | 285 | (expand-file-name "DISTRIB" data-directory))) |
433ae6f6 RS |
286 | |
287 | (defun describe-copying () | |
288 | "Display info on how you may redistribute copies of GNU Emacs." | |
289 | (interactive) | |
290 | (find-file-read-only | |
1e6dacf6 | 291 | (expand-file-name "COPYING" data-directory)) |
433ae6f6 RS |
292 | (goto-char (point-min))) |
293 | ||
76766f2d RS |
294 | (defun describe-project () |
295 | "Display info on the GNU project." | |
296 | (interactive) | |
297 | (find-file-read-only | |
298 | (expand-file-name "GNU" data-directory)) | |
299 | (goto-char (point-min))) | |
300 | ||
433ae6f6 RS |
301 | (defun describe-no-warranty () |
302 | "Display info on all the kinds of warranty Emacs does NOT have." | |
303 | (interactive) | |
304 | (describe-copying) | |
305 | (let (case-fold-search) | |
306 | (search-forward "NO WARRANTY") | |
307 | (recenter 0))) | |
308 | ||
61c6b658 | 309 | (defun describe-prefix-bindings () |
c7cba9cb RS |
310 | "Describe the bindings of the prefix used to reach this command. |
311 | The prefix described consists of all but the last event | |
312 | of the key sequence that ran this command." | |
61c6b658 | 313 | (interactive) |
ccc06dcc KH |
314 | (let* ((key (this-command-keys))) |
315 | (describe-bindings | |
316 | (if (stringp key) | |
317 | (substring key 0 (1- (length key))) | |
318 | (let ((prefix (make-vector (1- (length key)) nil)) | |
319 | (i 0)) | |
320 | (while (< i (length prefix)) | |
321 | (aset prefix i (aref key i)) | |
322 | (setq i (1+ i))) | |
323 | prefix))))) | |
c7cba9cb RS |
324 | ;; Make C-h after a prefix, when not specifically bound, |
325 | ;; run describe-prefix-bindings. | |
61c6b658 RS |
326 | (setq prefix-help-command 'describe-prefix-bindings) |
327 | ||
433ae6f6 RS |
328 | (defun view-emacs-news () |
329 | "Display info on recent changes to Emacs." | |
330 | (interactive) | |
1e6dacf6 | 331 | (find-file-read-only (expand-file-name "NEWS" data-directory))) |
433ae6f6 | 332 | |
7ee71cf1 RS |
333 | (defun view-emacs-FAQ () |
334 | "Display the Emacs Frequently Asked Questions (FAQ) file." | |
335 | (interactive) | |
336 | (find-file-read-only (expand-file-name "FAQ" data-directory))) | |
337 | ||
433ae6f6 RS |
338 | (defun view-lossage () |
339 | "Display last 100 input keystrokes." | |
340 | (interactive) | |
341 | (with-output-to-temp-buffer "*Help*" | |
298a7c8c RS |
342 | (princ (mapconcat (function (lambda (key) |
343 | (if (or (integerp key) | |
344 | (symbolp key) | |
345 | (listp key)) | |
346 | (single-key-description key) | |
347 | (prin1-to-string key nil)))) | |
348 | (recent-keys) | |
349 | " ")) | |
433ae6f6 RS |
350 | (save-excursion |
351 | (set-buffer standard-output) | |
352 | (goto-char (point-min)) | |
353 | (while (progn (move-to-column 50) (not (eobp))) | |
354 | (search-forward " " nil t) | |
c46bbd92 KH |
355 | (insert "\n")) |
356 | (help-mode)) | |
433ae6f6 RS |
357 | (print-help-return-message))) |
358 | ||
2fc9d9f4 | 359 | (defalias 'help 'help-for-help) |
41b8542b | 360 | (make-help-screen help-for-help |
224d56a3 | 361 | "a b c f C-f i k C-k l m n p s t v w C-c C-d C-n C-w, or ? for more help:" |
76766f2d | 362 | "You have typed \\[help-command], the help character. Type a Help option: |
efcce2d2 | 363 | \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.) |
433ae6f6 | 364 | |
21ee8c42 RM |
365 | a command-apropos. Give a substring, and see a list of commands |
366 | (functions interactively callable) that contain | |
367 | that substring. See also the apropos command. | |
af6a9de9 RS |
368 | b describe-bindings. Display table of all key bindings. |
369 | c describe-key-briefly. Type a command key sequence; | |
21ee8c42 | 370 | it prints the function name that sequence runs. |
af6a9de9 | 371 | f describe-function. Type a function name and get documentation of it. |
21ee8c42 RM |
372 | C-f Info-goto-emacs-command-node. Type a function name; |
373 | it takes you to the Info node for that command. | |
7ee71cf1 | 374 | F view-emacs-FAQ. Shows emacs frequently asked questions file. |
af6a9de9 RS |
375 | i info. The info documentation reader. |
376 | k describe-key. Type a command key sequence; | |
21ee8c42 RM |
377 | it displays the full documentation. |
378 | C-k Info-goto-emacs-key-command-node. Type a command key sequence; | |
379 | it takes you to the Info node for the command bound to that key. | |
af6a9de9 RS |
380 | l view-lossage. Shows last 100 characters you typed. |
381 | m describe-mode. Print documentation of current major mode, | |
21ee8c42 | 382 | which describes the commands peculiar to it. |
af6a9de9 RS |
383 | n view-emacs-news. Shows emacs news file. |
384 | p finder-by-keyword. Find packages matching a given topic keyword. | |
385 | s describe-syntax. Display contents of syntax table, plus explanations | |
386 | t help-with-tutorial. Select the Emacs learn-by-doing tutorial. | |
387 | v describe-variable. Type name of a variable; | |
21ee8c42 | 388 | it displays the variable's documentation and value. |
af6a9de9 | 389 | w where-is. Type command name; it prints which keystrokes |
21ee8c42 | 390 | invoke that command. |
433ae6f6 RS |
391 | C-c print Emacs copying permission (General Public License). |
392 | C-d print Emacs ordering information. | |
393 | C-n print news of recent Emacs changes. | |
76766f2d | 394 | C-p print information about the GNU project. |
433ae6f6 | 395 | C-w print information on absence of warranty for GNU Emacs." |
41b8542b | 396 | help-map) |
433ae6f6 RS |
397 | |
398 | ;; Return a function which is called by the list containing point. | |
399 | ;; If that gives no function, return a function whose name is around point. | |
400 | ;; If that doesn't give a function, return nil. | |
401 | (defun function-called-at-point () | |
402 | (or (condition-case () | |
403 | (save-excursion | |
404 | (save-restriction | |
405 | (narrow-to-region (max (point-min) (- (point) 1000)) (point-max)) | |
406 | (backward-up-list 1) | |
407 | (forward-char 1) | |
408 | (let (obj) | |
409 | (setq obj (read (current-buffer))) | |
410 | (and (symbolp obj) (fboundp obj) obj)))) | |
411 | (error nil)) | |
412 | (condition-case () | |
413 | (save-excursion | |
414 | (forward-sexp -1) | |
415 | (skip-chars-forward "'") | |
416 | (let ((obj (read (current-buffer)))) | |
417 | (and (symbolp obj) (fboundp obj) obj))) | |
418 | (error nil)))) | |
419 | ||
ca5ed196 RS |
420 | (defun describe-function-find-file (function) |
421 | (let ((files load-history) | |
422 | file functions) | |
423 | (while files | |
424 | (if (memq function (cdr (car files))) | |
425 | (setq file (car (car files)) files nil)) | |
426 | (setq files (cdr files))) | |
427 | file)) | |
428 | ||
433ae6f6 RS |
429 | (defun describe-function (function) |
430 | "Display the full documentation of FUNCTION (a symbol)." | |
431 | (interactive | |
432 | (let ((fn (function-called-at-point)) | |
433 | (enable-recursive-minibuffers t) | |
434 | val) | |
435 | (setq val (completing-read (if fn | |
436 | (format "Describe function (default %s): " fn) | |
437 | "Describe function: ") | |
438 | obarray 'fboundp t)) | |
439 | (list (if (equal val "") | |
440 | fn (intern val))))) | |
441 | (with-output-to-temp-buffer "*Help*" | |
442 | (prin1 function) | |
443 | (princ ": ") | |
444 | (let* ((def (symbol-function function)) | |
445 | (beg (if (commandp def) "an interactive " "a "))) | |
7f26b180 RM |
446 | (princ (cond ((or (stringp def) |
447 | (vectorp def)) | |
6f6bfb85 | 448 | "a keyboard macro") |
433ae6f6 | 449 | ((subrp def) |
6f6bfb85 | 450 | (concat beg "built-in function")) |
dbc4e1c1 | 451 | ((byte-code-function-p def) |
6f6bfb85 | 452 | (concat beg "compiled Lisp function")) |
433ae6f6 | 453 | ((symbolp def) |
6f6bfb85 | 454 | (format "alias for `%s'" def)) |
433ae6f6 | 455 | ((eq (car-safe def) 'lambda) |
6f6bfb85 | 456 | (concat beg "Lisp function")) |
433ae6f6 | 457 | ((eq (car-safe def) 'macro) |
6f6bfb85 | 458 | "a Lisp macro") |
433ae6f6 | 459 | ((eq (car-safe def) 'mocklisp) |
6f6bfb85 | 460 | "a mocklisp function") |
433ae6f6 | 461 | ((eq (car-safe def) 'autoload) |
6f6bfb85 | 462 | (format "%s autoloaded Lisp %s" |
762435dd | 463 | (if (commandp def) "an interactive" "an") |
433ae6f6 | 464 | (if (nth 4 def) "macro" "function") |
ab67260b RS |
465 | ;;; Including the file name made this line too long. |
466 | ;;; (nth 1 def) | |
467 | )) | |
433ae6f6 | 468 | (t ""))) |
ca5ed196 RS |
469 | (let ((file (describe-function-find-file function))) |
470 | (if file | |
471 | (progn | |
472 | (princ " in `") | |
159a4895 RS |
473 | ;; We used to add .el to the file name, |
474 | ;; but that's completely wrong when the user used load-file. | |
a5743acc RS |
475 | (princ file) |
476 | (princ "'")))) | |
6f6bfb85 | 477 | (princ ".") |
4591cb90 | 478 | (terpri) |
7f26b180 RM |
479 | (let ((arglist (cond ((byte-code-function-p def) |
480 | (car (append def nil))) | |
481 | ((eq (car-safe def) 'lambda) | |
482 | (nth 1 def)) | |
483 | (t t)))) | |
484 | (if (listp arglist) | |
485 | (progn | |
486 | (princ (cons function | |
487 | (mapcar (lambda (arg) | |
488 | (if (memq arg '(&optional &rest)) | |
489 | arg | |
490 | (intern (upcase (symbol-name arg))))) | |
491 | arglist))) | |
492 | (terpri)))) | |
4591cb90 | 493 | (if (documentation function) |
cdd672cc RS |
494 | (progn (terpri) |
495 | (princ (documentation function))) | |
4591cb90 | 496 | (princ "not documented")) |
7f26b180 | 497 | ) |
433ae6f6 | 498 | (print-help-return-message) |
c46bbd92 KH |
499 | (save-excursion |
500 | (set-buffer standard-output) | |
501 | (help-mode) | |
502 | ;; Return the text we displayed. | |
503 | (buffer-string)))) | |
433ae6f6 RS |
504 | |
505 | (defun variable-at-point () | |
506 | (condition-case () | |
507 | (save-excursion | |
508 | (forward-sexp -1) | |
509 | (skip-chars-forward "'") | |
510 | (let ((obj (read (current-buffer)))) | |
511 | (and (symbolp obj) (boundp obj) obj))) | |
512 | (error nil))) | |
513 | ||
514 | (defun describe-variable (variable) | |
515 | "Display the full documentation of VARIABLE (a symbol). | |
516 | Returns the documentation as a string, also." | |
517 | (interactive | |
518 | (let ((v (variable-at-point)) | |
519 | (enable-recursive-minibuffers t) | |
520 | val) | |
521 | (setq val (completing-read (if v | |
522 | (format "Describe variable (default %s): " v) | |
523 | "Describe variable: ") | |
524 | obarray 'boundp t)) | |
525 | (list (if (equal val "") | |
526 | v (intern val))))) | |
527 | (with-output-to-temp-buffer "*Help*" | |
528 | (prin1 variable) | |
433ae6f6 | 529 | (if (not (boundp variable)) |
3e483e01 RS |
530 | (princ " is void") |
531 | (princ "'s value is ") | |
433ae6f6 | 532 | (prin1 (symbol-value variable))) |
7e76ae23 | 533 | (terpri) |
b872e1da | 534 | (if (local-variable-p variable) |
3e483e01 RS |
535 | (progn |
536 | (princ (format "Local in buffer %s; " (buffer-name))) | |
537 | (if (not (default-boundp variable)) | |
538 | (princ "globally void") | |
539 | (princ "global value is ") | |
540 | (prin1 (default-value variable))) | |
541 | (terpri))) | |
7e76ae23 | 542 | (terpri) |
433ae6f6 RS |
543 | (princ "Documentation:") |
544 | (terpri) | |
545 | (let ((doc (documentation-property variable 'variable-documentation))) | |
546 | (if doc | |
547 | (princ (substitute-command-keys doc)) | |
548 | (princ "not documented as a variable."))) | |
549 | (print-help-return-message) | |
c46bbd92 KH |
550 | (save-excursion |
551 | (set-buffer standard-output) | |
552 | (help-mode) | |
553 | ;; Return the text we displayed. | |
554 | (buffer-string)))) | |
433ae6f6 | 555 | |
54c0b967 RS |
556 | (defun where-is (definition) |
557 | "Print message listing key sequences that invoke specified command. | |
558 | Argument is a command definition, usually a symbol with a function definition." | |
559 | (interactive | |
560 | (let ((fn (function-called-at-point)) | |
561 | (enable-recursive-minibuffers t) | |
562 | val) | |
563 | (setq val (completing-read (if fn | |
564 | (format "Where is command (default %s): " fn) | |
565 | "Where is command: ") | |
566 | obarray 'fboundp t)) | |
567 | (list (if (equal val "") | |
568 | fn (intern val))))) | |
569 | (let* ((keys (where-is-internal definition overriding-local-map nil nil)) | |
570 | (keys1 (mapconcat 'key-description keys ", "))) | |
571 | (if (> (length keys1) 0) | |
572 | (message "%s is on %s" definition keys1) | |
573 | (message "%s is not on any key" definition))) | |
574 | nil) | |
575 | ||
433ae6f6 RS |
576 | (defun command-apropos (string) |
577 | "Like apropos but lists only symbols that are names of commands | |
578 | \(interactively callable functions). Argument REGEXP is a regular expression | |
579 | that is matched against command symbol names. Returns list of symbols and | |
580 | documentation found." | |
581 | (interactive "sCommand apropos (regexp): ") | |
582 | (let ((message | |
583 | (let ((standard-output (get-buffer-create "*Help*"))) | |
584 | (print-help-return-message 'identity)))) | |
cba9a9dc | 585 | (if (apropos string t 'commandp t) |
78e3ef3c | 586 | (and message (message message))))) |
433ae6f6 RS |
587 | |
588 | (defun locate-library (library &optional nosuffix) | |
589 | "Show the full path name of Emacs library LIBRARY. | |
590 | This command searches the directories in `load-path' like `M-x load-library' | |
591 | to find the file that `M-x load-library RET LIBRARY RET' would load. | |
592 | Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el' | |
593 | to the specified name LIBRARY (a la calling `load' instead of `load-library')." | |
594 | (interactive "sLocate library: ") | |
595 | (catch 'answer | |
596 | (mapcar | |
597 | '(lambda (dir) | |
598 | (mapcar | |
599 | '(lambda (suf) | |
600 | (let ((try (expand-file-name (concat library suf) dir))) | |
601 | (and (file-readable-p try) | |
602 | (null (file-directory-p try)) | |
603 | (progn | |
604 | (message "Library is file %s" try) | |
605 | (throw 'answer try))))) | |
606 | (if nosuffix '("") '(".elc" ".el" "")))) | |
607 | load-path) | |
608 | (message "No library %s in search path" library) | |
609 | nil)) | |
1a06eabd ER |
610 | |
611 | ;;; help.el ends here |