1 ;;; help.el --- help commands for XEmacs.
3 ;; Copyright (C) 1985, 1986, 1992-4, 1997 Free Software Foundation, Inc.
6 ;; Keywords: help, internal, dumped
8 ;; This file is part of XEmacs.
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)
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Synched up with: FSF 19.30.
29 ;; This file is dumped with XEmacs.
31 ;; This code implements XEmacs's on-line help system, the one invoked by
32 ;;`M-x help-for-help'.
34 ;; 06/11/1997 -- Converted to use char-after instead of broken
35 ;; following-char. -slb
39 ;; Get the macro make-help-screen when this is compiled,
40 ;; or run interpreted, but not when the compiled code is loaded.
41 (eval-when-compile (require 'help-macro))
44 "Support for on-line help systems."
47 (defgroup help-appearance nil
48 "Appearance of help buffers."
51 (defvar help-map (let ((map (make-sparse-keymap)))
52 (set-keymap-name map 'help-map)
54 map (gettext "(Type ? for further options)"))
56 "Keymap for characters following the Help key.")
58 ;; global-map definitions moved to keydefs.el
59 (fset 'help-command help-map)
61 (define-key help-map (vector help-char) 'help-for-help)
62 (define-key help-map "?" 'help-for-help)
63 (define-key help-map 'help 'help-for-help)
64 (define-key help-map '(f1) 'help-for-help)
66 (define-key help-map "\C-l" 'describe-copying) ; on \C-c in FSFmacs
67 (define-key help-map "\C-d" 'describe-distribution)
68 (define-key help-map "\C-w" 'describe-no-warranty)
69 (define-key help-map "a" 'hyper-apropos) ; 'command-apropos in FSFmacs
70 (define-key help-map "A" 'command-apropos)
72 (define-key help-map "b" 'describe-bindings)
73 (define-key help-map "B" 'describe-beta)
74 (define-key help-map "\C-p" 'describe-pointer)
76 (define-key help-map "C" 'customize)
77 (define-key help-map "c" 'describe-key-briefly)
78 (define-key help-map "k" 'describe-key)
80 (define-key help-map "d" 'describe-function)
81 (define-key help-map "e" 'describe-last-error)
82 (define-key help-map "f" 'describe-function)
84 (define-key help-map "F" 'xemacs-local-faq)
86 (define-key help-map "i" 'info)
87 (define-key help-map '(control i) 'Info-query)
88 ;; FSFmacs has Info-goto-emacs-command-node on C-f, no binding
90 (define-key help-map '(control c) 'Info-goto-emacs-command-node)
91 (define-key help-map '(control k) 'Info-goto-emacs-key-command-node)
92 (define-key help-map '(control f) 'Info-elisp-ref)
94 (define-key help-map "l" 'view-lossage)
96 (define-key help-map "m" 'describe-mode)
98 (define-key help-map "\C-n" 'view-emacs-news)
99 (define-key help-map "n" 'view-emacs-news)
101 (define-key help-map "p" 'finder-by-keyword)
103 ;; Do this right with an autoload cookie in finder.el.
104 ;;(autoload 'finder-by-keyword "finder"
105 ;; "Find packages matching a given keyword." t)
107 (define-key help-map "s" 'describe-syntax)
109 (define-key help-map "t" 'help-with-tutorial)
111 (define-key help-map "w" 'where-is)
113 (define-key help-map "v" 'describe-variable)
115 (if (fboundp 'view-last-error)
116 (define-key help-map "e" 'view-last-error))
119 (define-key help-map "q" 'help-quit)
121 ;#### This stuff was an attempt to have font locking and hyperlinks in the
122 ;help buffer, but it doesn't really work. Some of this stuff comes from
123 ;FSF Emacs; but the FSF Emacs implementation is rather broken, as usual.
124 ;What needs to happen is this:
126 ; -- we probably need a "hyperlink mode" from which help-mode is derived.
127 ; -- this means we probably need multiple inheritance of modes!
128 ; Thankfully this is not hard to implement; we already have the
129 ; ability for a keymap to have multiple parents. However, we'd
130 ; have to define any multiply-inherited-from modes using a standard
131 ; `define-mode' construction instead of manually doing it, because
132 ; we don't want each guy calling `kill-all-local-variables' and
133 ; messing up the previous one.
134 ; -- we need to scan the buffer ourselves (not from font-lock, because
135 ; the user might not have font-lock enabled) and highlight only
136 ; those words that are *documented* functions and variables (and
137 ; probably excluding words without dashes in them unless enclosed
138 ; in quotes, so that common words like "list" and "point" don't
140 ; -- we should *not* use font-lock keywords like below. Instead we
141 ; should add the font-lock stuff ourselves during the scanning phase,
142 ; if font-lock is enabled in this buffer.
144 ;(defun help-follow-reference (event extent user-data)
145 ; (let ((symbol (intern-soft (extent-string extent))))
146 ; (cond ((and symbol (fboundp symbol))
147 ; (describe-function symbol))
148 ; ((and symbol (boundp symbol))
149 ; (describe-variable symbol))
152 ;(defvar help-font-lock-keywords
153 ; (let ((name-char "[-+a-zA-Z0-9_*]") (sym-char "[-+a-zA-Z0-9_:*]"))
156 ; ;; The symbol itself.
157 ; (list (concat "\\`\\(" name-char "+\\)\\(:\\)?")
158 ; '(1 (if (match-beginning 2)
159 ; 'font-lock-function-name-face
160 ; 'font-lock-variable-name-face)
163 ; ;; Words inside `' which tend to be symbol names.
164 ; (list (concat "`\\(" sym-char sym-char "+\\)'")
166 ; 'font-lock-reference-face
167 ; (add-list-mode-item (match-beginning 1)
170 ; 'help-follow-reference))
173 ; ;; CLisp `:' keywords as references.
174 ; (list (concat "\\<:" sym-char "+\\>") 0 'font-lock-reference-face t)))
175 ; "Default expressions to highlight in Help mode.")
177 ;(put 'help-mode 'font-lock-defaults '(help-font-lock-keywords))
179 (define-derived-mode help-mode view-major-mode "Help"
180 "Major mode for viewing help text.
181 Entry to this mode runs the normal hook `help-mode-hook'.
186 (define-key help-mode-map "q" 'help-mode-quit)
187 (define-key help-mode-map "Q" 'help-mode-bury)
188 (define-key help-mode-map "f" 'find-function-at-point)
189 (define-key help-mode-map "d" 'describe-function-at-point)
190 (define-key help-mode-map "v" 'describe-variable-at-point)
191 (define-key help-mode-map "i" 'Info-elisp-ref)
192 (define-key help-mode-map "c" 'customize-variable)
193 (define-key help-mode-map [tab] 'help-next-symbol)
194 (define-key help-mode-map [(shift tab)] 'help-prev-symbol)
195 (define-key help-mode-map "n" 'help-next-section)
196 (define-key help-mode-map "p" 'help-prev-section)
198 (defun describe-function-at-point ()
199 "Describe directly the function at point in the other window."
201 (let ((symb (function-at-point)))
203 (describe-function symb))))
205 (defun describe-variable-at-point ()
206 "Describe directly the variable at point in the other window."
208 (let ((symb (variable-at-point)))
210 (describe-variable symb))))
212 (defun help-next-symbol ()
213 "Move point to the next quoted symbol."
215 (search-forward "`" nil t))
217 (defun help-prev-symbol ()
218 "Move point to the previous quoted symbol."
220 (search-backward "'" nil t))
222 (defun help-next-section ()
223 "Move point to the next quoted symbol."
225 (search-forward-regexp "^\\w+:" nil t))
227 (defun help-prev-section ()
228 "Move point to the previous quoted symbol."
230 (search-backward-regexp "^\\w+:" nil t))
232 (defun help-mode-bury ()
233 "Bury the help buffer, possibly restoring the previous window configuration."
237 (defun help-mode-quit (&optional bury)
238 "Exit from help mode, possibly restoring the previous window configuration.
239 If the optional argument BURY is non-nil, the help buffer is buried,
240 otherwise it is killed."
242 (let ((buf (current-buffer)))
243 (cond (help-window-config
244 (set-window-configuration help-window-config))
245 ((not (one-window-p))
255 ;; This is a grody hack of the same genotype as `advertised-undo'; if the
256 ;; bindings of Backspace and C-h are the same, we want the menubar to claim
257 ;; that `info' is invoked with `C-h i', not `BS i'.
259 (defun deprecated-help-command ()
261 (if (eq 'help-command (key-binding "\C-h"))
262 (setq unread-command-event (character-to-event ?\C-h))
265 ;;(define-key global-map 'backspace 'deprecated-help-command)
267 ;; This function has been moved to help-nomule.el and mule-help.el.
268 ;; TUTORIAL arg is XEmacs addition
269 ;(defun help-with-tutorial (&optional tutorial)
270 ; "Select the XEmacs learn-by-doing tutorial.
271 ;Optional arg TUTORIAL specifies the tutorial file; default is \"TUTORIAL\"."
273 ; (if (null tutorial)
274 ; (setq tutorial "TUTORIAL"))
275 ; (let ((file (expand-file-name (concat "~/" tutorial))))
276 ; (delete-other-windows)
277 ; (if (get-file-buffer file)
278 ; (switch-to-buffer (get-file-buffer file))
279 ; (switch-to-buffer (create-file-buffer file))
280 ; (setq buffer-file-name file)
281 ; (setq default-directory (expand-file-name "~/"))
282 ; (setq buffer-auto-save-file-name nil)
283 ; (insert-file-contents (expand-file-name tutorial data-directory))
284 ; (goto-char (point-min))
285 ; (search-forward "\n<<")
286 ; (delete-region (point-at-bol) (point-at-eol))
287 ; (let ((n (- (window-height (selected-window))
288 ; (count-lines (point-min) (point))
292 ; ;; Some people get confused by the large gap.
294 ; (insert "[Middle of page left blank for didactic purposes. "
295 ; "Text continues below]")
296 ; (newline (- n (/ n 2)))))
297 ; (goto-char (point-min))
298 ; (set-buffer-modified-p nil))))
300 ;; used by describe-key, describe-key-briefly, insert-key-binding, etc.
302 (defun key-or-menu-binding (key &optional menu-flag)
303 "Return the command invoked by KEY.
304 Like `key-binding', but handles menu events and toolbar presses correctly.
305 KEY is any value returned by `next-command-event'.
306 MENU-FLAG is a symbol that should be set to t if KEY is a menu event,
309 (and menu-flag (set menu-flag nil))
310 ;; If the key typed was really a menu selection, grab the form out
311 ;; of the event object and intuit the function that would be called,
312 ;; and describe that instead.
313 (if (and (vectorp key) (= 1 (length key))
314 (or (misc-user-event-p (aref key 0))
315 (eq (car-safe (aref key 0)) 'menu-selection)))
316 (let ((event (aref key 0)))
317 (setq defn (if (eventp event)
318 (list (event-function event) (event-object event))
320 (and menu-flag (set menu-flag t))
321 (when (eq (car defn) 'eval)
322 (setq defn (car (cdr defn))))
323 (when (eq (car-safe defn) 'call-interactively)
324 (setq defn (car (cdr defn))))
325 (when (and (consp defn) (null (cdr defn)))
326 (setq defn (car defn))))
328 (setq defn (key-binding key)))
329 ;; kludge: if a toolbar button was pressed on, try to find the
330 ;; binding of the toolbar button.
331 (if (and (eq defn 'press-toolbar-button)
333 (button-press-event-p (aref key (1- (length key)))))
334 ;; wait for the button release. We're on shaky ground here ...
335 (let ((event (next-command-event))
337 (if (and (button-release-event-p event)
338 (event-over-toolbar-p event)
339 (eq 'release-and-activate-toolbar-button
340 (key-binding (vector event)))
341 (setq button (event-toolbar-button event)))
342 (toolbar-button-callback button)
343 ;; if anything went wrong, try returning the binding of
344 ;; the button-up event, of the original binding
345 (or (key-or-menu-binding (vector event))
351 (defun describe-key-briefly (key &optional insert)
352 "Print the name of the function KEY invokes. KEY is a string.
353 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
354 (interactive "kDescribe key briefly: \nP")
355 (let ((standard-output (if insert (current-buffer) t))
357 (setq defn (key-or-menu-binding key 'menup))
358 (if (or (null defn) (integerp defn))
359 (princ (format "%s is undefined" (key-description key)))
360 ;; If it's a keyboard macro which trivially invokes another command,
361 ;; document that instead.
362 (if (or (stringp defn) (vectorp defn))
363 (setq defn (or (key-binding defn)
365 (let ((last-event (and (vectorp key)
366 (aref key (1- (length key))))))
367 (princ (format (cond (insert
369 ((or (button-press-event-p last-event)
370 (button-release-event-p last-event))
371 (gettext "%s at that spot runs the command %s"))
373 (gettext "%s runs the command %s")))
374 ;; This used to say 'This menu item' but it
375 ;; could also be a scrollbar event. We can't
376 ;; distinguish at the moment.
378 (if insert "item" "This item")
379 (key-description key))
380 (if (symbolp defn) defn (prin1-to-string defn))))))))
382 ;; #### this is a horrible piece of shit function that should
383 ;; not exist. In FSF 19.30 this function has gotten three times
384 ;; as long and has tons and tons of dumb shit checking
385 ;; special-display-buffer-names and such crap. I absolutely
386 ;; refuse to insert that Ebolification here. I wanted to delete
387 ;; this function entirely but Mly bitched.
389 ;; If your user-land code calls this function, rewrite it to
390 ;; call with-displaying-help-buffer.
392 (defun print-help-return-message (&optional function)
393 "Display or return message saying how to restore windows after help command.
394 Computes a message and applies the optional argument FUNCTION to it.
395 If FUNCTION is nil, applies `message' to it, thus printing it."
396 (and (not (get-buffer-window standard-output))
398 (or function 'message)
400 (substitute-command-keys
403 (gettext "Type \\[delete-other-windows] to remove help window.")
404 (gettext "Type \\[switch-to-buffer] RET to remove help window."))
405 (gettext "Type \\[switch-to-buffer-other-window] RET to restore the other window.")))
406 (substitute-command-keys
407 (gettext " \\[scroll-other-window] to scroll the help."))))))
409 (defcustom help-selects-help-window t
410 "*If nil, use the \"old Emacs\" behavior for Help buffers.
411 This just displays the buffer in another window, rather than selecting
414 :group 'help-appearance)
416 (defcustom help-max-help-buffers 10
417 "*Maximum help buffers to allow before they start getting killed.
418 If this is a positive integer, before a help buffer is displayed
419 by `with-displaying-help-buffer', any excess help buffers which
420 are not being displayed are first killed. Otherwise, if it is
421 zero or nil, only one help buffer, \"*Help*\" is ever used."
422 :type '(choice integer (const :tag "None" nil))
423 :group 'help-appearance)
425 (defvar help-buffer-list nil
426 "List of help buffers used by `help-register-and-maybe-prune-excess'")
428 (defun help-register-and-maybe-prune-excess (newbuf)
429 "Register use of a help buffer and possibly kill any excess ones."
430 ;; remove new buffer from list
431 (setq help-buffer-list (remove newbuf help-buffer-list))
432 ;; maybe kill excess help buffers
433 (if (and (integerp help-max-help-buffers)
434 (> (length help-buffer-list) help-max-help-buffers))
435 (let ((keep-list nil)
436 (num-kill (- (length help-buffer-list)
437 help-max-help-buffers)))
438 (while help-buffer-list
439 (let ((buf (car help-buffer-list)))
440 (if (and (or (equal buf newbuf) (get-buffer buf))
441 (string-match "^*Help" buf)
442 (save-excursion (set-buffer buf)
443 (eq major-mode 'help-mode)))
444 (if (and (>= num-kill (length help-buffer-list))
445 (not (get-buffer-window buf t t)))
447 (setq keep-list (cons buf keep-list)))))
448 (setq help-buffer-list (cdr help-buffer-list)))
449 (setq help-buffer-list (nreverse keep-list))))
451 (setq help-buffer-list (cons newbuf help-buffer-list)))
453 (defvar help-buffer-prefix-string "Help"
454 "Initial string to use in constructing help buffer names.
455 You should never set this directory, only let-bind it.")
457 (defun help-buffer-name (name)
458 "Return a name for a Help buffer using string NAME for context."
459 (if (and (integerp help-max-help-buffers)
460 (> help-max-help-buffers 0)
462 (if help-buffer-prefix-string
463 (format "*%s: %s*" help-buffer-prefix-string name)
464 (format "*%s*" name))
465 (format "*%s*" help-buffer-prefix-string)))
467 ;; Use this function for displaying help when C-h something is pressed
468 ;; or in similar situations. Do *not* use it when you are displaying
469 ;; a help message and then prompting for input in the minibuffer --
470 ;; this macro usually selects the help buffer, which is not what you
471 ;; want in those situations.
473 ;; #### Should really be a macro to eliminate the requirement of
474 ;; caller to code a lambda form in THUNK -- mrb
476 ;; #### BEFORE you rush to make this a macro, think about backward
477 ;; compatibility. The right way would be to create a macro with
478 ;; another name (which is a shame, because w-d-h-b is a perfect name
479 ;; for a macro) that uses with-displaying-help-buffer internally.
481 (defcustom mode-for-help 'help-mode
482 "*Mode that help buffers are put into.")
484 (defvar help-sticky-window nil
485 ;; Window into which help buffers will be displayed, rather than
486 ;; always searching for a new one. This is INTERNAL and liable to
487 ;; change its interface and/or name at any moment. It should be
491 (defvar help-window-config nil)
493 (make-variable-buffer-local 'help-window-config)
494 (put 'help-window-config 'permanent-local t)
496 (defun with-displaying-help-buffer (thunk &optional name)
497 "Form which makes a help buffer with given NAME and evaluates BODY there.
498 The actual name of the buffer is generated by the function `help-buffer-name'."
499 (let* ((winconfig (current-window-configuration))
500 (was-one-window (one-window-p))
501 (buffer-name (help-buffer-name name))
503 (not (and (windows-of-buffer buffer-name) ;shortcut
504 (memq (selected-frame)
505 (mapcar 'window-frame
506 (windows-of-buffer buffer-name)))))))
507 (help-register-and-maybe-prune-excess buffer-name)
508 ;; if help-sticky-window is bogus or deleted, get rid of it.
509 (if (and help-sticky-window (or (not (windowp help-sticky-window))
510 (not (window-live-p help-sticky-window))))
511 (setq help-sticky-window nil))
513 (let ((temp-buffer-show-function
514 (if help-sticky-window
516 (set-window-buffer help-sticky-window buffer))
517 temp-buffer-show-function)))
518 (with-output-to-temp-buffer buffer-name
519 (prog1 (funcall thunk)
521 (set-buffer standard-output)
522 (funcall mode-for-help)))))
523 (let ((helpwin (get-buffer-window buffer-name)))
525 ;; If the *Help* buffer is already displayed on this
526 ;; frame, don't override the previous configuration
527 (when help-not-visible
528 (with-current-buffer (window-buffer helpwin)
529 (setq help-window-config winconfig)))
530 (when help-selects-help-window
531 (select-window helpwin))
532 (cond ((eq helpwin (selected-window))
533 (display-message 'command
534 (substitute-command-keys "Type \\[help-mode-quit] to remove help window, \\[scroll-up] to scroll the help.")))
536 (display-message 'command
537 (substitute-command-keys "Type \\[delete-other-windows] to remove help window, \\[scroll-other-window] to scroll the help.")))
539 (display-message 'command
540 (substitute-command-keys "Type \\[switch-to-buffer-other-window] to restore the other window, \\[scroll-other-window] to scroll the help.")))))))))
542 (defun describe-key (key)
543 "Display documentation of the function invoked by KEY.
544 KEY is a string, or vector of events.
545 When called interactively, KEY may also be a menu selection."
546 (interactive "kDescribe key: ")
547 (let ((defn (key-or-menu-binding key))
548 (key-string (key-description key)))
549 (if (or (null defn) (integerp defn))
550 (message "%s is undefined" key-string)
551 (with-displaying-help-buffer
556 (princ (format "`%s'" defn))
559 (cond ((or (stringp defn) (vectorp defn))
560 (let ((cmd (key-binding defn)))
562 (princ "a keyboard macro")
564 (princ "a keyboard macro which runs the command ")
567 (if (documentation cmd) (princ (documentation cmd)))))))
568 ((and (consp defn) (not (eq 'lambda (car-safe defn))))
569 (let ((describe-function-show-arglist nil))
570 (describe-function-1 (car defn))))
572 (describe-function-1 defn))
573 ((documentation defn)
574 (princ (documentation defn)))
576 (princ "not documented"))))
577 (format "key `%s'" key-string)))))
579 (defun describe-mode ()
580 "Display documentation of current major mode and minor modes.
581 For this to work correctly for a minor mode, the mode's indicator variable
582 \(listed in `minor-mode-alist') must also be a function whose documentation
583 describes the minor mode."
585 (with-displaying-help-buffer
587 ;; XEmacs change: print the major-mode documentation before
591 (princ (documentation major-mode))
592 (princ "\n\n----\n\n")
593 (let ((minor-modes minor-mode-alist))
595 (let* ((minor-mode (car (car minor-modes)))
596 (indicator (car (cdr (car minor-modes)))))
597 ;; Document a minor mode if it is listed in minor-mode-alist,
598 ;; bound locally in this buffer, non-nil, and has a function
600 (if (and (boundp minor-mode)
601 (symbol-value minor-mode)
602 (fboundp minor-mode))
603 (let ((pretty-minor-mode minor-mode))
604 (if (string-match "-mode\\'" (symbol-name minor-mode))
605 (setq pretty-minor-mode
607 (substring (symbol-name minor-mode)
608 0 (match-beginning 0)))))
609 (while (and (consp indicator) (extentp (car indicator)))
610 (setq indicator (cdr indicator)))
611 (while (and indicator (symbolp indicator))
612 (setq indicator (symbol-value indicator)))
613 (princ (format "%s minor mode (indicator%s):\n"
614 pretty-minor-mode indicator))
615 (princ (documentation minor-mode))
616 (princ "\n\n----\n\n"))))
617 (setq minor-modes (cdr minor-modes)))))
618 (format "%s mode" mode-name)))
620 ;; So keyboard macro definitions are documented correctly
621 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
623 (defun describe-distribution ()
624 "Display info on how to obtain the latest version of XEmacs."
627 (locate-data-file "DISTRIB")))
629 (defun describe-beta ()
630 "Display info on how to deal with Beta versions of XEmacs."
633 (locate-data-file "BETA"))
634 (goto-char (point-min)))
636 (defun describe-copying ()
637 "Display info on how you may redistribute copies of XEmacs."
640 (locate-data-file "COPYING"))
641 (goto-char (point-min)))
643 (defun describe-pointer ()
644 "Show a list of all defined mouse buttons, and their definitions."
646 (describe-bindings nil t))
648 (defun describe-project ()
649 "Display info on the GNU project."
652 (locate-data-file "GNU"))
653 (goto-char (point-min)))
655 (defun describe-no-warranty ()
656 "Display info on all the kinds of warranty XEmacs does NOT have."
659 (let (case-fold-search)
660 (search-forward "NO WARRANTY")
663 (defun describe-bindings (&optional prefix mouse-only-p)
664 "Show a list of all defined keys, and their definitions.
665 The list is put in a buffer, which is displayed.
666 If optional first argument PREFIX is supplied, only commands
667 which start with that sequence of keys are described.
668 If optional second argument MOUSE-ONLY-P (prefix arg, interactively)
669 is non-nil then only the mouse bindings are displayed."
670 (interactive (list nil current-prefix-arg))
671 (with-displaying-help-buffer
673 (describe-bindings-1 prefix mouse-only-p))
674 (format "bindings for %s" major-mode)))
676 (defun describe-bindings-1 (&optional prefix mouse-only-p)
677 (let ((heading (if mouse-only-p
678 (gettext "button binding\n------ -------\n")
679 (gettext "key binding\n--- -------\n")))
680 (buffer (current-buffer))
681 (minor minor-mode-map-alist)
682 (extent-maps (mapcar-extents
684 nil (current-buffer) (point) (point) nil 'keymap))
685 (local (current-local-map))
687 (set-buffer standard-output)
689 (insert "Bindings for Text Region:\n"
691 (describe-bindings-internal
692 (car extent-maps) nil shadow prefix mouse-only-p)
694 (setq shadow (cons (car extent-maps) shadow)
695 extent-maps (cdr extent-maps)))
697 (let ((sym (car (car minor)))
698 (map (cdr (car minor))))
699 (if (symbol-value-in-buffer sym buffer nil)
701 (insert (format "Minor Mode Bindings for `%s':\n"
704 (describe-bindings-internal map nil shadow prefix mouse-only-p)
706 (setq shadow (cons map shadow))))
707 (setq minor (cdr minor))))
710 (insert "Local Bindings:\n" heading)
711 (describe-bindings-internal local nil shadow prefix mouse-only-p)
713 (setq shadow (cons local shadow))))
714 (insert "Global Bindings:\n" heading)
715 (describe-bindings-internal (current-global-map)
716 nil shadow prefix mouse-only-p)
717 (when (and prefix function-key-map (not mouse-only-p))
718 (insert "\nFunction key map translations:\n" heading)
719 (describe-bindings-internal function-key-map nil nil
720 prefix mouse-only-p))
724 (defun describe-prefix-bindings ()
725 "Describe the bindings of the prefix used to reach this command.
726 The prefix described consists of all but the last event
727 of the key sequence that ran this command."
729 (let* ((key (this-command-keys))
730 (prefix (make-vector (1- (length key)) nil))
733 (while (< i (length prefix))
734 (aset prefix i (aref key i))
736 (with-displaying-help-buffer
738 (princ "Key bindings starting with ")
739 (princ (key-description prefix))
741 (describe-bindings-1 prefix nil))
742 (format "%s prefix" (key-description prefix)))))
744 ;; Make C-h after a prefix, when not specifically bound,
745 ;; run describe-prefix-bindings.
746 (setq prefix-help-command 'describe-prefix-bindings)
748 (defun describe-installation ()
749 "Display a buffer showing information about this XEmacs was compiled."
751 (if (and (boundp 'Installation-string)
752 (stringp Installation-string))
753 (with-displaying-help-buffer
756 (if (fboundp 'decode-coding-string)
757 (decode-coding-string Installation-string 'automatic-conversion)
758 Installation-string)))
760 (error "No Installation information available.")))
762 (defun view-emacs-news ()
763 "Display info on recent changes to XEmacs."
765 (find-file (locate-data-file "NEWS")))
767 (defun xemacs-www-page ()
768 "Go to the XEmacs World Wide Web page."
770 (if (fboundp 'browse-url)
771 (browse-url "http://www.xemacs.org/")
772 (error "xemacs-www-page requires browse-url")))
774 (defun xemacs-www-faq ()
775 "View the latest and greatest XEmacs FAQ using the World Wide Web."
777 (if (fboundp 'browse-url)
778 (browse-url "http://www.xemacs.org/faq/index.html")
779 (error "xemacs-www-faq requires browse-url")))
781 (defun xemacs-local-faq ()
782 "View the local copy of the XEmacs FAQ.
783 If you have access to the World Wide Web, you should use `xemacs-www-faq'
784 instead, to ensure that you get the most up-to-date information."
786 (save-window-excursion
788 (Info-find-node "xemacs-faq" "Top"))
789 (switch-to-buffer "*info*"))
791 (defcustom view-lossage-key-count 100
792 "*Number of keys `view-lossage' shows.
793 The maximum number of available keys is governed by `recent-keys-ring-size'."
797 (defcustom view-lossage-message-count 100
798 "*Number of minibuffer messages `view-lossage' shows."
802 (defun print-recent-messages (n)
803 "Print N most recent messages to standard-output, most recent first.
804 If N is nil, all messages will be printed."
806 (let ((buffer (get-buffer-create " *Message-Log*"))
808 (goto-char (point-max buffer) buffer)
809 (set-buffer standard-output)
810 (while (and (not (bobp buffer))
811 (or (null n) (>= (decf n) 0)))
812 (setq oldpoint (point buffer))
813 (setq extent (extent-at oldpoint buffer
814 'message-multiline nil 'before))
815 ;; If the message was multiline, move all the way to the
818 (goto-char (extent-start-position extent) buffer)
819 (forward-line -1 buffer))
820 (insert-buffer-substring buffer (point buffer) oldpoint)))))
822 (defun view-lossage ()
823 "Display recent input keystrokes and recent minibuffer messages.
824 The number of keys shown is controlled by `view-lossage-key-count'.
825 The number of messages shown is controlled by `view-lossage-message-count'."
827 (with-displaying-help-buffer
829 (princ (key-description (recent-keys view-lossage-key-count)))
831 (set-buffer standard-output)
832 (goto-char (point-min))
833 (insert "Recent keystrokes:\n\n")
834 (while (progn (move-to-column 50) (not (eobp)))
835 (search-forward " " nil t)
837 ;; XEmacs addition: copy the messages from " *Message-Log*",
838 ;; reversing their order and handling multiline messages
840 (princ "\n\n\nRecent minibuffer messages (most recent first):\n\n")
841 (print-recent-messages view-lossage-message-count))
844 (define-function 'help 'help-for-help)
846 (make-help-screen help-for-help
847 "A B C F I K L M N P S T V W C-c C-d C-f C-i C-k C-n C-w; ? for more help:"
849 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
851 \\[hyper-apropos] Type a substring; it shows a hypertext list of
852 functions and variables that contain that substring.
853 See also the `apropos' command.
854 \\[command-apropos] Type a substring; it shows a list of commands
855 (interactively callable functions) that contain that substring.
856 \\[describe-bindings] Table of all key bindings.
857 \\[describe-key-briefly] Type a command key sequence;
858 it displays the function name that sequence runs.
859 \\[customize] Customize Emacs options.
860 \\[Info-goto-emacs-command-node] Type a function name; it displays the Info node for that command.
861 \\[describe-function] Type a function name; it shows its documentation.
862 \\[Info-elisp-ref] Type a function name; it jumps to the full documentation
863 in the XEmacs Lisp Programmer's Manual.
864 \\[xemacs-local-faq] Local copy of the XEmacs FAQ.
865 \\[info] Info documentation reader.
866 \\[Info-query] Type an Info file name; it displays it in Info reader.
867 \\[describe-key] Type a command key sequence;
868 it displays the documentation for the command bound to that key.
869 \\[Info-goto-emacs-key-command-node] Type a command key sequence;
870 it displays the Info node for the command bound to that key.
871 \\[view-lossage] Recent input keystrokes and minibuffer messages.
872 \\[describe-mode] Documentation of current major and minor modes.
873 \\[view-emacs-news] News of recent XEmacs changes.
874 \\[finder-by-keyword] Type a topic keyword; it finds matching packages.
875 \\[describe-pointer] Table of all mouse-button bindings.
876 \\[describe-syntax] Contents of syntax table with explanations.
877 \\[help-with-tutorial] XEmacs learn-by-doing tutorial.
878 \\[describe-variable] Type a variable name; it displays its documentation and value.
879 \\[where-is] Type a command name; it displays which keystrokes invoke that command.
880 \\[describe-distribution] XEmacs ordering information.
881 \\[describe-no-warranty] Information on absence of warranty for XEmacs.
882 \\[describe-copying] XEmacs copying permission (General Public License)."
885 (defmacro with-syntax-table (syntab &rest body)
886 "Evaluate BODY with the SYNTAB as the current syntax table."
887 `(let ((stab (syntax-table)))
890 (set-syntax-table (copy-syntax-table ,syntab))
892 (set-syntax-table stab))))
893 (put 'with-syntax-table 'lisp-indent-function 1)
894 (put 'with-syntax-table 'edebug-form-spec '(form body))
896 (defun function-called-at-point ()
897 "Return the function which is called by the list containing point.
898 If that gives no function, return the function whose name is around point.
899 If that doesn't give a function, return nil."
903 (narrow-to-region (max (point-min) (- (point) 1000))
908 (setq obj (read (current-buffer)))
909 (and (symbolp obj) (fboundp obj) obj)))))
911 (with-syntax-table emacs-lisp-mode-syntax-table
913 (or (not (zerop (skip-syntax-backward "_w")))
914 (eq (char-syntax (char-after (point))) ?w)
915 (eq (char-syntax (char-after (point))) ?_)
917 (skip-chars-forward "`'")
918 (let ((obj (read (current-buffer))))
919 (and (symbolp obj) (fboundp obj) obj)))))))
921 (defun function-at-point ()
922 "Return the function whose name is around point.
923 If that gives no function, return the function which is called by the
924 list containing point. If that doesn't give a function, return nil."
926 (with-syntax-table emacs-lisp-mode-syntax-table
928 (or (not (zerop (skip-syntax-backward "_w")))
929 (eq (char-syntax (char-after (point))) ?w)
930 (eq (char-syntax (char-after (point))) ?_)
932 (skip-chars-forward "`'")
933 (let ((obj (read (current-buffer))))
934 (and (symbolp obj) (fboundp obj) obj)))))
938 (narrow-to-region (max (point-min) (- (point) 1000))
943 (setq obj (read (current-buffer)))
944 (and (symbolp obj) (fboundp obj) obj)))))))
946 (defun function-at-event (event)
947 "Return the function whose name is around the position of EVENT.
948 EVENT should be a mouse event. When calling from a popup or context menu,
949 use `last-popup-menu-event' to find out where the mouse was clicked.
950 \(You cannot use (interactive \"e\"), unfortunately. This returns a
953 If the event contains no position, or the position is not over text, or
954 there is no function around that point, nil is returned."
955 (if (and event (event-buffer event) (event-point event))
957 (set-buffer (event-buffer event))
958 (goto-char (event-point event))
959 (function-at-point))))
961 ;; Default to nil for the non-hackers? Not until we find a way to
962 ;; distinguish hackers from non-hackers automatically!
963 (defcustom describe-function-show-arglist t
964 "*If non-nil, describe-function will show its arglist,
965 unless the function is autoloaded."
967 :group 'help-appearance)
969 (defun describe-symbol-find-file (symbol)
970 (loop for (file . load-data) in load-history
971 do (when (memq symbol load-data)
974 (define-obsolete-function-alias
975 'describe-function-find-file
976 'describe-symbol-find-file)
978 (defun describe-function (function)
979 "Display the full documentation of FUNCTION (a symbol).
980 When run interactively, it defaults to any function found by
981 `function-at-point'."
983 (let* ((fn (function-at-point))
984 (val (let ((enable-recursive-minibuffers t))
987 (format (gettext "Describe function (default %s): ")
989 (gettext "Describe function: "))
990 obarray 'fboundp t nil 'function-history
992 (list (intern val))))
993 (with-displaying-help-buffer
995 (describe-function-1 function)
996 ;; Return the text we displayed.
997 (buffer-string nil nil standard-output))
998 (format "function `%s'" function)))
1000 (defun function-obsolete-p (function)
1001 "Return non-nil if FUNCTION is obsolete."
1002 (not (null (get function 'byte-obsolete-info))))
1004 (defun function-obsoleteness-doc (function)
1005 "If FUNCTION is obsolete, return a string describing this."
1006 (let ((obsolete (get function 'byte-obsolete-info)))
1008 (format "Obsolete; %s"
1009 (if (stringp (car obsolete))
1011 (format "use `%s' instead." (car obsolete)))))))
1013 (defun function-compatible-p (function)
1014 "Return non-nil if FUNCTION is present for Emacs compatibility."
1015 (not (null (get function 'byte-compatible-info))))
1017 (defun function-compatibility-doc (function)
1018 "If FUNCTION is Emacs compatible, return a string describing this."
1019 (let ((compatible (get function 'byte-compatible-info)))
1021 (format "Emacs Compatible; %s"
1022 (if (stringp (car compatible))
1024 (format "use `%s' instead." (car compatible)))))))
1026 ;Here are all the possibilities below spelled out, for the benefit
1027 ;of the I18N3 snarfer.
1029 ;(gettext "a built-in function")
1030 ;(gettext "an interactive built-in function")
1031 ;(gettext "a built-in macro")
1032 ;(gettext "an interactive built-in macro")
1033 ;(gettext "a compiled Lisp function")
1034 ;(gettext "an interactive compiled Lisp function")
1035 ;(gettext "a compiled Lisp macro")
1036 ;(gettext "an interactive compiled Lisp macro")
1037 ;(gettext "a Lisp function")
1038 ;(gettext "an interactive Lisp function")
1039 ;(gettext "a Lisp macro")
1040 ;(gettext "an interactive Lisp macro")
1041 ;(gettext "a mocklisp function")
1042 ;(gettext "an interactive mocklisp function")
1043 ;(gettext "a mocklisp macro")
1044 ;(gettext "an interactive mocklisp macro")
1045 ;(gettext "an autoloaded Lisp function")
1046 ;(gettext "an interactive autoloaded Lisp function")
1047 ;(gettext "an autoloaded Lisp macro")
1048 ;(gettext "an interactive autoloaded Lisp macro")
1050 ;; taken out of `describe-function-1'
1051 (defun function-arglist (function)
1052 "Return a string giving the argument list of FUNCTION.
1055 (function-arglist 'function-arglist)
1056 => (function-arglist FUNCTION)
1058 This function is used by `describe-function-1' to list function
1059 arguments in the standard Lisp style."
1060 (let* ((fnc (indirect-function function))
1061 (fndef (if (eq (car-safe fnc) 'macro)
1065 (cond ((compiled-function-p fndef)
1066 (compiled-function-arglist fndef))
1067 ((eq (car-safe fndef) 'lambda)
1070 (let* ((doc (documentation function))
1071 (args (and (string-match
1072 "[\n\t ]*\narguments: ?(\\(.*\\))\n?\\'"
1074 (match-string 1 doc))))
1075 ;; If there are no arguments documented for the
1076 ;; subr, rather don't print anything.
1077 (cond ((null args) t)
1078 ((equal args "") nil)
1081 (cond ((listp arglist)
1083 (cons function (mapcar (lambda (arg)
1084 (if (memq arg '(&optional &rest))
1086 (intern (upcase (symbol-name arg)))))
1090 (format "(%s %s)" function arglist)))))
1092 (defun function-documentation (function &optional strip-arglist)
1093 "Return a string giving the documentation for FUNCTION, if any.
1094 If the optional argument STRIP-ARGLIST is non-nil, remove the arglist
1095 part of the documentation of internal subroutines."
1096 (let ((doc (condition-case nil
1097 (or (documentation function)
1098 (gettext "not documented"))
1099 (void-function ""))))
1100 (if (and strip-arglist
1101 (string-match "[\n\t ]*\narguments: ?(\\(.*\\))\n?\\'" doc))
1102 (setq doc (substring doc 0 (match-beginning 0))))
1104 ; (let ((name-char "[-+a-zA-Z0-9_*]") (sym-char "[-+a-zA-Z0-9_:*]"))
1107 ; ;; The symbol itself.
1108 ; (list (concat "\\`\\(" name-char "+\\)\\(:\\)?")
1109 ; '(1 (if (match-beginning 2)
1110 ; 'font-lock-function-name-face
1111 ; 'font-lock-variable-name-face)
1114 ; ;; Words inside `' which tend to be symbol names.
1115 ; (list (concat "`\\(" sym-char sym-char "+\\)'")
1117 ; 'font-lock-reference-face
1118 ; (add-list-mode-item (match-beginning 1)
1121 ; 'help-follow-reference))
1124 ; ;; CLisp `:' keywords as references.
1125 ; (list (concat "\\<:" sym-char "+\\>") 0 'font-lock-reference-face t)))
1127 (defvar help-symbol-regexp
1128 (let ((sym-char "[+a-zA-Z0-9_:*]")
1129 (sym-char-no-dash "[-+a-zA-Z0-9_:*]"))
1131 ;; a symbol with a - in it.
1132 "\\<\\(" sym-char-no-dash "+\\(-" sym-char-no-dash "+\\)+\\)\\>"
1134 "`\\(" sym-char "+\\)'"
1137 (defun help-symbol-run-function-1 (ev ex fun)
1138 (let ((help-sticky-window
1139 ;; if we were called from a help buffer, make sure the new help
1140 ;; goes in the same window.
1141 (if (and (event-buffer ev)
1142 (symbol-value-in-buffer 'help-window-config
1145 help-sticky-window)))
1146 (funcall fun (extent-property ex 'help-symbol))))
1148 (defun help-symbol-run-function (fun)
1149 (let ((ex (extent-at-event last-popup-menu-event 'help-symbol)))
1151 (help-symbol-run-function-1 last-popup-menu-event ex fun))))
1153 (defvar help-symbol-function-context-menu
1155 ["View %_Documentation" (help-symbol-run-function 'describe-function)]
1156 ["Find %_Function Source" (help-symbol-run-function 'find-function)]
1159 (defvar help-symbol-variable-context-menu
1161 ["View %_Documentation" (help-symbol-run-function 'describe-variable)]
1162 ["Find %_Variable Source" (help-symbol-run-function 'find-variable)]
1165 (defvar help-symbol-function-and-variable-context-menu
1167 ["View Function %_Documentation" (help-symbol-run-function
1168 'describe-function)]
1169 ["View Variable D%_ocumentation" (help-symbol-run-function
1170 'describe-variable)]
1171 ["Find %_Function Source" (help-symbol-run-function 'find-function)]
1172 ["Find %_Variable Source" (help-symbol-run-function 'find-variable)]
1175 (defun frob-help-extents (buffer)
1176 ;; Look through BUFFER, starting at the buffer's point and continuing
1177 ;; till end of file, and find documented functions and variables.
1178 ;; any such symbol found is tagged with an extent, that sets up these
1180 ;; 1. mouse-face is 'highlight (so the extent gets highlighted on mouse over)
1181 ;; 2. help-symbol is the name of the symbol.
1182 ;; 3. context-menu is a list of context menu items, specific to whether
1183 ;; the symbol is a function, variable, or both.
1184 ;; 4. activate-function will cause the function or variable to be described,
1185 ;; replacing the existing help contents.
1189 (while (re-search-forward help-symbol-regexp nil t)
1190 (setq b (or (match-beginning 2) (match-beginning 4)))
1191 (setq e (or (match-end 2) (match-end 4)))
1192 (setq name (buffer-substring b e))
1193 (let* ((sym (intern-soft name))
1194 (var (and sym (boundp sym)
1195 (documentation-property sym
1196 'variable-documentation t)))
1197 (fun (and sym (fboundp sym)
1198 (documentation sym t))))
1200 (let ((ex (make-extent b e)))
1201 (set-extent-property ex 'mouse-face 'highlight)
1202 (set-extent-property ex 'help-symbol sym)
1203 (set-extent-property
1205 (cond ((and var fun)
1206 help-symbol-function-and-variable-context-menu)
1207 (var help-symbol-variable-context-menu)
1208 (fun help-symbol-function-context-menu)))
1209 (set-extent-property
1210 ex 'activate-function
1213 (help-symbol-run-function-1 ev ex 'describe-function))
1215 (help-symbol-run-function-1 ev ex 'describe-variable))))
1216 ))))))) ;; 11 parentheses!
1218 (defun describe-function-1 (function &optional nodoc)
1219 "This function does the work for `describe-function'."
1220 (princ (format "`%s' is " function))
1221 (let* ((def function)
1222 aliases file-name autoload-file kbd-macro-p fndef macrop)
1223 (while (and (symbolp def) (fboundp def))
1224 (when (not (eq def function))
1227 ;; I18N3 Need gettext due to concat
1230 "\n which is an alias for `%s', "
1232 (format "an alias for `%s', " (symbol-name def)))))
1233 (setq def (symbol-function def)))
1234 (if (and (fboundp 'compiled-function-annotation)
1235 (compiled-function-p def))
1236 (setq file-name (compiled-function-annotation def)))
1237 (if (eq 'macro (car-safe def))
1238 (setq fndef (cdr def)
1239 file-name (and (compiled-function-p (cdr def))
1240 (fboundp 'compiled-function-annotation)
1241 (compiled-function-annotation (cdr def)))
1244 (if aliases (princ aliases))
1245 (let ((int #'(lambda (string an-p macro-p)
1248 (cond ((commandp def)
1253 (if macro-p " macro" " function")))
1255 (cond ((or (stringp def) (vectorp def))
1256 (princ "a keyboard macro.")
1257 (setq kbd-macro-p t))
1259 (funcall int "built-in" nil macrop))
1260 ((compiled-function-p fndef)
1261 (funcall int "compiled Lisp" nil macrop))
1262 ((eq (car-safe fndef) 'lambda)
1263 (funcall int "Lisp" nil macrop))
1264 ((eq (car-safe fndef) 'mocklisp)
1265 (funcall int "mocklisp" nil macrop))
1266 ((eq (car-safe def) 'autoload)
1267 (setq autoload-file (elt def 1))
1268 (funcall int "autoloaded Lisp" t (elt def 4)))
1269 ((and (symbolp def) (not (fboundp def)))
1270 (princ "a symbol with a void (unbound) function definition."))
1275 (princ (format " -- autoloads from \"%s\"\n" autoload-file)))
1277 (setq file-name (describe-symbol-find-file function)))
1279 (princ (format " -- loaded from \"%s\"\n" file-name)))
1281 (if describe-function-show-arglist
1282 (let ((arglist (function-arglist function)))
1288 (princ "These characters are executed:\n\n\t")
1289 (princ (key-description def))
1290 (cond ((setq def (key-binding def))
1291 (princ (format "\n\nwhich executes the command `%s'.\n\n"
1293 (describe-function-1 def))))
1296 ;; tell the user about obsoleteness.
1297 ;; If the function is obsolete and is aliased, don't
1298 ;; even bother to report the documentation, as a further
1299 ;; encouragement to use the new function.
1300 (let ((obsolete (function-obsoleteness-doc function))
1301 (compatible (function-compatibility-doc function)))
1310 (unless (and obsolete aliases)
1311 (let ((doc (function-documentation function t)))
1312 (princ "Documentation:\n")
1313 (let ((oldp (point standard-output))
1316 (setq newp (point standard-output))
1317 (goto-char oldp standard-output)
1318 (frob-help-extents standard-output)
1319 (goto-char newp standard-output))
1320 (unless (or (equal doc "")
1321 (eq ?\n (aref doc (1- (length doc)))))
1325 ;;; [Obnoxious, whining people who complain very LOUDLY on Usenet
1326 ;;; are binding this to keys.]
1327 (defun describe-function-arglist (function)
1328 (interactive (list (or (function-at-point)
1329 (error "no function call at point"))))
1331 (message (function-arglist function)))
1333 (defun variable-at-point ()
1335 (with-syntax-table emacs-lisp-mode-syntax-table
1337 (or (not (zerop (skip-syntax-backward "_w")))
1338 (eq (char-syntax (char-after (point))) ?w)
1339 (eq (char-syntax (char-after (point))) ?_)
1341 (skip-chars-forward "'")
1342 (let ((obj (read (current-buffer))))
1343 (and (symbolp obj) (boundp obj) obj))))))
1345 (defun variable-at-event (event)
1346 "Return the variable whose name is around the position of EVENT.
1347 EVENT should be a mouse event. When calling from a popup or context menu,
1348 use `last-popup-menu-event' to find out where the mouse was clicked.
1349 \(You cannot use (interactive \"e\"), unfortunately. This returns a
1352 If the event contains no position, or the position is not over text, or
1353 there is no variable around that point, nil is returned."
1354 (if (and event (event-buffer event) (event-point event))
1356 (set-buffer (event-buffer event))
1357 (goto-char (event-point event))
1358 (variable-at-point))))
1360 (defun variable-obsolete-p (variable)
1361 "Return non-nil if VARIABLE is obsolete."
1362 (not (null (get variable 'byte-obsolete-variable))))
1364 (defun variable-obsoleteness-doc (variable)
1365 "If VARIABLE is obsolete, return a string describing this."
1366 (let ((obsolete (get variable 'byte-obsolete-variable)))
1368 (format "Obsolete; %s"
1369 (if (stringp obsolete)
1371 (format "use `%s' instead." obsolete))))))
1373 (defun variable-compatible-p (variable)
1374 "Return non-nil if VARIABLE is Emacs compatible."
1375 (not (null (get variable 'byte-compatible-variable))))
1377 (defun variable-compatibility-doc (variable)
1378 "If VARIABLE is Emacs compatible, return a string describing this."
1379 (let ((compatible (get variable 'byte-compatible-variable)))
1381 (format "Emacs Compatible; %s"
1382 (if (stringp compatible)
1384 (format "use `%s' instead." compatible))))))
1386 (defun built-in-variable-doc (variable)
1387 "Return a string describing whether VARIABLE is built-in."
1388 (let ((type (built-in-variable-type variable)))
1390 (integer "a built-in integer variable")
1391 (const-integer "a built-in constant integer variable")
1392 (boolean "a built-in boolean variable")
1393 (const-boolean "a built-in constant boolean variable")
1394 (object "a simple built-in variable")
1395 (const-object "a simple built-in constant variable")
1396 (const-specifier "a built-in constant specifier variable")
1397 (current-buffer "a built-in buffer-local variable")
1398 (const-current-buffer "a built-in constant buffer-local variable")
1399 (default-buffer "a built-in default buffer-local variable")
1400 (selected-console "a built-in console-local variable")
1401 (const-selected-console "a built-in constant console-local variable")
1402 (default-console "a built-in default console-local variable")
1404 (if type "an unknown type of built-in variable?"
1405 "a variable declared in Lisp")))))
1407 (defun describe-variable (variable)
1408 "Display the full documentation of VARIABLE (a symbol)."
1410 (let* ((v (variable-at-point))
1411 (val (let ((enable-recursive-minibuffers t))
1414 (format "Describe variable (default %s): " v)
1415 (gettext "Describe variable: "))
1416 obarray 'boundp t nil 'variable-history
1418 (list (intern val))))
1419 (with-displaying-help-buffer
1421 (let ((origvar variable)
1423 (let ((print-escape-newlines t))
1424 (princ (format "`%s' is " (symbol-name variable)))
1425 (while (variable-alias variable)
1426 (let ((newvar (variable-alias variable)))
1428 ;; I18N3 Need gettext due to concat
1431 (format "\n which is an alias for `%s',"
1432 (symbol-name newvar))))
1434 (format "an alias for `%s',"
1435 (symbol-name newvar))))
1436 (setq variable newvar)))
1438 (princ (format "%s" aliases)))
1439 (princ (built-in-variable-doc variable))
1441 (let ((file-name (describe-symbol-find-file variable)))
1443 (princ (format " -- loaded from \"%s\"\n" file-name))))
1445 (if (not (boundp variable))
1447 (prin1 (symbol-value variable))
1450 (cond ((local-variable-p variable (current-buffer))
1451 (let* ((void (cons nil nil))
1452 (def (condition-case nil
1453 (default-value variable)
1455 (princ "This value is specific to the current buffer.\n")
1456 (if (local-variable-p variable nil)
1457 (princ "(Its value is local to each buffer.)\n"))
1459 (if (if (eq def void)
1461 (not (eq (symbol-value variable) def)))
1462 ;; #### I18N3 doesn't localize properly!
1463 (progn (princ "Default-value: ")
1469 ((local-variable-p variable (current-buffer) t)
1470 (princ "Setting it would make its value buffer-local.\n\n"))))
1471 (princ "Documentation:")
1473 (let ((doc (documentation-property variable 'variable-documentation))
1474 (obsolete (variable-obsoleteness-doc origvar))
1475 (compatible (variable-compatibility-doc origvar)))
1484 ;; don't bother to print anything if variable is obsolete and aliased.
1485 (when (or (not obsolete) (not aliases))
1487 ;; note: documentation-property calls substitute-command-keys.
1488 (let ((oldp (point standard-output))
1491 (setq newp (point standard-output))
1492 (goto-char oldp standard-output)
1493 (frob-help-extents standard-output)
1494 (goto-char newp standard-output))
1495 (princ "not documented as a variable."))))
1497 (format "variable `%s'" variable)))
1499 (defun sorted-key-descriptions (keys &optional separator)
1500 "Sort and separate the key descriptions for KEYS.
1501 The sorting is done by length (shortest bindings first), and the bindings
1502 are separated with SEPARATOR (\", \" by default)."
1503 (mapconcat 'key-description
1504 (sort keys #'(lambda (x y)
1505 (< (length x) (length y))))
1506 (or separator ", ")))
1508 (defun where-is (definition &optional insert)
1509 "Print message listing key sequences that invoke specified command.
1510 Argument is a command definition, usually a symbol with a function definition.
1511 When run interactively, it defaults to any function found by
1512 `function-at-point'.
1513 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
1515 (let ((fn (function-at-point))
1516 (enable-recursive-minibuffers t)
1518 (setq val (read-command
1519 (if fn (format "Where is command (default %s): " fn)
1520 "Where is command: ")
1521 (and fn (symbol-name fn))))
1522 (list (if (equal (symbol-name val) "")
1524 current-prefix-arg)))
1525 (let ((keys (where-is-internal definition)))
1528 (princ (format "%s (%s)" (sorted-key-descriptions keys)
1529 definition) (current-buffer))
1530 (message "%s is on %s" definition (sorted-key-descriptions keys)))
1532 (princ (format (if (commandp definition) "M-x %s RET"
1533 "M-: (%s ...)") definition) (current-buffer))
1534 (message "%s is not on any keys" definition))))
1537 ;; `locate-library' moved to "packages.el"
1540 ;; Functions ported from C into Lisp in XEmacs
1542 (defun describe-syntax ()
1543 "Describe the syntax specifications in the syntax table.
1544 The descriptions are inserted in a buffer, which is then displayed."
1546 (with-displaying-help-buffer
1548 ;; defined in syntax.el
1549 (describe-syntax-table (syntax-table) standard-output))
1550 (format "syntax-table for %s" major-mode)))
1552 (defun list-processes ()
1553 "Display a list of all processes.
1554 \(Any processes listed as Exited or Signaled are actually eliminated
1555 after the listing is made.)"
1557 (with-output-to-temp-buffer "*Process List*"
1558 (set-buffer standard-output)
1559 (buffer-disable-undo standard-output)
1560 (make-local-variable 'truncate-lines)
1561 (setq truncate-lines t)
1562 ;; 00000000001111111111222222222233333333334444444444
1563 ;; 01234567890123456789012345678901234567890123456789
1564 ;; rewritten for I18N3. This one should stay rewritten
1565 ;; so that the dashes will line up properly.
1566 (princ "Proc Status Buffer Tty Command\n---- ------ ------ --- -------\n")
1567 (let ((tail (process-list)))
1569 (let* ((p (car tail))
1570 (pid (process-id p))
1571 (s (process-status p)))
1572 (setq tail (cdr tail))
1573 (princ (format "%-13s" (process-name p)))
1575 (if (and (eq s 'exit) (/= (process-exit-status p) 0))
1576 (princ (format " %d" (process-exit-status p))))
1577 (if (memq s '(signal exit closed))
1578 ;; Do delete-exited-processes' work
1580 (indent-to 22 1) ;####
1581 (let ((b (process-buffer p)))
1584 ((not (buffer-name b))
1587 (princ (buffer-name b)))))
1588 (indent-to 37 1) ;####
1589 (let ((tn (process-tty-name p)))
1593 (princ (format "%s" tn)))))
1594 (indent-to 49 1) ;####
1595 (if (not (integerp pid))
1597 (princ "network stream connection ")
1601 (let ((cmd (process-command p)))
1604 (setq cmd (cdr cmd))
1605 (if cmd (princ " ")))))
1608 ;; Stop gap for 21.0 until we do help-char etc properly.
1609 (defun help-keymap-with-help-key (keymap form)
1610 "Return a copy of KEYMAP with an help-key binding according to help-char
1611 invoking FORM like help-form. An existing binding is not overridden.
1612 If FORM is nil then no binding is made."
1613 (let ((map (copy-keymap keymap))
1614 (key (if (characterp help-char)
1615 (vector (character-to-event help-char))
1617 (when (and form key (not (lookup-key map key)))
1619 `(lambda () (interactive) (help-print-help-form ,form))))
1622 (defun help-print-help-form (form)
1623 (let ((string (eval form)))
1624 (if (stringp string)
1625 (with-displaying-help-buffer
1628 ;;; help.el ends here