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