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