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