home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / prim / help.el.z / help.el
Encoding:
Text File  |  1998-05-21  |  48.1 KB  |  1,324 lines

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