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