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