428
|
1 ;;; help.el --- help commands for XEmacs.
|
|
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
|
|
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)
|
2030
|
464 "Register help buffer named NEWBUF and possibly kill excess ones."
|
|
465 ;; don't let client code pass us bogus NEWBUF---if it gets in the list,
|
|
466 ;; help can become unusable
|
|
467 (unless (stringp newbuf)
|
|
468 (error 'wrong-type-argument "help buffer name must be string" newbuf))
|
428
|
469 ;; remove new buffer from list
|
|
470 (setq help-buffer-list (remove newbuf help-buffer-list))
|
|
471 ;; maybe kill excess help buffers
|
|
472 (if (and (integerp help-max-help-buffers)
|
|
473 (> (length help-buffer-list) help-max-help-buffers))
|
|
474 (let ((keep-list nil)
|
|
475 (num-kill (- (length help-buffer-list)
|
|
476 help-max-help-buffers)))
|
|
477 (while help-buffer-list
|
|
478 (let ((buf (car help-buffer-list)))
|
|
479 (if (and (or (equal buf newbuf) (get-buffer buf))
|
|
480 (string-match "^*Help" buf)
|
|
481 (save-excursion (set-buffer buf)
|
|
482 (eq major-mode 'help-mode)))
|
|
483 (if (and (>= num-kill (length help-buffer-list))
|
|
484 (not (get-buffer-window buf t t)))
|
|
485 (kill-buffer buf)
|
|
486 (setq keep-list (cons buf keep-list)))))
|
|
487 (setq help-buffer-list (cdr help-buffer-list)))
|
|
488 (setq help-buffer-list (nreverse keep-list))))
|
|
489 ;; push new buffer
|
|
490 (setq help-buffer-list (cons newbuf help-buffer-list)))
|
|
491
|
|
492 (defvar help-buffer-prefix-string "Help"
|
|
493 "Initial string to use in constructing help buffer names.
|
2030
|
494 You should never set this directly, only let-bind it.")
|
428
|
495
|
|
496 (defun help-buffer-name (name)
|
|
497 "Return a name for a Help buffer using string NAME for context."
|
|
498 (if (and (integerp help-max-help-buffers)
|
|
499 (> help-max-help-buffers 0)
|
|
500 (stringp name))
|
|
501 (if help-buffer-prefix-string
|
|
502 (format "*%s: %s*" help-buffer-prefix-string name)
|
|
503 (format "*%s*" name))
|
|
504 (format "*%s*" help-buffer-prefix-string)))
|
|
505
|
863
|
506 ;; with-displaying-help-buffer
|
428
|
507
|
|
508 ;; #### Should really be a macro to eliminate the requirement of
|
|
509 ;; caller to code a lambda form in THUNK -- mrb
|
|
510
|
|
511 ;; #### BEFORE you rush to make this a macro, think about backward
|
|
512 ;; compatibility. The right way would be to create a macro with
|
|
513 ;; another name (which is a shame, because w-d-h-b is a perfect name
|
|
514 ;; for a macro) that uses with-displaying-help-buffer internally.
|
|
515
|
442
|
516 (defcustom mode-for-help 'help-mode
|
|
517 "*Mode that help buffers are put into.")
|
|
518
|
1123
|
519 (defcustom mode-for-temp-buffer 'temp-buffer-mode
|
|
520 "*Mode that help buffers are put into.")
|
|
521
|
442
|
522 (defvar help-sticky-window nil
|
|
523 ;; Window into which help buffers will be displayed, rather than
|
|
524 ;; always searching for a new one. This is INTERNAL and liable to
|
|
525 ;; change its interface and/or name at any moment. It should be
|
|
526 ;; bound, not set.
|
|
527 )
|
|
528
|
|
529 (defvar help-window-config nil)
|
|
530
|
|
531 (make-variable-buffer-local 'help-window-config)
|
|
532 (put 'help-window-config 'permanent-local t)
|
|
533
|
1123
|
534 (defmacro with-displaying-temp-buffer (name &rest body)
|
2030
|
535 "Make a help buffer with given NAME and evaluate BODY, sending stdout there.
|
1123
|
536
|
|
537 Use this function for displaying information in temporary buffers, where the
|
|
538 user will typically view the information and then exit using
|
|
539 \\<temp-buffer-mode-map>\\[help-mode-quit].
|
863
|
540
|
2030
|
541 On exit from this form, the buffer is put into the mode specified in
|
|
542 `mode-for-temp-buffer' and displayed, typically in a popup window. Ie,
|
|
543 the buffer is a scratchpad which is displayed all at once in formatted
|
|
544 form.
|
|
545
|
|
546 N.B. Write to this buffer with functions like `princ', not `insert'."
|
1123
|
547 `(let* ((winconfig (current-window-configuration))
|
|
548 (was-one-window (one-window-p))
|
|
549 (buffer-name ,name)
|
|
550 (help-not-visible
|
|
551 (not (and (windows-of-buffer buffer-name) ;shortcut
|
|
552 (memq (selected-frame)
|
|
553 (mapcar 'window-frame
|
|
554 (windows-of-buffer buffer-name)))))))
|
428
|
555 (help-register-and-maybe-prune-excess buffer-name)
|
442
|
556 ;; if help-sticky-window is bogus or deleted, get rid of it.
|
|
557 (if (and help-sticky-window (or (not (windowp help-sticky-window))
|
|
558 (not (window-live-p help-sticky-window))))
|
|
559 (setq help-sticky-window nil))
|
|
560 (prog1
|
|
561 (let ((temp-buffer-show-function
|
|
562 (if help-sticky-window
|
|
563 #'(lambda (buffer)
|
|
564 (set-window-buffer help-sticky-window buffer))
|
|
565 temp-buffer-show-function)))
|
|
566 (with-output-to-temp-buffer buffer-name
|
1123
|
567 (prog1 (progn ,@body)
|
442
|
568 (save-excursion
|
|
569 (set-buffer standard-output)
|
1123
|
570 (funcall mode-for-temp-buffer)))))
|
428
|
571 (let ((helpwin (get-buffer-window buffer-name)))
|
|
572 (when helpwin
|
1123
|
573 ;; If the temp buffer is already displayed on this
|
442
|
574 ;; frame, don't override the previous configuration
|
|
575 (when help-not-visible
|
|
576 (with-current-buffer (window-buffer helpwin)
|
|
577 (setq help-window-config winconfig)))
|
428
|
578 (when help-selects-help-window
|
|
579 (select-window helpwin))
|
|
580 (cond ((eq helpwin (selected-window))
|
|
581 (display-message 'command
|
1123
|
582 (substitute-command-keys "Type \\[help-mode-quit] to remove window, \\[scroll-up] to scroll the text.")))
|
428
|
583 (was-one-window
|
|
584 (display-message 'command
|
1123
|
585 (substitute-command-keys "Type \\[delete-other-windows] to remove window, \\[scroll-other-window] to scroll the text.")))
|
428
|
586 (t
|
|
587 (display-message 'command
|
1123
|
588 (substitute-command-keys "Type \\[switch-to-buffer-other-window] to restore the other window, \\[scroll-other-window] to scroll the text.")))))))))
|
|
589
|
|
590 (put 'with-displaying-temp-buffer 'lisp-indent-function 1)
|
|
591
|
|
592 (defun with-displaying-help-buffer (thunk &optional name)
|
|
593 "Form which makes a help buffer with given NAME and evaluates BODY there.
|
|
594 The actual name of the buffer is generated by the function `help-buffer-name'.
|
|
595
|
|
596 Use this function for displaying help when C-h something is pressed or
|
|
597 in similar situations. Do *not* use it when you are displaying a help
|
|
598 message and then prompting for input in the minibuffer -- this macro
|
|
599 usually selects the help buffer, which is not what you want in those
|
|
600 situations."
|
|
601 (let ((mode-for-temp-buffer mode-for-help))
|
|
602 (with-displaying-temp-buffer (help-buffer-name name)
|
|
603 (funcall thunk))))
|
428
|
604
|
|
605 (defun describe-key (key)
|
|
606 "Display documentation of the function invoked by KEY.
|
|
607 KEY is a string, or vector of events.
|
|
608 When called interactively, KEY may also be a menu selection."
|
|
609 (interactive "kDescribe key: ")
|
|
610 (let ((defn (key-or-menu-binding key))
|
|
611 (key-string (key-description key)))
|
|
612 (if (or (null defn) (integerp defn))
|
|
613 (message "%s is undefined" key-string)
|
|
614 (with-displaying-help-buffer
|
|
615 (lambda ()
|
|
616 (princ key-string)
|
|
617 (princ " runs ")
|
|
618 (if (symbolp defn)
|
|
619 (princ (format "`%s'" defn))
|
|
620 (princ defn))
|
|
621 (princ "\n\n")
|
|
622 (cond ((or (stringp defn) (vectorp defn))
|
|
623 (let ((cmd (key-binding defn)))
|
|
624 (if (not cmd)
|
|
625 (princ "a keyboard macro")
|
|
626 (progn
|
|
627 (princ "a keyboard macro which runs the command ")
|
|
628 (princ cmd)
|
|
629 (princ ":\n\n")
|
|
630 (if (documentation cmd) (princ (documentation cmd)))))))
|
|
631 ((and (consp defn) (not (eq 'lambda (car-safe defn))))
|
|
632 (let ((describe-function-show-arglist nil))
|
|
633 (describe-function-1 (car defn))))
|
|
634 ((symbolp defn)
|
|
635 (describe-function-1 defn))
|
|
636 ((documentation defn)
|
|
637 (princ (documentation defn)))
|
|
638 (t
|
|
639 (princ "not documented"))))
|
|
640 (format "key `%s'" key-string)))))
|
|
641
|
|
642 (defun describe-mode ()
|
|
643 "Display documentation of current major mode and minor modes.
|
|
644 For this to work correctly for a minor mode, the mode's indicator variable
|
|
645 \(listed in `minor-mode-alist') must also be a function whose documentation
|
|
646 describes the minor mode."
|
|
647 (interactive)
|
|
648 (with-displaying-help-buffer
|
|
649 (lambda ()
|
|
650 ;; XEmacs change: print the major-mode documentation before
|
|
651 ;; the minor modes.
|
|
652 (princ mode-name)
|
|
653 (princ " mode:\n")
|
|
654 (princ (documentation major-mode))
|
|
655 (princ "\n\n----\n\n")
|
|
656 (let ((minor-modes minor-mode-alist))
|
|
657 (while minor-modes
|
|
658 (let* ((minor-mode (car (car minor-modes)))
|
|
659 (indicator (car (cdr (car minor-modes)))))
|
|
660 ;; Document a minor mode if it is listed in minor-mode-alist,
|
|
661 ;; bound locally in this buffer, non-nil, and has a function
|
|
662 ;; definition.
|
|
663 (if (and (boundp minor-mode)
|
|
664 (symbol-value minor-mode)
|
|
665 (fboundp minor-mode))
|
|
666 (let ((pretty-minor-mode minor-mode))
|
|
667 (if (string-match "-mode\\'" (symbol-name minor-mode))
|
|
668 (setq pretty-minor-mode
|
|
669 (capitalize
|
|
670 (substring (symbol-name minor-mode)
|
|
671 0 (match-beginning 0)))))
|
|
672 (while (and (consp indicator) (extentp (car indicator)))
|
|
673 (setq indicator (cdr indicator)))
|
|
674 (while (and indicator (symbolp indicator))
|
|
675 (setq indicator (symbol-value indicator)))
|
732
|
676 (princ (format "%s minor mode (%s):\n"
|
|
677 pretty-minor-mode
|
|
678 (if indicator
|
|
679 (format "indicator%s" indicator)
|
|
680 "no indicator")))
|
428
|
681 (princ (documentation minor-mode))
|
|
682 (princ "\n\n----\n\n"))))
|
|
683 (setq minor-modes (cdr minor-modes)))))
|
|
684 (format "%s mode" mode-name)))
|
|
685
|
|
686 ;; So keyboard macro definitions are documented correctly
|
|
687 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
|
|
688
|
462
|
689 ;; view a read-only file intelligently
|
|
690 (defun Help-find-file (file)
|
|
691 (if (fboundp 'view-file)
|
|
692 (view-file file)
|
|
693 (find-file-read-only file)
|
|
694 (goto-char (point-min))))
|
|
695
|
428
|
696 (defun describe-distribution ()
|
|
697 "Display info on how to obtain the latest version of XEmacs."
|
|
698 (interactive)
|
2537
|
699 (save-window-excursion
|
|
700 (info)
|
|
701 (Info-find-node "xemacs-faq" "Q1.1.1"))
|
|
702 (switch-to-buffer "*info*"))
|
428
|
703
|
|
704 (defun describe-beta ()
|
|
705 "Display info on how to deal with Beta versions of XEmacs."
|
|
706 (interactive)
|
2537
|
707 (save-window-excursion
|
|
708 (info "(beta)Top"))
|
|
709 (switch-to-buffer "*info*"))
|
428
|
710
|
|
711 (defun describe-copying ()
|
|
712 "Display info on how you may redistribute copies of XEmacs."
|
|
713 (interactive)
|
462
|
714 (Help-find-file (locate-data-file "COPYING")))
|
428
|
715
|
|
716 (defun describe-pointer ()
|
|
717 "Show a list of all defined mouse buttons, and their definitions."
|
|
718 (interactive)
|
|
719 (describe-bindings nil t))
|
|
720
|
|
721 (defun describe-no-warranty ()
|
|
722 "Display info on all the kinds of warranty XEmacs does NOT have."
|
|
723 (interactive)
|
|
724 (describe-copying)
|
|
725 (let (case-fold-search)
|
|
726 (search-forward "NO WARRANTY")
|
|
727 (recenter 0)))
|
|
728
|
|
729 (defun describe-bindings (&optional prefix mouse-only-p)
|
|
730 "Show a list of all defined keys, and their definitions.
|
|
731 The list is put in a buffer, which is displayed.
|
444
|
732 If optional first argument PREFIX is supplied, only commands
|
|
733 which start with that sequence of keys are described.
|
|
734 If optional second argument MOUSE-ONLY-P (prefix arg, interactively)
|
|
735 is non-nil then only the mouse bindings are displayed."
|
428
|
736 (interactive (list nil current-prefix-arg))
|
|
737 (with-displaying-help-buffer
|
|
738 (lambda ()
|
|
739 (describe-bindings-1 prefix mouse-only-p))
|
|
740 (format "bindings for %s" major-mode)))
|
|
741
|
|
742 (defun describe-bindings-1 (&optional prefix mouse-only-p)
|
|
743 (let ((heading (if mouse-only-p
|
|
744 (gettext "button binding\n------ -------\n")
|
|
745 (gettext "key binding\n--- -------\n")))
|
|
746 (buffer (current-buffer))
|
|
747 (minor minor-mode-map-alist)
|
430
|
748 (extent-maps (mapcar-extents
|
|
749 'extent-keymap
|
|
750 nil (current-buffer) (point) (point) nil 'keymap))
|
428
|
751 (local (current-local-map))
|
|
752 (shadow '()))
|
|
753 (set-buffer standard-output)
|
430
|
754 (while extent-maps
|
|
755 (insert "Bindings for Text Region:\n"
|
|
756 heading)
|
|
757 (describe-bindings-internal
|
|
758 (car extent-maps) nil shadow prefix mouse-only-p)
|
|
759 (insert "\n")
|
|
760 (setq shadow (cons (car extent-maps) shadow)
|
|
761 extent-maps (cdr extent-maps)))
|
428
|
762 (while minor
|
|
763 (let ((sym (car (car minor)))
|
|
764 (map (cdr (car minor))))
|
|
765 (if (symbol-value-in-buffer sym buffer nil)
|
|
766 (progn
|
|
767 (insert (format "Minor Mode Bindings for `%s':\n"
|
|
768 sym)
|
|
769 heading)
|
|
770 (describe-bindings-internal map nil shadow prefix mouse-only-p)
|
|
771 (insert "\n")
|
|
772 (setq shadow (cons map shadow))))
|
|
773 (setq minor (cdr minor))))
|
|
774 (if local
|
|
775 (progn
|
|
776 (insert "Local Bindings:\n" heading)
|
|
777 (describe-bindings-internal local nil shadow prefix mouse-only-p)
|
|
778 (insert "\n")
|
|
779 (setq shadow (cons local shadow))))
|
771
|
780 (if (console-on-window-system-p)
|
|
781 (progn
|
|
782 (insert "Global Window-System-Only Bindings:\n" heading)
|
|
783 (describe-bindings-internal global-window-system-map nil
|
|
784 shadow prefix mouse-only-p)
|
|
785 (push global-window-system-map shadow))
|
|
786 (insert "Global TTY-Only Bindings:\n" heading)
|
|
787 (describe-bindings-internal global-tty-map nil
|
|
788 shadow prefix mouse-only-p)
|
|
789 (push global-tty-map shadow))
|
|
790 (insert "\nGlobal Bindings:\n" heading)
|
428
|
791 (describe-bindings-internal (current-global-map)
|
|
792 nil shadow prefix mouse-only-p)
|
|
793 (when (and prefix function-key-map (not mouse-only-p))
|
|
794 (insert "\nFunction key map translations:\n" heading)
|
|
795 (describe-bindings-internal function-key-map nil nil
|
|
796 prefix mouse-only-p))
|
|
797 (set-buffer buffer)
|
|
798 standard-output))
|
|
799
|
|
800 (defun describe-prefix-bindings ()
|
|
801 "Describe the bindings of the prefix used to reach this command.
|
|
802 The prefix described consists of all but the last event
|
|
803 of the key sequence that ran this command."
|
|
804 (interactive)
|
|
805 (let* ((key (this-command-keys))
|
|
806 (prefix (make-vector (1- (length key)) nil))
|
|
807 i)
|
|
808 (setq i 0)
|
|
809 (while (< i (length prefix))
|
|
810 (aset prefix i (aref key i))
|
|
811 (setq i (1+ i)))
|
|
812 (with-displaying-help-buffer
|
|
813 (lambda ()
|
|
814 (princ "Key bindings starting with ")
|
|
815 (princ (key-description prefix))
|
|
816 (princ ":\n\n")
|
|
817 (describe-bindings-1 prefix nil))
|
|
818 (format "%s prefix" (key-description prefix)))))
|
|
819
|
|
820 ;; Make C-h after a prefix, when not specifically bound,
|
|
821 ;; run describe-prefix-bindings.
|
|
822 (setq prefix-help-command 'describe-prefix-bindings)
|
|
823
|
|
824 (defun describe-installation ()
|
|
825 "Display a buffer showing information about this XEmacs was compiled."
|
|
826 (interactive)
|
|
827 (if (and (boundp 'Installation-string)
|
|
828 (stringp Installation-string))
|
|
829 (with-displaying-help-buffer
|
|
830 (lambda ()
|
442
|
831 (princ
|
|
832 (if (fboundp 'decode-coding-string)
|
|
833 (decode-coding-string Installation-string 'automatic-conversion)
|
|
834 Installation-string)))
|
428
|
835 "Installation")
|
|
836 (error "No Installation information available.")))
|
|
837
|
|
838 (defun view-emacs-news ()
|
|
839 "Display info on recent changes to XEmacs."
|
|
840 (interactive)
|
462
|
841 (Help-find-file (locate-data-file "NEWS")))
|
428
|
842
|
|
843 (defun xemacs-www-page ()
|
|
844 "Go to the XEmacs World Wide Web page."
|
|
845 (interactive)
|
776
|
846 (if-fboundp 'browse-url
|
442
|
847 (browse-url "http://www.xemacs.org/")
|
428
|
848 (error "xemacs-www-page requires browse-url")))
|
|
849
|
|
850 (defun xemacs-www-faq ()
|
|
851 "View the latest and greatest XEmacs FAQ using the World Wide Web."
|
|
852 (interactive)
|
776
|
853 (if-fboundp 'browse-url
|
442
|
854 (browse-url "http://www.xemacs.org/faq/index.html")
|
428
|
855 (error "xemacs-www-faq requires browse-url")))
|
|
856
|
|
857 (defun xemacs-local-faq ()
|
|
858 "View the local copy of the XEmacs FAQ.
|
|
859 If you have access to the World Wide Web, you should use `xemacs-www-faq'
|
|
860 instead, to ensure that you get the most up-to-date information."
|
|
861 (interactive)
|
|
862 (save-window-excursion
|
|
863 (info)
|
|
864 (Info-find-node "xemacs-faq" "Top"))
|
|
865 (switch-to-buffer "*info*"))
|
|
866
|
462
|
867 (defun view-sample-init-el ()
|
|
868 "Display the sample init.el file."
|
|
869 (interactive)
|
|
870 (Help-find-file (locate-data-file "sample.init.el")))
|
|
871
|
428
|
872 (defcustom view-lossage-key-count 100
|
|
873 "*Number of keys `view-lossage' shows.
|
|
874 The maximum number of available keys is governed by `recent-keys-ring-size'."
|
|
875 :type 'integer
|
|
876 :group 'help)
|
|
877
|
|
878 (defcustom view-lossage-message-count 100
|
|
879 "*Number of minibuffer messages `view-lossage' shows."
|
|
880 :type 'integer
|
|
881 :group 'help)
|
|
882
|
|
883 (defun print-recent-messages (n)
|
|
884 "Print N most recent messages to standard-output, most recent first.
|
|
885 If N is nil, all messages will be printed."
|
793
|
886 (clear-message) ;; make sure current message goes into log
|
428
|
887 (save-excursion
|
|
888 (let ((buffer (get-buffer-create " *Message-Log*"))
|
|
889 oldpoint extent)
|
|
890 (goto-char (point-max buffer) buffer)
|
|
891 (set-buffer standard-output)
|
|
892 (while (and (not (bobp buffer))
|
|
893 (or (null n) (>= (decf n) 0)))
|
|
894 (setq oldpoint (point buffer))
|
|
895 (setq extent (extent-at oldpoint buffer
|
|
896 'message-multiline nil 'before))
|
|
897 ;; If the message was multiline, move all the way to the
|
|
898 ;; beginning.
|
|
899 (if extent
|
|
900 (goto-char (extent-start-position extent) buffer)
|
|
901 (forward-line -1 buffer))
|
|
902 (insert-buffer-substring buffer (point buffer) oldpoint)))))
|
|
903
|
793
|
904 (defun view-warnings ()
|
|
905 "Display warnings issued."
|
|
906 (interactive)
|
|
907 (with-displaying-help-buffer
|
|
908 (lambda ()
|
|
909 (let ((buf (get-buffer "*Warnings*")))
|
|
910 (when buf
|
|
911 (save-excursion
|
|
912 (set-buffer standard-output)
|
|
913 (map-extents
|
|
914 #'(lambda (extent arg)
|
|
915 (goto-char (point-min))
|
|
916 (insert (extent-string extent)))
|
|
917 buf)))))
|
|
918 "warnings"))
|
|
919
|
|
920 (defun view-lossage (&optional no-keys)
|
428
|
921 "Display recent input keystrokes and recent minibuffer messages.
|
|
922 The number of keys shown is controlled by `view-lossage-key-count'.
|
1038
|
923 The number of messages shown is controlled by `view-lossage-message-count'.
|
|
924
|
|
925 If optional arg NO-KEYS (prefix arg, interactively) is non-nil,
|
|
926 then recent input keystrokes output is omitted."
|
|
927 (interactive "P")
|
428
|
928 (with-displaying-help-buffer
|
|
929 (lambda ()
|
793
|
930 (unless no-keys
|
|
931 (princ (key-description (recent-keys view-lossage-key-count)))
|
|
932 (save-excursion
|
|
933 (set-buffer standard-output)
|
|
934 (goto-char (point-min))
|
|
935 (insert "Recent keystrokes:\n\n")
|
|
936 (while (progn (move-to-column 50) (not (eobp)))
|
|
937 (search-forward " " nil t)
|
|
938 (insert "\n")))
|
|
939 (princ "\n\n\n"))
|
|
940 ;; Copy the messages from " *Message-Log*", reversing their order and
|
|
941 ;; handling multiline messages correctly.
|
|
942 (princ "Recent minibuffer messages (most recent first):\n\n")
|
428
|
943 (print-recent-messages view-lossage-message-count))
|
|
944 "lossage"))
|
|
945
|
|
946 (define-function 'help 'help-for-help)
|
|
947
|
|
948 (make-help-screen help-for-help
|
|
949 "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
|
950 (concat
|
|
951 "Type a Help option:
|
428
|
952 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
|
|
953
|
502
|
954 Help on key bindings:
|
|
955
|
|
956 \\[describe-bindings] Table of all key bindings.
|
|
957 \\[describe-key-briefly] Type a key sequence or select a menu item;
|
|
958 it displays the corresponding command name.
|
|
959 \\[describe-key] Type a key sequence or select a menu item;
|
|
960 it displays the documentation for the command bound to that key.
|
|
961 (Terser but more up-to-date than what's in the manual.)
|
|
962 \\[Info-goto-emacs-key-command-node] Type a key sequence or select a menu item;
|
|
963 it jumps to the full documentation in the XEmacs User's Manual
|
|
964 for the corresponding command.
|
|
965 \\[view-lossage] Recent input keystrokes and minibuffer messages.
|
|
966 \\[describe-mode] Documentation of current major and minor modes.
|
|
967 \\[describe-pointer] Table of all mouse-button bindings.
|
|
968 \\[where-is] Type a command name; it displays which keystrokes invoke that command.
|
|
969
|
|
970 Help on functions and variables:
|
|
971
|
428
|
972 \\[hyper-apropos] Type a substring; it shows a hypertext list of
|
|
973 functions and variables that contain that substring.
|
502
|
974 \\[command-apropos] Older version of apropos; superseded by previous command.
|
|
975 \\[apropos-documentation] Type a substring; it shows a hypertext list of
|
|
976 functions and variables containing that substring anywhere
|
|
977 in their documentation.
|
|
978 \\[Info-goto-emacs-command-node] Type a command name; it jumps to the full documentation
|
|
979 in the XEmacs User's Manual.
|
|
980 \\[describe-function] Type a command or function name; it shows its documentation.
|
|
981 (Terser but more up-to-date than what's in the manual.)
|
|
982 \\[Info-elisp-ref] Type a function name; it jumps to the full documentation
|
|
983 in the XEmacs Lisp Reference Manual.
|
|
984 \\[Info-search-index-in-xemacs-and-lispref] Type a substring; it looks it up in the indices of both
|
|
985 the XEmacs User's Manual and the XEmacs Lisp Reference Manual.
|
|
986 It jumps to the first match (preferring an exact match); you
|
|
987 can use `\\<Info-mode-map>\\[Info-index-next]\\<help-map>' to successively visit other matches.
|
|
988 \\[describe-variable] Type a variable name; it displays its documentation and value.
|
|
989
|
|
990 Miscellaneous:
|
|
991
|
|
992 "
|
|
993 (if (string-match "beta" emacs-version)
|
|
994 "\\[describe-beta] Special considerations about running a beta version of XEmacs.
|
|
995 "
|
|
996 "")
|
|
997 "
|
428
|
998 \\[customize] Customize Emacs options.
|
502
|
999 \\[describe-distribution] How to obtain XEmacs.
|
|
1000 \\[describe-last-error] Information about the most recent error.
|
428
|
1001 \\[xemacs-local-faq] Local copy of the XEmacs FAQ.
|
|
1002 \\[info] Info documentation reader.
|
|
1003 \\[Info-query] Type an Info file name; it displays it in Info reader.
|
502
|
1004 \\[describe-copying] XEmacs copying permission (General Public License).
|
428
|
1005 \\[view-emacs-news] News of recent XEmacs changes.
|
|
1006 \\[finder-by-keyword] Type a topic keyword; it finds matching packages.
|
|
1007 \\[describe-syntax] Contents of syntax table with explanations.
|
502
|
1008 \\[view-sample-init-el] View the sample init.el that comes with XEmacs.
|
428
|
1009 \\[help-with-tutorial] XEmacs learn-by-doing tutorial.
|
502
|
1010 \\[describe-no-warranty] Information on absence of warranty for XEmacs."
|
|
1011 )
|
428
|
1012 help-map)
|
|
1013
|
|
1014 (defun function-called-at-point ()
|
|
1015 "Return the function which is called by the list containing point.
|
|
1016 If that gives no function, return the function whose name is around point.
|
|
1017 If that doesn't give a function, return nil."
|
|
1018 (or (ignore-errors
|
|
1019 (save-excursion
|
|
1020 (save-restriction
|
|
1021 (narrow-to-region (max (point-min) (- (point) 1000))
|
|
1022 (point-max))
|
|
1023 (backward-up-list 1)
|
|
1024 (forward-char 1)
|
|
1025 (let (obj)
|
|
1026 (setq obj (read (current-buffer)))
|
|
1027 (and (symbolp obj) (fboundp obj) obj)))))
|
|
1028 (ignore-errors
|
|
1029 (with-syntax-table emacs-lisp-mode-syntax-table
|
|
1030 (save-excursion
|
|
1031 (or (not (zerop (skip-syntax-backward "_w")))
|
|
1032 (eq (char-syntax (char-after (point))) ?w)
|
|
1033 (eq (char-syntax (char-after (point))) ?_)
|
|
1034 (forward-sexp -1))
|
|
1035 (skip-chars-forward "`'")
|
|
1036 (let ((obj (read (current-buffer))))
|
|
1037 (and (symbolp obj) (fboundp obj) obj)))))))
|
|
1038
|
|
1039 (defun function-at-point ()
|
|
1040 "Return the function whose name is around point.
|
|
1041 If that gives no function, return the function which is called by the
|
|
1042 list containing point. If that doesn't give a function, return nil."
|
|
1043 (or (ignore-errors
|
|
1044 (with-syntax-table emacs-lisp-mode-syntax-table
|
|
1045 (save-excursion
|
|
1046 (or (not (zerop (skip-syntax-backward "_w")))
|
|
1047 (eq (char-syntax (char-after (point))) ?w)
|
|
1048 (eq (char-syntax (char-after (point))) ?_)
|
|
1049 (forward-sexp -1))
|
|
1050 (skip-chars-forward "`'")
|
|
1051 (let ((obj (read (current-buffer))))
|
|
1052 (and (symbolp obj) (fboundp obj) obj)))))
|
|
1053 (ignore-errors
|
|
1054 (save-excursion
|
|
1055 (save-restriction
|
|
1056 (narrow-to-region (max (point-min) (- (point) 1000))
|
|
1057 (point-max))
|
|
1058 (backward-up-list 1)
|
|
1059 (forward-char 1)
|
|
1060 (let (obj)
|
|
1061 (setq obj (read (current-buffer)))
|
|
1062 (and (symbolp obj) (fboundp obj) obj)))))))
|
|
1063
|
442
|
1064 (defun function-at-event (event)
|
|
1065 "Return the function whose name is around the position of EVENT.
|
|
1066 EVENT should be a mouse event. When calling from a popup or context menu,
|
|
1067 use `last-popup-menu-event' to find out where the mouse was clicked.
|
|
1068 \(You cannot use (interactive \"e\"), unfortunately. This returns a
|
|
1069 misc-user event.)
|
|
1070
|
|
1071 If the event contains no position, or the position is not over text, or
|
|
1072 there is no function around that point, nil is returned."
|
|
1073 (if (and event (event-buffer event) (event-point event))
|
|
1074 (save-excursion
|
|
1075 (set-buffer (event-buffer event))
|
|
1076 (goto-char (event-point event))
|
|
1077 (function-at-point))))
|
|
1078
|
428
|
1079 ;; Default to nil for the non-hackers? Not until we find a way to
|
|
1080 ;; distinguish hackers from non-hackers automatically!
|
|
1081 (defcustom describe-function-show-arglist t
|
|
1082 "*If non-nil, describe-function will show its arglist,
|
|
1083 unless the function is autoloaded."
|
|
1084 :type 'boolean
|
|
1085 :group 'help-appearance)
|
|
1086
|
|
1087 (defun describe-symbol-find-file (symbol)
|
|
1088 (loop for (file . load-data) in load-history
|
|
1089 do (when (memq symbol load-data)
|
|
1090 (return file))))
|
|
1091
|
|
1092 (define-obsolete-function-alias
|
|
1093 'describe-function-find-file
|
|
1094 'describe-symbol-find-file)
|
|
1095
|
|
1096 (defun describe-function (function)
|
|
1097 "Display the full documentation of FUNCTION (a symbol).
|
|
1098 When run interactively, it defaults to any function found by
|
|
1099 `function-at-point'."
|
|
1100 (interactive
|
|
1101 (let* ((fn (function-at-point))
|
|
1102 (val (let ((enable-recursive-minibuffers t))
|
|
1103 (completing-read
|
|
1104 (if fn
|
|
1105 (format (gettext "Describe function (default %s): ")
|
|
1106 fn)
|
|
1107 (gettext "Describe function: "))
|
430
|
1108 obarray 'fboundp t nil 'function-history
|
|
1109 (symbol-name fn)))))
|
|
1110 (list (intern val))))
|
428
|
1111 (with-displaying-help-buffer
|
|
1112 (lambda ()
|
|
1113 (describe-function-1 function)
|
|
1114 ;; Return the text we displayed.
|
|
1115 (buffer-string nil nil standard-output))
|
|
1116 (format "function `%s'" function)))
|
|
1117
|
|
1118 (defun function-obsolete-p (function)
|
|
1119 "Return non-nil if FUNCTION is obsolete."
|
|
1120 (not (null (get function 'byte-obsolete-info))))
|
|
1121
|
|
1122 (defun function-obsoleteness-doc (function)
|
|
1123 "If FUNCTION is obsolete, return a string describing this."
|
|
1124 (let ((obsolete (get function 'byte-obsolete-info)))
|
|
1125 (if obsolete
|
|
1126 (format "Obsolete; %s"
|
|
1127 (if (stringp (car obsolete))
|
|
1128 (car obsolete)
|
|
1129 (format "use `%s' instead." (car obsolete)))))))
|
|
1130
|
|
1131 (defun function-compatible-p (function)
|
|
1132 "Return non-nil if FUNCTION is present for Emacs compatibility."
|
|
1133 (not (null (get function 'byte-compatible-info))))
|
|
1134
|
|
1135 (defun function-compatibility-doc (function)
|
|
1136 "If FUNCTION is Emacs compatible, return a string describing this."
|
|
1137 (let ((compatible (get function 'byte-compatible-info)))
|
|
1138 (if compatible
|
|
1139 (format "Emacs Compatible; %s"
|
|
1140 (if (stringp (car compatible))
|
|
1141 (car compatible)
|
|
1142 (format "use `%s' instead." (car compatible)))))))
|
|
1143
|
|
1144 ;Here are all the possibilities below spelled out, for the benefit
|
|
1145 ;of the I18N3 snarfer.
|
|
1146 ;
|
|
1147 ;(gettext "a built-in function")
|
|
1148 ;(gettext "an interactive built-in function")
|
|
1149 ;(gettext "a built-in macro")
|
|
1150 ;(gettext "an interactive built-in macro")
|
|
1151 ;(gettext "a compiled Lisp function")
|
|
1152 ;(gettext "an interactive compiled Lisp function")
|
|
1153 ;(gettext "a compiled Lisp macro")
|
|
1154 ;(gettext "an interactive compiled Lisp macro")
|
|
1155 ;(gettext "a Lisp function")
|
|
1156 ;(gettext "an interactive Lisp function")
|
|
1157 ;(gettext "a Lisp macro")
|
|
1158 ;(gettext "an interactive Lisp macro")
|
|
1159 ;(gettext "a mocklisp function")
|
|
1160 ;(gettext "an interactive mocklisp function")
|
|
1161 ;(gettext "a mocklisp macro")
|
|
1162 ;(gettext "an interactive mocklisp macro")
|
|
1163 ;(gettext "an autoloaded Lisp function")
|
|
1164 ;(gettext "an interactive autoloaded Lisp function")
|
|
1165 ;(gettext "an autoloaded Lisp macro")
|
|
1166 ;(gettext "an interactive autoloaded Lisp macro")
|
|
1167
|
|
1168 ;; taken out of `describe-function-1'
|
|
1169 (defun function-arglist (function)
|
|
1170 "Return a string giving the argument list of FUNCTION.
|
|
1171 For example:
|
|
1172
|
|
1173 (function-arglist 'function-arglist)
|
|
1174 => (function-arglist FUNCTION)
|
|
1175
|
|
1176 This function is used by `describe-function-1' to list function
|
|
1177 arguments in the standard Lisp style."
|
440
|
1178 (let* ((fnc (indirect-function function))
|
|
1179 (fndef (if (eq (car-safe fnc) 'macro)
|
|
1180 (cdr fnc)
|
|
1181 fnc))
|
428
|
1182 (arglist
|
440
|
1183 (cond ((compiled-function-p fndef)
|
|
1184 (compiled-function-arglist fndef))
|
|
1185 ((eq (car-safe fndef) 'lambda)
|
|
1186 (nth 1 fndef))
|
|
1187 ((subrp fndef)
|
|
1188 (let* ((doc (documentation function))
|
|
1189 (args (and (string-match
|
|
1190 "[\n\t ]*\narguments: ?(\\(.*\\))\n?\\'"
|
|
1191 doc)
|
|
1192 (match-string 1 doc))))
|
|
1193 ;; If there are no arguments documented for the
|
|
1194 ;; subr, rather don't print anything.
|
|
1195 (cond ((null args) t)
|
|
1196 ((equal args "") nil)
|
|
1197 (args))))
|
|
1198 (t t))))
|
428
|
1199 (cond ((listp arglist)
|
|
1200 (prin1-to-string
|
|
1201 (cons function (mapcar (lambda (arg)
|
|
1202 (if (memq arg '(&optional &rest))
|
|
1203 arg
|
|
1204 (intern (upcase (symbol-name arg)))))
|
|
1205 arglist))
|
|
1206 t))
|
|
1207 ((stringp arglist)
|
|
1208 (format "(%s %s)" function arglist)))))
|
|
1209
|
|
1210 (defun function-documentation (function &optional strip-arglist)
|
|
1211 "Return a string giving the documentation for FUNCTION, if any.
|
|
1212 If the optional argument STRIP-ARGLIST is non-nil, remove the arglist
|
|
1213 part of the documentation of internal subroutines."
|
|
1214 (let ((doc (condition-case nil
|
|
1215 (or (documentation function)
|
|
1216 (gettext "not documented"))
|
2275
|
1217 (void-function "(alias for undefined function)")
|
|
1218 (error "(unexpected error from `documention')"))))
|
428
|
1219 (if (and strip-arglist
|
|
1220 (string-match "[\n\t ]*\narguments: ?(\\(.*\\))\n?\\'" doc))
|
|
1221 (setq doc (substring doc 0 (match-beginning 0))))
|
|
1222 doc))
|
442
|
1223
|
462
|
1224 ;; replacement for `princ' that puts the text in the specified face,
|
|
1225 ;; if possible
|
|
1226 (defun Help-princ-face (object face)
|
|
1227 (cond ((bufferp standard-output)
|
464
|
1228 (let ((opoint (point standard-output)))
|
|
1229 (princ object)
|
|
1230 (put-nonduplicable-text-property opoint (point standard-output)
|
|
1231 'face face standard-output)))
|
|
1232 ((markerp standard-output)
|
|
1233 (let ((buf (marker-buffer standard-output))
|
|
1234 (pos (marker-position standard-output)))
|
|
1235 (princ object)
|
|
1236 (put-nonduplicable-text-property
|
|
1237 pos (marker-position standard-output) 'face face buf)))
|
1779
|
1238 (t (princ object))))
|
462
|
1239
|
|
1240 ;; replacement for `prin1' that puts the text in the specified face,
|
|
1241 ;; if possible
|
|
1242 (defun Help-prin1-face (object face)
|
|
1243 (cond ((bufferp standard-output)
|
464
|
1244 (let ((opoint (point standard-output)))
|
|
1245 (prin1 object)
|
|
1246 (put-nonduplicable-text-property opoint (point standard-output)
|
|
1247 'face face standard-output)))
|
|
1248 ((markerp standard-output)
|
|
1249 (let ((buf (marker-buffer standard-output))
|
|
1250 (pos (marker-position standard-output)))
|
|
1251 (prin1 object)
|
|
1252 (put-nonduplicable-text-property
|
|
1253 pos (marker-position standard-output) 'face face buf)))
|
1779
|
1254 (t (prin1 object))))
|
462
|
1255
|
442
|
1256 (defvar help-symbol-regexp
|
|
1257 (let ((sym-char "[+a-zA-Z0-9_:*]")
|
|
1258 (sym-char-no-dash "[-+a-zA-Z0-9_:*]"))
|
|
1259 (concat "\\("
|
|
1260 ;; a symbol with a - in it.
|
|
1261 "\\<\\(" sym-char-no-dash "+\\(-" sym-char-no-dash "+\\)+\\)\\>"
|
|
1262 "\\|"
|
|
1263 "`\\(" sym-char "+\\)'"
|
|
1264 "\\)")))
|
|
1265
|
|
1266 (defun help-symbol-run-function-1 (ev ex fun)
|
|
1267 (let ((help-sticky-window
|
|
1268 ;; if we were called from a help buffer, make sure the new help
|
|
1269 ;; goes in the same window.
|
|
1270 (if (and (event-buffer ev)
|
|
1271 (symbol-value-in-buffer 'help-window-config
|
|
1272 (event-buffer ev)))
|
|
1273 (event-window ev)
|
|
1274 help-sticky-window)))
|
|
1275 (funcall fun (extent-property ex 'help-symbol))))
|
|
1276
|
|
1277 (defun help-symbol-run-function (fun)
|
|
1278 (let ((ex (extent-at-event last-popup-menu-event 'help-symbol)))
|
|
1279 (when ex
|
|
1280 (help-symbol-run-function-1 last-popup-menu-event ex fun))))
|
|
1281
|
|
1282 (defvar help-symbol-function-context-menu
|
462
|
1283 '(["View %_Documentation" (help-symbol-run-function 'describe-function)]
|
442
|
1284 ["Find %_Function Source" (help-symbol-run-function 'find-function)]
|
462
|
1285 ["Find %_Tag" (help-symbol-run-function 'find-tag)]
|
442
|
1286 ))
|
|
1287
|
|
1288 (defvar help-symbol-variable-context-menu
|
462
|
1289 '(["View %_Documentation" (help-symbol-run-function 'describe-variable)]
|
442
|
1290 ["Find %_Variable Source" (help-symbol-run-function 'find-variable)]
|
462
|
1291 ["Find %_Tag" (help-symbol-run-function 'find-tag)]
|
442
|
1292 ))
|
|
1293
|
|
1294 (defvar help-symbol-function-and-variable-context-menu
|
462
|
1295 '(["View Function %_Documentation" (help-symbol-run-function
|
442
|
1296 'describe-function)]
|
|
1297 ["View Variable D%_ocumentation" (help-symbol-run-function
|
|
1298 'describe-variable)]
|
|
1299 ["Find %_Function Source" (help-symbol-run-function 'find-function)]
|
|
1300 ["Find %_Variable Source" (help-symbol-run-function 'find-variable)]
|
462
|
1301 ["Find %_Tag" (help-symbol-run-function 'find-tag)]
|
442
|
1302 ))
|
|
1303
|
|
1304 (defun frob-help-extents (buffer)
|
|
1305 ;; Look through BUFFER, starting at the buffer's point and continuing
|
|
1306 ;; till end of file, and find documented functions and variables.
|
|
1307 ;; any such symbol found is tagged with an extent, that sets up these
|
|
1308 ;; properties:
|
|
1309 ;; 1. mouse-face is 'highlight (so the extent gets highlighted on mouse over)
|
|
1310 ;; 2. help-symbol is the name of the symbol.
|
464
|
1311 ;; 3. face is 'hyper-apropos-hyperlink.
|
462
|
1312 ;; 4. context-menu is a list of context menu items, specific to whether
|
442
|
1313 ;; the symbol is a function, variable, or both.
|
462
|
1314 ;; 5. activate-function will cause the function or variable to be described,
|
442
|
1315 ;; replacing the existing help contents.
|
|
1316 (save-excursion
|
|
1317 (set-buffer buffer)
|
|
1318 (let (b e name)
|
|
1319 (while (re-search-forward help-symbol-regexp nil t)
|
|
1320 (setq b (or (match-beginning 2) (match-beginning 4)))
|
|
1321 (setq e (or (match-end 2) (match-end 4)))
|
|
1322 (setq name (buffer-substring b e))
|
|
1323 (let* ((sym (intern-soft name))
|
|
1324 (var (and sym (boundp sym)
|
|
1325 (documentation-property sym
|
|
1326 'variable-documentation t)))
|
|
1327 (fun (and sym (fboundp sym)
|
2275
|
1328 (condition-case nil
|
|
1329 (documentation sym t)
|
|
1330 (void-function "(alias for undefined function)")
|
|
1331 (error "(unexpected error from `documention')")))))
|
442
|
1332 (when (or var fun)
|
|
1333 (let ((ex (make-extent b e)))
|
622
|
1334 (require 'hyper-apropos)
|
442
|
1335 (set-extent-property ex 'mouse-face 'highlight)
|
|
1336 (set-extent-property ex 'help-symbol sym)
|
464
|
1337 (set-extent-property ex 'face 'hyper-apropos-hyperlink)
|
442
|
1338 (set-extent-property
|
|
1339 ex 'context-menu
|
|
1340 (cond ((and var fun)
|
|
1341 help-symbol-function-and-variable-context-menu)
|
|
1342 (var help-symbol-variable-context-menu)
|
|
1343 (fun help-symbol-function-context-menu)))
|
|
1344 (set-extent-property
|
|
1345 ex 'activate-function
|
|
1346 (if fun
|
|
1347 #'(lambda (ev ex)
|
|
1348 (help-symbol-run-function-1 ev ex 'describe-function))
|
|
1349 #'(lambda (ev ex)
|
|
1350 (help-symbol-run-function-1 ev ex 'describe-variable))))
|
|
1351 ))))))) ;; 11 parentheses!
|
428
|
1352
|
|
1353 (defun describe-function-1 (function &optional nodoc)
|
|
1354 "This function does the work for `describe-function'."
|
462
|
1355 (princ "`")
|
|
1356 ;; (Help-princ-face function 'font-lock-function-name-face) overkill
|
|
1357 (princ function)
|
|
1358 (princ "' is ")
|
428
|
1359 (let* ((def function)
|
|
1360 aliases file-name autoload-file kbd-macro-p fndef macrop)
|
|
1361 (while (and (symbolp def) (fboundp def))
|
|
1362 (when (not (eq def function))
|
|
1363 (setq aliases
|
|
1364 (if aliases
|
|
1365 ;; I18N3 Need gettext due to concat
|
|
1366 (concat aliases
|
|
1367 (format
|
|
1368 "\n which is an alias for `%s', "
|
|
1369 (symbol-name def)))
|
|
1370 (format "an alias for `%s', " (symbol-name def)))))
|
|
1371 (setq def (symbol-function def)))
|
|
1372 (if (and (fboundp 'compiled-function-annotation)
|
|
1373 (compiled-function-p def))
|
502
|
1374 (setq file-name (declare-fboundp (compiled-function-annotation def))))
|
428
|
1375 (if (eq 'macro (car-safe def))
|
|
1376 (setq fndef (cdr def)
|
|
1377 file-name (and (compiled-function-p (cdr def))
|
|
1378 (fboundp 'compiled-function-annotation)
|
502
|
1379 (declare-fboundp
|
|
1380 (compiled-function-annotation (cdr def))))
|
428
|
1381 macrop t)
|
|
1382 (setq fndef def))
|
|
1383 (if aliases (princ aliases))
|
|
1384 (let ((int #'(lambda (string an-p macro-p)
|
|
1385 (princ (format
|
|
1386 (gettext (concat
|
|
1387 (cond ((commandp def)
|
|
1388 "an interactive ")
|
|
1389 (an-p "an ")
|
|
1390 (t "a "))
|
|
1391 "%s"
|
|
1392 (if macro-p " macro" " function")))
|
|
1393 string)))))
|
|
1394 (cond ((or (stringp def) (vectorp def))
|
|
1395 (princ "a keyboard macro.")
|
|
1396 (setq kbd-macro-p t))
|
|
1397 ((subrp fndef)
|
|
1398 (funcall int "built-in" nil macrop))
|
|
1399 ((compiled-function-p fndef)
|
|
1400 (funcall int "compiled Lisp" nil macrop))
|
|
1401 ((eq (car-safe fndef) 'lambda)
|
|
1402 (funcall int "Lisp" nil macrop))
|
|
1403 ((eq (car-safe fndef) 'mocklisp)
|
|
1404 (funcall int "mocklisp" nil macrop))
|
|
1405 ((eq (car-safe def) 'autoload)
|
|
1406 (setq autoload-file (elt def 1))
|
|
1407 (funcall int "autoloaded Lisp" t (elt def 4)))
|
|
1408 ((and (symbolp def) (not (fboundp def)))
|
|
1409 (princ "a symbol with a void (unbound) function definition."))
|
|
1410 (t
|
|
1411 nil)))
|
|
1412 (princ "\n")
|
|
1413 (if autoload-file
|
|
1414 (princ (format " -- autoloads from \"%s\"\n" autoload-file)))
|
|
1415 (or file-name
|
|
1416 (setq file-name (describe-symbol-find-file function)))
|
|
1417 (if file-name
|
|
1418 (princ (format " -- loaded from \"%s\"\n" file-name)))
|
|
1419 ;; (terpri)
|
|
1420 (if describe-function-show-arglist
|
|
1421 (let ((arglist (function-arglist function)))
|
|
1422 (when arglist
|
464
|
1423 (require 'hyper-apropos)
|
|
1424 (Help-princ-face arglist 'hyper-apropos-documentation)
|
428
|
1425 (terpri))))
|
|
1426 (terpri)
|
|
1427 (cond (kbd-macro-p
|
|
1428 (princ "These characters are executed:\n\n\t")
|
|
1429 (princ (key-description def))
|
|
1430 (cond ((setq def (key-binding def))
|
|
1431 (princ (format "\n\nwhich executes the command `%s'.\n\n"
|
|
1432 def))
|
|
1433 (describe-function-1 def))))
|
|
1434 (nodoc nil)
|
|
1435 (t
|
|
1436 ;; tell the user about obsoleteness.
|
|
1437 ;; If the function is obsolete and is aliased, don't
|
|
1438 ;; even bother to report the documentation, as a further
|
|
1439 ;; encouragement to use the new function.
|
|
1440 (let ((obsolete (function-obsoleteness-doc function))
|
|
1441 (compatible (function-compatibility-doc function)))
|
|
1442 (when obsolete
|
|
1443 (princ obsolete)
|
|
1444 (terpri)
|
|
1445 (terpri))
|
|
1446 (when compatible
|
|
1447 (princ compatible)
|
|
1448 (terpri)
|
|
1449 (terpri))
|
|
1450 (unless (and obsolete aliases)
|
|
1451 (let ((doc (function-documentation function t)))
|
|
1452 (princ "Documentation:\n")
|
442
|
1453 (let ((oldp (point standard-output))
|
|
1454 newp)
|
|
1455 (princ doc)
|
|
1456 (setq newp (point standard-output))
|
|
1457 (goto-char oldp standard-output)
|
|
1458 (frob-help-extents standard-output)
|
|
1459 (goto-char newp standard-output))
|
428
|
1460 (unless (or (equal doc "")
|
|
1461 (eq ?\n (aref doc (1- (length doc)))))
|
|
1462 (terpri)))))))))
|
|
1463
|
|
1464
|
|
1465 ;;; [Obnoxious, whining people who complain very LOUDLY on Usenet
|
|
1466 ;;; are binding this to keys.]
|
|
1467 (defun describe-function-arglist (function)
|
|
1468 (interactive (list (or (function-at-point)
|
|
1469 (error "no function call at point"))))
|
|
1470 (message nil)
|
|
1471 (message (function-arglist function)))
|
|
1472
|
|
1473 (defun variable-at-point ()
|
|
1474 (ignore-errors
|
|
1475 (with-syntax-table emacs-lisp-mode-syntax-table
|
|
1476 (save-excursion
|
|
1477 (or (not (zerop (skip-syntax-backward "_w")))
|
|
1478 (eq (char-syntax (char-after (point))) ?w)
|
|
1479 (eq (char-syntax (char-after (point))) ?_)
|
|
1480 (forward-sexp -1))
|
|
1481 (skip-chars-forward "'")
|
|
1482 (let ((obj (read (current-buffer))))
|
|
1483 (and (symbolp obj) (boundp obj) obj))))))
|
|
1484
|
442
|
1485 (defun variable-at-event (event)
|
|
1486 "Return the variable whose name is around the position of EVENT.
|
|
1487 EVENT should be a mouse event. When calling from a popup or context menu,
|
|
1488 use `last-popup-menu-event' to find out where the mouse was clicked.
|
|
1489 \(You cannot use (interactive \"e\"), unfortunately. This returns a
|
|
1490 misc-user event.)
|
|
1491
|
|
1492 If the event contains no position, or the position is not over text, or
|
|
1493 there is no variable around that point, nil is returned."
|
|
1494 (if (and event (event-buffer event) (event-point event))
|
|
1495 (save-excursion
|
|
1496 (set-buffer (event-buffer event))
|
|
1497 (goto-char (event-point event))
|
|
1498 (variable-at-point))))
|
|
1499
|
428
|
1500 (defun variable-obsolete-p (variable)
|
|
1501 "Return non-nil if VARIABLE is obsolete."
|
|
1502 (not (null (get variable 'byte-obsolete-variable))))
|
|
1503
|
|
1504 (defun variable-obsoleteness-doc (variable)
|
|
1505 "If VARIABLE is obsolete, return a string describing this."
|
|
1506 (let ((obsolete (get variable 'byte-obsolete-variable)))
|
|
1507 (if obsolete
|
|
1508 (format "Obsolete; %s"
|
|
1509 (if (stringp obsolete)
|
|
1510 obsolete
|
|
1511 (format "use `%s' instead." obsolete))))))
|
|
1512
|
|
1513 (defun variable-compatible-p (variable)
|
|
1514 "Return non-nil if VARIABLE is Emacs compatible."
|
|
1515 (not (null (get variable 'byte-compatible-variable))))
|
|
1516
|
|
1517 (defun variable-compatibility-doc (variable)
|
|
1518 "If VARIABLE is Emacs compatible, return a string describing this."
|
|
1519 (let ((compatible (get variable 'byte-compatible-variable)))
|
|
1520 (if compatible
|
|
1521 (format "Emacs Compatible; %s"
|
|
1522 (if (stringp compatible)
|
|
1523 compatible
|
|
1524 (format "use `%s' instead." compatible))))))
|
|
1525
|
|
1526 (defun built-in-variable-doc (variable)
|
|
1527 "Return a string describing whether VARIABLE is built-in."
|
|
1528 (let ((type (built-in-variable-type variable)))
|
|
1529 (case type
|
|
1530 (integer "a built-in integer variable")
|
|
1531 (const-integer "a built-in constant integer variable")
|
|
1532 (boolean "a built-in boolean variable")
|
|
1533 (const-boolean "a built-in constant boolean variable")
|
|
1534 (object "a simple built-in variable")
|
|
1535 (const-object "a simple built-in constant variable")
|
|
1536 (const-specifier "a built-in constant specifier variable")
|
|
1537 (current-buffer "a built-in buffer-local variable")
|
|
1538 (const-current-buffer "a built-in constant buffer-local variable")
|
|
1539 (default-buffer "a built-in default buffer-local variable")
|
|
1540 (selected-console "a built-in console-local variable")
|
|
1541 (const-selected-console "a built-in constant console-local variable")
|
|
1542 (default-console "a built-in default console-local variable")
|
|
1543 (t
|
|
1544 (if type "an unknown type of built-in variable?"
|
|
1545 "a variable declared in Lisp")))))
|
|
1546
|
|
1547 (defun describe-variable (variable)
|
|
1548 "Display the full documentation of VARIABLE (a symbol)."
|
|
1549 (interactive
|
|
1550 (let* ((v (variable-at-point))
|
|
1551 (val (let ((enable-recursive-minibuffers t))
|
|
1552 (completing-read
|
|
1553 (if v
|
|
1554 (format "Describe variable (default %s): " v)
|
|
1555 (gettext "Describe variable: "))
|
430
|
1556 obarray 'boundp t nil 'variable-history
|
|
1557 (symbol-name v)))))
|
|
1558 (list (intern val))))
|
428
|
1559 (with-displaying-help-buffer
|
|
1560 (lambda ()
|
|
1561 (let ((origvar variable)
|
|
1562 aliases)
|
|
1563 (let ((print-escape-newlines t))
|
462
|
1564 (princ "`")
|
|
1565 ;; (Help-princ-face (symbol-name variable)
|
502
|
1566 ;; 'font-lock-variable-name-face) overkill
|
462
|
1567 (princ (symbol-name variable))
|
|
1568 (princ "' is ")
|
428
|
1569 (while (variable-alias variable)
|
|
1570 (let ((newvar (variable-alias variable)))
|
|
1571 (if aliases
|
|
1572 ;; I18N3 Need gettext due to concat
|
|
1573 (setq aliases
|
|
1574 (concat aliases
|
|
1575 (format "\n which is an alias for `%s',"
|
|
1576 (symbol-name newvar))))
|
|
1577 (setq aliases
|
|
1578 (format "an alias for `%s',"
|
|
1579 (symbol-name newvar))))
|
|
1580 (setq variable newvar)))
|
|
1581 (if aliases
|
|
1582 (princ (format "%s" aliases)))
|
|
1583 (princ (built-in-variable-doc variable))
|
|
1584 (princ ".\n")
|
|
1585 (let ((file-name (describe-symbol-find-file variable)))
|
|
1586 (if file-name
|
|
1587 (princ (format " -- loaded from \"%s\"\n" file-name))))
|
|
1588 (princ "\nValue: ")
|
464
|
1589 (require 'hyper-apropos)
|
|
1590 (if (not (boundp variable))
|
|
1591 (Help-princ-face "void\n" 'hyper-apropos-documentation)
|
|
1592 (Help-prin1-face (symbol-value variable)
|
|
1593 'hyper-apropos-documentation)
|
428
|
1594 (terpri))
|
|
1595 (terpri)
|
|
1596 (cond ((local-variable-p variable (current-buffer))
|
|
1597 (let* ((void (cons nil nil))
|
|
1598 (def (condition-case nil
|
|
1599 (default-value variable)
|
|
1600 (error void))))
|
|
1601 (princ "This value is specific to the current buffer.\n")
|
|
1602 (if (local-variable-p variable nil)
|
|
1603 (princ "(Its value is local to each buffer.)\n"))
|
|
1604 (terpri)
|
|
1605 (if (if (eq def void)
|
|
1606 (boundp variable)
|
|
1607 (not (eq (symbol-value variable) def)))
|
|
1608 ;; #### I18N3 doesn't localize properly!
|
|
1609 (progn (princ "Default-value: ")
|
|
1610 (if (eq def void)
|
|
1611 (princ "void\n")
|
|
1612 (prin1 def)
|
|
1613 (terpri))
|
|
1614 (terpri)))))
|
|
1615 ((local-variable-p variable (current-buffer) t)
|
|
1616 (princ "Setting it would make its value buffer-local.\n\n"))))
|
|
1617 (princ "Documentation:")
|
|
1618 (terpri)
|
|
1619 (let ((doc (documentation-property variable 'variable-documentation))
|
|
1620 (obsolete (variable-obsoleteness-doc origvar))
|
|
1621 (compatible (variable-compatibility-doc origvar)))
|
|
1622 (when obsolete
|
|
1623 (princ obsolete)
|
|
1624 (terpri)
|
|
1625 (terpri))
|
|
1626 (when compatible
|
|
1627 (princ compatible)
|
|
1628 (terpri)
|
|
1629 (terpri))
|
|
1630 ;; don't bother to print anything if variable is obsolete and aliased.
|
|
1631 (when (or (not obsolete) (not aliases))
|
|
1632 (if doc
|
|
1633 ;; note: documentation-property calls substitute-command-keys.
|
442
|
1634 (let ((oldp (point standard-output))
|
|
1635 newp)
|
|
1636 (princ doc)
|
|
1637 (setq newp (point standard-output))
|
|
1638 (goto-char oldp standard-output)
|
|
1639 (frob-help-extents standard-output)
|
|
1640 (goto-char newp standard-output))
|
428
|
1641 (princ "not documented as a variable."))))
|
|
1642 (terpri)))
|
|
1643 (format "variable `%s'" variable)))
|
|
1644
|
|
1645 (defun sorted-key-descriptions (keys &optional separator)
|
|
1646 "Sort and separate the key descriptions for KEYS.
|
|
1647 The sorting is done by length (shortest bindings first), and the bindings
|
|
1648 are separated with SEPARATOR (\", \" by default)."
|
|
1649 (mapconcat 'key-description
|
|
1650 (sort keys #'(lambda (x y)
|
|
1651 (< (length x) (length y))))
|
|
1652 (or separator ", ")))
|
|
1653
|
|
1654 (defun where-is (definition &optional insert)
|
|
1655 "Print message listing key sequences that invoke specified command.
|
|
1656 Argument is a command definition, usually a symbol with a function definition.
|
|
1657 When run interactively, it defaults to any function found by
|
|
1658 `function-at-point'.
|
|
1659 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
|
|
1660 (interactive
|
|
1661 (let ((fn (function-at-point))
|
|
1662 (enable-recursive-minibuffers t)
|
|
1663 val)
|
|
1664 (setq val (read-command
|
|
1665 (if fn (format "Where is command (default %s): " fn)
|
456
|
1666 "Where is command: ")
|
|
1667 (and fn (symbol-name fn))))
|
428
|
1668 (list (if (equal (symbol-name val) "")
|
|
1669 fn val)
|
|
1670 current-prefix-arg)))
|
|
1671 (let ((keys (where-is-internal definition)))
|
|
1672 (if keys
|
|
1673 (if insert
|
|
1674 (princ (format "%s (%s)" (sorted-key-descriptions keys)
|
|
1675 definition) (current-buffer))
|
|
1676 (message "%s is on %s" definition (sorted-key-descriptions keys)))
|
|
1677 (if insert
|
|
1678 (princ (format (if (commandp definition) "M-x %s RET"
|
|
1679 "M-: (%s ...)") definition) (current-buffer))
|
|
1680 (message "%s is not on any keys" definition))))
|
|
1681 nil)
|
|
1682
|
|
1683 ;; `locate-library' moved to "packages.el"
|
|
1684
|
|
1685
|
|
1686 ;; Functions ported from C into Lisp in XEmacs
|
|
1687
|
|
1688 (defun describe-syntax ()
|
|
1689 "Describe the syntax specifications in the syntax table.
|
|
1690 The descriptions are inserted in a buffer, which is then displayed."
|
|
1691 (interactive)
|
|
1692 (with-displaying-help-buffer
|
|
1693 (lambda ()
|
|
1694 ;; defined in syntax.el
|
|
1695 (describe-syntax-table (syntax-table) standard-output))
|
|
1696 (format "syntax-table for %s" major-mode)))
|
|
1697
|
|
1698 (defun list-processes ()
|
|
1699 "Display a list of all processes.
|
|
1700 \(Any processes listed as Exited or Signaled are actually eliminated
|
|
1701 after the listing is made.)"
|
|
1702 (interactive)
|
|
1703 (with-output-to-temp-buffer "*Process List*"
|
|
1704 (set-buffer standard-output)
|
|
1705 (buffer-disable-undo standard-output)
|
|
1706 (make-local-variable 'truncate-lines)
|
|
1707 (setq truncate-lines t)
|
|
1708 ;; 00000000001111111111222222222233333333334444444444
|
|
1709 ;; 01234567890123456789012345678901234567890123456789
|
|
1710 ;; rewritten for I18N3. This one should stay rewritten
|
|
1711 ;; so that the dashes will line up properly.
|
|
1712 (princ "Proc Status Buffer Tty Command\n---- ------ ------ --- -------\n")
|
|
1713 (let ((tail (process-list)))
|
|
1714 (while tail
|
|
1715 (let* ((p (car tail))
|
|
1716 (pid (process-id p))
|
|
1717 (s (process-status p)))
|
|
1718 (setq tail (cdr tail))
|
|
1719 (princ (format "%-13s" (process-name p)))
|
|
1720 (princ s)
|
|
1721 (if (and (eq s 'exit) (/= (process-exit-status p) 0))
|
|
1722 (princ (format " %d" (process-exit-status p))))
|
|
1723 (if (memq s '(signal exit closed))
|
|
1724 ;; Do delete-exited-processes' work
|
|
1725 (delete-process p))
|
|
1726 (indent-to 22 1) ;####
|
|
1727 (let ((b (process-buffer p)))
|
|
1728 (cond ((not b)
|
|
1729 (princ "(none)"))
|
|
1730 ((not (buffer-name b))
|
|
1731 (princ "(killed)"))
|
|
1732 (t
|
|
1733 (princ (buffer-name b)))))
|
|
1734 (indent-to 37 1) ;####
|
|
1735 (let ((tn (process-tty-name p)))
|
|
1736 (cond ((not tn)
|
|
1737 (princ "(none)"))
|
|
1738 (t
|
|
1739 (princ (format "%s" tn)))))
|
|
1740 (indent-to 49 1) ;####
|
|
1741 (if (not (integerp pid))
|
|
1742 (progn
|
|
1743 (princ "network stream connection ")
|
|
1744 (princ (car pid))
|
|
1745 (princ "@")
|
|
1746 (princ (cdr pid)))
|
|
1747 (let ((cmd (process-command p)))
|
|
1748 (while cmd
|
|
1749 (princ (car cmd))
|
|
1750 (setq cmd (cdr cmd))
|
|
1751 (if cmd (princ " ")))))
|
|
1752 (terpri))))))
|
|
1753
|
440
|
1754 ;; Stop gap for 21.0 until we do help-char etc properly.
|
428
|
1755 (defun help-keymap-with-help-key (keymap form)
|
|
1756 "Return a copy of KEYMAP with an help-key binding according to help-char
|
|
1757 invoking FORM like help-form. An existing binding is not overridden.
|
|
1758 If FORM is nil then no binding is made."
|
|
1759 (let ((map (copy-keymap keymap))
|
|
1760 (key (if (characterp help-char)
|
|
1761 (vector (character-to-event help-char))
|
|
1762 help-char)))
|
|
1763 (when (and form key (not (lookup-key map key)))
|
|
1764 (define-key map key
|
|
1765 `(lambda () (interactive) (help-print-help-form ,form))))
|
|
1766 map))
|
|
1767
|
|
1768 (defun help-print-help-form (form)
|
|
1769 (let ((string (eval form)))
|
|
1770 (if (stringp string)
|
|
1771 (with-displaying-help-buffer
|
|
1772 (insert string)))))
|
|
1773
|
|
1774 ;;; help.el ends here
|