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