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