Mercurial > hg > xemacs-beta
annotate lisp/help.el @ 5594:cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
2011-11-09 Aidan Kehoe <kehoea@parhasard.net>
* help.el (describe-function-1):
When printing compiled functions, mention whether they're
built-in.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 09 Nov 2011 12:51:10 +0000 |
parents | ac37a5f7e5be |
children | a81a739181dc |
rev | line source |
---|---|
3368 | 1 ;; help.el --- help commands for XEmacs. |
428 | 2 |
3 ;; Copyright (C) 1985, 1986, 1992-4, 1997 Free Software Foundation, Inc. | |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
4 ;; Copyright (C) 2001, 2002, 2003, 2010 Ben Wing. |
428 | 5 |
6 ;; Maintainer: FSF | |
7 ;; Keywords: help, internal, dumped | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
11 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
12 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
13 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
14 ;; option) any later version. |
428 | 15 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
19 ;; for more details. |
428 | 20 |
21 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 23 |
24 ;;; Synched up with: FSF 19.30. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; This file is dumped with XEmacs. | |
29 | |
30 ;; This code implements XEmacs's on-line help system, the one invoked by | |
31 ;;`M-x help-for-help'. | |
32 | |
33 ;; 06/11/1997 -- Converted to use char-after instead of broken | |
34 ;; following-char. -slb | |
35 | |
36 ;;; Code: | |
37 | |
38 ;; Get the macro make-help-screen when this is compiled, | |
39 ;; or run interpreted, but not when the compiled code is loaded. | |
40 (eval-when-compile (require 'help-macro)) | |
41 | |
3368 | 42 (require 'loadhist) ;; For symbol-file. |
43 | |
428 | 44 (defgroup help nil |
45 "Support for on-line help systems." | |
46 :group 'emacs) | |
47 | |
48 (defgroup help-appearance nil | |
49 "Appearance of help buffers." | |
50 :group 'help) | |
51 | |
52 (defvar help-map (let ((map (make-sparse-keymap))) | |
53 (set-keymap-name map 'help-map) | |
54 (set-keymap-prompt | |
444 | 55 map (gettext "(Type ? for further options)")) |
428 | 56 map) |
57 "Keymap for characters following the Help key.") | |
58 | |
59 ;; global-map definitions moved to keydefs.el | |
60 (fset 'help-command help-map) | |
61 | |
62 (define-key help-map (vector help-char) 'help-for-help) | |
63 (define-key help-map "?" 'help-for-help) | |
64 (define-key help-map 'help 'help-for-help) | |
65 (define-key help-map '(f1) 'help-for-help) | |
66 | |
67 (define-key help-map "a" 'hyper-apropos) ; 'command-apropos in FSFmacs | |
502 | 68 (define-key help-map "A" 'command-hyper-apropos) |
69 ;; #### should be hyper-apropos-documentation, once that's written. | |
70 (define-key help-map "\C-a" 'apropos-documentation) | |
428 | 71 |
72 (define-key help-map "b" 'describe-bindings) | |
73 (define-key help-map "B" 'describe-beta) | |
74 | |
502 | 75 (define-key help-map "c" 'describe-key-briefly) |
428 | 76 (define-key help-map "C" 'customize) |
502 | 77 ;; FSFmacs has Info-goto-emacs-command-node on C-f, no binding |
78 ;; for Info-elisp-ref | |
79 (define-key help-map "\C-c" 'Info-goto-emacs-command-node) | |
428 | 80 |
81 (define-key help-map "d" 'describe-function) | |
502 | 82 (define-key help-map "\C-d" 'describe-distribution) |
83 | |
84 (define-key help-map "e" (if (fboundp 'view-last-error) 'view-last-error | |
85 'describe-last-error)) | |
86 | |
428 | 87 (define-key help-map "f" 'describe-function) |
502 | 88 ;; #### not a good interface. no way to specify that C-h is preferred |
89 ;; as a prefix and not BS. should instead be specified as part of | |
90 ;; `define-key'. | |
91 ;; (put 'describe-function 'preferred-key-sequence "\C-hf") | |
428 | 92 (define-key help-map "F" 'xemacs-local-faq) |
502 | 93 (define-key help-map "\C-f" 'Info-elisp-ref) |
428 | 94 |
95 (define-key help-map "i" 'info) | |
502 | 96 (define-key help-map "I" 'Info-search-index-in-xemacs-and-lispref) |
97 (define-key help-map "\C-i" 'Info-query) | |
98 | |
99 (define-key help-map "k" 'describe-key) | |
100 (define-key help-map "\C-k" 'Info-goto-emacs-key-command-node) | |
428 | 101 |
102 (define-key help-map "l" 'view-lossage) | |
502 | 103 (define-key help-map "\C-l" 'describe-copying) ; on \C-c in FSFmacs |
428 | 104 |
105 (define-key help-map "m" 'describe-mode) | |
106 | |
502 | 107 (define-key help-map "n" 'view-emacs-news) |
428 | 108 (define-key help-map "\C-n" 'view-emacs-news) |
109 | |
110 (define-key help-map "p" 'finder-by-keyword) | |
502 | 111 (define-key help-map "\C-p" 'describe-pointer) |
3074 | 112 (define-key help-map "P" 'view-xemacs-problems) |
502 | 113 |
114 (define-key help-map "q" 'help-quit) | |
428 | 115 |
116 ;; Do this right with an autoload cookie in finder.el. | |
117 ;;(autoload 'finder-by-keyword "finder" | |
118 ;; "Find packages matching a given keyword." t) | |
119 | |
120 (define-key help-map "s" 'describe-syntax) | |
502 | 121 (define-key help-map "S" 'view-sample-init-el) |
428 | 122 |
123 (define-key help-map "t" 'help-with-tutorial) | |
124 | |
125 (define-key help-map "v" 'describe-variable) | |
126 | |
502 | 127 (define-key help-map "w" 'where-is) |
128 (define-key help-map "\C-w" 'describe-no-warranty) | |
428 | 129 |
502 | 130 ;; #### It would be nice if the code below to add hyperlinks was |
131 ;; generalized. We would probably need a "hyperlink mode" from which | |
132 ;; help-mode is derived. This means we probably need multiple | |
133 ;; inheritance of modes! Thankfully this is not hard to implement; we | |
134 ;; already have the ability for a keymap to have multiple parents. | |
135 ;; However, we'd have to define any multiply-inherited-from modes using | |
136 ;; a standard `define-mode' construction instead of manually doing it, | |
137 ;; because we don't want each guy calling `kill-all-local-variables' and | |
138 ;; messing up the previous one. | |
428 | 139 |
140 (define-derived-mode help-mode view-major-mode "Help" | |
141 "Major mode for viewing help text. | |
142 Entry to this mode runs the normal hook `help-mode-hook'. | |
143 Commands: | |
144 \\{help-mode-map}" | |
145 ) | |
146 | |
147 (define-key help-mode-map "q" 'help-mode-quit) | |
148 (define-key help-mode-map "Q" 'help-mode-bury) | |
149 (define-key help-mode-map "f" 'find-function-at-point) | |
150 (define-key help-mode-map "d" 'describe-function-at-point) | |
151 (define-key help-mode-map "v" 'describe-variable-at-point) | |
152 (define-key help-mode-map "i" 'Info-elisp-ref) | |
153 (define-key help-mode-map "c" 'customize-variable) | |
154 (define-key help-mode-map [tab] 'help-next-symbol) | |
155 (define-key help-mode-map [(shift tab)] 'help-prev-symbol) | |
3368 | 156 (define-key help-mode-map [return] 'help-find-source-or-scroll-up) |
157 (define-key help-mode-map [button2] 'help-mouse-find-source-or-track) | |
428 | 158 (define-key help-mode-map "n" 'help-next-section) |
159 (define-key help-mode-map "p" 'help-prev-section) | |
160 | |
1123 | 161 (define-derived-mode temp-buffer-mode view-major-mode "Temp" |
162 "Major mode for viewing temporary buffers. | |
163 Exit using \\<temp-buffer-mode-map>\\[help-mode-quit]. | |
164 | |
165 Entry to this mode runs the normal hook `temp-buffer-mode-hook'. | |
166 Commands: | |
167 \\{temp-buffer-mode-map}" | |
168 ) | |
169 | |
170 (define-key temp-buffer-mode-map "q" 'help-mode-quit) | |
171 (define-key temp-buffer-mode-map "Q" 'help-mode-bury) | |
172 | |
428 | 173 (defun describe-function-at-point () |
174 "Describe directly the function at point in the other window." | |
175 (interactive) | |
176 (let ((symb (function-at-point))) | |
177 (when symb | |
178 (describe-function symb)))) | |
179 | |
180 (defun describe-variable-at-point () | |
181 "Describe directly the variable at point in the other window." | |
182 (interactive) | |
183 (let ((symb (variable-at-point))) | |
184 (when symb | |
185 (describe-variable symb)))) | |
186 | |
187 (defun help-next-symbol () | |
188 "Move point to the next quoted symbol." | |
189 (interactive) | |
190 (search-forward "`" nil t)) | |
191 | |
192 (defun help-prev-symbol () | |
193 "Move point to the previous quoted symbol." | |
194 (interactive) | |
195 (search-backward "'" nil t)) | |
196 | |
197 (defun help-next-section () | |
198 "Move point to the next quoted symbol." | |
199 (interactive) | |
200 (search-forward-regexp "^\\w+:" nil t)) | |
201 | |
202 (defun help-prev-section () | |
203 "Move point to the previous quoted symbol." | |
204 (interactive) | |
205 (search-backward-regexp "^\\w+:" nil t)) | |
206 | |
207 (defun help-mode-bury () | |
208 "Bury the help buffer, possibly restoring the previous window configuration." | |
209 (interactive) | |
210 (help-mode-quit t)) | |
211 | |
212 (defun help-mode-quit (&optional bury) | |
213 "Exit from help mode, possibly restoring the previous window configuration. | |
214 If the optional argument BURY is non-nil, the help buffer is buried, | |
215 otherwise it is killed." | |
216 (interactive) | |
217 (let ((buf (current-buffer))) | |
442 | 218 (cond (help-window-config |
219 (set-window-configuration help-window-config)) | |
428 | 220 ((not (one-window-p)) |
221 (delete-window))) | |
222 (if bury | |
223 (bury-buffer buf) | |
224 (kill-buffer buf)))) | |
225 | |
226 (defun help-quit () | |
227 (interactive) | |
228 nil) | |
229 | |
771 | 230 (define-obsolete-function-alias 'deprecated-help-command 'help-for-help) |
428 | 231 |
232 ;;(define-key global-map 'backspace 'deprecated-help-command) | |
233 | |
771 | 234 (defconst tutorial-supported-languages |
235 '( | |
236 ("Croatian" hr iso-8859-2) | |
237 ("Czech" cs iso-8859-2) | |
238 ("Dutch" nl iso-8859-1) | |
239 ("English" nil raw-text) | |
240 ("French" fr iso-8859-1) | |
241 ("German" de iso-8859-1) | |
242 ("Norwegian" no iso-8859-1) | |
243 ("Polish" pl iso-8859-2) | |
244 ("Romanian" ro iso-8859-2) | |
245 ("Slovak" sk iso-8859-2) | |
246 ("Slovenian" sl iso-8859-2) | |
247 ("Spanish" es iso-8859-1) | |
248 ("Swedish" se iso-8859-1) | |
249 ) | |
250 "Alist of supported languages in TUTORIAL files. | |
251 Add languages here, as more are translated.") | |
252 | |
253 ;; TUTORIAL arg is XEmacs addition | |
254 (defun help-with-tutorial (&optional tutorial language) | |
255 "Select the XEmacs learn-by-doing tutorial. | |
256 Optional arg TUTORIAL specifies the tutorial file; if not specified or | |
257 if this command is invoked interactively, the tutorial appropriate to | |
258 the current language environment is used. If there is no tutorial | |
259 written in that language, or if this version of XEmacs has no | |
260 international (Mule) support, the English-language tutorial is used. | |
261 With a prefix argument, you are asked to select which language." | |
262 (interactive "i\nP") | |
263 (when (and language (consp language)) | |
264 (setq language | |
265 (if (featurep 'mule) | |
266 (or (declare-fboundp (read-language-name 'tutorial "Language: ")) | |
267 (error "No tutorial file of the specified language")) | |
268 (let ((completion-ignore-case t)) | |
269 (completing-read "Language: " | |
270 tutorial-supported-languages nil t))))) | |
271 (or language | |
272 (setq language | |
273 (if (featurep 'mule) (declare-boundp current-language-environment) | |
274 "English"))) | |
275 (or tutorial | |
276 (setq tutorial | |
277 (cond ((featurep 'mule) | |
278 (or (declare-fboundp (get-language-info language 'tutorial)) | |
279 "TUTORIAL")) | |
280 ((equal language "English") "TUTORIAL") | |
281 (t (format "TUTORIAL.%s" | |
282 (cadr (assoc language | |
283 tutorial-supported-languages))))))) | |
284 (let ((file (expand-file-name tutorial "~"))) | |
285 (delete-other-windows) | |
286 (let ((buffer (or (get-file-buffer file) | |
287 (create-file-buffer file))) | |
288 (window-configuration (current-window-configuration))) | |
289 (condition-case error-data | |
290 (progn | |
291 (switch-to-buffer buffer) | |
292 (setq buffer-file-name file) | |
293 (setq default-directory (expand-file-name "~/")) | |
294 (setq buffer-auto-save-file-name nil) | |
295 ;; Because of non-Mule users, TUTORIALs are not coded | |
296 ;; independently, so we must guess the coding according to | |
297 ;; the language. | |
298 (let ((coding-system-for-read | |
299 (if (featurep 'mule) | |
300 (with-fboundp 'get-language-info | |
301 (or (get-language-info language | |
302 'tutorial-coding-system) | |
303 (car (get-language-info language | |
304 'coding-system)))) | |
305 (nth 2 (assoc language tutorial-supported-languages))))) | |
306 (insert-file-contents (locate-data-file tutorial))) | |
307 (goto-char (point-min)) | |
308 ;; [The 'didactic' blank lines: possibly insert blank lines | |
309 ;; around <<nya nya nya>> and replace << >> with [ ].] No more | |
310 ;; didactic blank lines. It was just a bad idea, anyway. I | |
311 ;; rewrote the TUTORIAL so it doesn't need them. However, some | |
312 ;; tutorials in other languages haven't yet been updated. #### | |
313 ;; Delete this code when they're all updated. | |
314 (if (re-search-forward "^<<.+>>" nil t) | |
315 (let ((n (- (window-height (selected-window)) | |
316 (count-lines (point-min) (point-at-bol)) | |
317 6))) | |
318 (if (< n 12) | |
319 (progn (beginning-of-line) (kill-line)) | |
320 ;; Some people get confused by the large gap | |
321 (delete-backward-char 2) | |
322 (insert "]") | |
323 (beginning-of-line) | |
324 (save-excursion | |
325 (delete-char 2) | |
326 (insert "[")) | |
327 (newline (/ n 2)) | |
328 (next-line 1) | |
329 (newline (- n (/ n 2)))))) | |
330 (goto-char (point-min)) | |
331 (set-buffer-modified-p nil)) | |
332 ;; TUTORIAL was not found: kill the buffer and restore the | |
333 ;; window configuration. | |
334 (file-error (kill-buffer buffer) | |
335 (set-window-configuration window-configuration) | |
336 ;; Now, signal the error | |
337 (signal (car error-data) (cdr error-data))))))) | |
428 | 338 |
339 ;; used by describe-key, describe-key-briefly, insert-key-binding, etc. | |
340 (defun key-or-menu-binding (key &optional menu-flag) | |
341 "Return the command invoked by KEY. | |
342 Like `key-binding', but handles menu events and toolbar presses correctly. | |
343 KEY is any value returned by `next-command-event'. | |
344 MENU-FLAG is a symbol that should be set to t if KEY is a menu event, | |
444 | 345 or nil otherwise." |
428 | 346 (let (defn) |
347 (and menu-flag (set menu-flag nil)) | |
348 ;; If the key typed was really a menu selection, grab the form out | |
349 ;; of the event object and intuit the function that would be called, | |
350 ;; and describe that instead. | |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
351 (if (and (vectorp key) (eql 1 (length key)) |
428 | 352 (or (misc-user-event-p (aref key 0)) |
353 (eq (car-safe (aref key 0)) 'menu-selection))) | |
354 (let ((event (aref key 0))) | |
355 (setq defn (if (eventp event) | |
356 (list (event-function event) (event-object event)) | |
357 (cdr event))) | |
358 (and menu-flag (set menu-flag t)) | |
359 (when (eq (car defn) 'eval) | |
360 (setq defn (car (cdr defn)))) | |
361 (when (eq (car-safe defn) 'call-interactively) | |
362 (setq defn (car (cdr defn)))) | |
363 (when (and (consp defn) (null (cdr defn))) | |
364 (setq defn (car defn)))) | |
365 ;; else | |
366 (setq defn (key-binding key))) | |
367 ;; kludge: if a toolbar button was pressed on, try to find the | |
368 ;; binding of the toolbar button. | |
369 (if (and (eq defn 'press-toolbar-button) | |
370 (vectorp key) | |
371 (button-press-event-p (aref key (1- (length key))))) | |
372 ;; wait for the button release. We're on shaky ground here ... | |
373 (let ((event (next-command-event)) | |
374 button) | |
375 (if (and (button-release-event-p event) | |
376 (event-over-toolbar-p event) | |
377 (eq 'release-and-activate-toolbar-button | |
378 (key-binding (vector event))) | |
379 (setq button (event-toolbar-button event))) | |
380 (toolbar-button-callback button) | |
381 ;; if anything went wrong, try returning the binding of | |
382 ;; the button-up event, of the original binding | |
383 (or (key-or-menu-binding (vector event)) | |
384 defn))) | |
385 ;; no toolbar kludge | |
386 defn) | |
387 )) | |
388 | |
389 (defun describe-key-briefly (key &optional insert) | |
390 "Print the name of the function KEY invokes. KEY is a string. | |
391 If INSERT (the prefix arg) is non-nil, insert the message in the buffer." | |
392 (interactive "kDescribe key briefly: \nP") | |
393 (let ((standard-output (if insert (current-buffer) t)) | |
394 defn menup) | |
395 (setq defn (key-or-menu-binding key 'menup)) | |
396 (if (or (null defn) (integerp defn)) | |
397 (princ (format "%s is undefined" (key-description key))) | |
398 ;; If it's a keyboard macro which trivially invokes another command, | |
399 ;; document that instead. | |
400 (if (or (stringp defn) (vectorp defn)) | |
401 (setq defn (or (key-binding defn) | |
402 defn))) | |
403 (let ((last-event (and (vectorp key) | |
404 (aref key (1- (length key)))))) | |
405 (princ (format (cond (insert | |
406 "%s (%s)") | |
407 ((or (button-press-event-p last-event) | |
408 (button-release-event-p last-event)) | |
409 (gettext "%s at that spot runs the command %s")) | |
410 (t | |
411 (gettext "%s runs the command %s"))) | |
412 ;; This used to say 'This menu item' but it | |
413 ;; could also be a scrollbar event. We can't | |
414 ;; distinguish at the moment. | |
415 (if menup | |
416 (if insert "item" "This item") | |
417 (key-description key)) | |
418 (if (symbolp defn) defn (prin1-to-string defn)))))))) | |
419 | |
420 ;; #### this is a horrible piece of shit function that should | |
421 ;; not exist. In FSF 19.30 this function has gotten three times | |
422 ;; as long and has tons and tons of dumb shit checking | |
423 ;; special-display-buffer-names and such crap. I absolutely | |
424 ;; refuse to insert that Ebolification here. I wanted to delete | |
425 ;; this function entirely but Mly bitched. | |
426 ;; | |
427 ;; If your user-land code calls this function, rewrite it to | |
428 ;; call with-displaying-help-buffer. | |
429 | |
430 (defun print-help-return-message (&optional function) | |
431 "Display or return message saying how to restore windows after help command. | |
432 Computes a message and applies the optional argument FUNCTION to it. | |
433 If FUNCTION is nil, applies `message' to it, thus printing it." | |
434 (and (not (get-buffer-window standard-output)) | |
435 (funcall | |
436 (or function 'message) | |
437 (concat | |
438 (substitute-command-keys | |
439 (if (one-window-p t) | |
440 (if pop-up-windows | |
441 (gettext "Type \\[delete-other-windows] to remove help window.") | |
442 (gettext "Type \\[switch-to-buffer] RET to remove help window.")) | |
443 (gettext "Type \\[switch-to-buffer-other-window] RET to restore the other window."))) | |
444 (substitute-command-keys | |
445 (gettext " \\[scroll-other-window] to scroll the help.")))))) | |
446 | |
447 (defcustom help-selects-help-window t | |
448 "*If nil, use the \"old Emacs\" behavior for Help buffers. | |
449 This just displays the buffer in another window, rather than selecting | |
450 the window." | |
451 :type 'boolean | |
452 :group 'help-appearance) | |
453 | |
454 (defcustom help-max-help-buffers 10 | |
455 "*Maximum help buffers to allow before they start getting killed. | |
456 If this is a positive integer, before a help buffer is displayed | |
457 by `with-displaying-help-buffer', any excess help buffers which | |
458 are not being displayed are first killed. Otherwise, if it is | |
459 zero or nil, only one help buffer, \"*Help*\" is ever used." | |
460 :type '(choice integer (const :tag "None" nil)) | |
461 :group 'help-appearance) | |
462 | |
463 (defvar help-buffer-list nil | |
464 "List of help buffers used by `help-register-and-maybe-prune-excess'") | |
465 | |
466 (defun help-register-and-maybe-prune-excess (newbuf) | |
2030 | 467 "Register help buffer named NEWBUF and possibly kill excess ones." |
468 ;; don't let client code pass us bogus NEWBUF---if it gets in the list, | |
469 ;; help can become unusable | |
470 (unless (stringp newbuf) | |
471 (error 'wrong-type-argument "help buffer name must be string" newbuf)) | |
428 | 472 ;; remove new buffer from list |
473 (setq help-buffer-list (remove newbuf help-buffer-list)) | |
474 ;; maybe kill excess help buffers | |
475 (if (and (integerp help-max-help-buffers) | |
476 (> (length help-buffer-list) help-max-help-buffers)) | |
477 (let ((keep-list nil) | |
478 (num-kill (- (length help-buffer-list) | |
479 help-max-help-buffers))) | |
480 (while help-buffer-list | |
481 (let ((buf (car help-buffer-list))) | |
482 (if (and (or (equal buf newbuf) (get-buffer buf)) | |
483 (string-match "^*Help" buf) | |
484 (save-excursion (set-buffer buf) | |
485 (eq major-mode 'help-mode))) | |
486 (if (and (>= num-kill (length help-buffer-list)) | |
487 (not (get-buffer-window buf t t))) | |
488 (kill-buffer buf) | |
489 (setq keep-list (cons buf keep-list))))) | |
490 (setq help-buffer-list (cdr help-buffer-list))) | |
491 (setq help-buffer-list (nreverse keep-list)))) | |
492 ;; push new buffer | |
493 (setq help-buffer-list (cons newbuf help-buffer-list))) | |
494 | |
495 (defvar help-buffer-prefix-string "Help" | |
496 "Initial string to use in constructing help buffer names. | |
2030 | 497 You should never set this directly, only let-bind it.") |
428 | 498 |
499 (defun help-buffer-name (name) | |
500 "Return a name for a Help buffer using string NAME for context." | |
501 (if (and (integerp help-max-help-buffers) | |
502 (> help-max-help-buffers 0) | |
503 (stringp name)) | |
504 (if help-buffer-prefix-string | |
505 (format "*%s: %s*" help-buffer-prefix-string name) | |
506 (format "*%s*" name)) | |
507 (format "*%s*" help-buffer-prefix-string))) | |
508 | |
863 | 509 ;; with-displaying-help-buffer |
428 | 510 |
511 ;; #### Should really be a macro to eliminate the requirement of | |
512 ;; caller to code a lambda form in THUNK -- mrb | |
513 | |
514 ;; #### BEFORE you rush to make this a macro, think about backward | |
515 ;; compatibility. The right way would be to create a macro with | |
516 ;; another name (which is a shame, because w-d-h-b is a perfect name | |
517 ;; for a macro) that uses with-displaying-help-buffer internally. | |
518 | |
442 | 519 (defcustom mode-for-help 'help-mode |
520 "*Mode that help buffers are put into.") | |
521 | |
1123 | 522 (defcustom mode-for-temp-buffer 'temp-buffer-mode |
523 "*Mode that help buffers are put into.") | |
524 | |
442 | 525 (defvar help-sticky-window nil |
526 ;; Window into which help buffers will be displayed, rather than | |
527 ;; always searching for a new one. This is INTERNAL and liable to | |
528 ;; change its interface and/or name at any moment. It should be | |
529 ;; bound, not set. | |
530 ) | |
531 | |
532 (defvar help-window-config nil) | |
533 | |
534 (make-variable-buffer-local 'help-window-config) | |
535 (put 'help-window-config 'permanent-local t) | |
536 | |
1123 | 537 (defmacro with-displaying-temp-buffer (name &rest body) |
2030 | 538 "Make a help buffer with given NAME and evaluate BODY, sending stdout there. |
1123 | 539 |
540 Use this function for displaying information in temporary buffers, where the | |
541 user will typically view the information and then exit using | |
542 \\<temp-buffer-mode-map>\\[help-mode-quit]. | |
863 | 543 |
2030 | 544 On exit from this form, the buffer is put into the mode specified in |
545 `mode-for-temp-buffer' and displayed, typically in a popup window. Ie, | |
546 the buffer is a scratchpad which is displayed all at once in formatted | |
547 form. | |
548 | |
549 N.B. Write to this buffer with functions like `princ', not `insert'." | |
1123 | 550 `(let* ((winconfig (current-window-configuration)) |
551 (was-one-window (one-window-p)) | |
552 (buffer-name ,name) | |
553 (help-not-visible | |
554 (not (and (windows-of-buffer buffer-name) ;shortcut | |
555 (memq (selected-frame) | |
556 (mapcar 'window-frame | |
557 (windows-of-buffer buffer-name))))))) | |
428 | 558 (help-register-and-maybe-prune-excess buffer-name) |
442 | 559 ;; if help-sticky-window is bogus or deleted, get rid of it. |
560 (if (and help-sticky-window (or (not (windowp help-sticky-window)) | |
561 (not (window-live-p help-sticky-window)))) | |
562 (setq help-sticky-window nil)) | |
563 (prog1 | |
564 (let ((temp-buffer-show-function | |
565 (if help-sticky-window | |
566 #'(lambda (buffer) | |
567 (set-window-buffer help-sticky-window buffer)) | |
568 temp-buffer-show-function))) | |
569 (with-output-to-temp-buffer buffer-name | |
1123 | 570 (prog1 (progn ,@body) |
442 | 571 (save-excursion |
572 (set-buffer standard-output) | |
1123 | 573 (funcall mode-for-temp-buffer))))) |
428 | 574 (let ((helpwin (get-buffer-window buffer-name))) |
575 (when helpwin | |
1123 | 576 ;; If the temp buffer is already displayed on this |
442 | 577 ;; frame, don't override the previous configuration |
578 (when help-not-visible | |
579 (with-current-buffer (window-buffer helpwin) | |
580 (setq help-window-config winconfig))) | |
428 | 581 (when help-selects-help-window |
582 (select-window helpwin)) | |
583 (cond ((eq helpwin (selected-window)) | |
584 (display-message 'command | |
1123 | 585 (substitute-command-keys "Type \\[help-mode-quit] to remove window, \\[scroll-up] to scroll the text."))) |
428 | 586 (was-one-window |
587 (display-message 'command | |
1123 | 588 (substitute-command-keys "Type \\[delete-other-windows] to remove window, \\[scroll-other-window] to scroll the text."))) |
428 | 589 (t |
590 (display-message 'command | |
1123 | 591 (substitute-command-keys "Type \\[switch-to-buffer-other-window] to restore the other window, \\[scroll-other-window] to scroll the text."))))))))) |
592 | |
593 (put 'with-displaying-temp-buffer 'lisp-indent-function 1) | |
594 | |
595 (defun with-displaying-help-buffer (thunk &optional name) | |
596 "Form which makes a help buffer with given NAME and evaluates BODY there. | |
597 The actual name of the buffer is generated by the function `help-buffer-name'. | |
598 | |
599 Use this function for displaying help when C-h something is pressed or | |
600 in similar situations. Do *not* use it when you are displaying a help | |
601 message and then prompting for input in the minibuffer -- this macro | |
602 usually selects the help buffer, which is not what you want in those | |
603 situations." | |
604 (let ((mode-for-temp-buffer mode-for-help)) | |
605 (with-displaying-temp-buffer (help-buffer-name name) | |
606 (funcall thunk)))) | |
428 | 607 |
608 (defun describe-key (key) | |
609 "Display documentation of the function invoked by KEY. | |
610 KEY is a string, or vector of events. | |
611 When called interactively, KEY may also be a menu selection." | |
612 (interactive "kDescribe key: ") | |
613 (let ((defn (key-or-menu-binding key)) | |
614 (key-string (key-description key))) | |
615 (if (or (null defn) (integerp defn)) | |
616 (message "%s is undefined" key-string) | |
617 (with-displaying-help-buffer | |
618 (lambda () | |
619 (princ key-string) | |
620 (princ " runs ") | |
621 (if (symbolp defn) | |
622 (princ (format "`%s'" defn)) | |
623 (princ defn)) | |
624 (princ "\n\n") | |
625 (cond ((or (stringp defn) (vectorp defn)) | |
626 (let ((cmd (key-binding defn))) | |
627 (if (not cmd) | |
628 (princ "a keyboard macro") | |
629 (progn | |
630 (princ "a keyboard macro which runs the command ") | |
631 (princ cmd) | |
632 (princ ":\n\n") | |
633 (if (documentation cmd) (princ (documentation cmd))))))) | |
634 ((and (consp defn) (not (eq 'lambda (car-safe defn)))) | |
635 (let ((describe-function-show-arglist nil)) | |
636 (describe-function-1 (car defn)))) | |
637 ((symbolp defn) | |
638 (describe-function-1 defn)) | |
639 ((documentation defn) | |
640 (princ (documentation defn))) | |
641 (t | |
642 (princ "not documented")))) | |
643 (format "key `%s'" key-string))))) | |
644 | |
645 (defun describe-mode () | |
646 "Display documentation of current major mode and minor modes. | |
647 For this to work correctly for a minor mode, the mode's indicator variable | |
648 \(listed in `minor-mode-alist') must also be a function whose documentation | |
649 describes the minor mode." | |
650 (interactive) | |
651 (with-displaying-help-buffer | |
652 (lambda () | |
653 ;; XEmacs change: print the major-mode documentation before | |
654 ;; the minor modes. | |
655 (princ mode-name) | |
656 (princ " mode:\n") | |
657 (princ (documentation major-mode)) | |
658 (princ "\n\n----\n\n") | |
659 (let ((minor-modes minor-mode-alist)) | |
660 (while minor-modes | |
661 (let* ((minor-mode (car (car minor-modes))) | |
662 (indicator (car (cdr (car minor-modes))))) | |
663 ;; Document a minor mode if it is listed in minor-mode-alist, | |
664 ;; bound locally in this buffer, non-nil, and has a function | |
665 ;; definition. | |
666 (if (and (boundp minor-mode) | |
667 (symbol-value minor-mode) | |
668 (fboundp minor-mode)) | |
669 (let ((pretty-minor-mode minor-mode)) | |
670 (if (string-match "-mode\\'" (symbol-name minor-mode)) | |
671 (setq pretty-minor-mode | |
672 (capitalize | |
673 (substring (symbol-name minor-mode) | |
674 0 (match-beginning 0))))) | |
675 (while (and (consp indicator) (extentp (car indicator))) | |
676 (setq indicator (cdr indicator))) | |
677 (while (and indicator (symbolp indicator)) | |
678 (setq indicator (symbol-value indicator))) | |
732 | 679 (princ (format "%s minor mode (%s):\n" |
680 pretty-minor-mode | |
681 (if indicator | |
682 (format "indicator%s" indicator) | |
683 "no indicator"))) | |
428 | 684 (princ (documentation minor-mode)) |
685 (princ "\n\n----\n\n")))) | |
686 (setq minor-modes (cdr minor-modes))))) | |
687 (format "%s mode" mode-name))) | |
688 | |
689 ;; So keyboard macro definitions are documented correctly | |
690 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro)) | |
691 | |
462 | 692 ;; view a read-only file intelligently |
693 (defun Help-find-file (file) | |
694 (if (fboundp 'view-file) | |
695 (view-file file) | |
696 (find-file-read-only file) | |
697 (goto-char (point-min)))) | |
698 | |
428 | 699 (defun describe-distribution () |
700 "Display info on how to obtain the latest version of XEmacs." | |
701 (interactive) | |
2537 | 702 (save-window-excursion |
703 (info) | |
704 (Info-find-node "xemacs-faq" "Q1.1.1")) | |
705 (switch-to-buffer "*info*")) | |
428 | 706 |
707 (defun describe-beta () | |
708 "Display info on how to deal with Beta versions of XEmacs." | |
709 (interactive) | |
2537 | 710 (save-window-excursion |
711 (info "(beta)Top")) | |
712 (switch-to-buffer "*info*")) | |
428 | 713 |
714 (defun describe-copying () | |
715 "Display info on how you may redistribute copies of XEmacs." | |
716 (interactive) | |
462 | 717 (Help-find-file (locate-data-file "COPYING"))) |
428 | 718 |
719 (defun describe-pointer () | |
720 "Show a list of all defined mouse buttons, and their definitions." | |
721 (interactive) | |
722 (describe-bindings nil t)) | |
723 | |
724 (defun describe-no-warranty () | |
725 "Display info on all the kinds of warranty XEmacs does NOT have." | |
726 (interactive) | |
727 (describe-copying) | |
728 (let (case-fold-search) | |
729 (search-forward "NO WARRANTY") | |
730 (recenter 0))) | |
731 | |
732 (defun describe-bindings (&optional prefix mouse-only-p) | |
733 "Show a list of all defined keys, and their definitions. | |
734 The list is put in a buffer, which is displayed. | |
444 | 735 If optional first argument PREFIX is supplied, only commands |
736 which start with that sequence of keys are described. | |
737 If optional second argument MOUSE-ONLY-P (prefix arg, interactively) | |
738 is non-nil then only the mouse bindings are displayed." | |
428 | 739 (interactive (list nil current-prefix-arg)) |
740 (with-displaying-help-buffer | |
741 (lambda () | |
742 (describe-bindings-1 prefix mouse-only-p)) | |
743 (format "bindings for %s" major-mode))) | |
744 | |
745 (defun describe-bindings-1 (&optional prefix mouse-only-p) | |
746 (let ((heading (if mouse-only-p | |
747 (gettext "button binding\n------ -------\n") | |
748 (gettext "key binding\n--- -------\n"))) | |
749 (buffer (current-buffer)) | |
750 (minor minor-mode-map-alist) | |
430 | 751 (extent-maps (mapcar-extents |
752 'extent-keymap | |
753 nil (current-buffer) (point) (point) nil 'keymap)) | |
428 | 754 (local (current-local-map)) |
755 (shadow '())) | |
756 (set-buffer standard-output) | |
430 | 757 (while extent-maps |
758 (insert "Bindings for Text Region:\n" | |
759 heading) | |
760 (describe-bindings-internal | |
761 (car extent-maps) nil shadow prefix mouse-only-p) | |
762 (insert "\n") | |
763 (setq shadow (cons (car extent-maps) shadow) | |
764 extent-maps (cdr extent-maps))) | |
428 | 765 (while minor |
766 (let ((sym (car (car minor))) | |
767 (map (cdr (car minor)))) | |
768 (if (symbol-value-in-buffer sym buffer nil) | |
769 (progn | |
770 (insert (format "Minor Mode Bindings for `%s':\n" | |
771 sym) | |
772 heading) | |
773 (describe-bindings-internal map nil shadow prefix mouse-only-p) | |
774 (insert "\n") | |
775 (setq shadow (cons map shadow)))) | |
776 (setq minor (cdr minor)))) | |
777 (if local | |
778 (progn | |
779 (insert "Local Bindings:\n" heading) | |
780 (describe-bindings-internal local nil shadow prefix mouse-only-p) | |
781 (insert "\n") | |
782 (setq shadow (cons local shadow)))) | |
771 | 783 (if (console-on-window-system-p) |
784 (progn | |
785 (insert "Global Window-System-Only Bindings:\n" heading) | |
786 (describe-bindings-internal global-window-system-map nil | |
787 shadow prefix mouse-only-p) | |
788 (push global-window-system-map shadow)) | |
789 (insert "Global TTY-Only Bindings:\n" heading) | |
790 (describe-bindings-internal global-tty-map nil | |
791 shadow prefix mouse-only-p) | |
792 (push global-tty-map shadow)) | |
793 (insert "\nGlobal Bindings:\n" heading) | |
428 | 794 (describe-bindings-internal (current-global-map) |
795 nil shadow prefix mouse-only-p) | |
796 (when (and prefix function-key-map (not mouse-only-p)) | |
797 (insert "\nFunction key map translations:\n" heading) | |
798 (describe-bindings-internal function-key-map nil nil | |
799 prefix mouse-only-p)) | |
800 (set-buffer buffer) | |
801 standard-output)) | |
802 | |
803 (defun describe-prefix-bindings () | |
804 "Describe the bindings of the prefix used to reach this command. | |
805 The prefix described consists of all but the last event | |
806 of the key sequence that ran this command." | |
807 (interactive) | |
808 (let* ((key (this-command-keys)) | |
809 (prefix (make-vector (1- (length key)) nil)) | |
810 i) | |
811 (setq i 0) | |
812 (while (< i (length prefix)) | |
813 (aset prefix i (aref key i)) | |
814 (setq i (1+ i))) | |
815 (with-displaying-help-buffer | |
816 (lambda () | |
817 (princ "Key bindings starting with ") | |
818 (princ (key-description prefix)) | |
819 (princ ":\n\n") | |
820 (describe-bindings-1 prefix nil)) | |
821 (format "%s prefix" (key-description prefix))))) | |
822 | |
823 ;; Make C-h after a prefix, when not specifically bound, | |
824 ;; run describe-prefix-bindings. | |
825 (setq prefix-help-command 'describe-prefix-bindings) | |
826 | |
827 (defun describe-installation () | |
828 "Display a buffer showing information about this XEmacs was compiled." | |
829 (interactive) | |
4246 | 830 (if (and-boundp 'Installation-string |
831 (stringp Installation-string)) | |
428 | 832 (with-displaying-help-buffer |
833 (lambda () | |
4246 | 834 (princ Installation-string)) |
428 | 835 "Installation") |
4246 | 836 (error 'unimplemented "No Installation information available."))) |
428 | 837 |
838 (defun view-emacs-news () | |
839 "Display info on recent changes to XEmacs." | |
840 (interactive) | |
2986 | 841 (Help-find-file (expand-file-name "NEWS" data-directory))) |
428 | 842 |
3074 | 843 (defun view-xemacs-problems () |
844 "Display known problems with XEmacs." | |
845 (interactive) | |
846 (Help-find-file (expand-file-name "PROBLEMS" data-directory))) | |
847 | |
428 | 848 (defun xemacs-www-page () |
849 "Go to the XEmacs World Wide Web page." | |
850 (interactive) | |
776 | 851 (if-fboundp 'browse-url |
442 | 852 (browse-url "http://www.xemacs.org/") |
428 | 853 (error "xemacs-www-page requires browse-url"))) |
854 | |
855 (defun xemacs-www-faq () | |
856 "View the latest and greatest XEmacs FAQ using the World Wide Web." | |
857 (interactive) | |
776 | 858 (if-fboundp 'browse-url |
442 | 859 (browse-url "http://www.xemacs.org/faq/index.html") |
428 | 860 (error "xemacs-www-faq requires browse-url"))) |
861 | |
862 (defun xemacs-local-faq () | |
863 "View the local copy of the XEmacs FAQ. | |
864 If you have access to the World Wide Web, you should use `xemacs-www-faq' | |
865 instead, to ensure that you get the most up-to-date information." | |
866 (interactive) | |
867 (save-window-excursion | |
868 (info) | |
869 (Info-find-node "xemacs-faq" "Top")) | |
870 (switch-to-buffer "*info*")) | |
871 | |
462 | 872 (defun view-sample-init-el () |
873 "Display the sample init.el file." | |
874 (interactive) | |
875 (Help-find-file (locate-data-file "sample.init.el"))) | |
876 | |
428 | 877 (defcustom view-lossage-key-count 100 |
878 "*Number of keys `view-lossage' shows. | |
879 The maximum number of available keys is governed by `recent-keys-ring-size'." | |
880 :type 'integer | |
881 :group 'help) | |
882 | |
883 (defcustom view-lossage-message-count 100 | |
884 "*Number of minibuffer messages `view-lossage' shows." | |
885 :type 'integer | |
886 :group 'help) | |
887 | |
888 (defun print-recent-messages (n) | |
889 "Print N most recent messages to standard-output, most recent first. | |
890 If N is nil, all messages will be printed." | |
793 | 891 (clear-message) ;; make sure current message goes into log |
428 | 892 (save-excursion |
893 (let ((buffer (get-buffer-create " *Message-Log*")) | |
894 oldpoint extent) | |
895 (goto-char (point-max buffer) buffer) | |
896 (set-buffer standard-output) | |
897 (while (and (not (bobp buffer)) | |
898 (or (null n) (>= (decf n) 0))) | |
899 (setq oldpoint (point buffer)) | |
900 (setq extent (extent-at oldpoint buffer | |
901 'message-multiline nil 'before)) | |
902 ;; If the message was multiline, move all the way to the | |
903 ;; beginning. | |
904 (if extent | |
905 (goto-char (extent-start-position extent) buffer) | |
906 (forward-line -1 buffer)) | |
907 (insert-buffer-substring buffer (point buffer) oldpoint))))) | |
908 | |
793 | 909 (defun view-warnings () |
910 "Display warnings issued." | |
911 (interactive) | |
912 (with-displaying-help-buffer | |
913 (lambda () | |
914 (let ((buf (get-buffer "*Warnings*"))) | |
915 (when buf | |
916 (save-excursion | |
917 (set-buffer standard-output) | |
918 (map-extents | |
919 #'(lambda (extent arg) | |
920 (goto-char (point-min)) | |
921 (insert (extent-string extent))) | |
922 buf))))) | |
923 "warnings")) | |
924 | |
925 (defun view-lossage (&optional no-keys) | |
428 | 926 "Display recent input keystrokes and recent minibuffer messages. |
927 The number of keys shown is controlled by `view-lossage-key-count'. | |
1038 | 928 The number of messages shown is controlled by `view-lossage-message-count'. |
929 | |
930 If optional arg NO-KEYS (prefix arg, interactively) is non-nil, | |
931 then recent input keystrokes output is omitted." | |
932 (interactive "P") | |
428 | 933 (with-displaying-help-buffer |
934 (lambda () | |
793 | 935 (unless no-keys |
936 (princ (key-description (recent-keys view-lossage-key-count))) | |
937 (save-excursion | |
938 (set-buffer standard-output) | |
939 (goto-char (point-min)) | |
940 (insert "Recent keystrokes:\n\n") | |
941 (while (progn (move-to-column 50) (not (eobp))) | |
942 (search-forward " " nil t) | |
943 (insert "\n"))) | |
944 (princ "\n\n\n")) | |
945 ;; Copy the messages from " *Message-Log*", reversing their order and | |
946 ;; handling multiline messages correctly. | |
947 (princ "Recent minibuffer messages (most recent first):\n\n") | |
428 | 948 (print-recent-messages view-lossage-message-count)) |
949 "lossage")) | |
950 | |
951 (define-function 'help 'help-for-help) | |
952 | |
953 (make-help-screen help-for-help | |
954 "A B C F I K L M N P S T V W C-c C-d C-f C-i C-k C-n C-w; ? for more help:" | |
502 | 955 (concat |
956 "Type a Help option: | |
428 | 957 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.) |
958 | |
502 | 959 Help on key bindings: |
960 | |
961 \\[describe-bindings] Table of all key bindings. | |
962 \\[describe-key-briefly] Type a key sequence or select a menu item; | |
963 it displays the corresponding command name. | |
964 \\[describe-key] Type a key sequence or select a menu item; | |
965 it displays the documentation for the command bound to that key. | |
966 (Terser but more up-to-date than what's in the manual.) | |
967 \\[Info-goto-emacs-key-command-node] Type a key sequence or select a menu item; | |
968 it jumps to the full documentation in the XEmacs User's Manual | |
969 for the corresponding command. | |
970 \\[view-lossage] Recent input keystrokes and minibuffer messages. | |
971 \\[describe-mode] Documentation of current major and minor modes. | |
972 \\[describe-pointer] Table of all mouse-button bindings. | |
973 \\[where-is] Type a command name; it displays which keystrokes invoke that command. | |
974 | |
975 Help on functions and variables: | |
976 | |
428 | 977 \\[hyper-apropos] Type a substring; it shows a hypertext list of |
978 functions and variables that contain that substring. | |
502 | 979 \\[command-apropos] Older version of apropos; superseded by previous command. |
980 \\[apropos-documentation] Type a substring; it shows a hypertext list of | |
981 functions and variables containing that substring anywhere | |
982 in their documentation. | |
983 \\[Info-goto-emacs-command-node] Type a command name; it jumps to the full documentation | |
984 in the XEmacs User's Manual. | |
985 \\[describe-function] Type a command or function name; it shows its documentation. | |
986 (Terser but more up-to-date than what's in the manual.) | |
987 \\[Info-elisp-ref] Type a function name; it jumps to the full documentation | |
988 in the XEmacs Lisp Reference Manual. | |
989 \\[Info-search-index-in-xemacs-and-lispref] Type a substring; it looks it up in the indices of both | |
990 the XEmacs User's Manual and the XEmacs Lisp Reference Manual. | |
991 It jumps to the first match (preferring an exact match); you | |
992 can use `\\<Info-mode-map>\\[Info-index-next]\\<help-map>' to successively visit other matches. | |
993 \\[describe-variable] Type a variable name; it displays its documentation and value. | |
994 | |
995 Miscellaneous: | |
996 | |
997 " | |
998 (if (string-match "beta" emacs-version) | |
999 "\\[describe-beta] Special considerations about running a beta version of XEmacs. | |
1000 " | |
1001 "") | |
1002 " | |
3074 | 1003 \\[view-xemacs-problems] Known problems. |
428 | 1004 \\[customize] Customize Emacs options. |
502 | 1005 \\[describe-distribution] How to obtain XEmacs. |
1006 \\[describe-last-error] Information about the most recent error. | |
428 | 1007 \\[xemacs-local-faq] Local copy of the XEmacs FAQ. |
1008 \\[info] Info documentation reader. | |
1009 \\[Info-query] Type an Info file name; it displays it in Info reader. | |
502 | 1010 \\[describe-copying] XEmacs copying permission (General Public License). |
428 | 1011 \\[view-emacs-news] News of recent XEmacs changes. |
1012 \\[finder-by-keyword] Type a topic keyword; it finds matching packages. | |
1013 \\[describe-syntax] Contents of syntax table with explanations. | |
502 | 1014 \\[view-sample-init-el] View the sample init.el that comes with XEmacs. |
428 | 1015 \\[help-with-tutorial] XEmacs learn-by-doing tutorial. |
502 | 1016 \\[describe-no-warranty] Information on absence of warranty for XEmacs." |
1017 ) | |
428 | 1018 help-map) |
1019 | |
1020 (defun function-called-at-point () | |
1021 "Return the function which is called by the list containing point. | |
1022 If that gives no function, return the function whose name is around point. | |
1023 If that doesn't give a function, return nil." | |
1024 (or (ignore-errors | |
1025 (save-excursion | |
1026 (save-restriction | |
1027 (narrow-to-region (max (point-min) (- (point) 1000)) | |
1028 (point-max)) | |
1029 (backward-up-list 1) | |
1030 (forward-char 1) | |
1031 (let (obj) | |
1032 (setq obj (read (current-buffer))) | |
1033 (and (symbolp obj) (fboundp obj) obj))))) | |
1034 (ignore-errors | |
1035 (with-syntax-table emacs-lisp-mode-syntax-table | |
1036 (save-excursion | |
1037 (or (not (zerop (skip-syntax-backward "_w"))) | |
1038 (eq (char-syntax (char-after (point))) ?w) | |
1039 (eq (char-syntax (char-after (point))) ?_) | |
1040 (forward-sexp -1)) | |
1041 (skip-chars-forward "`'") | |
1042 (let ((obj (read (current-buffer)))) | |
1043 (and (symbolp obj) (fboundp obj) obj))))))) | |
1044 | |
1045 (defun function-at-point () | |
1046 "Return the function whose name is around point. | |
1047 If that gives no function, return the function which is called by the | |
1048 list containing point. If that doesn't give a function, return nil." | |
1049 (or (ignore-errors | |
1050 (with-syntax-table emacs-lisp-mode-syntax-table | |
1051 (save-excursion | |
1052 (or (not (zerop (skip-syntax-backward "_w"))) | |
1053 (eq (char-syntax (char-after (point))) ?w) | |
1054 (eq (char-syntax (char-after (point))) ?_) | |
1055 (forward-sexp -1)) | |
1056 (skip-chars-forward "`'") | |
1057 (let ((obj (read (current-buffer)))) | |
1058 (and (symbolp obj) (fboundp obj) obj))))) | |
1059 (ignore-errors | |
1060 (save-excursion | |
1061 (save-restriction | |
1062 (narrow-to-region (max (point-min) (- (point) 1000)) | |
1063 (point-max)) | |
1064 (backward-up-list 1) | |
1065 (forward-char 1) | |
1066 (let (obj) | |
1067 (setq obj (read (current-buffer))) | |
1068 (and (symbolp obj) (fboundp obj) obj))))))) | |
1069 | |
442 | 1070 (defun function-at-event (event) |
1071 "Return the function whose name is around the position of EVENT. | |
1072 EVENT should be a mouse event. When calling from a popup or context menu, | |
1073 use `last-popup-menu-event' to find out where the mouse was clicked. | |
1074 \(You cannot use (interactive \"e\"), unfortunately. This returns a | |
1075 misc-user event.) | |
1076 | |
1077 If the event contains no position, or the position is not over text, or | |
1078 there is no function around that point, nil is returned." | |
1079 (if (and event (event-buffer event) (event-point event)) | |
1080 (save-excursion | |
1081 (set-buffer (event-buffer event)) | |
1082 (goto-char (event-point event)) | |
1083 (function-at-point)))) | |
1084 | |
428 | 1085 ;; Default to nil for the non-hackers? Not until we find a way to |
1086 ;; distinguish hackers from non-hackers automatically! | |
1087 (defcustom describe-function-show-arglist t | |
4695
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1088 "*If non-nil, describe-function will show the function's arglist." |
428 | 1089 :type 'boolean |
1090 :group 'help-appearance) | |
1091 | |
3368 | 1092 (define-obsolete-function-alias |
1093 ;; Moved to using the version in loadhist.el | |
1094 'describe-function-find-symbol | |
1095 'symbol-file) | |
428 | 1096 |
1097 (define-obsolete-function-alias | |
1098 'describe-function-find-file | |
3368 | 1099 'symbol-file) |
428 | 1100 |
1101 (defun describe-function (function) | |
1102 "Display the full documentation of FUNCTION (a symbol). | |
1103 When run interactively, it defaults to any function found by | |
1104 `function-at-point'." | |
1105 (interactive | |
1106 (let* ((fn (function-at-point)) | |
1107 (val (let ((enable-recursive-minibuffers t)) | |
1108 (completing-read | |
1109 (if fn | |
1110 (format (gettext "Describe function (default %s): ") | |
1111 fn) | |
1112 (gettext "Describe function: ")) | |
430 | 1113 obarray 'fboundp t nil 'function-history |
1114 (symbol-name fn))))) | |
1115 (list (intern val)))) | |
428 | 1116 (with-displaying-help-buffer |
1117 (lambda () | |
1118 (describe-function-1 function) | |
1119 ;; Return the text we displayed. | |
1120 (buffer-string nil nil standard-output)) | |
1121 (format "function `%s'" function))) | |
1122 | |
1123 (defun function-obsolete-p (function) | |
1124 "Return non-nil if FUNCTION is obsolete." | |
1125 (not (null (get function 'byte-obsolete-info)))) | |
1126 | |
1127 (defun function-obsoleteness-doc (function) | |
1128 "If FUNCTION is obsolete, return a string describing this." | |
1129 (let ((obsolete (get function 'byte-obsolete-info))) | |
1130 (if obsolete | |
1131 (format "Obsolete; %s" | |
1132 (if (stringp (car obsolete)) | |
1133 (car obsolete) | |
1134 (format "use `%s' instead." (car obsolete))))))) | |
1135 | |
1136 (defun function-compatible-p (function) | |
1137 "Return non-nil if FUNCTION is present for Emacs compatibility." | |
1138 (not (null (get function 'byte-compatible-info)))) | |
1139 | |
1140 (defun function-compatibility-doc (function) | |
1141 "If FUNCTION is Emacs compatible, return a string describing this." | |
1142 (let ((compatible (get function 'byte-compatible-info))) | |
1143 (if compatible | |
1144 (format "Emacs Compatible; %s" | |
1145 (if (stringp (car compatible)) | |
1146 (car compatible) | |
1147 (format "use `%s' instead." (car compatible))))))) | |
1148 | |
1149 ;Here are all the possibilities below spelled out, for the benefit | |
1150 ;of the I18N3 snarfer. | |
1151 ; | |
1152 ;(gettext "a built-in function") | |
1153 ;(gettext "an interactive built-in function") | |
1154 ;(gettext "a built-in macro") | |
1155 ;(gettext "an interactive built-in macro") | |
1156 ;(gettext "a compiled Lisp function") | |
1157 ;(gettext "an interactive compiled Lisp function") | |
1158 ;(gettext "a compiled Lisp macro") | |
1159 ;(gettext "an interactive compiled Lisp macro") | |
1160 ;(gettext "a Lisp function") | |
1161 ;(gettext "an interactive Lisp function") | |
1162 ;(gettext "a Lisp macro") | |
1163 ;(gettext "an interactive Lisp macro") | |
1164 ;(gettext "an autoloaded Lisp function") | |
1165 ;(gettext "an interactive autoloaded Lisp function") | |
1166 ;(gettext "an autoloaded Lisp macro") | |
1167 ;(gettext "an interactive autoloaded Lisp macro") | |
1168 | |
1169 ;; taken out of `describe-function-1' | |
1170 (defun function-arglist (function) | |
1171 "Return a string giving the argument list of FUNCTION. | |
1172 For example: | |
1173 | |
1174 (function-arglist 'function-arglist) | |
4694
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1175 => \"(function-arglist FUNCTION)\" |
428 | 1176 |
1177 This function is used by `describe-function-1' to list function | |
1178 arguments in the standard Lisp style." | |
440 | 1179 (let* ((fnc (indirect-function function)) |
1180 (fndef (if (eq (car-safe fnc) 'macro) | |
1181 (cdr fnc) | |
1182 fnc)) | |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1183 (args (cdr (function-documentation-1 function t))) |
428 | 1184 (arglist |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1185 (or args |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1186 (cond ((compiled-function-p fndef) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1187 (compiled-function-arglist fndef)) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1188 ((eq (car-safe fndef) 'lambda) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1189 (nth 1 fndef)) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1190 ((or (subrp fndef) (eq 'autoload (car-safe fndef))) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1191 |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1192 ;; If there are no arguments documented for the |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1193 ;; subr, rather don't print anything. |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1194 (cond ((null args) t) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1195 ((equal args "") nil) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1196 (args))) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1197 (t t)))) |
4694
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1198 (print-gensym nil)) |
428 | 1199 (cond ((listp arglist) |
1200 (prin1-to-string | |
4694
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1201 (cons function (loop |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1202 for arg in arglist |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1203 collect (if (memq arg '(&optional &rest)) |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1204 arg |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1205 (make-symbol (upcase (symbol-name |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1206 arg)))))) |
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1207 |
428 | 1208 t)) |
1209 ((stringp arglist) | |
5076
d555581e3cba
fix issues with display of argument docstrings
Ben Wing <ben@xemacs.org>
parents:
5071
diff
changeset
|
1210 (if (> (length arglist) 0) |
d555581e3cba
fix issues with display of argument docstrings
Ben Wing <ben@xemacs.org>
parents:
5071
diff
changeset
|
1211 (format "(%s %s)" function arglist) |
d555581e3cba
fix issues with display of argument docstrings
Ben Wing <ben@xemacs.org>
parents:
5071
diff
changeset
|
1212 (format "(%s)" function)))))) |
428 | 1213 |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1214 ;; If STRIP-ARGLIST is true, return a cons (DOC . ARGS) of the documentation |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1215 ;; with any embedded arglist stripped out, and the arglist that was stripped |
5071 | 1216 ;; out. If STRIP-ARGLIST is false, the cons will be (FULL-DOC . nil), |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1217 ;; where FULL-DOC is the full documentation without the embedded arglist |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1218 ;; stripped out. |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1219 (defun function-documentation-1 (function &optional strip-arglist) |
428 | 1220 (let ((doc (condition-case nil |
1221 (or (documentation function) | |
1222 (gettext "not documented")) | |
2275 | 1223 (void-function "(alias for undefined function)") |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1224 (error "(unexpected error from `documentation')"))) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1225 args) |
4695
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1226 (when (and strip-arglist |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1227 (string-match "[\n\t ]*\narguments: ?(\\(.*\\))\n?\\'" doc)) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1228 (setq args (match-string 1 doc)) |
4695
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1229 (setq doc (substring doc 0 (match-beginning 0))) |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1230 (and args (setq args (replace-in-string args "[ ]*\\\\\n[ \t]*" " " t))) |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1231 (and (eql 0 (length doc)) (setq doc (gettext "not documented")))) |
5070
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1232 (cons doc args))) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1233 |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1234 (defun function-documentation (function &optional strip-arglist) |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1235 "Return a string giving the documentation for FUNCTION, if any. |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1236 If the optional argument STRIP-ARGLIST is non-nil, remove the arglist |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1237 part of the documentation of internal subroutines, CL lambda forms, etc." |
b0f4adffca7d
fix so that CL docstrings (with &key, etc.) handled properly
Ben Wing <ben@xemacs.org>
parents:
5017
diff
changeset
|
1238 (car (function-documentation-1 function strip-arglist))) |
442 | 1239 |
462 | 1240 ;; replacement for `princ' that puts the text in the specified face, |
1241 ;; if possible | |
1242 (defun Help-princ-face (object face) | |
1243 (cond ((bufferp standard-output) | |
464 | 1244 (let ((opoint (point standard-output))) |
1245 (princ object) | |
1246 (put-nonduplicable-text-property opoint (point standard-output) | |
1247 'face face standard-output))) | |
1248 ((markerp standard-output) | |
1249 (let ((buf (marker-buffer standard-output)) | |
1250 (pos (marker-position standard-output))) | |
1251 (princ object) | |
1252 (put-nonduplicable-text-property | |
1253 pos (marker-position standard-output) 'face face buf))) | |
1779 | 1254 (t (princ object)))) |
462 | 1255 |
1256 ;; replacement for `prin1' that puts the text in the specified face, | |
1257 ;; if possible | |
1258 (defun Help-prin1-face (object face) | |
1259 (cond ((bufferp standard-output) | |
464 | 1260 (let ((opoint (point standard-output))) |
1261 (prin1 object) | |
1262 (put-nonduplicable-text-property opoint (point standard-output) | |
1263 'face face standard-output))) | |
1264 ((markerp standard-output) | |
1265 (let ((buf (marker-buffer standard-output)) | |
1266 (pos (marker-position standard-output))) | |
1267 (prin1 object) | |
1268 (put-nonduplicable-text-property | |
1269 pos (marker-position standard-output) 'face face buf))) | |
1779 | 1270 (t (prin1 object)))) |
462 | 1271 |
442 | 1272 (defvar help-symbol-regexp |
1273 (let ((sym-char "[+a-zA-Z0-9_:*]") | |
1274 (sym-char-no-dash "[-+a-zA-Z0-9_:*]")) | |
1275 (concat "\\(" | |
1276 ;; a symbol with a - in it. | |
1277 "\\<\\(" sym-char-no-dash "+\\(-" sym-char-no-dash "+\\)+\\)\\>" | |
1278 "\\|" | |
1279 "`\\(" sym-char "+\\)'" | |
1280 "\\)"))) | |
1281 | |
1282 (defun help-symbol-run-function-1 (ev ex fun) | |
1283 (let ((help-sticky-window | |
1284 ;; if we were called from a help buffer, make sure the new help | |
1285 ;; goes in the same window. | |
1286 (if (and (event-buffer ev) | |
1287 (symbol-value-in-buffer 'help-window-config | |
1288 (event-buffer ev))) | |
1289 (event-window ev) | |
1290 help-sticky-window))) | |
1291 (funcall fun (extent-property ex 'help-symbol)))) | |
1292 | |
1293 (defun help-symbol-run-function (fun) | |
1294 (let ((ex (extent-at-event last-popup-menu-event 'help-symbol))) | |
1295 (when ex | |
1296 (help-symbol-run-function-1 last-popup-menu-event ex fun)))) | |
1297 | |
1298 (defvar help-symbol-function-context-menu | |
462 | 1299 '(["View %_Documentation" (help-symbol-run-function 'describe-function)] |
4103 | 1300 ["Find %_Function Source" (help-symbol-run-function 'find-function) |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1301 (fboundp 'find-function)] |
462 | 1302 ["Find %_Tag" (help-symbol-run-function 'find-tag)] |
442 | 1303 )) |
1304 | |
1305 (defvar help-symbol-variable-context-menu | |
462 | 1306 '(["View %_Documentation" (help-symbol-run-function 'describe-variable)] |
4103 | 1307 ["Find %_Variable Source" (help-symbol-run-function 'find-variable) |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1308 (fboundp 'find-variable)] |
462 | 1309 ["Find %_Tag" (help-symbol-run-function 'find-tag)] |
442 | 1310 )) |
1311 | |
1312 (defvar help-symbol-function-and-variable-context-menu | |
462 | 1313 '(["View Function %_Documentation" (help-symbol-run-function |
442 | 1314 'describe-function)] |
1315 ["View Variable D%_ocumentation" (help-symbol-run-function | |
1316 'describe-variable)] | |
4103 | 1317 ["Find %_Function Source" (help-symbol-run-function 'find-function) |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1318 (fboundp 'find-function)] |
4103 | 1319 ["Find %_Variable Source" (help-symbol-run-function 'find-variable) |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1320 (fboundp 'find-variable)] |
462 | 1321 ["Find %_Tag" (help-symbol-run-function 'find-tag)] |
442 | 1322 )) |
1323 | |
1324 (defun frob-help-extents (buffer) | |
1325 ;; Look through BUFFER, starting at the buffer's point and continuing | |
1326 ;; till end of file, and find documented functions and variables. | |
1327 ;; any such symbol found is tagged with an extent, that sets up these | |
1328 ;; properties: | |
1329 ;; 1. mouse-face is 'highlight (so the extent gets highlighted on mouse over) | |
1330 ;; 2. help-symbol is the name of the symbol. | |
464 | 1331 ;; 3. face is 'hyper-apropos-hyperlink. |
462 | 1332 ;; 4. context-menu is a list of context menu items, specific to whether |
442 | 1333 ;; the symbol is a function, variable, or both. |
462 | 1334 ;; 5. activate-function will cause the function or variable to be described, |
442 | 1335 ;; replacing the existing help contents. |
1336 (save-excursion | |
1337 (set-buffer buffer) | |
1338 (let (b e name) | |
1339 (while (re-search-forward help-symbol-regexp nil t) | |
1340 (setq b (or (match-beginning 2) (match-beginning 4))) | |
1341 (setq e (or (match-end 2) (match-end 4))) | |
1342 (setq name (buffer-substring b e)) | |
1343 (let* ((sym (intern-soft name)) | |
1344 (var (and sym (boundp sym) | |
1345 (documentation-property sym | |
1346 'variable-documentation t))) | |
1347 (fun (and sym (fboundp sym) | |
2275 | 1348 (condition-case nil |
1349 (documentation sym t) | |
1350 (void-function "(alias for undefined function)") | |
1351 (error "(unexpected error from `documention')"))))) | |
442 | 1352 (when (or var fun) |
1353 (let ((ex (make-extent b e))) | |
622 | 1354 (require 'hyper-apropos) |
3368 | 1355 |
442 | 1356 (set-extent-property ex 'mouse-face 'highlight) |
1357 (set-extent-property ex 'help-symbol sym) | |
464 | 1358 (set-extent-property ex 'face 'hyper-apropos-hyperlink) |
442 | 1359 (set-extent-property |
1360 ex 'context-menu | |
1361 (cond ((and var fun) | |
1362 help-symbol-function-and-variable-context-menu) | |
1363 (var help-symbol-variable-context-menu) | |
1364 (fun help-symbol-function-context-menu))) | |
1365 (set-extent-property | |
1366 ex 'activate-function | |
1367 (if fun | |
1368 #'(lambda (ev ex) | |
1369 (help-symbol-run-function-1 ev ex 'describe-function)) | |
1370 #'(lambda (ev ex) | |
1371 (help-symbol-run-function-1 ev ex 'describe-variable)))) | |
1372 ))))))) ;; 11 parentheses! | |
428 | 1373 |
1374 (defun describe-function-1 (function &optional nodoc) | |
1375 "This function does the work for `describe-function'." | |
462 | 1376 (princ "`") |
1377 ;; (Help-princ-face function 'font-lock-function-name-face) overkill | |
1378 (princ function) | |
1379 (princ "' is ") | |
428 | 1380 (let* ((def function) |
4595
a1a8728fec10
Distinguish between special forms and subrs, #'describe-function-1.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4535
diff
changeset
|
1381 aliases file-name kbd-macro-p fndef macrop) |
428 | 1382 (while (and (symbolp def) (fboundp def)) |
1383 (when (not (eq def function)) | |
1384 (setq aliases | |
1385 (if aliases | |
1386 ;; I18N3 Need gettext due to concat | |
1387 (concat aliases | |
1388 (format | |
1389 "\n which is an alias for `%s', " | |
1390 (symbol-name def))) | |
1391 (format "an alias for `%s', " (symbol-name def))))) | |
1392 (setq def (symbol-function def))) | |
1393 (if (eq 'macro (car-safe def)) | |
1394 (setq fndef (cdr def) | |
1395 macrop t) | |
1396 (setq fndef def)) | |
1397 (if aliases (princ aliases)) | |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1398 (labels |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1399 ((int (string an-p macro-p) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1400 (princ (format |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1401 (gettext (concat |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1402 (cond ((commandp def) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1403 "an interactive ") |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1404 (an-p "an ") |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1405 (t "a ")) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1406 "%s" |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1407 (cond |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1408 ((eq 'neither macro-p) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1409 "") |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1410 (macro-p " macro") |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1411 (t " function")))) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1412 string)))) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1413 (declare (inline int)) |
428 | 1414 (cond ((or (stringp def) (vectorp def)) |
1415 (princ "a keyboard macro.") | |
1416 (setq kbd-macro-p t)) | |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4695
diff
changeset
|
1417 ((special-operator-p fndef) |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1418 (int "built-in special operator" nil 'neither)) |
428 | 1419 ((subrp fndef) |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1420 (int "built-in" nil macrop)) |
428 | 1421 ((compiled-function-p fndef) |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1422 (int (concat (if (built-in-symbol-file function 'defun) |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1423 "built-in " |
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1424 "") "compiled Lisp") nil macrop)) |
428 | 1425 ((eq (car-safe fndef) 'lambda) |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1426 (int "Lisp" nil macrop)) |
428 | 1427 ((eq (car-safe def) 'autoload) |
5594
cc8ea7ed4286
Mention when compiled functions are built-in, help.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5473
diff
changeset
|
1428 (int "autoloaded Lisp" t (elt def 4))) |
428 | 1429 ((and (symbolp def) (not (fboundp def))) |
1430 (princ "a symbol with a void (unbound) function definition.")) | |
1431 (t | |
1432 nil))) | |
1433 (princ "\n") | |
1434 (or file-name | |
4535
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1435 (setq file-name (symbol-file function 'defun))) |
3368 | 1436 (when file-name |
1437 (princ " -- loaded from \"") | |
1438 (if (not (bufferp standard-output)) | |
1439 (princ file-name) | |
1440 (let ((opoint (point standard-output)) | |
1441 e) | |
1442 (require 'hyper-apropos) | |
1443 (princ file-name) | |
1444 (setq e (make-extent opoint (point standard-output) | |
1445 standard-output)) | |
1446 (set-extent-property e 'face 'hyper-apropos-hyperlink) | |
1447 (set-extent-property e 'mouse-face 'highlight) | |
1448 (set-extent-property e 'find-function-symbol function))) | |
1449 (princ "\"\n")) | |
428 | 1450 (if describe-function-show-arglist |
1451 (let ((arglist (function-arglist function))) | |
1452 (when arglist | |
464 | 1453 (require 'hyper-apropos) |
1454 (Help-princ-face arglist 'hyper-apropos-documentation) | |
428 | 1455 (terpri)))) |
1456 (terpri) | |
1457 (cond (kbd-macro-p | |
1458 (princ "These characters are executed:\n\n\t") | |
1459 (princ (key-description def)) | |
1460 (cond ((setq def (key-binding def)) | |
1461 (princ (format "\n\nwhich executes the command `%s'.\n\n" | |
1462 def)) | |
1463 (describe-function-1 def)))) | |
1464 (nodoc nil) | |
1465 (t | |
1466 ;; tell the user about obsoleteness. | |
1467 ;; If the function is obsolete and is aliased, don't | |
1468 ;; even bother to report the documentation, as a further | |
1469 ;; encouragement to use the new function. | |
1470 (let ((obsolete (function-obsoleteness-doc function)) | |
1471 (compatible (function-compatibility-doc function))) | |
1472 (when obsolete | |
1473 (princ obsolete) | |
1474 (terpri) | |
1475 (terpri)) | |
1476 (when compatible | |
1477 (princ compatible) | |
1478 (terpri) | |
1479 (terpri)) | |
1480 (unless (and obsolete aliases) | |
1481 (let ((doc (function-documentation function t))) | |
1482 (princ "Documentation:\n") | |
442 | 1483 (let ((oldp (point standard-output)) |
1484 newp) | |
1485 (princ doc) | |
1486 (setq newp (point standard-output)) | |
1487 (goto-char oldp standard-output) | |
1488 (frob-help-extents standard-output) | |
1489 (goto-char newp standard-output)) | |
428 | 1490 (unless (or (equal doc "") |
1491 (eq ?\n (aref doc (1- (length doc))))) | |
4335
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1492 (terpri))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1493 (when (commandp function) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1494 (princ "\nInvoked with:\n") |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1495 (let ((global-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1496 (where-is-internal function global-map)) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1497 (global-tty-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1498 (where-is-internal function global-tty-map)) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1499 (global-window-system-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1500 (where-is-internal function global-window-system-map))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1501 (if (or global-binding global-tty-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1502 global-window-system-binding) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1503 (if (and (equal global-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1504 global-tty-binding) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1505 (equal global-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1506 global-window-system-binding)) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1507 (princ |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1508 (substitute-command-keys |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1509 (format "\n\\[%s]" function))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1510 (when (and global-window-system-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1511 (not (equal global-window-system-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1512 global-binding))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1513 (princ |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1514 (format |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1515 "\n%s\n -- under window systems\n" |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1516 (mapconcat #'key-description |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1517 global-window-system-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1518 ", ")))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1519 (when (and global-tty-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1520 (not (equal global-tty-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1521 global-binding))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1522 (princ |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1523 (format |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1524 "\n%s\n -- under TTYs\n" |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1525 (mapconcat #'key-description |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1526 global-tty-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1527 ", ")))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1528 (when global-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1529 (princ |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1530 (format |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1531 "\n%s\n -- generally (that is, unless\ |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1532 overridden by TTY- or |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1533 window-system-specific mappings)\n" |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1534 (mapconcat #'key-description |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1535 global-binding |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1536 ", "))))) |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1537 (princ (substitute-command-keys |
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1538 (format "\n\\[%s]" function)))))))))))) |
428 | 1539 |
1540 ;;; [Obnoxious, whining people who complain very LOUDLY on Usenet | |
1541 ;;; are binding this to keys.] | |
1542 (defun describe-function-arglist (function) | |
1543 (interactive (list (or (function-at-point) | |
1544 (error "no function call at point")))) | |
1545 (message nil) | |
1546 (message (function-arglist function))) | |
1547 | |
1548 (defun variable-at-point () | |
1549 (ignore-errors | |
1550 (with-syntax-table emacs-lisp-mode-syntax-table | |
1551 (save-excursion | |
1552 (or (not (zerop (skip-syntax-backward "_w"))) | |
1553 (eq (char-syntax (char-after (point))) ?w) | |
1554 (eq (char-syntax (char-after (point))) ?_) | |
1555 (forward-sexp -1)) | |
1556 (skip-chars-forward "'") | |
1557 (let ((obj (read (current-buffer)))) | |
1558 (and (symbolp obj) (boundp obj) obj)))))) | |
1559 | |
442 | 1560 (defun variable-at-event (event) |
1561 "Return the variable whose name is around the position of EVENT. | |
1562 EVENT should be a mouse event. When calling from a popup or context menu, | |
1563 use `last-popup-menu-event' to find out where the mouse was clicked. | |
1564 \(You cannot use (interactive \"e\"), unfortunately. This returns a | |
1565 misc-user event.) | |
1566 | |
1567 If the event contains no position, or the position is not over text, or | |
1568 there is no variable around that point, nil is returned." | |
1569 (if (and event (event-buffer event) (event-point event)) | |
1570 (save-excursion | |
1571 (set-buffer (event-buffer event)) | |
1572 (goto-char (event-point event)) | |
1573 (variable-at-point)))) | |
1574 | |
428 | 1575 (defun variable-obsolete-p (variable) |
1576 "Return non-nil if VARIABLE is obsolete." | |
1577 (not (null (get variable 'byte-obsolete-variable)))) | |
1578 | |
1579 (defun variable-obsoleteness-doc (variable) | |
1580 "If VARIABLE is obsolete, return a string describing this." | |
1581 (let ((obsolete (get variable 'byte-obsolete-variable))) | |
1582 (if obsolete | |
1583 (format "Obsolete; %s" | |
1584 (if (stringp obsolete) | |
1585 obsolete | |
1586 (format "use `%s' instead." obsolete)))))) | |
1587 | |
1588 (defun variable-compatible-p (variable) | |
1589 "Return non-nil if VARIABLE is Emacs compatible." | |
1590 (not (null (get variable 'byte-compatible-variable)))) | |
1591 | |
1592 (defun variable-compatibility-doc (variable) | |
1593 "If VARIABLE is Emacs compatible, return a string describing this." | |
1594 (let ((compatible (get variable 'byte-compatible-variable))) | |
1595 (if compatible | |
1596 (format "Emacs Compatible; %s" | |
1597 (if (stringp compatible) | |
1598 compatible | |
1599 (format "use `%s' instead." compatible)))))) | |
1600 | |
1601 (defun built-in-variable-doc (variable) | |
1602 "Return a string describing whether VARIABLE is built-in." | |
1603 (let ((type (built-in-variable-type variable))) | |
1604 (case type | |
1605 (integer "a built-in integer variable") | |
1606 (const-integer "a built-in constant integer variable") | |
1607 (boolean "a built-in boolean variable") | |
1608 (const-boolean "a built-in constant boolean variable") | |
1609 (object "a simple built-in variable") | |
1610 (const-object "a simple built-in constant variable") | |
1611 (const-specifier "a built-in constant specifier variable") | |
1612 (current-buffer "a built-in buffer-local variable") | |
1613 (const-current-buffer "a built-in constant buffer-local variable") | |
1614 (default-buffer "a built-in default buffer-local variable") | |
1615 (selected-console "a built-in console-local variable") | |
1616 (const-selected-console "a built-in constant console-local variable") | |
1617 (default-console "a built-in default console-local variable") | |
1618 (t | |
1619 (if type "an unknown type of built-in variable?" | |
1620 "a variable declared in Lisp"))))) | |
1621 | |
1622 (defun describe-variable (variable) | |
1623 "Display the full documentation of VARIABLE (a symbol)." | |
1624 (interactive | |
1625 (let* ((v (variable-at-point)) | |
1626 (val (let ((enable-recursive-minibuffers t)) | |
1627 (completing-read | |
1628 (if v | |
1629 (format "Describe variable (default %s): " v) | |
1630 (gettext "Describe variable: ")) | |
430 | 1631 obarray 'boundp t nil 'variable-history |
1632 (symbol-name v))))) | |
1633 (list (intern val)))) | |
428 | 1634 (with-displaying-help-buffer |
1635 (lambda () | |
1636 (let ((origvar variable) | |
1637 aliases) | |
1638 (let ((print-escape-newlines t)) | |
462 | 1639 (princ "`") |
1640 ;; (Help-princ-face (symbol-name variable) | |
502 | 1641 ;; 'font-lock-variable-name-face) overkill |
462 | 1642 (princ (symbol-name variable)) |
1643 (princ "' is ") | |
428 | 1644 (while (variable-alias variable) |
1645 (let ((newvar (variable-alias variable))) | |
1646 (if aliases | |
1647 ;; I18N3 Need gettext due to concat | |
1648 (setq aliases | |
1649 (concat aliases | |
1650 (format "\n which is an alias for `%s'," | |
1651 (symbol-name newvar)))) | |
1652 (setq aliases | |
1653 (format "an alias for `%s'," | |
1654 (symbol-name newvar)))) | |
1655 (setq variable newvar))) | |
1656 (if aliases | |
1657 (princ (format "%s" aliases))) | |
1658 (princ (built-in-variable-doc variable)) | |
1659 (princ ".\n") | |
3368 | 1660 (require 'hyper-apropos) |
4535
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1661 (let ((file-name (symbol-file variable 'defvar)) |
3368 | 1662 opoint e) |
1663 (when file-name | |
1664 (princ " -- loaded from \"") | |
1665 (if (not (bufferp standard-output)) | |
1666 (princ file-name) | |
1667 (setq opoint (point standard-output)) | |
1668 (princ file-name) | |
1669 (setq e (make-extent opoint (point standard-output) | |
1670 standard-output)) | |
1671 (set-extent-property e 'face 'hyper-apropos-hyperlink) | |
1672 (set-extent-property e 'mouse-face 'highlight) | |
1673 (set-extent-property e 'find-variable-symbol variable)) | |
1674 (princ"\"\n"))) | |
428 | 1675 (princ "\nValue: ") |
464 | 1676 (if (not (boundp variable)) |
1677 (Help-princ-face "void\n" 'hyper-apropos-documentation) | |
1678 (Help-prin1-face (symbol-value variable) | |
1679 'hyper-apropos-documentation) | |
428 | 1680 (terpri)) |
1681 (terpri) | |
1682 (cond ((local-variable-p variable (current-buffer)) | |
1683 (let* ((void (cons nil nil)) | |
1684 (def (condition-case nil | |
1685 (default-value variable) | |
1686 (error void)))) | |
1687 (princ "This value is specific to the current buffer.\n") | |
1688 (if (local-variable-p variable nil) | |
1689 (princ "(Its value is local to each buffer.)\n")) | |
1690 (terpri) | |
1691 (if (if (eq def void) | |
1692 (boundp variable) | |
1693 (not (eq (symbol-value variable) def))) | |
1694 ;; #### I18N3 doesn't localize properly! | |
1695 (progn (princ "Default-value: ") | |
1696 (if (eq def void) | |
1697 (princ "void\n") | |
1698 (prin1 def) | |
1699 (terpri)) | |
1700 (terpri))))) | |
1701 ((local-variable-p variable (current-buffer) t) | |
1702 (princ "Setting it would make its value buffer-local.\n\n")))) | |
1703 (princ "Documentation:") | |
1704 (terpri) | |
1705 (let ((doc (documentation-property variable 'variable-documentation)) | |
1706 (obsolete (variable-obsoleteness-doc origvar)) | |
1707 (compatible (variable-compatibility-doc origvar))) | |
1708 (when obsolete | |
1709 (princ obsolete) | |
1710 (terpri) | |
1711 (terpri)) | |
1712 (when compatible | |
1713 (princ compatible) | |
1714 (terpri) | |
1715 (terpri)) | |
1716 ;; don't bother to print anything if variable is obsolete and aliased. | |
1717 (when (or (not obsolete) (not aliases)) | |
1718 (if doc | |
1719 ;; note: documentation-property calls substitute-command-keys. | |
442 | 1720 (let ((oldp (point standard-output)) |
1721 newp) | |
1722 (princ doc) | |
1723 (setq newp (point standard-output)) | |
1724 (goto-char oldp standard-output) | |
1725 (frob-help-extents standard-output) | |
1726 (goto-char newp standard-output)) | |
428 | 1727 (princ "not documented as a variable.")))) |
1728 (terpri))) | |
1729 (format "variable `%s'" variable))) | |
1730 | |
1731 (defun sorted-key-descriptions (keys &optional separator) | |
1732 "Sort and separate the key descriptions for KEYS. | |
1733 The sorting is done by length (shortest bindings first), and the bindings | |
1734 are separated with SEPARATOR (\", \" by default)." | |
1735 (mapconcat 'key-description | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5076
diff
changeset
|
1736 (sort* keys #'< :key #'length) |
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5076
diff
changeset
|
1737 (or separator ", "))) |
428 | 1738 |
1739 (defun where-is (definition &optional insert) | |
1740 "Print message listing key sequences that invoke specified command. | |
1741 Argument is a command definition, usually a symbol with a function definition. | |
1742 When run interactively, it defaults to any function found by | |
1743 `function-at-point'. | |
1744 If INSERT (the prefix arg) is non-nil, insert the message in the buffer." | |
1745 (interactive | |
1746 (let ((fn (function-at-point)) | |
1747 (enable-recursive-minibuffers t) | |
1748 val) | |
1749 (setq val (read-command | |
1750 (if fn (format "Where is command (default %s): " fn) | |
456 | 1751 "Where is command: ") |
1752 (and fn (symbol-name fn)))) | |
428 | 1753 (list (if (equal (symbol-name val) "") |
1754 fn val) | |
1755 current-prefix-arg))) | |
1756 (let ((keys (where-is-internal definition))) | |
1757 (if keys | |
1758 (if insert | |
1759 (princ (format "%s (%s)" (sorted-key-descriptions keys) | |
1760 definition) (current-buffer)) | |
1761 (message "%s is on %s" definition (sorted-key-descriptions keys))) | |
1762 (if insert | |
1763 (princ (format (if (commandp definition) "M-x %s RET" | |
1764 "M-: (%s ...)") definition) (current-buffer)) | |
1765 (message "%s is not on any keys" definition)))) | |
1766 nil) | |
1767 | |
1768 ;; `locate-library' moved to "packages.el" | |
1769 | |
1770 | |
1771 ;; Functions ported from C into Lisp in XEmacs | |
1772 | |
1773 (defun describe-syntax () | |
1774 "Describe the syntax specifications in the syntax table. | |
1775 The descriptions are inserted in a buffer, which is then displayed." | |
1776 (interactive) | |
1777 (with-displaying-help-buffer | |
1778 (lambda () | |
1779 ;; defined in syntax.el | |
1780 (describe-syntax-table (syntax-table) standard-output)) | |
1781 (format "syntax-table for %s" major-mode))) | |
1782 | |
1783 (defun list-processes () | |
1784 "Display a list of all processes. | |
1785 \(Any processes listed as Exited or Signaled are actually eliminated | |
1786 after the listing is made.)" | |
1787 (interactive) | |
1788 (with-output-to-temp-buffer "*Process List*" | |
1789 (set-buffer standard-output) | |
1790 (buffer-disable-undo standard-output) | |
1791 (make-local-variable 'truncate-lines) | |
1792 (setq truncate-lines t) | |
1793 ;; 00000000001111111111222222222233333333334444444444 | |
1794 ;; 01234567890123456789012345678901234567890123456789 | |
1795 ;; rewritten for I18N3. This one should stay rewritten | |
1796 ;; so that the dashes will line up properly. | |
1797 (princ "Proc Status Buffer Tty Command\n---- ------ ------ --- -------\n") | |
1798 (let ((tail (process-list))) | |
1799 (while tail | |
1800 (let* ((p (car tail)) | |
1801 (pid (process-id p)) | |
1802 (s (process-status p))) | |
1803 (setq tail (cdr tail)) | |
1804 (princ (format "%-13s" (process-name p))) | |
1805 (princ s) | |
1806 (if (and (eq s 'exit) (/= (process-exit-status p) 0)) | |
1807 (princ (format " %d" (process-exit-status p)))) | |
1808 (if (memq s '(signal exit closed)) | |
1809 ;; Do delete-exited-processes' work | |
1810 (delete-process p)) | |
1811 (indent-to 22 1) ;#### | |
1812 (let ((b (process-buffer p))) | |
1813 (cond ((not b) | |
1814 (princ "(none)")) | |
1815 ((not (buffer-name b)) | |
1816 (princ "(killed)")) | |
1817 (t | |
1818 (princ (buffer-name b))))) | |
1819 (indent-to 37 1) ;#### | |
1820 (let ((tn (process-tty-name p))) | |
1821 (cond ((not tn) | |
1822 (princ "(none)")) | |
1823 (t | |
1824 (princ (format "%s" tn))))) | |
1825 (indent-to 49 1) ;#### | |
1826 (if (not (integerp pid)) | |
1827 (progn | |
1828 (princ "network stream connection ") | |
1829 (princ (car pid)) | |
1830 (princ "@") | |
1831 (princ (cdr pid))) | |
1832 (let ((cmd (process-command p))) | |
1833 (while cmd | |
1834 (princ (car cmd)) | |
1835 (setq cmd (cdr cmd)) | |
1836 (if cmd (princ " "))))) | |
1837 (terpri)))))) | |
1838 | |
440 | 1839 ;; Stop gap for 21.0 until we do help-char etc properly. |
428 | 1840 (defun help-keymap-with-help-key (keymap form) |
1841 "Return a copy of KEYMAP with an help-key binding according to help-char | |
1842 invoking FORM like help-form. An existing binding is not overridden. | |
1843 If FORM is nil then no binding is made." | |
1844 (let ((map (copy-keymap keymap)) | |
1845 (key (if (characterp help-char) | |
1846 (vector (character-to-event help-char)) | |
1847 help-char))) | |
1848 (when (and form key (not (lookup-key map key))) | |
1849 (define-key map key | |
1850 `(lambda () (interactive) (help-print-help-form ,form)))) | |
1851 map)) | |
1852 | |
1853 (defun help-print-help-form (form) | |
1854 (let ((string (eval form))) | |
1855 (if (stringp string) | |
1856 (with-displaying-help-buffer | |
1857 (insert string))))) | |
1858 | |
3368 | 1859 (defun help-find-source-or-scroll-up (&optional pos) |
1860 "Follow any cross reference to source code; if none, scroll up. " | |
1861 (interactive "d") | |
1862 (let ((e (extent-at pos nil 'find-function-symbol))) | |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1863 (if (and-fboundp 'find-function e) |
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1864 (with-fboundp 'find-function |
4103 | 1865 (find-function (extent-property e 'find-function-symbol))) |
3368 | 1866 (setq e (extent-at pos nil 'find-variable-symbol)) |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1867 (if (and-fboundp 'find-variable e) |
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1868 (with-fboundp 'find-variable |
4103 | 1869 (find-variable (extent-property e 'find-variable-symbol))) |
1870 (scroll-up 1))))) | |
3368 | 1871 |
1872 (defun help-mouse-find-source-or-track (event) | |
1873 "Follow any cross reference to source code under the mouse; | |
1874 if none, call mouse-track. " | |
1875 (interactive "e") | |
1876 (mouse-set-point event) | |
1877 (let ((e (extent-at (point) nil 'find-function-symbol))) | |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1878 (if (and-fboundp 'find-function e) |
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1879 (with-fboundp 'find-function |
4103 | 1880 (find-function (extent-property e 'find-function-symbol))) |
3368 | 1881 (setq e (extent-at (point) nil 'find-variable-symbol)) |
5368
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1882 (if (and-fboundp 'find-variable e) |
ed74d2ca7082
Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents:
5366
diff
changeset
|
1883 (with-fboundp 'find-variable |
4103 | 1884 (find-variable (extent-property e 'find-variable-symbol))) |
3368 | 1885 (mouse-track event))))) |
1886 | |
4506
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1887 (define-minor-mode temp-buffer-resize-mode |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1888 "Toggle the mode which makes windows smaller for temporary buffers. |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1889 With prefix argument ARG, turn the resizing of windows displaying temporary |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1890 buffers on if ARG is positive or off otherwise. |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1891 This makes the window the right height for its contents, but never |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1892 less than `window-min-height' nor a higher proportion of its frame than |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1893 `temp-buffer-max-height'. (Note the differing semantics of the latter |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1894 versus GNU Emacs, where `temp-buffer-max-height' is an integer number of |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1895 lines.) |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1896 This applies to `help', `apropos' and `completion' buffers, and some others." |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1897 :global t :group 'help |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1898 ;; XEmacs; our implementation of this is very different. |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1899 (setq temp-buffer-shrink-to-fit temp-buffer-resize-mode)) |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1900 |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1901 ;; GNU name for this function. |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1902 (defalias 'resize-temp-buffer-window 'shrink-window-if-larger-than-buffer) |
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1903 |
428 | 1904 ;;; help.el ends here |