209
|
1 ;;; help.el --- help commands for XEmacs.
|
|
2
|
|
3 ;; Copyright (C) 1985, 1986, 1992-4, 1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: FSF
|
|
6 ;; Keywords: help, internal, dumped
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
|
24
|
|
25 ;;; Synched up with: FSF 19.30.
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; This file is dumped with XEmacs.
|
|
30
|
|
31 ;; This code implements XEmacs's on-line help system, the one invoked by
|
|
32 ;;`M-x help-for-help'.
|
|
33
|
|
34 ;; 06/11/1997 -- Converted to use char-after instead of broken
|
|
35 ;; following-char. -slb
|
|
36
|
|
37 ;;; Code:
|
|
38
|
|
39 ;; Get the macro make-help-screen when this is compiled,
|
|
40 ;; or run interpreted, but not when the compiled code is loaded.
|
211
|
41 (eval-when-compile (require 'help-macro))
|
209
|
42
|
227
|
43 (defgroup help nil
|
|
44 "Support for on-line help systems."
|
|
45 :group 'emacs)
|
|
46
|
209
|
47 (defgroup help-appearance nil
|
227
|
48 "Appearance of help buffers."
|
209
|
49 :group 'help)
|
|
50
|
|
51 (defvar help-map (let ((map (make-sparse-keymap)))
|
|
52 (set-keymap-name map 'help-map)
|
|
53 (set-keymap-prompt
|
|
54 map (purecopy (gettext "(Type ? for further options)")))
|
|
55 map)
|
|
56 "Keymap for characters following the Help key.")
|
|
57
|
|
58 ;; global-map definitions moved to keydefs.el
|
|
59 (fset 'help-command help-map)
|
|
60
|
|
61 (define-key help-map (vector help-char) 'help-for-help)
|
|
62 (define-key help-map "?" 'help-for-help)
|
|
63 (define-key help-map 'help 'help-for-help)
|
243
|
64 (define-key help-map '(f1) 'help-for-help)
|
209
|
65
|
|
66 (define-key help-map "\C-l" 'describe-copying) ; on \C-c in FSFmacs
|
|
67 (define-key help-map "\C-d" 'describe-distribution)
|
|
68 (define-key help-map "\C-w" 'describe-no-warranty)
|
|
69 (define-key help-map "a" 'hyper-apropos) ; 'command-apropos in FSFmacs
|
|
70 (define-key help-map "A" 'command-apropos)
|
|
71
|
|
72 (define-key help-map "b" 'describe-bindings)
|
|
73 (define-key help-map "B" 'describe-beta)
|
|
74 (define-key help-map "\C-p" 'describe-pointer)
|
|
75
|
|
76 (define-key help-map "C" 'customize)
|
|
77 (define-key help-map "c" 'describe-key-briefly)
|
|
78 (define-key help-map "k" 'describe-key)
|
|
79
|
|
80 (define-key help-map "d" 'describe-function)
|
|
81 (define-key help-map "e" 'describe-last-error)
|
|
82 (define-key help-map "f" 'describe-function)
|
|
83
|
|
84 (define-key help-map "F" 'xemacs-local-faq)
|
|
85
|
|
86 ;;; Setup so Hyperbole can be autoloaded from a key.
|
|
87 ;;; Choose a key on which to place the Hyperbole menus.
|
|
88 ;;; For most people this key binding will work and will be equivalent
|
|
89 ;;; to {C-h h}.
|
|
90 ;;;
|
239
|
91 (when (featurep 'infodock) ; This isn't used in XEmacs
|
|
92 ;; #### This needs fixing for InfoDock 4.0.
|
|
93 (or (where-is-internal 'hyperbole)
|
|
94 (where-is-internal 'hui:menu)
|
|
95 (define-key help-map "h" 'hyperbole))
|
|
96 (autoload 'hyperbole "hsite" "Hyperbole info manager menus." t))
|
209
|
97
|
|
98 (define-key help-map "i" 'info)
|
|
99 (define-key help-map '(control i) 'Info-query)
|
|
100 ;; FSFmacs has Info-goto-emacs-command-node on C-f, no binding
|
|
101 ;; for Info-elisp-ref
|
|
102 (define-key help-map '(control c) 'Info-goto-emacs-command-node)
|
|
103 (define-key help-map '(control k) 'Info-goto-emacs-key-command-node)
|
|
104 (define-key help-map '(control f) 'Info-elisp-ref)
|
|
105
|
|
106 (define-key help-map "l" 'view-lossage)
|
|
107
|
|
108 (define-key help-map "m" 'describe-mode)
|
|
109
|
|
110 (define-key help-map "\C-n" 'view-emacs-news)
|
|
111 (define-key help-map "n" 'view-emacs-news)
|
|
112
|
|
113 (define-key help-map "p" 'finder-by-keyword)
|
239
|
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)
|
209
|
118
|
|
119 (define-key help-map "s" 'describe-syntax)
|
|
120
|
|
121 (define-key help-map "t" 'help-with-tutorial)
|
|
122
|
|
123 (define-key help-map "w" 'where-is)
|
|
124
|
|
125 (define-key help-map "v" 'describe-variable)
|
|
126
|
|
127 (if (fboundp 'view-last-error)
|
|
128 (define-key help-map "e" 'view-last-error))
|
|
129
|
|
130
|
|
131 (define-key help-map "q" 'help-quit)
|
|
132
|
|
133 ;#### This stuff was an attempt to have font locking and hyperlinks in the
|
|
134 ;help buffer, but it doesn't really work. Some of this stuff comes from
|
|
135 ;FSF Emacs; but the FSF Emacs implementation is rather broken, as usual.
|
|
136 ;What needs to happen is this:
|
|
137 ;
|
|
138 ; -- we probably need a "hyperlink mode" from which help-mode is derived.
|
|
139 ; -- this means we probably need multiple inheritance of modes!
|
|
140 ; Thankfully this is not hard to implement; we already have the
|
|
141 ; ability for a keymap to have multiple parents. However, we'd
|
|
142 ; have to define any multiply-inherited-from modes using a standard
|
|
143 ; `define-mode' construction instead of manually doing it, because
|
|
144 ; we don't want each guy calling `kill-all-local-variables' and
|
|
145 ; messing up the previous one.
|
|
146 ; -- we need to scan the buffer ourselves (not from font-lock, because
|
|
147 ; the user might not have font-lock enabled) and highlight only
|
|
148 ; those words that are *documented* functions and variables (and
|
|
149 ; probably excluding words without dashes in them unless enclosed
|
|
150 ; in quotes, so that common words like "list" and "point" don't
|
|
151 ; become hyperlinks.
|
|
152 ; -- we should *not* use font-lock keywords like below. Instead we
|
|
153 ; should add the font-lock stuff ourselves during the scanning phase,
|
|
154 ; if font-lock is enabled in this buffer.
|
|
155
|
|
156 ;(defun help-follow-reference (event extent user-data)
|
|
157 ; (let ((symbol (intern-soft (extent-string extent))))
|
|
158 ; (cond ((and symbol (fboundp symbol))
|
|
159 ; (describe-function symbol))
|
|
160 ; ((and symbol (boundp symbol))
|
|
161 ; (describe-variable symbol))
|
|
162 ; (t nil))))
|
|
163
|
|
164 ;(defvar help-font-lock-keywords
|
|
165 ; (let ((name-char "[-+a-zA-Z0-9_*]") (sym-char "[-+a-zA-Z0-9_:*]"))
|
|
166 ; (list
|
|
167 ; ;;
|
|
168 ; ;; The symbol itself.
|
|
169 ; (list (concat "\\`\\(" name-char "+\\)\\(:\\)?")
|
|
170 ; '(1 (if (match-beginning 2)
|
|
171 ; 'font-lock-function-name-face
|
|
172 ; 'font-lock-variable-name-face)
|
|
173 ; nil t))
|
|
174 ; ;;
|
|
175 ; ;; Words inside `' which tend to be symbol names.
|
|
176 ; (list (concat "`\\(" sym-char sym-char "+\\)'")
|
|
177 ; 1 '(prog1
|
|
178 ; 'font-lock-reference-face
|
|
179 ; (add-list-mode-item (match-beginning 1)
|
|
180 ; (match-end 1)
|
|
181 ; nil
|
|
182 ; 'help-follow-reference))
|
|
183 ; t)
|
|
184 ; ;;
|
|
185 ; ;; CLisp `:' keywords as references.
|
|
186 ; (list (concat "\\<:" sym-char "+\\>") 0 'font-lock-reference-face t)))
|
|
187 ; "Default expressions to highlight in Help mode.")
|
|
188
|
|
189 ;(put 'help-mode 'font-lock-defaults '(help-font-lock-keywords))
|
|
190
|
|
191 (define-derived-mode help-mode view-major-mode "Help"
|
|
192 "Major mode for viewing help text.
|
|
193 Entry to this mode runs the normal hook `help-mode-hook'.
|
|
194 Commands:
|
|
195 \\{help-mode-map}"
|
|
196 )
|
|
197
|
|
198 (define-key help-mode-map "q" 'help-mode-quit)
|
231
|
199 (define-key help-mode-map "Q" 'help-mode-bury)
|
209
|
200 (define-key help-mode-map "f" 'find-function-at-point)
|
231
|
201 (define-key help-mode-map "d" 'describe-function-at-point)
|
|
202 (define-key help-mode-map "v" 'describe-variable-at-point)
|
|
203 (define-key help-mode-map "i" 'Info-elisp-ref)
|
|
204 (define-key help-mode-map "c" 'customize-variable)
|
|
205 (define-key help-mode-map [tab] 'help-next-symbol)
|
|
206 (define-key help-mode-map [(shift tab)] 'help-prev-symbol)
|
|
207 (define-key help-mode-map "n" 'help-next-section)
|
|
208 (define-key help-mode-map "p" 'help-prev-section)
|
209
|
209
|
|
210 (defun describe-function-at-point ()
|
|
211 "Describe directly the function at point in the other window."
|
|
212 (interactive)
|
|
213 (let ((symb (function-at-point)))
|
|
214 (when symb
|
|
215 (describe-function symb))))
|
231
|
216
|
209
|
217 (defun describe-variable-at-point ()
|
|
218 "Describe directly the variable at point in the other window."
|
|
219 (interactive)
|
|
220 (let ((symb (variable-at-point)))
|
|
221 (when symb
|
|
222 (describe-variable symb))))
|
231
|
223
|
209
|
224 (defun help-next-symbol ()
|
|
225 "Move point to the next quoted symbol."
|
|
226 (interactive)
|
|
227 (search-forward "`" nil t))
|
231
|
228
|
209
|
229 (defun help-prev-symbol ()
|
|
230 "Move point to the previous quoted symbol."
|
|
231 (interactive)
|
|
232 (search-backward "'" nil t))
|
231
|
233
|
|
234 (defun help-next-section ()
|
|
235 "Move point to the next quoted symbol."
|
|
236 (interactive)
|
|
237 (search-forward-regexp "^\\w+:" nil t))
|
209
|
238
|
231
|
239 (defun help-prev-section ()
|
|
240 "Move point to the previous quoted symbol."
|
|
241 (interactive)
|
|
242 (search-backward-regexp "^\\w+:" nil t))
|
209
|
243
|
231
|
244 (defun help-mode-bury ()
|
|
245 "Buries the buffer, possibly restoring the previous window configuration."
|
|
246 (interactive)
|
|
247 (help-mode-quit t))
|
|
248
|
|
249 (defun help-mode-quit (&optional bury)
|
209
|
250 "Exits from help mode, possibly restoring the previous window configuration.
|
231
|
251 If the optional argument BURY is non-nil, the help buffer is buried,
|
|
252 otherwise it is killed."
|
209
|
253 (interactive)
|
|
254 (let ((buf (current-buffer)))
|
|
255 (cond ((frame-property (selected-frame) 'help-window-config)
|
|
256 (set-window-configuration
|
|
257 (frame-property (selected-frame) 'help-window-config))
|
|
258 (set-frame-property (selected-frame) 'help-window-config nil))
|
|
259 ((not (one-window-p))
|
|
260 (delete-window)))
|
231
|
261 (if bury
|
|
262 (bury-buffer buf)
|
|
263 (kill-buffer buf))))
|
209
|
264
|
|
265 (defun help-quit ()
|
|
266 (interactive)
|
|
267 nil)
|
|
268
|
|
269 ;; This is a grody hack of the same genotype as `advertised-undo'; if the
|
|
270 ;; bindings of Backspace and C-h are the same, we want the menubar to claim
|
|
271 ;; that `info' in invoked with `C-h i', not `BS i'.
|
|
272
|
|
273 (defun deprecated-help-command ()
|
|
274 (interactive)
|
|
275 (if (eq 'help-command (key-binding "\C-h"))
|
|
276 (setq unread-command-event (character-to-event ?\C-h))
|
|
277 (help-for-help)))
|
|
278
|
|
279 ;;(define-key global-map 'backspace 'deprecated-help-command)
|
|
280
|
|
281 ;; This function has been moved to help-nomule.el and mule-help.el.
|
|
282 ;; TUTORIAL arg is XEmacs addition
|
|
283 ;(defun help-with-tutorial (&optional tutorial)
|
|
284 ; "Select the XEmacs learn-by-doing tutorial.
|
|
285 ;Optional arg TUTORIAL specifies the tutorial file; default is \"TUTORIAL\"."
|
|
286 ; (interactive)
|
|
287 ; (if (null tutorial)
|
|
288 ; (setq tutorial "TUTORIAL"))
|
|
289 ; (let ((file (expand-file-name (concat "~/" tutorial))))
|
|
290 ; (delete-other-windows)
|
|
291 ; (if (get-file-buffer file)
|
|
292 ; (switch-to-buffer (get-file-buffer file))
|
|
293 ; (switch-to-buffer (create-file-buffer file))
|
|
294 ; (setq buffer-file-name file)
|
|
295 ; (setq default-directory (expand-file-name "~/"))
|
|
296 ; (setq buffer-auto-save-file-name nil)
|
|
297 ; (insert-file-contents (expand-file-name tutorial data-directory))
|
|
298 ; (goto-char (point-min))
|
|
299 ; (search-forward "\n<<")
|
|
300 ; (delete-region (point-at-bol) (point-at-eol))
|
|
301 ; (let ((n (- (window-height (selected-window))
|
|
302 ; (count-lines (point-min) (point))
|
|
303 ; 6)))
|
|
304 ; (if (< n 12)
|
|
305 ; (newline n)
|
|
306 ; ;; Some people get confused by the large gap.
|
|
307 ; (newline (/ n 2))
|
|
308 ; (insert "[Middle of page left blank for didactic purposes. "
|
|
309 ; "Text continues below]")
|
|
310 ; (newline (- n (/ n 2)))))
|
|
311 ; (goto-char (point-min))
|
|
312 ; (set-buffer-modified-p nil))))
|
|
313
|
|
314 ;; used by describe-key, describe-key-briefly, insert-key-binding, etc.
|
|
315
|
|
316 (defun key-or-menu-binding (key &optional menu-flag)
|
|
317 "Return the command invoked by KEY.
|
|
318 Like `key-binding', but handles menu events and toolbar presses correctly.
|
|
319 KEY is any value returned by `next-command-event'.
|
|
320 MENU-FLAG is a symbol that should be set to T if KEY is a menu event,
|
|
321 or NIL otherwise"
|
|
322 (let (defn)
|
|
323 (and menu-flag (set menu-flag nil))
|
|
324 ;; If the key typed was really a menu selection, grab the form out
|
|
325 ;; of the event object and intuit the function that would be called,
|
|
326 ;; and describe that instead.
|
|
327 (if (and (vectorp key) (= 1 (length key))
|
|
328 (or (misc-user-event-p (aref key 0))
|
|
329 (eq (car-safe (aref key 0)) 'menu-selection)))
|
|
330 (let ((event (aref key 0)))
|
|
331 (setq defn (if (eventp event)
|
|
332 (list (event-function event) (event-object event))
|
|
333 (cdr event)))
|
|
334 (and menu-flag (set menu-flag t))
|
|
335 (when (eq (car defn) 'eval)
|
|
336 (setq defn (car (cdr defn))))
|
|
337 (when (eq (car-safe defn) 'call-interactively)
|
|
338 (setq defn (car (cdr defn))))
|
|
339 (when (and (consp defn) (null (cdr defn)))
|
|
340 (setq defn (car defn))))
|
|
341 ;; else
|
|
342 (setq defn (key-binding key)))
|
|
343 ;; kludge: if a toolbar button was pressed on, try to find the
|
|
344 ;; binding of the toolbar button.
|
|
345 (if (and (eq defn 'press-toolbar-button)
|
|
346 (vectorp key)
|
|
347 (button-press-event-p (aref key (1- (length key)))))
|
|
348 ;; wait for the button release. We're on shaky ground here ...
|
|
349 (let ((event (next-command-event))
|
|
350 button)
|
|
351 (if (and (button-release-event-p event)
|
|
352 (event-over-toolbar-p event)
|
|
353 (eq 'release-and-activate-toolbar-button
|
|
354 (key-binding (vector event)))
|
|
355 (setq button (event-toolbar-button event)))
|
|
356 (toolbar-button-callback button)
|
|
357 ;; if anything went wrong, try returning the binding of
|
|
358 ;; the button-up event, of the original binding
|
|
359 (or (key-or-menu-binding (vector event))
|
|
360 defn)))
|
|
361 ;; no toolbar kludge
|
|
362 defn)
|
|
363 ))
|
|
364
|
|
365 (defun describe-key-briefly (key)
|
|
366 "Print the name of the function KEY invokes. KEY is a string."
|
|
367 (interactive "kDescribe key briefly: ")
|
|
368 (let (defn menup)
|
|
369 (setq defn (key-or-menu-binding key 'menup))
|
|
370 (if (or (null defn) (integerp defn))
|
|
371 (message "%s is undefined" (key-description key))
|
|
372 ;; If it's a keyboard macro which trivially invokes another command,
|
|
373 ;; document that instead.
|
|
374 (if (or (stringp defn) (vectorp defn))
|
|
375 (setq defn (or (key-binding defn)
|
|
376 defn)))
|
|
377 (let ((last-event (and (vectorp key)
|
|
378 (aref key (1- (length key))))))
|
|
379 (message (if (or (button-press-event-p last-event)
|
|
380 (button-release-event-p last-event))
|
|
381 (gettext "%s at that spot runs the command %s")
|
|
382 (gettext "%s runs the command %s"))
|
|
383 ;; This used to say 'This menu item' but it could also
|
|
384 ;; be a scrollbar event. We can't distinguish at the
|
|
385 ;; moment.
|
|
386 (if menup "This item" (key-description key))
|
243
|
387 (format (if (symbolp defn) "`%s'" "%s") defn))))))
|
209
|
388
|
|
389 ;; #### this is a horrible piece of shit function that should
|
|
390 ;; not exist. In FSF 19.30 this function has gotten three times
|
|
391 ;; as long and has tons and tons of dumb shit checking
|
|
392 ;; special-display-buffer-names and such crap. I absolutely
|
|
393 ;; refuse to insert that Ebolification here. I wanted to delete
|
|
394 ;; this function entirely but Mly bitched.
|
|
395 ;;
|
|
396 ;; If your user-land code calls this function, rewrite it to
|
|
397 ;; call with-displaying-help-buffer.
|
|
398
|
|
399 (defun print-help-return-message (&optional function)
|
|
400 "Display or return message saying how to restore windows after help command.
|
|
401 Computes a message and applies the optional argument FUNCTION to it.
|
|
402 If FUNCTION is nil, applies `message' to it, thus printing it."
|
|
403 (and (not (get-buffer-window standard-output))
|
|
404 (funcall
|
|
405 (or function 'message)
|
|
406 (concat
|
|
407 (substitute-command-keys
|
|
408 (if (one-window-p t)
|
|
409 (if pop-up-windows
|
|
410 (gettext "Type \\[delete-other-windows] to remove help window.")
|
|
411 (gettext "Type \\[switch-to-buffer] RET to remove help window."))
|
|
412 (gettext "Type \\[switch-to-buffer-other-window] RET to restore the other window.")))
|
|
413 (substitute-command-keys
|
|
414 (gettext " \\[scroll-other-window] to scroll the help."))))))
|
|
415
|
|
416 (defcustom help-selects-help-window t
|
|
417 "*If nil, use the \"old Emacs\" behavior for Help buffers.
|
|
418 This just displays the buffer in another window, rather than selecting
|
|
419 the window."
|
|
420 :type 'boolean
|
|
421 :group 'help-appearance)
|
|
422
|
259
|
423 (defcustom help-max-help-buffers 10
|
|
424 "*Maximum help buffers to allow before they start getting killed.
|
|
425 If this is a positive integer, before a help buffer is displayed
|
|
426 by `with-displaying-help-buffer', any excess help buffers which
|
|
427 are not being displayed are first killed. Otherwise, if it is
|
|
428 zero or nil, only one help buffer, \"*Help*\" is ever used."
|
|
429 :type '(choice integer (const :tag "None" nil))
|
|
430 :group 'help-appearance)
|
|
431
|
|
432 (defvar help-buffer-list nil
|
|
433 "List of help buffers used by `help-register-and-maybe-prune-excess'")
|
|
434
|
|
435 (defun help-register-and-maybe-prune-excess (newbuf)
|
|
436 "Register use of a help buffer and possibly kill any excess ones."
|
|
437 ;; remove new buffer from list
|
|
438 (setq help-buffer-list (remove newbuf help-buffer-list))
|
|
439 ;; maybe kill excess help buffers
|
|
440 (if (and (integerp help-max-help-buffers)
|
|
441 (> (length help-buffer-list) help-max-help-buffers))
|
|
442 (let ((keep-list nil)
|
|
443 (num-kill (- (length help-buffer-list)
|
|
444 help-max-help-buffers)))
|
|
445 (while help-buffer-list
|
|
446 (let ((buf (car help-buffer-list)))
|
|
447 (if (and (or (equal buf newbuf) (get-buffer buf))
|
|
448 (string-match "^*Help" buf)
|
|
449 (save-excursion (set-buffer buf)
|
|
450 (eq major-mode 'help-mode)))
|
|
451 (if (and (>= num-kill (length help-buffer-list))
|
|
452 (not (get-buffer-window buf t t)))
|
|
453 (kill-buffer buf)
|
|
454 (setq keep-list (cons buf keep-list)))))
|
|
455 (setq help-buffer-list (cdr help-buffer-list)))
|
|
456 (setq help-buffer-list (nreverse keep-list))))
|
|
457 ;; push new buffer
|
|
458 (setq help-buffer-list (cons newbuf help-buffer-list)))
|
|
459
|
231
|
460 (defun help-buffer-name (name)
|
|
461 "Return a name for a Help buffer using string NAME for context."
|
259
|
462 (if (and (integerp help-max-help-buffers)
|
|
463 (> help-max-help-buffers 0)
|
|
464 (stringp name))
|
231
|
465 (format "*Help: %s*" name)
|
|
466 "*Help*"))
|
|
467
|
209
|
468 ;; Use this function for displaying help when C-h something is pressed
|
|
469 ;; or in similar situations. Do *not* use it when you are displaying
|
|
470 ;; a help message and then prompting for input in the minibuffer --
|
|
471 ;; this macro usually selects the help buffer, which is not what you
|
|
472 ;; want in those situations.
|
231
|
473 (defmacro with-displaying-help-buffer (name &rest body)
|
|
474 "Form which makes a help buffer with given NAME and evaluates BODY there.
|
|
475 The actual name of the buffer is generated by the function `help-buffer-name'."
|
|
476 `(let* ((winconfig (current-window-configuration))
|
|
477 (was-one-window (one-window-p))
|
|
478 (buffer-name (help-buffer-name ,name))
|
|
479 (help-not-visible
|
|
480 (not (and (windows-of-buffer buffer-name) ;shortcut
|
|
481 (member (selected-frame)
|
|
482 (mapcar 'window-frame
|
|
483 (windows-of-buffer buffer-name)))))))
|
259
|
484 (help-register-and-maybe-prune-excess buffer-name)
|
231
|
485 (prog1 (with-output-to-temp-buffer buffer-name
|
|
486 (prog1 ,@body
|
|
487 (save-excursion
|
|
488 (set-buffer standard-output)
|
|
489 (help-mode))))
|
|
490 (let ((helpwin (get-buffer-window buffer-name)))
|
|
491 (when helpwin
|
|
492 (with-current-buffer (window-buffer helpwin)
|
|
493 ;; If the *Help* buffer is already displayed on this
|
|
494 ;; frame, don't override the previous configuration
|
|
495 (when help-not-visible
|
|
496 (set-frame-property (selected-frame)
|
|
497 'help-window-config winconfig)))
|
|
498 (when help-selects-help-window
|
|
499 (select-window helpwin))
|
|
500 (cond ((eq helpwin (selected-window))
|
|
501 (display-message 'command
|
|
502 (substitute-command-keys "Type \\[help-mode-quit] to remove help window, \\[scroll-up] to scroll the help.")))
|
|
503 (was-one-window
|
|
504 (display-message 'command
|
|
505 (substitute-command-keys "Type \\[delete-other-windows] to remove help window, \\[scroll-other-window] to scroll the help.")))
|
|
506 (t
|
|
507 (display-message 'command
|
|
508 (substitute-command-keys "Type \\[switch-to-buffer-other-window] to restore the other window, \\[scroll-other-window] to scroll the help.")))))))))
|
|
509 (put 'with-displaying-help-buffer 'lisp-indent-function 1)
|
|
510 (put 'with-displaying-help-buffer 'edebug-form-spec '(form body))
|
209
|
511
|
|
512 (defun describe-key (key)
|
|
513 "Display documentation of the function invoked by KEY.
|
|
514 KEY is a string, or vector of events.
|
|
515 When called interactively, KEY may also be a menu selection."
|
|
516 (interactive "kDescribe key: ")
|
231
|
517 (let ((defn (key-or-menu-binding key))
|
|
518 (key-string (key-description key)))
|
209
|
519 (if (or (null defn) (integerp defn))
|
231
|
520 (message "%s is undefined" key-string)
|
|
521 (with-displaying-help-buffer (format "key `%s'" key-string)
|
|
522 (princ key-string)
|
|
523 (princ " runs ")
|
243
|
524 (if (symbolp defn)
|
|
525 (princ (format "`%s'" defn))
|
|
526 (princ defn))
|
231
|
527 (princ "\n\n")
|
|
528 (cond ((or (stringp defn) (vectorp defn))
|
|
529 (let ((cmd (key-binding defn)))
|
|
530 (if (not cmd)
|
|
531 (princ "a keyboard macro")
|
|
532 (progn
|
|
533 (princ "a keyboard macro which runs the command ")
|
243
|
534 (princ cmd)
|
231
|
535 (princ ":\n\n")
|
|
536 (if (documentation cmd) (princ (documentation cmd)))))))
|
|
537 ((and (consp defn) (not (eq 'lambda (car-safe defn))))
|
|
538 (let ((describe-function-show-arglist nil))
|
|
539 (describe-function-1 (car defn))))
|
|
540 ((symbolp defn)
|
|
541 (describe-function-1 defn))
|
|
542 ((documentation defn)
|
|
543 (princ (documentation defn)))
|
|
544 (t
|
|
545 (princ "not documented")))))))
|
209
|
546
|
|
547 (defun describe-mode ()
|
|
548 "Display documentation of current major mode and minor modes.
|
|
549 For this to work correctly for a minor mode, the mode's indicator variable
|
|
550 \(listed in `minor-mode-alist') must also be a function whose documentation
|
|
551 describes the minor mode."
|
|
552 (interactive)
|
231
|
553 (with-displaying-help-buffer (format "%s mode" mode-name)
|
|
554 ;; XEmacs change: print the major-mode documentation before
|
|
555 ;; the minor modes.
|
|
556 (princ mode-name)
|
|
557 (princ " mode:\n")
|
|
558 (princ (documentation major-mode))
|
|
559 (princ "\n\n----\n\n")
|
|
560 (let ((minor-modes minor-mode-alist))
|
|
561 (while minor-modes
|
|
562 (let* ((minor-mode (car (car minor-modes)))
|
|
563 (indicator (car (cdr (car minor-modes)))))
|
|
564 ;; Document a minor mode if it is listed in minor-mode-alist,
|
|
565 ;; bound locally in this buffer, non-nil, and has a function
|
|
566 ;; definition.
|
|
567 (if (and (boundp minor-mode)
|
|
568 (symbol-value minor-mode)
|
|
569 (fboundp minor-mode))
|
|
570 (let ((pretty-minor-mode minor-mode))
|
|
571 (if (string-match "-mode\\'" (symbol-name minor-mode))
|
|
572 (setq pretty-minor-mode
|
|
573 (capitalize
|
|
574 (substring (symbol-name minor-mode)
|
|
575 0 (match-beginning 0)))))
|
|
576 (while (and (consp indicator) (extentp (car indicator)))
|
|
577 (setq indicator (cdr indicator)))
|
|
578 (while (and indicator (symbolp indicator))
|
|
579 (setq indicator (symbol-value indicator)))
|
|
580 (princ (format "%s minor mode (indicator%s):\n"
|
|
581 pretty-minor-mode indicator))
|
|
582 (princ (documentation minor-mode))
|
|
583 (princ "\n\n----\n\n"))))
|
|
584 (setq minor-modes (cdr minor-modes))))))
|
209
|
585
|
|
586 ;; So keyboard macro definitions are documented correctly
|
|
587 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
|
|
588
|
|
589 (defun describe-distribution ()
|
|
590 "Display info on how to obtain the latest version of XEmacs."
|
|
591 (interactive)
|
|
592 (find-file-read-only
|
249
|
593 (locate-data-file "DISTRIB")))
|
209
|
594
|
|
595 (defun describe-beta ()
|
|
596 "Display info on how to deal with Beta versions of XEmacs."
|
|
597 (interactive)
|
|
598 (find-file-read-only
|
249
|
599 (locate-data-file "BETA"))
|
209
|
600 (goto-char (point-min)))
|
|
601
|
|
602 (defun describe-copying ()
|
|
603 "Display info on how you may redistribute copies of XEmacs."
|
|
604 (interactive)
|
|
605 (find-file-read-only
|
249
|
606 (locate-data-file "COPYING"))
|
209
|
607 (goto-char (point-min)))
|
|
608
|
|
609 (defun describe-pointer ()
|
|
610 "Show a list of all defined mouse buttons, and their definitions."
|
|
611 (interactive)
|
|
612 (describe-bindings nil t))
|
|
613
|
|
614 (defun describe-project ()
|
|
615 "Display info on the GNU project."
|
|
616 (interactive)
|
|
617 (find-file-read-only
|
249
|
618 (locate-data-file "GNU"))
|
209
|
619 (goto-char (point-min)))
|
|
620
|
|
621 (defun describe-no-warranty ()
|
|
622 "Display info on all the kinds of warranty XEmacs does NOT have."
|
|
623 (interactive)
|
|
624 (describe-copying)
|
|
625 (let (case-fold-search)
|
|
626 (search-forward "NO WARRANTY")
|
|
627 (recenter 0)))
|
|
628
|
|
629 (defun describe-bindings (&optional prefix mouse-only-p)
|
|
630 "Show a list of all defined keys, and their definitions.
|
|
631 The list is put in a buffer, which is displayed.
|
|
632 If the optional argument PREFIX is supplied, only commands which
|
|
633 start with that sequence of keys are described.
|
|
634 If the second argument (prefix arg, interactively) is non-null
|
|
635 then only the mouse bindings are displayed."
|
|
636 (interactive (list nil current-prefix-arg))
|
231
|
637 (with-displaying-help-buffer (format "bindings for %s" major-mode)
|
|
638 (describe-bindings-1 prefix mouse-only-p)))
|
209
|
639
|
|
640 (defun describe-bindings-1 (&optional prefix mouse-only-p)
|
|
641 (let ((heading (if mouse-only-p
|
|
642 (gettext "button binding\n------ -------\n")
|
|
643 (gettext "key binding\n--- -------\n")))
|
|
644 (buffer (current-buffer))
|
|
645 (minor minor-mode-map-alist)
|
|
646 (local (current-local-map))
|
|
647 (shadow '()))
|
|
648 (set-buffer standard-output)
|
|
649 (while minor
|
|
650 (let ((sym (car (car minor)))
|
|
651 (map (cdr (car minor))))
|
|
652 (if (symbol-value-in-buffer sym buffer nil)
|
|
653 (progn
|
|
654 (insert (format "Minor Mode Bindings for `%s':\n"
|
|
655 sym)
|
|
656 heading)
|
|
657 (describe-bindings-internal map nil shadow prefix mouse-only-p)
|
|
658 (insert "\n")
|
|
659 (setq shadow (cons map shadow))))
|
|
660 (setq minor (cdr minor))))
|
|
661 (if local
|
|
662 (progn
|
|
663 (insert "Local Bindings:\n" heading)
|
|
664 (describe-bindings-internal local nil shadow prefix mouse-only-p)
|
|
665 (insert "\n")
|
|
666 (setq shadow (cons local shadow))))
|
|
667 (insert "Global Bindings:\n" heading)
|
|
668 (describe-bindings-internal (current-global-map)
|
|
669 nil shadow prefix mouse-only-p)
|
|
670 (when (and prefix function-key-map (not mouse-only-p))
|
|
671 (insert "\nFunction key map translations:\n" heading)
|
231
|
672 (describe-bindings-internal function-key-map nil nil
|
|
673 prefix mouse-only-p))
|
209
|
674 (set-buffer buffer)))
|
|
675
|
|
676 (defun describe-prefix-bindings ()
|
|
677 "Describe the bindings of the prefix used to reach this command.
|
|
678 The prefix described consists of all but the last event
|
|
679 of the key sequence that ran this command."
|
|
680 (interactive)
|
|
681 (let* ((key (this-command-keys))
|
|
682 (prefix (make-vector (1- (length key)) nil))
|
|
683 i)
|
|
684 (setq i 0)
|
|
685 (while (< i (length prefix))
|
|
686 (aset prefix i (aref key i))
|
|
687 (setq i (1+ i)))
|
231
|
688 (with-displaying-help-buffer (format "%s prefix" (key-description prefix))
|
|
689 (princ "Key bindings starting with ")
|
|
690 (princ (key-description prefix))
|
|
691 (princ ":\n\n")
|
|
692 (describe-bindings-1 prefix nil))))
|
209
|
693
|
|
694 ;; Make C-h after a prefix, when not specifically bound,
|
|
695 ;; run describe-prefix-bindings.
|
|
696 (setq prefix-help-command 'describe-prefix-bindings)
|
|
697
|
261
|
698 (defun describe-installation ()
|
|
699 "Display a buffer showing information about this XEmacs was compiled."
|
|
700 (interactive)
|
|
701 (if (and (boundp 'Installation-string)
|
|
702 (stringp Installation-string))
|
|
703 (with-displaying-help-buffer "Installation"
|
|
704 (princ Installation-string))
|
|
705 (error "No Installation information available.")))
|
|
706
|
209
|
707 (defun view-emacs-news ()
|
|
708 "Display info on recent changes to XEmacs."
|
|
709 (interactive)
|
249
|
710 (find-file (locate-data-file "NEWS")))
|
209
|
711
|
|
712 (defun xemacs-www-page ()
|
|
713 "Go to the XEmacs World Wide Web page."
|
|
714 (interactive)
|
219
|
715 (if (boundp 'browse-url-browser-function)
|
|
716 (funcall browse-url-browser-function "http://www.xemacs.org/")
|
|
717 (error "xemacs-www-page requires browse-url")))
|
209
|
718
|
|
719 (defun xemacs-www-faq ()
|
|
720 "View the latest and greatest XEmacs FAQ using the World Wide Web."
|
|
721 (interactive)
|
219
|
722 (if (boundp 'browse-url-browser-function)
|
|
723 (funcall browse-url-browser-function
|
|
724 "http://www.xemacs.org/faq/index.html")
|
|
725 (error "xemacs-www-faq requires browse-url")))
|
209
|
726
|
|
727 (defun xemacs-local-faq ()
|
|
728 "View the local copy of the XEmacs FAQ.
|
|
729 If you have access to the World Wide Web, you should use `xemacs-www-faq'
|
|
730 instead, to ensure that you get the most up-to-date information."
|
|
731 (interactive)
|
|
732 (save-window-excursion
|
|
733 (info)
|
|
734 (Info-find-node "xemacs-faq" "Top"))
|
|
735 (switch-to-buffer "*info*"))
|
|
736
|
|
737 (defcustom view-lossage-key-count 100
|
|
738 "*Number of keys `view-lossage' shows.
|
|
739 The maximum number of available keys is governed by `recent-keys-ring-size'."
|
|
740 :type 'integer
|
|
741 :group 'help)
|
|
742
|
|
743 (defcustom view-lossage-message-count 100
|
|
744 "*Number of minibuffer messages `view-lossage' shows."
|
|
745 :type 'integer
|
|
746 :group 'help)
|
|
747
|
|
748 (defun view-lossage ()
|
|
749 "Display recent input keystrokes and recent minibuffer messages.
|
|
750 The number of keys shown is controlled by `view-lossage-key-count'.
|
|
751 The number of messages shown is controlled by `view-lossage-message-count'."
|
|
752 (interactive)
|
231
|
753 (with-displaying-help-buffer "lossage"
|
|
754 (princ (key-description (recent-keys view-lossage-key-count)))
|
|
755 (save-excursion
|
|
756 (set-buffer standard-output)
|
|
757 (goto-char (point-min))
|
|
758 (insert "Recent keystrokes:\n\n")
|
|
759 (while (progn (move-to-column 50) (not (eobp)))
|
|
760 (search-forward " " nil t)
|
|
761 (insert "\n")))
|
|
762 ;; XEmacs addition
|
|
763 (princ "\n\n\nRecent minibuffer messages (most recent first):\n\n")
|
|
764 (save-excursion
|
|
765 (let ((buffer (get-buffer-create " *Message-Log*"))
|
|
766 (count 0)
|
|
767 oldpoint)
|
|
768 (set-buffer buffer)
|
|
769 (goto-char (point-max))
|
|
770 (set-buffer standard-output)
|
|
771 (while (and (> (point buffer) (point-min buffer))
|
|
772 (< count view-lossage-message-count))
|
|
773 (setq oldpoint (point buffer))
|
|
774 (forward-line -1 buffer)
|
|
775 (insert-buffer-substring buffer (point buffer) oldpoint)
|
|
776 (setq count (1+ count)))))))
|
209
|
777
|
|
778 (define-function 'help 'help-for-help)
|
211
|
779
|
|
780 (make-help-screen help-for-help
|
|
781 "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:"
|
|
782 "Type a Help option:
|
209
|
783 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
|
|
784
|
|
785 \\[hyper-apropos] Type a substring; it shows a hypertext list of
|
|
786 functions and variables that contain that substring.
|
|
787 See also the `apropos' command.
|
|
788 \\[command-apropos] Type a substring; it shows a list of commands
|
|
789 (interactively callable functions) that contain that substring.
|
|
790 \\[describe-bindings] Table of all key bindings.
|
|
791 \\[describe-key-briefly] Type a command key sequence;
|
|
792 it displays the function name that sequence runs.
|
211
|
793 \\[customize] Customize Emacs options.
|
209
|
794 \\[Info-goto-emacs-command-node] Type a function name; it displays the Info node for that command.
|
|
795 \\[describe-function] Type a function name; it shows its documentation.
|
|
796 \\[Info-elisp-ref] Type a function name; it jumps to the full documentation
|
|
797 in the XEmacs Lisp Programmer's Manual.
|
|
798 \\[xemacs-local-faq] Local copy of the XEmacs FAQ.
|
|
799 \\[info] Info documentation reader.
|
|
800 \\[Info-query] Type an Info file name; it displays it in Info reader.
|
|
801 \\[describe-key] Type a command key sequence;
|
|
802 it displays the documentation for the command bound to that key.
|
|
803 \\[Info-goto-emacs-key-command-node] Type a command key sequence;
|
|
804 it displays the Info node for the command bound to that key.
|
|
805 \\[view-lossage] Recent input keystrokes and minibuffer messages.
|
|
806 \\[describe-mode] Documentation of current major and minor modes.
|
|
807 \\[view-emacs-news] News of recent XEmacs changes.
|
|
808 \\[finder-by-keyword] Type a topic keyword; it finds matching packages.
|
|
809 \\[describe-pointer] Table of all mouse-button bindings.
|
|
810 \\[describe-syntax] Contents of syntax table with explanations.
|
|
811 \\[help-with-tutorial] XEmacs learn-by-doing tutorial.
|
|
812 \\[describe-variable] Type a variable name; it displays its documentation and value.
|
|
813 \\[where-is] Type a command name; it displays which keystrokes invoke that command.
|
|
814 \\[describe-distribution] XEmacs ordering information.
|
|
815 \\[describe-no-warranty] Information on absence of warranty for XEmacs.
|
211
|
816 \\[describe-copying] XEmacs copying permission (General Public License)."
|
|
817 help-map)
|
209
|
818
|
231
|
819 (defmacro with-syntax-table (syntab &rest body)
|
|
820 "Evaluate BODY with the syntax-table SYNTAB"
|
|
821 `(let ((stab (syntax-table)))
|
|
822 (unwind-protect
|
|
823 (progn
|
|
824 (set-syntax-table (copy-syntax-table ,syntab))
|
|
825 ,@body)
|
|
826 (set-syntax-table stab))))
|
|
827 (put 'with-syntax-table 'lisp-indent-function 1)
|
|
828 (put 'with-syntax-table 'edebug-form-spec '(form body))
|
|
829
|
209
|
830 (defun function-called-at-point ()
|
|
831 "Return the function which is called by the list containing point.
|
|
832 If that gives no function, return the function whose name is around point.
|
|
833 If that doesn't give a function, return nil."
|
231
|
834 (or (ignore-errors
|
|
835 (save-excursion
|
|
836 (save-restriction
|
|
837 (narrow-to-region (max (point-min) (- (point) 1000))
|
|
838 (point-max))
|
|
839 (backward-up-list 1)
|
|
840 (forward-char 1)
|
|
841 (let (obj)
|
|
842 (setq obj (read (current-buffer)))
|
|
843 (and (symbolp obj) (fboundp obj) obj)))))
|
|
844 (ignore-errors
|
|
845 (with-syntax-table emacs-lisp-mode-syntax-table
|
209
|
846 (save-excursion
|
231
|
847 (or (not (zerop (skip-syntax-backward "_w")))
|
|
848 (eq (char-syntax (char-after (point))) ?w)
|
|
849 (eq (char-syntax (char-after (point))) ?_)
|
|
850 (forward-sexp -1))
|
|
851 (skip-chars-forward "`'")
|
|
852 (let ((obj (read (current-buffer))))
|
|
853 (and (symbolp obj) (fboundp obj) obj)))))))
|
209
|
854
|
|
855 (defun function-at-point ()
|
|
856 "Return the function whose name is around point.
|
|
857 If that gives no function, return the function which is called by the
|
|
858 list containing point. If that doesn't give a function, return nil."
|
231
|
859 (or (ignore-errors
|
|
860 (with-syntax-table emacs-lisp-mode-syntax-table
|
209
|
861 (save-excursion
|
231
|
862 (or (not (zerop (skip-syntax-backward "_w")))
|
|
863 (eq (char-syntax (char-after (point))) ?w)
|
|
864 (eq (char-syntax (char-after (point))) ?_)
|
|
865 (forward-sexp -1))
|
|
866 (skip-chars-forward "`'")
|
|
867 (let ((obj (read (current-buffer))))
|
|
868 (and (symbolp obj) (fboundp obj) obj)))))
|
|
869 (ignore-errors
|
|
870 (save-excursion
|
|
871 (save-restriction
|
|
872 (narrow-to-region (max (point-min) (- (point) 1000))
|
|
873 (point-max))
|
|
874 (backward-up-list 1)
|
|
875 (forward-char 1)
|
|
876 (let (obj)
|
|
877 (setq obj (read (current-buffer)))
|
|
878 (and (symbolp obj) (fboundp obj) obj)))))))
|
209
|
879
|
|
880 ;; Default to nil for the non-hackers? Not until we find a way to
|
|
881 ;; distinguish hackers from non-hackers automatically!
|
|
882 (defcustom describe-function-show-arglist t
|
|
883 "*If non-nil, describe-function will show its arglist,
|
|
884 unless the function is autoloaded."
|
|
885 :type 'boolean
|
|
886 :group 'help-appearance)
|
|
887
|
233
|
888 (defun describe-symbol-find-file (function)
|
209
|
889 (let ((files load-history)
|
|
890 file)
|
|
891 (while files
|
|
892 (if (memq function (cdr (car files)))
|
|
893 (setq file (car (car files))
|
|
894 files nil))
|
|
895 (setq files (cdr files)))
|
|
896 file))
|
233
|
897 (define-obsolete-function-alias
|
|
898 'describe-function-find-file
|
|
899 'describe-symbol-find-file)
|
209
|
900
|
|
901 (defun describe-function (function)
|
|
902 "Display the full documentation of FUNCTION (a symbol).
|
|
903 When run interactively, it defaults to any function found by
|
|
904 `function-at-point'."
|
|
905 (interactive
|
|
906 (let* ((fn (function-at-point))
|
|
907 (val (let ((enable-recursive-minibuffers t))
|
|
908 (completing-read
|
|
909 (if fn
|
|
910 (format (gettext "Describe function (default %s): ")
|
|
911 fn)
|
|
912 (gettext "Describe function: "))
|
|
913 obarray 'fboundp t nil 'function-history))))
|
|
914 (list (if (equal val "") fn (intern val)))))
|
231
|
915 (with-displaying-help-buffer (format "function `%s'" function)
|
|
916 (describe-function-1 function)))
|
209
|
917
|
|
918 (defun function-obsolete-p (function)
|
|
919 "Return non-nil if FUNCTION is obsolete."
|
|
920 (not (null (get function 'byte-obsolete-info))))
|
|
921
|
|
922 (defun function-obsoleteness-doc (function)
|
|
923 "If FUNCTION is obsolete, return a string describing this."
|
|
924 (let ((obsolete (get function 'byte-obsolete-info)))
|
|
925 (if obsolete
|
|
926 (format "Obsolete; %s"
|
|
927 (if (stringp (car obsolete))
|
|
928 (car obsolete)
|
|
929 (format "use `%s' instead." (car obsolete)))))))
|
|
930
|
|
931 (defun function-compatible-p (function)
|
|
932 "Return non-nil if FUNCTION is present for Emacs compatibility."
|
|
933 (not (null (get function 'byte-compatible-info))))
|
|
934
|
|
935 (defun function-compatibility-doc (function)
|
|
936 "If FUNCTION is Emacs compatible, return a string describing this."
|
|
937 (let ((compatible (get function 'byte-compatible-info)))
|
|
938 (if compatible
|
|
939 (format "Emacs Compatible; %s"
|
|
940 (if (stringp (car compatible))
|
|
941 (car compatible)
|
|
942 (format "use `%s' instead." (car compatible)))))))
|
|
943
|
|
944 ;Here are all the possibilities below spelled out, for the benefit
|
|
945 ;of the I18N3 snarfer.
|
|
946 ;
|
|
947 ;(gettext "a built-in function")
|
|
948 ;(gettext "an interactive built-in function")
|
|
949 ;(gettext "a built-in macro")
|
|
950 ;(gettext "an interactive built-in macro")
|
|
951 ;(gettext "a compiled Lisp function")
|
|
952 ;(gettext "an interactive compiled Lisp function")
|
|
953 ;(gettext "a compiled Lisp macro")
|
|
954 ;(gettext "an interactive compiled Lisp macro")
|
|
955 ;(gettext "a Lisp function")
|
|
956 ;(gettext "an interactive Lisp function")
|
|
957 ;(gettext "a Lisp macro")
|
|
958 ;(gettext "an interactive Lisp macro")
|
|
959 ;(gettext "a mocklisp function")
|
|
960 ;(gettext "an interactive mocklisp function")
|
|
961 ;(gettext "a mocklisp macro")
|
|
962 ;(gettext "an interactive mocklisp macro")
|
|
963 ;(gettext "an autoloaded Lisp function")
|
|
964 ;(gettext "an interactive autoloaded Lisp function")
|
|
965 ;(gettext "an autoloaded Lisp macro")
|
|
966 ;(gettext "an interactive autoloaded Lisp macro")
|
|
967
|
231
|
968 ;; taken out of `describe-function-1'
|
|
969 (defun function-arglist (function)
|
|
970 "Returns a string giving the argument list of FUNCTION.
|
|
971 For example:
|
|
972
|
|
973 (function-arglist 'function-arglist)
|
|
974 => (function-arglist FUNCTION)
|
|
975
|
|
976 This function is used by `describe-function-1' to list function
|
|
977 arguments in the standard Lisp style."
|
243
|
978 (let* ((fndef (indirect-function function))
|
231
|
979 (arglist
|
|
980 (cond ((compiled-function-p fndef)
|
|
981 (compiled-function-arglist fndef))
|
|
982 ((eq (car-safe fndef) 'lambda)
|
|
983 (nth 1 fndef))
|
|
984 ((subrp fndef)
|
|
985 (let ((doc (documentation function)))
|
|
986 (if (string-match "[\n\t ]*\narguments: ?(\\(.*\\))\n?\\'"
|
|
987 doc)
|
|
988 (substring doc (match-beginning 1) (match-end 1)))))
|
|
989 (t t))))
|
|
990 (cond ((listp arglist)
|
|
991 (prin1-to-string
|
|
992 (cons function (mapcar (lambda (arg)
|
|
993 (if (memq arg '(&optional &rest))
|
|
994 arg
|
|
995 (intern (upcase (symbol-name arg)))))
|
|
996 arglist))
|
|
997 t))
|
|
998 ((stringp arglist)
|
|
999 (format "(%s %s)" function arglist)))))
|
|
1000
|
|
1001 (defun function-documentation (function &optional strip-arglist)
|
|
1002 "Returns a string giving the documentation for FUNCTION if any.
|
|
1003 If the optional argument STRIP-ARGLIST is non-nil remove the arglist
|
|
1004 part of the documentation of internal subroutines."
|
|
1005 (let ((doc (condition-case nil
|
|
1006 (or (documentation function)
|
|
1007 (gettext "not documented"))
|
|
1008 (void-function ""))))
|
|
1009 (if (and strip-arglist
|
|
1010 (string-match "[\n\t ]*\narguments: ?(\\(.*\\))\n?\\'" doc))
|
|
1011 (setq doc (substring doc 0 (match-beginning 0))))
|
|
1012 doc))
|
|
1013
|
|
1014 (defun describe-function-1 (function &optional nodoc)
|
|
1015 "This function does the work for `describe-function'."
|
243
|
1016 (princ (format "`%s' is " function))
|
209
|
1017 (let* ((def function)
|
|
1018 aliases file-name autoload-file kbd-macro-p fndef macrop)
|
|
1019 (while (and (symbolp def) (fboundp def))
|
|
1020 (when (not (eq def function))
|
|
1021 (setq aliases
|
|
1022 (if aliases
|
|
1023 ;; I18N3 Need gettext due to concat
|
|
1024 (concat aliases
|
|
1025 (format
|
|
1026 "\n which is an alias for `%s', "
|
|
1027 (symbol-name def)))
|
|
1028 (format "an alias for `%s', " (symbol-name def)))))
|
|
1029 (setq def (symbol-function def)))
|
233
|
1030 (if (and (fboundp 'compiled-function-annotation)
|
|
1031 (compiled-function-p def))
|
209
|
1032 (setq file-name (compiled-function-annotation def)))
|
|
1033 (if (eq 'macro (car-safe def))
|
|
1034 (setq fndef (cdr def)
|
|
1035 file-name (and (compiled-function-p (cdr def))
|
233
|
1036 (fboundp 'compiled-function-annotation)
|
209
|
1037 (compiled-function-annotation (cdr def)))
|
|
1038 macrop t)
|
|
1039 (setq fndef def))
|
231
|
1040 (if aliases (princ aliases))
|
209
|
1041 (let ((int #'(lambda (string an-p macro-p)
|
|
1042 (princ (format
|
|
1043 (gettext (concat
|
|
1044 (cond ((commandp def)
|
|
1045 "an interactive ")
|
|
1046 (an-p "an ")
|
|
1047 (t "a "))
|
|
1048 "%s"
|
|
1049 (if macro-p " macro" " function")))
|
231
|
1050 string)))))
|
209
|
1051 (cond ((or (stringp def) (vectorp def))
|
231
|
1052 (princ "a keyboard macro.")
|
209
|
1053 (setq kbd-macro-p t))
|
|
1054 ((subrp fndef)
|
|
1055 (funcall int "built-in" nil macrop))
|
|
1056 ((compiled-function-p fndef)
|
|
1057 (funcall int "compiled Lisp" nil macrop))
|
|
1058 ((eq (car-safe fndef) 'lambda)
|
|
1059 (funcall int "Lisp" nil macrop))
|
|
1060 ((eq (car-safe fndef) 'mocklisp)
|
|
1061 (funcall int "mocklisp" nil macrop))
|
|
1062 ((eq (car-safe def) 'autoload)
|
|
1063 (setq autoload-file (elt def 1))
|
|
1064 (funcall int "autoloaded Lisp" t (elt def 4)))
|
|
1065 ((and (symbolp def) (not (fboundp def)))
|
231
|
1066 (princ "a symbol with a void (unbound) function definition."))
|
209
|
1067 (t
|
|
1068 nil)))
|
231
|
1069 (princ "\n")
|
209
|
1070 (if autoload-file
|
231
|
1071 (princ (format " -- autoloads from \"%s\"\n" autoload-file)))
|
209
|
1072 (or file-name
|
233
|
1073 (setq file-name (describe-symbol-find-file function)))
|
209
|
1074 (if file-name
|
231
|
1075 (princ (format " -- loaded from \"%s\"\n" file-name)))
|
|
1076 ;; (terpri)
|
209
|
1077 (if describe-function-show-arglist
|
231
|
1078 (let ((arglist (function-arglist function)))
|
|
1079 (when arglist
|
|
1080 (princ arglist)
|
|
1081 (terpri))))
|
|
1082 (terpri)
|
209
|
1083 (cond (kbd-macro-p
|
231
|
1084 (princ "These characters are executed:\n\n\t")
|
|
1085 (princ (key-description def))
|
209
|
1086 (cond ((setq def (key-binding def))
|
243
|
1087 (princ (format "\n\nwhich executes the command `%s'.\n\n"
|
|
1088 def))
|
231
|
1089 (describe-function-1 def))))
|
209
|
1090 (nodoc nil)
|
|
1091 (t
|
|
1092 ;; tell the user about obsoleteness.
|
|
1093 ;; If the function is obsolete and is aliased, don't
|
|
1094 ;; even bother to report the documentation, as a further
|
|
1095 ;; encouragement to use the new function.
|
|
1096 (let ((obsolete (function-obsoleteness-doc function))
|
|
1097 (compatible (function-compatibility-doc function)))
|
|
1098 (when obsolete
|
231
|
1099 (princ obsolete)
|
|
1100 (terpri)
|
|
1101 (terpri))
|
209
|
1102 (when compatible
|
231
|
1103 (princ compatible)
|
|
1104 (terpri)
|
|
1105 (terpri))
|
209
|
1106 (unless (and obsolete aliases)
|
231
|
1107 (let ((doc (function-documentation function t)))
|
|
1108 (princ "Documentation:\n")
|
|
1109 (princ doc)
|
|
1110 (unless (or (equal doc "")
|
|
1111 (eq ?\n (aref doc (1- (length doc)))))
|
|
1112 (terpri)))))))))
|
209
|
1113
|
|
1114
|
231
|
1115 ;;; [Obnoxious, whining people who complain very LOUDLY on Usenet
|
|
1116 ;;; are binding this to keys.]
|
223
|
1117 (defun describe-function-arglist (function)
|
|
1118 (interactive (list (or (function-at-point)
|
|
1119 (error "no function call at point"))))
|
231
|
1120 (message nil)
|
|
1121 (message (function-arglist function)))
|
209
|
1122
|
|
1123
|
|
1124 (defun variable-at-point ()
|
|
1125 (ignore-errors
|
231
|
1126 (with-syntax-table emacs-lisp-mode-syntax-table
|
|
1127 (save-excursion
|
|
1128 (or (not (zerop (skip-syntax-backward "_w")))
|
|
1129 (eq (char-syntax (char-after (point))) ?w)
|
|
1130 (eq (char-syntax (char-after (point))) ?_)
|
|
1131 (forward-sexp -1))
|
|
1132 (skip-chars-forward "'")
|
|
1133 (let ((obj (read (current-buffer))))
|
|
1134 (and (symbolp obj) (boundp obj) obj))))))
|
209
|
1135
|
|
1136 (defun variable-obsolete-p (variable)
|
|
1137 "Return non-nil if VARIABLE is obsolete."
|
|
1138 (not (null (get variable 'byte-obsolete-variable))))
|
|
1139
|
|
1140 (defun variable-obsoleteness-doc (variable)
|
|
1141 "If VARIABLE is obsolete, return a string describing this."
|
|
1142 (let ((obsolete (get variable 'byte-obsolete-variable)))
|
|
1143 (if obsolete
|
|
1144 (format "Obsolete; %s"
|
|
1145 (if (stringp obsolete)
|
|
1146 obsolete
|
|
1147 (format "use `%s' instead." obsolete))))))
|
|
1148
|
|
1149 (defun variable-compatible-p (variable)
|
|
1150 "Return non-nil if VARIABLE is Emacs compatible."
|
|
1151 (not (null (get variable 'byte-compatible-variable))))
|
|
1152
|
|
1153 (defun variable-compatibility-doc (variable)
|
|
1154 "If VARIABLE is Emacs compatible, return a string describing this."
|
|
1155 (let ((compatible (get variable 'byte-compatible-variable)))
|
|
1156 (if compatible
|
|
1157 (format "Emacs Compatible; %s"
|
|
1158 (if (stringp compatible)
|
|
1159 compatible
|
|
1160 (format "use `%s' instead." compatible))))))
|
|
1161
|
|
1162 (defun built-in-variable-doc (variable)
|
|
1163 "Return a string describing whether VARIABLE is built-in."
|
|
1164 (let ((type (built-in-variable-type variable)))
|
|
1165 (case type
|
|
1166 (integer "a built-in integer variable")
|
|
1167 (const-integer "a built-in constant integer variable")
|
|
1168 (boolean "a built-in boolean variable")
|
|
1169 (const-boolean "a built-in constant boolean variable")
|
|
1170 (object "a simple built-in variable")
|
|
1171 (const-object "a simple built-in constant variable")
|
|
1172 (const-specifier "a built-in constant specifier variable")
|
|
1173 (current-buffer "a built-in buffer-local variable")
|
|
1174 (const-current-buffer "a built-in constant buffer-local variable")
|
|
1175 (default-buffer "a built-in default buffer-local variable")
|
|
1176 (selected-console "a built-in console-local variable")
|
|
1177 (const-selected-console "a built-in constant console-local variable")
|
|
1178 (default-console "a built-in default console-local variable")
|
|
1179 (t
|
|
1180 (if type "an unknown type of built-in variable?"
|
|
1181 "a variable declared in Lisp")))))
|
|
1182
|
243
|
1183 (defcustom help-pretty-print-limit 100
|
|
1184 "Limit on length of lists above which pretty-printing of values is stopped.
|
|
1185 Setting this to 0 disables pretty-printing."
|
|
1186 :type 'integer
|
|
1187 :group 'help)
|
|
1188
|
|
1189 (defun help-maybe-pretty-print-value (object)
|
|
1190 "Pretty-print OBJECT, unless it is a long list.
|
|
1191 OBJECT is printed in the current buffer. Unless it is a list with
|
|
1192 more than `help-pretty-print-limit' elements, it is pretty-printed.
|
|
1193
|
|
1194 Uses `pp-internal' if defined, otherwise `cl-prettyprint'"
|
231
|
1195 (princ
|
259
|
1196 (let ((valstr
|
|
1197 (if (and (or (listp object) (vectorp object))
|
|
1198 (< (length object)
|
|
1199 help-pretty-print-limit))
|
|
1200 (with-output-to-string
|
|
1201 (with-syntax-table emacs-lisp-mode-syntax-table
|
|
1202 ;; print `#<...>' values better
|
|
1203 (modify-syntax-entry ?< "(>")
|
|
1204 (modify-syntax-entry ?> ")<")
|
|
1205 (let ((indent-line-function 'lisp-indent-line))
|
|
1206 (if (fboundp 'pp-internal)
|
|
1207 (progn
|
|
1208 (pp-internal object "\n")
|
|
1209 (terpri))
|
|
1210 (cl-prettyprint object)))))
|
|
1211 (format "\n%S\n" object))))
|
|
1212
|
|
1213 (if (string-match "^\n[^\n]*\n$" valstr)
|
|
1214 (substring valstr 1)
|
|
1215 valstr))))
|
231
|
1216
|
209
|
1217 (defun describe-variable (variable)
|
|
1218 "Display the full documentation of VARIABLE (a symbol)."
|
|
1219 (interactive
|
|
1220 (let* ((v (variable-at-point))
|
|
1221 (val (let ((enable-recursive-minibuffers t))
|
|
1222 (completing-read
|
|
1223 (if v
|
|
1224 (format "Describe variable (default %s): " v)
|
|
1225 (gettext "Describe variable: "))
|
|
1226 obarray 'boundp t nil 'variable-history))))
|
|
1227 (list (if (equal val "") v (intern val)))))
|
231
|
1228 (with-displaying-help-buffer (format "variable `%s'" variable)
|
|
1229 (let ((origvar variable)
|
|
1230 aliases)
|
|
1231 (let ((print-escape-newlines t))
|
|
1232 (princ (format "`%s' is " (symbol-name variable)))
|
|
1233 (while (variable-alias variable)
|
|
1234 (let ((newvar (variable-alias variable)))
|
|
1235 (if aliases
|
|
1236 ;; I18N3 Need gettext due to concat
|
|
1237 (setq aliases
|
|
1238 (concat aliases
|
|
1239 (format "\n which is an alias for `%s',"
|
|
1240 (symbol-name newvar))))
|
|
1241 (setq aliases
|
|
1242 (format "an alias for `%s',"
|
|
1243 (symbol-name newvar))))
|
|
1244 (setq variable newvar)))
|
|
1245 (if aliases
|
|
1246 (princ (format "%s" aliases)))
|
|
1247 (princ (built-in-variable-doc variable))
|
|
1248 (princ ".\n")
|
233
|
1249 (let ((file-name (describe-symbol-find-file variable)))
|
231
|
1250 (if file-name
|
|
1251 (princ (format " -- loaded from \"%s\"\n" file-name))))
|
|
1252 (princ "\nValue: ")
|
|
1253 (if (not (boundp variable))
|
|
1254 (princ "void\n")
|
243
|
1255 (help-maybe-pretty-print-value (symbol-value variable)))
|
231
|
1256 (terpri)
|
|
1257 (cond ((local-variable-p variable (current-buffer))
|
|
1258 (let* ((void (cons nil nil))
|
|
1259 (def (condition-case nil
|
|
1260 (default-value variable)
|
|
1261 (error void))))
|
|
1262 (princ "This value is specific to the current buffer.\n")
|
|
1263 (if (local-variable-p variable nil)
|
|
1264 (princ "(Its value is local to each buffer.)\n"))
|
|
1265 (terpri)
|
|
1266 (if (if (eq def void)
|
|
1267 (boundp variable)
|
|
1268 (not (eq (symbol-value variable) def)))
|
|
1269 ;; #### I18N3 doesn't localize properly!
|
|
1270 (progn (princ "Default-value: ")
|
|
1271 (if (eq def void)
|
|
1272 (princ "void\n")
|
243
|
1273 (help-maybe-pretty-print-value def))
|
231
|
1274 (terpri)))))
|
|
1275 ((local-variable-p variable (current-buffer) t)
|
|
1276 (princ "Setting it would make its value buffer-local.\n\n"))))
|
|
1277 (princ "Documentation:")
|
|
1278 (terpri)
|
|
1279 (let ((doc (documentation-property variable 'variable-documentation))
|
|
1280 (obsolete (variable-obsoleteness-doc origvar))
|
|
1281 (compatible (variable-compatibility-doc origvar)))
|
|
1282 (when obsolete
|
|
1283 (princ obsolete)
|
|
1284 (terpri)
|
|
1285 (terpri))
|
|
1286 (when compatible
|
|
1287 (princ compatible)
|
|
1288 (terpri)
|
|
1289 (terpri))
|
|
1290 ;; don't bother to print anything if variable is obsolete and aliased.
|
|
1291 (when (or (not obsolete) (not aliases))
|
|
1292 (if doc
|
|
1293 ;; note: documentation-property calls substitute-command-keys.
|
|
1294 (princ doc)
|
|
1295 (princ "not documented as a variable."))))
|
|
1296 (terpri))))
|
209
|
1297
|
|
1298 (defun sorted-key-descriptions (keys &optional separator)
|
|
1299 "Sort and separate the key descriptions for KEYS.
|
|
1300 The sorting is done by length (shortest bindings first), and the bindings
|
|
1301 are separated with SEPARATOR (\", \" by default)."
|
|
1302 (mapconcat 'key-description
|
|
1303 (sort keys #'(lambda (x y)
|
|
1304 (< (length x) (length y))))
|
|
1305 (or separator ", ")))
|
|
1306
|
|
1307 (defun where-is (definition)
|
|
1308 "Print message listing key sequences that invoke specified command.
|
|
1309 Argument is a command definition, usually a symbol with a function definition.
|
|
1310 When run interactively, it defaults to any function found by
|
|
1311 `function-at-point'."
|
|
1312 (interactive
|
|
1313 (let ((fn (function-at-point))
|
|
1314 (enable-recursive-minibuffers t)
|
|
1315 val)
|
|
1316 (setq val (read-command
|
|
1317 (if fn (format "Where is command (default %s): " fn)
|
|
1318 "Where is command: ")))
|
|
1319 (list (if (equal (symbol-name val) "")
|
|
1320 fn val))))
|
|
1321 (let ((keys (where-is-internal definition)))
|
|
1322 (if keys
|
|
1323 (message "%s is on %s" definition (sorted-key-descriptions keys))
|
|
1324 (message "%s is not on any keys" definition)))
|
|
1325 nil)
|
|
1326
|
|
1327 ;; `locate-library' moved to "packages.el"
|
|
1328
|
|
1329
|
|
1330 ;; Functions ported from C into Lisp in XEmacs
|
|
1331
|
|
1332 (defun describe-syntax ()
|
|
1333 "Describe the syntax specifications in the syntax table.
|
|
1334 The descriptions are inserted in a buffer, which is then displayed."
|
|
1335 (interactive)
|
231
|
1336 (with-displaying-help-buffer (format "syntax-table for %s" major-mode)
|
|
1337 ;; defined in syntax.el
|
|
1338 (describe-syntax-table (syntax-table) standard-output)))
|
209
|
1339
|
|
1340 (defun list-processes ()
|
|
1341 "Display a list of all processes.
|
|
1342 \(Any processes listed as Exited or Signaled are actually eliminated
|
|
1343 after the listing is made.)"
|
|
1344 (interactive)
|
|
1345 (with-output-to-temp-buffer "*Process List*"
|
|
1346 (set-buffer standard-output)
|
|
1347 (buffer-disable-undo standard-output)
|
|
1348 (make-local-variable 'truncate-lines)
|
|
1349 (setq truncate-lines t)
|
231
|
1350 ;; 00000000001111111111222222222233333333334444444444
|
|
1351 ;; 01234567890123456789012345678901234567890123456789
|
|
1352 ;; rewritten for I18N3. This one should stay rewritten
|
|
1353 ;; so that the dashes will line up properly.
|
|
1354 (princ "Proc Status Buffer Tty Command\n---- ------ ------ --- -------\n")
|
|
1355 (let ((tail (process-list)))
|
|
1356 (while tail
|
|
1357 (let* ((p (car tail))
|
|
1358 (pid (process-id p))
|
|
1359 (s (process-status p)))
|
|
1360 (setq tail (cdr tail))
|
|
1361 (princ (format "%-13s" (process-name p)))
|
|
1362 ;;(if (and (eq system-type 'vax-vms)
|
|
1363 ;; (eq s 'signal)
|
|
1364 ;; (< (process-exit-status p) NSIG))
|
|
1365 ;; (princ (aref sys_errlist (process-exit-status p))))
|
|
1366 (princ s)
|
|
1367 (if (and (eq s 'exit) (/= (process-exit-status p) 0))
|
|
1368 (princ (format " %d" (process-exit-status p))))
|
|
1369 (if (memq s '(signal exit closed))
|
|
1370 ;; Do delete-exited-processes' work
|
|
1371 (delete-process p))
|
|
1372 (indent-to 22 1) ;####
|
|
1373 (let ((b (process-buffer p)))
|
|
1374 (cond ((not b)
|
|
1375 (princ "(none)"))
|
|
1376 ((not (buffer-name b))
|
|
1377 (princ "(killed)"))
|
|
1378 (t
|
|
1379 (princ (buffer-name b)))))
|
|
1380 (indent-to 37 1) ;####
|
|
1381 (let ((tn (process-tty-name p)))
|
|
1382 (cond ((not tn)
|
|
1383 (princ "(none)"))
|
|
1384 (t
|
|
1385 (princ (format "%s" tn)))))
|
|
1386 (indent-to 49 1) ;####
|
|
1387 (if (not (integerp pid))
|
|
1388 (progn
|
|
1389 (princ "network stream connection ")
|
|
1390 (princ (car pid))
|
|
1391 (princ "@")
|
|
1392 (princ (cdr pid)))
|
|
1393 (let ((cmd (process-command p)))
|
|
1394 (while cmd
|
|
1395 (princ (car cmd))
|
|
1396 (setq cmd (cdr cmd))
|
|
1397 (if cmd (princ " ")))))
|
|
1398 (terpri))))))
|
209
|
1399
|
|
1400 ;;; help.el ends here
|