1 ;;; help.el --- help commands for XEmacs.
3 ;; Copyright (C) 1985, 1986, 1992-4, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 2001 Ben Wing.
7 ;; Keywords: help, internal, dumped
9 ;; This file is part of XEmacs.
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Synched up with: FSF 19.30.
30 ;; This file is dumped with XEmacs.
32 ;; This code implements XEmacs's on-line help system, the one invoked by
33 ;;`M-x help-for-help'.
35 ;; 06/11/1997 -- Converted to use char-after instead of broken
36 ;; following-char. -slb
40 ;; Get the macro make-help-screen when this is compiled,
41 ;; or run interpreted, but not when the compiled code is loaded.
42 (eval-when-compile (require 'help-macro))
45 "Support for on-line help systems."
48 (defgroup help-appearance nil
49 "Appearance of help buffers."
52 (defvar help-map (let ((map (make-sparse-keymap)))
53 (set-keymap-name map 'help-map)
55 map (gettext "(Type ? for further options)"))
57 "Keymap for characters following the Help key.")
59 ;; global-map definitions moved to keydefs.el
60 (fset 'help-command help-map)
62 (define-key help-map (vector help-char) 'help-for-help)
63 (define-key help-map "?" 'help-for-help)
64 (define-key help-map 'help 'help-for-help)
65 (define-key help-map '(f1) 'help-for-help)
67 (define-key help-map "\C-l" 'describe-copying) ; on \C-c in FSFmacs
68 (define-key help-map "\C-d" 'describe-distribution)
69 (define-key help-map "\C-w" 'describe-no-warranty)
70 (define-key help-map "a" 'hyper-apropos) ; 'command-apropos in FSFmacs
71 (define-key help-map "A" 'command-apropos)
73 (define-key help-map "b" 'describe-bindings)
74 (define-key help-map "B" 'describe-beta)
75 (define-key help-map "\C-p" 'describe-pointer)
77 (define-key help-map "C" 'customize)
78 (define-key help-map "c" 'describe-key-briefly)
79 (define-key help-map "k" 'describe-key)
81 (define-key help-map "d" 'describe-function)
82 (define-key help-map "e" 'describe-last-error)
83 (define-key help-map "f" 'describe-function)
85 (define-key help-map "F" 'xemacs-local-faq)
87 (define-key help-map "i" 'info)
88 (define-key help-map '(control i) 'Info-query)
89 ;; FSFmacs has Info-goto-emacs-command-node on C-f, no binding
91 (define-key help-map '(control c) 'Info-goto-emacs-command-node)
92 (define-key help-map '(control k) 'Info-goto-emacs-key-command-node)
93 (define-key help-map '(control f) 'Info-elisp-ref)
95 (define-key help-map "l" 'view-lossage)
97 (define-key help-map "m" 'describe-mode)
99 (define-key help-map "\C-n" 'view-emacs-news)
100 (define-key help-map "n" 'view-emacs-news)
102 (define-key help-map "p" 'finder-by-keyword)
104 ;; Do this right with an autoload cookie in finder.el.
105 ;;(autoload 'finder-by-keyword "finder"
106 ;; "Find packages matching a given keyword." t)
108 (define-key help-map "s" 'describe-syntax)
110 (define-key help-map "t" 'help-with-tutorial)
112 (define-key help-map "w" 'where-is)
114 (define-key help-map "v" 'describe-variable)
116 (if (fboundp 'view-last-error)
117 (define-key help-map "e" 'view-last-error))
120 (define-key help-map "q" 'help-quit)
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:
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
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.
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))
153 ;(defvar help-font-lock-keywords
154 ; (let ((name-char "[-+a-zA-Z0-9_*]") (sym-char "[-+a-zA-Z0-9_:*]"))
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)
164 ; ;; Words inside `' which tend to be symbol names.
165 ; (list (concat "`\\(" sym-char sym-char "+\\)'")
167 ; 'font-lock-reference-face
168 ; (add-list-mode-item (match-beginning 1)
171 ; 'help-follow-reference))
174 ; ;; CLisp `:' keywords as references.
175 ; (list (concat "\\<:" sym-char "+\\>") 0 'font-lock-reference-face t)))
176 ; "Default expressions to highlight in Help mode.")
178 ;(put 'help-mode 'font-lock-defaults '(help-font-lock-keywords))
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'.
187 (define-key help-mode-map "q" 'help-mode-quit)
188 (define-key help-mode-map "Q" 'help-mode-bury)
189 (define-key help-mode-map "f" 'find-function-at-point)
190 (define-key help-mode-map "d" 'describe-function-at-point)
191 (define-key help-mode-map "v" 'describe-variable-at-point)
192 (define-key help-mode-map "i" 'Info-elisp-ref)
193 (define-key help-mode-map "c" 'customize-variable)
194 (define-key help-mode-map [tab] 'help-next-symbol)
195 (define-key help-mode-map [(shift tab)] 'help-prev-symbol)
196 (define-key help-mode-map "n" 'help-next-section)
197 (define-key help-mode-map "p" 'help-prev-section)
199 (defun describe-function-at-point ()
200 "Describe directly the function at point in the other window."
202 (let ((symb (function-at-point)))
204 (describe-function symb))))
206 (defun describe-variable-at-point ()
207 "Describe directly the variable at point in the other window."
209 (let ((symb (variable-at-point)))
211 (describe-variable symb))))
213 (defun help-next-symbol ()
214 "Move point to the next quoted symbol."
216 (search-forward "`" nil t))
218 (defun help-prev-symbol ()
219 "Move point to the previous quoted symbol."
221 (search-backward "'" nil t))
223 (defun help-next-section ()
224 "Move point to the next quoted symbol."
226 (search-forward-regexp "^\\w+:" nil t))
228 (defun help-prev-section ()
229 "Move point to the previous quoted symbol."
231 (search-backward-regexp "^\\w+:" nil t))
233 (defun help-mode-bury ()
234 "Bury the help buffer, possibly restoring the previous window configuration."
238 (defun help-mode-quit (&optional bury)
239 "Exit from help mode, possibly restoring the previous window configuration.
240 If the optional argument BURY is non-nil, the help buffer is buried,
241 otherwise it is killed."
243 (let ((buf (current-buffer)))
244 (cond (help-window-config
245 (set-window-configuration help-window-config))
246 ((not (one-window-p))
256 ;; This is a grody hack of the same genotype as `advertised-undo'; if the
257 ;; bindings of Backspace and C-h are the same, we want the menubar to claim
258 ;; that `info' is invoked with `C-h i', not `BS i'.
260 (defun deprecated-help-command ()
262 (if (eq 'help-command (key-binding "\C-h"))
263 (setq unread-command-event (character-to-event ?\C-h))
266 ;;(define-key global-map 'backspace 'deprecated-help-command)
268 ;; help-with-tutorial moved to help-nomule.el and mule-help.el.
270 ;; used by describe-key, describe-key-briefly, insert-key-binding, etc.
271 (defun key-or-menu-binding (key &optional menu-flag)
272 "Return the command invoked by KEY.
273 Like `key-binding', but handles menu events and toolbar presses correctly.
274 KEY is any value returned by `next-command-event'.
275 MENU-FLAG is a symbol that should be set to t if KEY is a menu event,
278 (and menu-flag (set menu-flag nil))
279 ;; If the key typed was really a menu selection, grab the form out
280 ;; of the event object and intuit the function that would be called,
281 ;; and describe that instead.
282 (if (and (vectorp key) (= 1 (length key))
283 (or (misc-user-event-p (aref key 0))
284 (eq (car-safe (aref key 0)) 'menu-selection)))
285 (let ((event (aref key 0)))
286 (setq defn (if (eventp event)
287 (list (event-function event) (event-object event))
289 (and menu-flag (set menu-flag t))
290 (when (eq (car defn) 'eval)
291 (setq defn (car (cdr defn))))
292 (when (eq (car-safe defn) 'call-interactively)
293 (setq defn (car (cdr defn))))
294 (when (and (consp defn) (null (cdr defn)))
295 (setq defn (car defn))))
297 (setq defn (key-binding key)))
298 ;; kludge: if a toolbar button was pressed on, try to find the
299 ;; binding of the toolbar button.
300 (if (and (eq defn 'press-toolbar-button)
302 (button-press-event-p (aref key (1- (length key)))))
303 ;; wait for the button release. We're on shaky ground here ...
304 (let ((event (next-command-event))
306 (if (and (button-release-event-p event)
307 (event-over-toolbar-p event)
308 (eq 'release-and-activate-toolbar-button
309 (key-binding (vector event)))
310 (setq button (event-toolbar-button event)))
311 (toolbar-button-callback button)
312 ;; if anything went wrong, try returning the binding of
313 ;; the button-up event, of the original binding
314 (or (key-or-menu-binding (vector event))
320 (defun describe-key-briefly (key &optional insert)
321 "Print the name of the function KEY invokes. KEY is a string.
322 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
323 (interactive "kDescribe key briefly: \nP")
324 (let ((standard-output (if insert (current-buffer) t))
326 (setq defn (key-or-menu-binding key 'menup))
327 (if (or (null defn) (integerp defn))
328 (princ (format "%s is undefined" (key-description key)))
329 ;; If it's a keyboard macro which trivially invokes another command,
330 ;; document that instead.
331 (if (or (stringp defn) (vectorp defn))
332 (setq defn (or (key-binding defn)
334 (let ((last-event (and (vectorp key)
335 (aref key (1- (length key))))))
336 (princ (format (cond (insert
338 ((or (button-press-event-p last-event)
339 (button-release-event-p last-event))
340 (gettext "%s at that spot runs the command %s"))
342 (gettext "%s runs the command %s")))
343 ;; This used to say 'This menu item' but it
344 ;; could also be a scrollbar event. We can't
345 ;; distinguish at the moment.
347 (if insert "item" "This item")
348 (key-description key))
349 (if (symbolp defn) defn (prin1-to-string defn))))))))
351 ;; #### this is a horrible piece of shit function that should
352 ;; not exist. In FSF 19.30 this function has gotten three times
353 ;; as long and has tons and tons of dumb shit checking
354 ;; special-display-buffer-names and such crap. I absolutely
355 ;; refuse to insert that Ebolification here. I wanted to delete
356 ;; this function entirely but Mly bitched.
358 ;; If your user-land code calls this function, rewrite it to
359 ;; call with-displaying-help-buffer.
361 (defun print-help-return-message (&optional function)
362 "Display or return message saying how to restore windows after help command.
363 Computes a message and applies the optional argument FUNCTION to it.
364 If FUNCTION is nil, applies `message' to it, thus printing it."
365 (and (not (get-buffer-window standard-output))
367 (or function 'message)
369 (substitute-command-keys
372 (gettext "Type \\[delete-other-windows] to remove help window.")
373 (gettext "Type \\[switch-to-buffer] RET to remove help window."))
374 (gettext "Type \\[switch-to-buffer-other-window] RET to restore the other window.")))
375 (substitute-command-keys
376 (gettext " \\[scroll-other-window] to scroll the help."))))))
378 (defcustom help-selects-help-window t
379 "*If nil, use the \"old Emacs\" behavior for Help buffers.
380 This just displays the buffer in another window, rather than selecting
383 :group 'help-appearance)
385 (defcustom help-max-help-buffers 10
386 "*Maximum help buffers to allow before they start getting killed.
387 If this is a positive integer, before a help buffer is displayed
388 by `with-displaying-help-buffer', any excess help buffers which
389 are not being displayed are first killed. Otherwise, if it is
390 zero or nil, only one help buffer, \"*Help*\" is ever used."
391 :type '(choice integer (const :tag "None" nil))
392 :group 'help-appearance)
394 (defvar help-buffer-list nil
395 "List of help buffers used by `help-register-and-maybe-prune-excess'")
397 (defun help-register-and-maybe-prune-excess (newbuf)
398 "Register use of a help buffer and possibly kill any excess ones."
399 ;; remove new buffer from list
400 (setq help-buffer-list (remove newbuf help-buffer-list))
401 ;; maybe kill excess help buffers
402 (if (and (integerp help-max-help-buffers)
403 (> (length help-buffer-list) help-max-help-buffers))
404 (let ((keep-list nil)
405 (num-kill (- (length help-buffer-list)
406 help-max-help-buffers)))
407 (while help-buffer-list
408 (let ((buf (car help-buffer-list)))
409 (if (and (or (equal buf newbuf) (get-buffer buf))
410 (string-match "^*Help" buf)
411 (save-excursion (set-buffer buf)
412 (eq major-mode 'help-mode)))
413 (if (and (>= num-kill (length help-buffer-list))
414 (not (get-buffer-window buf t t)))
416 (setq keep-list (cons buf keep-list)))))
417 (setq help-buffer-list (cdr help-buffer-list)))
418 (setq help-buffer-list (nreverse keep-list))))
420 (setq help-buffer-list (cons newbuf help-buffer-list)))
422 (defvar help-buffer-prefix-string "Help"
423 "Initial string to use in constructing help buffer names.
424 You should never set this directory, only let-bind it.")
426 (defun help-buffer-name (name)
427 "Return a name for a Help buffer using string NAME for context."
428 (if (and (integerp help-max-help-buffers)
429 (> help-max-help-buffers 0)
431 (if help-buffer-prefix-string
432 (format "*%s: %s*" help-buffer-prefix-string name)
433 (format "*%s*" name))
434 (format "*%s*" help-buffer-prefix-string)))
436 ;; with-displaying-help-buffer
438 ;; #### Should really be a macro to eliminate the requirement of
439 ;; caller to code a lambda form in THUNK -- mrb
441 ;; #### BEFORE you rush to make this a macro, think about backward
442 ;; compatibility. The right way would be to create a macro with
443 ;; another name (which is a shame, because w-d-h-b is a perfect name
444 ;; for a macro) that uses with-displaying-help-buffer internally.
446 (defcustom mode-for-help 'help-mode
447 "*Mode that help buffers are put into.")
449 (defvar help-sticky-window nil
450 ;; Window into which help buffers will be displayed, rather than
451 ;; always searching for a new one. This is INTERNAL and liable to
452 ;; change its interface and/or name at any moment. It should be
456 (defvar help-window-config nil)
458 (make-variable-buffer-local 'help-window-config)
459 (put 'help-window-config 'permanent-local t)
461 (defun with-displaying-help-buffer (thunk &optional name)
462 "Form which makes a help buffer with given NAME and evaluates BODY there.
463 The actual name of the buffer is generated by the function `help-buffer-name'.
465 Use this function for displaying help when C-h something is pressed or
466 in similar situations. Do *not* use it when you are displaying a help
467 message and then prompting for input in the minibuffer -- this macro
468 usually selects the help buffer, which is not what you want in those
470 (let* ((winconfig (current-window-configuration))
471 (was-one-window (one-window-p))
472 (buffer-name (help-buffer-name name))
474 (not (and (windows-of-buffer buffer-name) ;shortcut
475 (memq (selected-frame)
476 (mapcar 'window-frame
477 (windows-of-buffer buffer-name)))))))
478 (help-register-and-maybe-prune-excess buffer-name)
479 ;; if help-sticky-window is bogus or deleted, get rid of it.
480 (if (and help-sticky-window (or (not (windowp help-sticky-window))
481 (not (window-live-p help-sticky-window))))
482 (setq help-sticky-window nil))
484 (let ((temp-buffer-show-function
485 (if help-sticky-window
487 (set-window-buffer help-sticky-window buffer))
488 temp-buffer-show-function)))
489 (with-output-to-temp-buffer buffer-name
490 (prog1 (funcall thunk)
492 (set-buffer standard-output)
493 (funcall mode-for-help)))))
494 (let ((helpwin (get-buffer-window buffer-name)))
496 ;; If the *Help* buffer is already displayed on this
497 ;; frame, don't override the previous configuration
498 (when help-not-visible
499 (with-current-buffer (window-buffer helpwin)
500 (setq help-window-config winconfig)))
501 (when help-selects-help-window
502 (select-window helpwin))
503 (cond ((eq helpwin (selected-window))
504 (display-message 'command
505 (substitute-command-keys "Type \\[help-mode-quit] to remove help window, \\[scroll-up] to scroll the help.")))
507 (display-message 'command
508 (substitute-command-keys "Type \\[delete-other-windows] to remove help window, \\[scroll-other-window] to scroll the help.")))
510 (display-message 'command
511 (substitute-command-keys "Type \\[switch-to-buffer-other-window] to restore the other window, \\[scroll-other-window] to scroll the help.")))))))))
513 (defun describe-key (key)
514 "Display documentation of the function invoked by KEY.
515 KEY is a string, or vector of events.
516 When called interactively, KEY may also be a menu selection."
517 (interactive "kDescribe key: ")
518 (let ((defn (key-or-menu-binding key))
519 (key-string (key-description key)))
520 (if (or (null defn) (integerp defn))
521 (message "%s is undefined" key-string)
522 (with-displaying-help-buffer
527 (princ (format "`%s'" defn))
530 (cond ((or (stringp defn) (vectorp defn))
531 (let ((cmd (key-binding defn)))
533 (princ "a keyboard macro")
535 (princ "a keyboard macro which runs the command ")
538 (if (documentation cmd) (princ (documentation cmd)))))))
539 ((and (consp defn) (not (eq 'lambda (car-safe defn))))
540 (let ((describe-function-show-arglist nil))
541 (describe-function-1 (car defn))))
543 (describe-function-1 defn))
544 ((documentation defn)
545 (princ (documentation defn)))
547 (princ "not documented"))))
548 (format "key `%s'" key-string)))))
550 (defun describe-mode ()
551 "Display documentation of current major mode and minor modes.
552 For this to work correctly for a minor mode, the mode's indicator variable
553 \(listed in `minor-mode-alist') must also be a function whose documentation
554 describes the minor mode."
556 (with-displaying-help-buffer
558 ;; XEmacs change: print the major-mode documentation before
562 (princ (documentation major-mode))
563 (princ "\n\n----\n\n")
564 (let ((minor-modes minor-mode-alist))
566 (let* ((minor-mode (car (car minor-modes)))
567 (indicator (car (cdr (car minor-modes)))))
568 ;; Document a minor mode if it is listed in minor-mode-alist,
569 ;; bound locally in this buffer, non-nil, and has a function
571 (if (and (boundp minor-mode)
572 (symbol-value minor-mode)
573 (fboundp minor-mode))
574 (let ((pretty-minor-mode minor-mode))
575 (if (string-match "-mode\\'" (symbol-name minor-mode))
576 (setq pretty-minor-mode
578 (substring (symbol-name minor-mode)
579 0 (match-beginning 0)))))
580 (while (and (consp indicator) (extentp (car indicator)))
581 (setq indicator (cdr indicator)))
582 (while (and indicator (symbolp indicator))
583 (setq indicator (symbol-value indicator)))
584 (princ (format "%s minor mode (%s):\n"
587 (format "indicator%s" indicator)
589 (princ (documentation minor-mode))
590 (princ "\n\n----\n\n"))))
591 (setq minor-modes (cdr minor-modes)))))
592 (format "%s mode" mode-name)))
594 ;; So keyboard macro definitions are documented correctly
595 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro))
597 ;; view a read-only file intelligently
598 (defun Help-find-file (file)
599 (if (fboundp 'view-file)
601 (find-file-read-only file)
602 (goto-char (point-min))))
604 (defun describe-distribution ()
605 "Display info on how to obtain the latest version of XEmacs."
607 (Help-find-file (locate-data-file "DISTRIB")))
609 (defun describe-beta ()
610 "Display info on how to deal with Beta versions of XEmacs."
612 (Help-find-file (locate-data-file "BETA")))
614 (defun describe-copying ()
615 "Display info on how you may redistribute copies of XEmacs."
617 (Help-find-file (locate-data-file "COPYING")))
619 (defun describe-pointer ()
620 "Show a list of all defined mouse buttons, and their definitions."
622 (describe-bindings nil t))
624 (defun describe-project ()
625 "Display info on the GNU project."
627 (Help-find-file (locate-data-file "GNU")))
629 (defun describe-no-warranty ()
630 "Display info on all the kinds of warranty XEmacs does NOT have."
633 (let (case-fold-search)
634 (search-forward "NO WARRANTY")
637 (defun describe-bindings (&optional prefix mouse-only-p)
638 "Show a list of all defined keys, and their definitions.
639 The list is put in a buffer, which is displayed.
640 If optional first argument PREFIX is supplied, only commands
641 which start with that sequence of keys are described.
642 If optional second argument MOUSE-ONLY-P (prefix arg, interactively)
643 is non-nil then only the mouse bindings are displayed."
644 (interactive (list nil current-prefix-arg))
645 (with-displaying-help-buffer
647 (describe-bindings-1 prefix mouse-only-p))
648 (format "bindings for %s" major-mode)))
650 (defun describe-bindings-1 (&optional prefix mouse-only-p)
651 (let ((heading (if mouse-only-p
652 (gettext "button binding\n------ -------\n")
653 (gettext "key binding\n--- -------\n")))
654 (buffer (current-buffer))
655 (minor minor-mode-map-alist)
656 (extent-maps (mapcar-extents
658 nil (current-buffer) (point) (point) nil 'keymap))
659 (local (current-local-map))
661 (set-buffer standard-output)
663 (insert "Bindings for Text Region:\n"
665 (describe-bindings-internal
666 (car extent-maps) nil shadow prefix mouse-only-p)
668 (setq shadow (cons (car extent-maps) shadow)
669 extent-maps (cdr extent-maps)))
671 (let ((sym (car (car minor)))
672 (map (cdr (car minor))))
673 (if (symbol-value-in-buffer sym buffer nil)
675 (insert (format "Minor Mode Bindings for `%s':\n"
678 (describe-bindings-internal map nil shadow prefix mouse-only-p)
680 (setq shadow (cons map shadow))))
681 (setq minor (cdr minor))))
684 (insert "Local Bindings:\n" heading)
685 (describe-bindings-internal local nil shadow prefix mouse-only-p)
687 (setq shadow (cons local shadow))))
688 (insert "Global Bindings:\n" heading)
689 (describe-bindings-internal (current-global-map)
690 nil shadow prefix mouse-only-p)
691 (when (and prefix function-key-map (not mouse-only-p))
692 (insert "\nFunction key map translations:\n" heading)
693 (describe-bindings-internal function-key-map nil nil
694 prefix mouse-only-p))
698 (defun describe-prefix-bindings ()
699 "Describe the bindings of the prefix used to reach this command.
700 The prefix described consists of all but the last event
701 of the key sequence that ran this command."
703 (let* ((key (this-command-keys))
704 (prefix (make-vector (1- (length key)) nil))
707 (while (< i (length prefix))
708 (aset prefix i (aref key i))
710 (with-displaying-help-buffer
712 (princ "Key bindings starting with ")
713 (princ (key-description prefix))
715 (describe-bindings-1 prefix nil))
716 (format "%s prefix" (key-description prefix)))))
718 ;; Make C-h after a prefix, when not specifically bound,
719 ;; run describe-prefix-bindings.
720 (setq prefix-help-command 'describe-prefix-bindings)
722 (defun describe-installation ()
723 "Display a buffer showing information about this XEmacs was compiled."
725 (if (and (boundp 'Installation-string)
726 (stringp Installation-string))
727 (with-displaying-help-buffer
730 (if (fboundp 'decode-coding-string)
731 (decode-coding-string Installation-string 'automatic-conversion)
732 Installation-string)))
734 (error "No Installation information available.")))
736 (defun view-emacs-news ()
737 "Display info on recent changes to XEmacs."
739 (Help-find-file (locate-data-file "NEWS")))
741 (defun xemacs-www-page ()
742 "Go to the XEmacs World Wide Web page."
744 (if (fboundp 'browse-url)
745 (browse-url "http://www.xemacs.org/")
746 (error "xemacs-www-page requires browse-url")))
748 (defun xemacs-www-faq ()
749 "View the latest and greatest XEmacs FAQ using the World Wide Web."
751 (if (fboundp 'browse-url)
752 (browse-url "http://www.xemacs.org/faq/index.html")
753 (error "xemacs-www-faq requires browse-url")))
755 (defun xemacs-local-faq ()
756 "View the local copy of the XEmacs FAQ.
757 If you have access to the World Wide Web, you should use `xemacs-www-faq'
758 instead, to ensure that you get the most up-to-date information."
760 (save-window-excursion
762 (Info-find-node "xemacs-faq" "Top"))
763 (switch-to-buffer "*info*"))
765 (defun view-sample-init-el ()
766 "Display the sample init.el file."
768 (Help-find-file (locate-data-file "sample.init.el")))
770 (defcustom view-lossage-key-count 100
771 "*Number of keys `view-lossage' shows.
772 The maximum number of available keys is governed by `recent-keys-ring-size'."
776 (defcustom view-lossage-message-count 100
777 "*Number of minibuffer messages `view-lossage' shows."
781 (defun print-recent-messages (n)
782 "Print N most recent messages to standard-output, most recent first.
783 If N is nil, all messages will be printed."
785 (let ((buffer (get-buffer-create " *Message-Log*"))
787 (goto-char (point-max buffer) buffer)
788 (set-buffer standard-output)
789 (while (and (not (bobp buffer))
790 (or (null n) (>= (decf n) 0)))
791 (setq oldpoint (point buffer))
792 (setq extent (extent-at oldpoint buffer
793 'message-multiline nil 'before))
794 ;; If the message was multiline, move all the way to the
797 (goto-char (extent-start-position extent) buffer)
798 (forward-line -1 buffer))
799 (insert-buffer-substring buffer (point buffer) oldpoint)))))
801 (defun view-lossage ()
802 "Display recent input keystrokes and recent minibuffer messages.
803 The number of keys shown is controlled by `view-lossage-key-count'.
804 The number of messages shown is controlled by `view-lossage-message-count'."
806 (with-displaying-help-buffer
808 (princ (key-description (recent-keys view-lossage-key-count)))
810 (set-buffer standard-output)
811 (goto-char (point-min))
812 (insert "Recent keystrokes:\n\n")
813 (while (progn (move-to-column 50) (not (eobp)))
814 (search-forward " " nil t)
816 ;; XEmacs addition: copy the messages from " *Message-Log*",
817 ;; reversing their order and handling multiline messages
819 (princ "\n\n\nRecent minibuffer messages (most recent first):\n\n")
820 (print-recent-messages view-lossage-message-count))
823 (define-function 'help 'help-for-help)
825 (make-help-screen help-for-help
826 "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:"
828 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.)
830 \\[hyper-apropos] Type a substring; it shows a hypertext list of
831 functions and variables that contain that substring.
832 See also the `apropos' command.
833 \\[command-apropos] Type a substring; it shows a list of commands
834 (interactively callable functions) that contain that substring.
835 \\[describe-bindings] Table of all key bindings.
836 \\[describe-key-briefly] Type a command key sequence;
837 it displays the function name that sequence runs.
838 \\[customize] Customize Emacs options.
839 \\[Info-goto-emacs-command-node] Type a function name; it displays the Info node for that command.
840 \\[describe-function] Type a function name; it shows its documentation.
841 \\[Info-elisp-ref] Type a function name; it jumps to the full documentation
842 in the XEmacs Lisp Programmer's Manual.
843 \\[xemacs-local-faq] Local copy of the XEmacs FAQ.
844 \\[info] Info documentation reader.
845 \\[Info-query] Type an Info file name; it displays it in Info reader.
846 \\[describe-key] Type a command key sequence;
847 it displays the documentation for the command bound to that key.
848 \\[Info-goto-emacs-key-command-node] Type a command key sequence;
849 it displays the Info node for the command bound to that key.
850 \\[view-lossage] Recent input keystrokes and minibuffer messages.
851 \\[describe-mode] Documentation of current major and minor modes.
852 \\[view-emacs-news] News of recent XEmacs changes.
853 \\[finder-by-keyword] Type a topic keyword; it finds matching packages.
854 \\[describe-pointer] Table of all mouse-button bindings.
855 \\[describe-syntax] Contents of syntax table with explanations.
856 \\[help-with-tutorial] XEmacs learn-by-doing tutorial.
857 \\[describe-variable] Type a variable name; it displays its documentation and value.
858 \\[where-is] Type a command name; it displays which keystrokes invoke that command.
859 \\[describe-distribution] XEmacs ordering information.
860 \\[describe-no-warranty] Information on absence of warranty for XEmacs.
861 \\[describe-copying] XEmacs copying permission (General Public License)."
864 (defmacro with-syntax-table (syntab &rest body)
865 "Evaluate BODY with the SYNTAB as the current syntax table."
866 `(let ((stab (syntax-table)))
869 (set-syntax-table (copy-syntax-table ,syntab))
871 (set-syntax-table stab))))
872 (put 'with-syntax-table 'lisp-indent-function 1)
873 (put 'with-syntax-table 'edebug-form-spec '(form body))
875 (defun function-called-at-point ()
876 "Return the function which is called by the list containing point.
877 If that gives no function, return the function whose name is around point.
878 If that doesn't give a function, return nil."
882 (narrow-to-region (max (point-min) (- (point) 1000))
887 (setq obj (read (current-buffer)))
888 (and (symbolp obj) (fboundp obj) obj)))))
890 (with-syntax-table emacs-lisp-mode-syntax-table
892 (or (not (zerop (skip-syntax-backward "_w")))
893 (eq (char-syntax (char-after (point))) ?w)
894 (eq (char-syntax (char-after (point))) ?_)
896 (skip-chars-forward "`'")
897 (let ((obj (read (current-buffer))))
898 (and (symbolp obj) (fboundp obj) obj)))))))
900 (defun function-at-point ()
901 "Return the function whose name is around point.
902 If that gives no function, return the function which is called by the
903 list containing point. If that doesn't give a function, return nil."
905 (with-syntax-table emacs-lisp-mode-syntax-table
907 (or (not (zerop (skip-syntax-backward "_w")))
908 (eq (char-syntax (char-after (point))) ?w)
909 (eq (char-syntax (char-after (point))) ?_)
911 (skip-chars-forward "`'")
912 (let ((obj (read (current-buffer))))
913 (and (symbolp obj) (fboundp obj) obj)))))
917 (narrow-to-region (max (point-min) (- (point) 1000))
922 (setq obj (read (current-buffer)))
923 (and (symbolp obj) (fboundp obj) obj)))))))
925 (defun function-at-event (event)
926 "Return the function whose name is around the position of EVENT.
927 EVENT should be a mouse event. When calling from a popup or context menu,
928 use `last-popup-menu-event' to find out where the mouse was clicked.
929 \(You cannot use (interactive \"e\"), unfortunately. This returns a
932 If the event contains no position, or the position is not over text, or
933 there is no function around that point, nil is returned."
934 (if (and event (event-buffer event) (event-point event))
936 (set-buffer (event-buffer event))
937 (goto-char (event-point event))
938 (function-at-point))))
940 ;; Default to nil for the non-hackers? Not until we find a way to
941 ;; distinguish hackers from non-hackers automatically!
942 (defcustom describe-function-show-arglist t
943 "*If non-nil, describe-function will show its arglist,
944 unless the function is autoloaded."
946 :group 'help-appearance)
948 (defun describe-symbol-find-file (symbol)
949 (loop for (file . load-data) in load-history
950 do (when (memq symbol load-data)
953 (define-obsolete-function-alias
954 'describe-function-find-file
955 'describe-symbol-find-file)
957 (defun describe-function (function)
958 "Display the full documentation of FUNCTION (a symbol).
959 When run interactively, it defaults to any function found by
960 `function-at-point'."
962 (let* ((fn (function-at-point))
963 (val (let ((enable-recursive-minibuffers t))
966 (format (gettext "Describe function (default %s): ")
968 (gettext "Describe function: "))
969 obarray 'fboundp t nil 'function-history
971 (list (intern val))))
972 (with-displaying-help-buffer
974 (describe-function-1 function)
975 ;; Return the text we displayed.
976 (buffer-string nil nil standard-output))
977 (format "function `%s'" function)))
979 (defun function-obsolete-p (function)
980 "Return non-nil if FUNCTION is obsolete."
981 (not (null (get function 'byte-obsolete-info))))
983 (defun function-obsoleteness-doc (function)
984 "If FUNCTION is obsolete, return a string describing this."
985 (let ((obsolete (get function 'byte-obsolete-info)))
987 (format "Obsolete; %s"
988 (if (stringp (car obsolete))
990 (format "use `%s' instead." (car obsolete)))))))
992 (defun function-compatible-p (function)
993 "Return non-nil if FUNCTION is present for Emacs compatibility."
994 (not (null (get function 'byte-compatible-info))))
996 (defun function-compatibility-doc (function)
997 "If FUNCTION is Emacs compatible, return a string describing this."
998 (let ((compatible (get function 'byte-compatible-info)))
1000 (format "Emacs Compatible; %s"
1001 (if (stringp (car compatible))
1003 (format "use `%s' instead." (car compatible)))))))
1005 ;Here are all the possibilities below spelled out, for the benefit
1006 ;of the I18N3 snarfer.
1008 ;(gettext "a built-in function")
1009 ;(gettext "an interactive built-in function")
1010 ;(gettext "a built-in macro")
1011 ;(gettext "an interactive built-in macro")
1012 ;(gettext "a compiled Lisp function")
1013 ;(gettext "an interactive compiled Lisp function")
1014 ;(gettext "a compiled Lisp macro")
1015 ;(gettext "an interactive compiled Lisp macro")
1016 ;(gettext "a Lisp function")
1017 ;(gettext "an interactive Lisp function")
1018 ;(gettext "a Lisp macro")
1019 ;(gettext "an interactive Lisp macro")
1020 ;(gettext "a mocklisp function")
1021 ;(gettext "an interactive mocklisp function")
1022 ;(gettext "a mocklisp macro")
1023 ;(gettext "an interactive mocklisp macro")
1024 ;(gettext "an autoloaded Lisp function")
1025 ;(gettext "an interactive autoloaded Lisp function")
1026 ;(gettext "an autoloaded Lisp macro")
1027 ;(gettext "an interactive autoloaded Lisp macro")
1029 ;; taken out of `describe-function-1'
1030 (defun function-arglist (function)
1031 "Return a string giving the argument list of FUNCTION.
1034 (function-arglist 'function-arglist)
1035 => (function-arglist FUNCTION)
1037 This function is used by `describe-function-1' to list function
1038 arguments in the standard Lisp style."
1039 (let* ((fnc (indirect-function function))
1040 (fndef (if (eq (car-safe fnc) 'macro)
1044 (cond ((compiled-function-p fndef)
1045 (compiled-function-arglist fndef))
1046 ((eq (car-safe fndef) 'lambda)
1049 (let* ((doc (documentation function))
1050 (args (and (string-match
1051 "[\n\t ]*\narguments: ?(\\(.*\\))\n?\\'"
1053 (match-string 1 doc))))
1054 ;; If there are no arguments documented for the
1055 ;; subr, rather don't print anything.
1056 (cond ((null args) t)
1057 ((equal args "") nil)
1060 (cond ((listp arglist)
1062 (cons function (mapcar (lambda (arg)
1063 (if (memq arg '(&optional &rest))
1065 (intern (upcase (symbol-name arg)))))
1069 (format "(%s %s)" function arglist)))))
1071 (defun function-documentation (function &optional strip-arglist)
1072 "Return a string giving the documentation for FUNCTION, if any.
1073 If the optional argument STRIP-ARGLIST is non-nil, remove the arglist
1074 part of the documentation of internal subroutines."
1075 (let ((doc (condition-case nil
1076 (or (documentation function)
1077 (gettext "not documented"))
1078 (void-function ""))))
1079 (if (and strip-arglist
1080 (string-match "[\n\t ]*\narguments: ?(\\(.*\\))\n?\\'" doc))
1081 (setq doc (substring doc 0 (match-beginning 0))))
1084 ;; replacement for `princ' that puts the text in the specified face,
1086 (defun Help-princ-face (object face)
1087 (cond ((bufferp standard-output)
1088 (let ((opoint (point standard-output)))
1090 (put-nonduplicable-text-property opoint (point standard-output)
1091 'face face standard-output)))
1092 ((markerp standard-output)
1093 (let ((buf (marker-buffer standard-output))
1094 (pos (marker-position standard-output)))
1096 (put-nonduplicable-text-property
1097 pos (marker-position standard-output) 'face face buf)))
1100 ;; replacement for `prin1' that puts the text in the specified face,
1102 (defun Help-prin1-face (object face)
1103 (cond ((bufferp standard-output)
1104 (let ((opoint (point standard-output)))
1106 (put-nonduplicable-text-property opoint (point standard-output)
1107 'face face standard-output)))
1108 ((markerp standard-output)
1109 (let ((buf (marker-buffer standard-output))
1110 (pos (marker-position standard-output)))
1112 (put-nonduplicable-text-property
1113 pos (marker-position standard-output) 'face face buf)))
1116 (defvar help-symbol-regexp
1117 (let ((sym-char "[+a-zA-Z0-9_:*]")
1118 (sym-char-no-dash "[-+a-zA-Z0-9_:*]"))
1120 ;; a symbol with a - in it.
1121 "\\<\\(" sym-char-no-dash "+\\(-" sym-char-no-dash "+\\)+\\)\\>"
1123 "`\\(" sym-char "+\\)'"
1126 (defun help-symbol-run-function-1 (ev ex fun)
1127 (let ((help-sticky-window
1128 ;; if we were called from a help buffer, make sure the new help
1129 ;; goes in the same window.
1130 (if (and (event-buffer ev)
1131 (symbol-value-in-buffer 'help-window-config
1134 help-sticky-window)))
1135 (funcall fun (extent-property ex 'help-symbol))))
1137 (defun help-symbol-run-function (fun)
1138 (let ((ex (extent-at-event last-popup-menu-event 'help-symbol)))
1140 (help-symbol-run-function-1 last-popup-menu-event ex fun))))
1142 (defvar help-symbol-function-context-menu
1143 '(["View %_Documentation" (help-symbol-run-function 'describe-function)]
1144 ["Find %_Function Source" (help-symbol-run-function 'find-function)]
1145 ["Find %_Tag" (help-symbol-run-function 'find-tag)]
1148 (defvar help-symbol-variable-context-menu
1149 '(["View %_Documentation" (help-symbol-run-function 'describe-variable)]
1150 ["Find %_Variable Source" (help-symbol-run-function 'find-variable)]
1151 ["Find %_Tag" (help-symbol-run-function 'find-tag)]
1154 (defvar help-symbol-function-and-variable-context-menu
1155 '(["View Function %_Documentation" (help-symbol-run-function
1156 'describe-function)]
1157 ["View Variable D%_ocumentation" (help-symbol-run-function
1158 'describe-variable)]
1159 ["Find %_Function Source" (help-symbol-run-function 'find-function)]
1160 ["Find %_Variable Source" (help-symbol-run-function 'find-variable)]
1161 ["Find %_Tag" (help-symbol-run-function 'find-tag)]
1164 (defun frob-help-extents (buffer)
1165 ;; Look through BUFFER, starting at the buffer's point and continuing
1166 ;; till end of file, and find documented functions and variables.
1167 ;; any such symbol found is tagged with an extent, that sets up these
1169 ;; 1. mouse-face is 'highlight (so the extent gets highlighted on mouse over)
1170 ;; 2. help-symbol is the name of the symbol.
1171 ;; 3. face is 'hyper-apropos-hyperlink.
1172 ;; 4. context-menu is a list of context menu items, specific to whether
1173 ;; the symbol is a function, variable, or both.
1174 ;; 5. activate-function will cause the function or variable to be described,
1175 ;; replacing the existing help contents.
1179 (while (re-search-forward help-symbol-regexp nil t)
1180 (setq b (or (match-beginning 2) (match-beginning 4)))
1181 (setq e (or (match-end 2) (match-end 4)))
1182 (setq name (buffer-substring b e))
1183 (let* ((sym (intern-soft name))
1184 (var (and sym (boundp sym)
1185 (documentation-property sym
1186 'variable-documentation t)))
1187 (fun (and sym (fboundp sym)
1188 (documentation sym t))))
1190 (let ((ex (make-extent b e)))
1191 (require 'hyper-apropos)
1192 (set-extent-property ex 'mouse-face 'highlight)
1193 (set-extent-property ex 'help-symbol sym)
1194 (set-extent-property ex 'face 'hyper-apropos-hyperlink)
1195 (set-extent-property
1197 (cond ((and var fun)
1198 help-symbol-function-and-variable-context-menu)
1199 (var help-symbol-variable-context-menu)
1200 (fun help-symbol-function-context-menu)))
1201 (set-extent-property
1202 ex 'activate-function
1205 (help-symbol-run-function-1 ev ex 'describe-function))
1207 (help-symbol-run-function-1 ev ex 'describe-variable))))
1208 ))))))) ;; 11 parentheses!
1210 (defun describe-function-1 (function &optional nodoc)
1211 "This function does the work for `describe-function'."
1213 ;; (Help-princ-face function 'font-lock-function-name-face) overkill
1216 (let* ((def function)
1217 aliases file-name autoload-file kbd-macro-p fndef macrop)
1218 (while (and (symbolp def) (fboundp def))
1219 (when (not (eq def function))
1222 ;; I18N3 Need gettext due to concat
1225 "\n which is an alias for `%s', "
1227 (format "an alias for `%s', " (symbol-name def)))))
1228 (setq def (symbol-function def)))
1229 (if (and (fboundp 'compiled-function-annotation)
1230 (compiled-function-p def))
1231 (setq file-name (compiled-function-annotation def)))
1232 (if (eq 'macro (car-safe def))
1233 (setq fndef (cdr def)
1234 file-name (and (compiled-function-p (cdr def))
1235 (fboundp 'compiled-function-annotation)
1236 (compiled-function-annotation (cdr def)))
1239 (if aliases (princ aliases))
1240 (let ((int #'(lambda (string an-p macro-p)
1243 (cond ((commandp def)
1248 (if macro-p " macro" " function")))
1250 (cond ((or (stringp def) (vectorp def))
1251 (princ "a keyboard macro.")
1252 (setq kbd-macro-p t))
1254 (funcall int "built-in" nil macrop))
1255 ((compiled-function-p fndef)
1256 (funcall int "compiled Lisp" nil macrop))
1257 ((eq (car-safe fndef) 'lambda)
1258 (funcall int "Lisp" nil macrop))
1259 ((eq (car-safe fndef) 'mocklisp)
1260 (funcall int "mocklisp" nil macrop))
1261 ((eq (car-safe def) 'autoload)
1262 (setq autoload-file (elt def 1))
1263 (funcall int "autoloaded Lisp" t (elt def 4)))
1264 ((and (symbolp def) (not (fboundp def)))
1265 (princ "a symbol with a void (unbound) function definition."))
1270 (princ (format " -- autoloads from \"%s\"\n" autoload-file)))
1272 (setq file-name (describe-symbol-find-file function)))
1274 (princ (format " -- loaded from \"%s\"\n" file-name)))
1276 (if describe-function-show-arglist
1277 (let ((arglist (function-arglist function)))
1279 (require 'hyper-apropos)
1280 (Help-princ-face arglist 'hyper-apropos-documentation)
1284 (princ "These characters are executed:\n\n\t")
1285 (princ (key-description def))
1286 (cond ((setq def (key-binding def))
1287 (princ (format "\n\nwhich executes the command `%s'.\n\n"
1289 (describe-function-1 def))))
1292 ;; tell the user about obsoleteness.
1293 ;; If the function is obsolete and is aliased, don't
1294 ;; even bother to report the documentation, as a further
1295 ;; encouragement to use the new function.
1296 (let ((obsolete (function-obsoleteness-doc function))
1297 (compatible (function-compatibility-doc function)))
1306 (unless (and obsolete aliases)
1307 (let ((doc (function-documentation function t)))
1308 (princ "Documentation:\n")
1309 (let ((oldp (point standard-output))
1312 (setq newp (point standard-output))
1313 (goto-char oldp standard-output)
1314 (frob-help-extents standard-output)
1315 (goto-char newp standard-output))
1316 (unless (or (equal doc "")
1317 (eq ?\n (aref doc (1- (length doc)))))
1321 ;;; [Obnoxious, whining people who complain very LOUDLY on Usenet
1322 ;;; are binding this to keys.]
1323 (defun describe-function-arglist (function)
1324 (interactive (list (or (function-at-point)
1325 (error "no function call at point"))))
1327 (message (function-arglist function)))
1329 (defun variable-at-point ()
1331 (with-syntax-table emacs-lisp-mode-syntax-table
1333 (or (not (zerop (skip-syntax-backward "_w")))
1334 (eq (char-syntax (char-after (point))) ?w)
1335 (eq (char-syntax (char-after (point))) ?_)
1337 (skip-chars-forward "'")
1338 (let ((obj (read (current-buffer))))
1339 (and (symbolp obj) (boundp obj) obj))))))
1341 (defun variable-at-event (event)
1342 "Return the variable whose name is around the position of EVENT.
1343 EVENT should be a mouse event. When calling from a popup or context menu,
1344 use `last-popup-menu-event' to find out where the mouse was clicked.
1345 \(You cannot use (interactive \"e\"), unfortunately. This returns a
1348 If the event contains no position, or the position is not over text, or
1349 there is no variable around that point, nil is returned."
1350 (if (and event (event-buffer event) (event-point event))
1352 (set-buffer (event-buffer event))
1353 (goto-char (event-point event))
1354 (variable-at-point))))
1356 (defun variable-obsolete-p (variable)
1357 "Return non-nil if VARIABLE is obsolete."
1358 (not (null (get variable 'byte-obsolete-variable))))
1360 (defun variable-obsoleteness-doc (variable)
1361 "If VARIABLE is obsolete, return a string describing this."
1362 (let ((obsolete (get variable 'byte-obsolete-variable)))
1364 (format "Obsolete; %s"
1365 (if (stringp obsolete)
1367 (format "use `%s' instead." obsolete))))))
1369 (defun variable-compatible-p (variable)
1370 "Return non-nil if VARIABLE is Emacs compatible."
1371 (not (null (get variable 'byte-compatible-variable))))
1373 (defun variable-compatibility-doc (variable)
1374 "If VARIABLE is Emacs compatible, return a string describing this."
1375 (let ((compatible (get variable 'byte-compatible-variable)))
1377 (format "Emacs Compatible; %s"
1378 (if (stringp compatible)
1380 (format "use `%s' instead." compatible))))))
1382 (defun built-in-variable-doc (variable)
1383 "Return a string describing whether VARIABLE is built-in."
1384 (let ((type (built-in-variable-type variable)))
1386 (integer "a built-in integer variable")
1387 (const-integer "a built-in constant integer variable")
1388 (boolean "a built-in boolean variable")
1389 (const-boolean "a built-in constant boolean variable")
1390 (object "a simple built-in variable")
1391 (const-object "a simple built-in constant variable")
1392 (const-specifier "a built-in constant specifier variable")
1393 (current-buffer "a built-in buffer-local variable")
1394 (const-current-buffer "a built-in constant buffer-local variable")
1395 (default-buffer "a built-in default buffer-local variable")
1396 (selected-console "a built-in console-local variable")
1397 (const-selected-console "a built-in constant console-local variable")
1398 (default-console "a built-in default console-local variable")
1400 (if type "an unknown type of built-in variable?"
1401 "a variable declared in Lisp")))))
1403 (defun describe-variable (variable)
1404 "Display the full documentation of VARIABLE (a symbol)."
1406 (let* ((v (variable-at-point))
1407 (val (let ((enable-recursive-minibuffers t))
1410 (format "Describe variable (default %s): " v)
1411 (gettext "Describe variable: "))
1412 obarray 'boundp t nil 'variable-history
1414 (list (intern val))))
1415 (with-displaying-help-buffer
1417 (let ((origvar variable)
1419 (let ((print-escape-newlines t))
1421 ;; (Help-princ-face (symbol-name variable)
1422 ;; 'font-lock-variable-name-face) overkill
1423 (princ (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 (require 'hyper-apropos)
1446 (if (not (boundp variable))
1447 (Help-princ-face "void\n" 'hyper-apropos-documentation)
1448 (Help-prin1-face (symbol-value variable)
1449 'hyper-apropos-documentation)
1452 (cond ((local-variable-p variable (current-buffer))
1453 (let* ((void (cons nil nil))
1454 (def (condition-case nil
1455 (default-value variable)
1457 (princ "This value is specific to the current buffer.\n")
1458 (if (local-variable-p variable nil)
1459 (princ "(Its value is local to each buffer.)\n"))
1461 (if (if (eq def void)
1463 (not (eq (symbol-value variable) def)))
1464 ;; #### I18N3 doesn't localize properly!
1465 (progn (princ "Default-value: ")
1471 ((local-variable-p variable (current-buffer) t)
1472 (princ "Setting it would make its value buffer-local.\n\n"))))
1473 (princ "Documentation:")
1475 (let ((doc (documentation-property variable 'variable-documentation))
1476 (obsolete (variable-obsoleteness-doc origvar))
1477 (compatible (variable-compatibility-doc origvar)))
1486 ;; don't bother to print anything if variable is obsolete and aliased.
1487 (when (or (not obsolete) (not aliases))
1489 ;; note: documentation-property calls substitute-command-keys.
1490 (let ((oldp (point standard-output))
1493 (setq newp (point standard-output))
1494 (goto-char oldp standard-output)
1495 (frob-help-extents standard-output)
1496 (goto-char newp standard-output))
1497 (princ "not documented as a variable."))))
1499 (format "variable `%s'" variable)))
1501 (defun sorted-key-descriptions (keys &optional separator)
1502 "Sort and separate the key descriptions for KEYS.
1503 The sorting is done by length (shortest bindings first), and the bindings
1504 are separated with SEPARATOR (\", \" by default)."
1505 (mapconcat 'key-description
1506 (sort keys #'(lambda (x y)
1507 (< (length x) (length y))))
1508 (or separator ", ")))
1510 (defun where-is (definition &optional insert)
1511 "Print message listing key sequences that invoke specified command.
1512 Argument is a command definition, usually a symbol with a function definition.
1513 When run interactively, it defaults to any function found by
1514 `function-at-point'.
1515 If INSERT (the prefix arg) is non-nil, insert the message in the buffer."
1517 (let ((fn (function-at-point))
1518 (enable-recursive-minibuffers t)
1520 (setq val (read-command
1521 (if fn (format "Where is command (default %s): " fn)
1522 "Where is command: ")
1523 (and fn (symbol-name fn))))
1524 (list (if (equal (symbol-name val) "")
1526 current-prefix-arg)))
1527 (let ((keys (where-is-internal definition)))
1530 (princ (format "%s (%s)" (sorted-key-descriptions keys)
1531 definition) (current-buffer))
1532 (message "%s is on %s" definition (sorted-key-descriptions keys)))
1534 (princ (format (if (commandp definition) "M-x %s RET"
1535 "M-: (%s ...)") definition) (current-buffer))
1536 (message "%s is not on any keys" definition))))
1539 ;; `locate-library' moved to "packages.el"
1542 ;; Functions ported from C into Lisp in XEmacs
1544 (defun describe-syntax ()
1545 "Describe the syntax specifications in the syntax table.
1546 The descriptions are inserted in a buffer, which is then displayed."
1548 (with-displaying-help-buffer
1550 ;; defined in syntax.el
1551 (describe-syntax-table (syntax-table) standard-output))
1552 (format "syntax-table for %s" major-mode)))
1554 (defun list-processes ()
1555 "Display a list of all processes.
1556 \(Any processes listed as Exited or Signaled are actually eliminated
1557 after the listing is made.)"
1559 (with-output-to-temp-buffer "*Process List*"
1560 (set-buffer standard-output)
1561 (buffer-disable-undo standard-output)
1562 (make-local-variable 'truncate-lines)
1563 (setq truncate-lines t)
1564 ;; 00000000001111111111222222222233333333334444444444
1565 ;; 01234567890123456789012345678901234567890123456789
1566 ;; rewritten for I18N3. This one should stay rewritten
1567 ;; so that the dashes will line up properly.
1568 (princ "Proc Status Buffer Tty Command\n---- ------ ------ --- -------\n")
1569 (let ((tail (process-list)))
1571 (let* ((p (car tail))
1572 (pid (process-id p))
1573 (s (process-status p)))
1574 (setq tail (cdr tail))
1575 (princ (format "%-13s" (process-name p)))
1577 (if (and (eq s 'exit) (/= (process-exit-status p) 0))
1578 (princ (format " %d" (process-exit-status p))))
1579 (if (memq s '(signal exit closed))
1580 ;; Do delete-exited-processes' work
1582 (indent-to 22 1) ;####
1583 (let ((b (process-buffer p)))
1586 ((not (buffer-name b))
1589 (princ (buffer-name b)))))
1590 (indent-to 37 1) ;####
1591 (let ((tn (process-tty-name p)))
1595 (princ (format "%s" tn)))))
1596 (indent-to 49 1) ;####
1597 (if (not (integerp pid))
1599 (princ "network stream connection ")
1603 (let ((cmd (process-command p)))
1606 (setq cmd (cdr cmd))
1607 (if cmd (princ " ")))))
1610 ;; Stop gap for 21.0 until we do help-char etc properly.
1611 (defun help-keymap-with-help-key (keymap form)
1612 "Return a copy of KEYMAP with an help-key binding according to help-char
1613 invoking FORM like help-form. An existing binding is not overridden.
1614 If FORM is nil then no binding is made."
1615 (let ((map (copy-keymap keymap))
1616 (key (if (characterp help-char)
1617 (vector (character-to-event help-char))
1619 (when (and form key (not (lookup-key map key)))
1621 `(lambda () (interactive) (help-print-help-form ,form))))
1624 (defun help-print-help-form (form)
1625 (let ((string (eval form)))
1626 (if (stringp string)
1627 (with-displaying-help-buffer
1630 ;;; help.el ends here