Mercurial > hg > xemacs-beta
annotate lisp/help.el @ 4787:2302bb5fa67d
Goodbye dk.xemacs.org
| author | Adrian Aichner <adrian@xemacs.org> |
|---|---|
| date | Mon, 21 Dec 2009 19:21:30 +0100 |
| parents | fee33ab25966 |
| children | 755ae5b97edb |
| rev | line source |
|---|---|
| 3368 | 1 ;; help.el --- help commands for XEmacs. |
| 428 | 2 |
| 3 ;; Copyright (C) 1985, 1986, 1992-4, 1997 Free Software Foundation, Inc. | |
| 2537 | 4 ;; Copyright (C) 2001, 2002, 2003 Ben Wing. |
| 428 | 5 |
| 6 ;; Maintainer: FSF | |
| 7 ;; Keywords: help, internal, dumped | |
| 8 | |
| 9 ;; This file is part of XEmacs. | |
| 10 | |
| 11 ;; XEmacs is free software; you can redistribute it and/or modify it | |
| 12 ;; under the terms of the GNU General Public License as published by | |
| 13 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 14 ;; any later version. | |
| 15 | |
| 16 ;; XEmacs is distributed in the hope that it will be useful, but | |
| 17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 19 ;; General Public License for more details. | |
| 20 | |
| 21 ;; You should have received a copy of the GNU General Public License | |
| 22 ;; along with XEmacs; see the file COPYING. If not, write to the | |
| 23 ;; Free Software Foundation, 59 Temple Place - Suite 330, | |
| 24 ;; Boston, MA 02111-1307, USA. | |
| 25 | |
| 26 ;;; Synched up with: FSF 19.30. | |
| 27 | |
| 28 ;;; Commentary: | |
| 29 | |
| 30 ;; This file is dumped with XEmacs. | |
| 31 | |
| 32 ;; This code implements XEmacs's on-line help system, the one invoked by | |
| 33 ;;`M-x help-for-help'. | |
| 34 | |
| 35 ;; 06/11/1997 -- Converted to use char-after instead of broken | |
| 36 ;; following-char. -slb | |
| 37 | |
| 38 ;;; Code: | |
| 39 | |
| 40 ;; Get the macro make-help-screen when this is compiled, | |
| 41 ;; or run interpreted, but not when the compiled code is loaded. | |
| 42 (eval-when-compile (require 'help-macro)) | |
| 43 | |
| 3368 | 44 (require 'loadhist) ;; For symbol-file. |
| 45 | |
| 428 | 46 (defgroup help nil |
| 47 "Support for on-line help systems." | |
| 48 :group 'emacs) | |
| 49 | |
| 50 (defgroup help-appearance nil | |
| 51 "Appearance of help buffers." | |
| 52 :group 'help) | |
| 53 | |
| 54 (defvar help-map (let ((map (make-sparse-keymap))) | |
| 55 (set-keymap-name map 'help-map) | |
| 56 (set-keymap-prompt | |
| 444 | 57 map (gettext "(Type ? for further options)")) |
| 428 | 58 map) |
| 59 "Keymap for characters following the Help key.") | |
| 60 | |
| 61 ;; global-map definitions moved to keydefs.el | |
| 62 (fset 'help-command help-map) | |
| 63 | |
| 64 (define-key help-map (vector help-char) 'help-for-help) | |
| 65 (define-key help-map "?" 'help-for-help) | |
| 66 (define-key help-map 'help 'help-for-help) | |
| 67 (define-key help-map '(f1) 'help-for-help) | |
| 68 | |
| 69 (define-key help-map "a" 'hyper-apropos) ; 'command-apropos in FSFmacs | |
| 502 | 70 (define-key help-map "A" 'command-hyper-apropos) |
| 71 ;; #### should be hyper-apropos-documentation, once that's written. | |
| 72 (define-key help-map "\C-a" 'apropos-documentation) | |
| 428 | 73 |
| 74 (define-key help-map "b" 'describe-bindings) | |
| 75 (define-key help-map "B" 'describe-beta) | |
| 76 | |
| 502 | 77 (define-key help-map "c" 'describe-key-briefly) |
| 428 | 78 (define-key help-map "C" 'customize) |
| 502 | 79 ;; FSFmacs has Info-goto-emacs-command-node on C-f, no binding |
| 80 ;; for Info-elisp-ref | |
| 81 (define-key help-map "\C-c" 'Info-goto-emacs-command-node) | |
| 428 | 82 |
| 83 (define-key help-map "d" 'describe-function) | |
| 502 | 84 (define-key help-map "\C-d" 'describe-distribution) |
| 85 | |
| 86 (define-key help-map "e" (if (fboundp 'view-last-error) 'view-last-error | |
| 87 'describe-last-error)) | |
| 88 | |
| 428 | 89 (define-key help-map "f" 'describe-function) |
| 502 | 90 ;; #### not a good interface. no way to specify that C-h is preferred |
| 91 ;; as a prefix and not BS. should instead be specified as part of | |
| 92 ;; `define-key'. | |
| 93 ;; (put 'describe-function 'preferred-key-sequence "\C-hf") | |
| 428 | 94 (define-key help-map "F" 'xemacs-local-faq) |
| 502 | 95 (define-key help-map "\C-f" 'Info-elisp-ref) |
| 428 | 96 |
| 97 (define-key help-map "i" 'info) | |
| 502 | 98 (define-key help-map "I" 'Info-search-index-in-xemacs-and-lispref) |
| 99 (define-key help-map "\C-i" 'Info-query) | |
| 100 | |
| 101 (define-key help-map "k" 'describe-key) | |
| 102 (define-key help-map "\C-k" 'Info-goto-emacs-key-command-node) | |
| 428 | 103 |
| 104 (define-key help-map "l" 'view-lossage) | |
| 502 | 105 (define-key help-map "\C-l" 'describe-copying) ; on \C-c in FSFmacs |
| 428 | 106 |
| 107 (define-key help-map "m" 'describe-mode) | |
| 108 | |
| 502 | 109 (define-key help-map "n" 'view-emacs-news) |
| 428 | 110 (define-key help-map "\C-n" 'view-emacs-news) |
| 111 | |
| 112 (define-key help-map "p" 'finder-by-keyword) | |
| 502 | 113 (define-key help-map "\C-p" 'describe-pointer) |
| 3074 | 114 (define-key help-map "P" 'view-xemacs-problems) |
| 502 | 115 |
| 116 (define-key help-map "q" 'help-quit) | |
| 428 | 117 |
| 118 ;; Do this right with an autoload cookie in finder.el. | |
| 119 ;;(autoload 'finder-by-keyword "finder" | |
| 120 ;; "Find packages matching a given keyword." t) | |
| 121 | |
| 122 (define-key help-map "s" 'describe-syntax) | |
| 502 | 123 (define-key help-map "S" 'view-sample-init-el) |
| 428 | 124 |
| 125 (define-key help-map "t" 'help-with-tutorial) | |
| 126 | |
| 127 (define-key help-map "v" 'describe-variable) | |
| 128 | |
| 502 | 129 (define-key help-map "w" 'where-is) |
| 130 (define-key help-map "\C-w" 'describe-no-warranty) | |
| 428 | 131 |
| 502 | 132 ;; #### It would be nice if the code below to add hyperlinks was |
| 133 ;; generalized. We would probably need a "hyperlink mode" from which | |
| 134 ;; help-mode is derived. This means we probably need multiple | |
| 135 ;; inheritance of modes! Thankfully this is not hard to implement; we | |
| 136 ;; already have the ability for a keymap to have multiple parents. | |
| 137 ;; However, we'd have to define any multiply-inherited-from modes using | |
| 138 ;; a standard `define-mode' construction instead of manually doing it, | |
| 139 ;; because we don't want each guy calling `kill-all-local-variables' and | |
| 140 ;; messing up the previous one. | |
| 428 | 141 |
| 142 (define-derived-mode help-mode view-major-mode "Help" | |
| 143 "Major mode for viewing help text. | |
| 144 Entry to this mode runs the normal hook `help-mode-hook'. | |
| 145 Commands: | |
| 146 \\{help-mode-map}" | |
| 147 ) | |
| 148 | |
| 149 (define-key help-mode-map "q" 'help-mode-quit) | |
| 150 (define-key help-mode-map "Q" 'help-mode-bury) | |
| 151 (define-key help-mode-map "f" 'find-function-at-point) | |
| 152 (define-key help-mode-map "d" 'describe-function-at-point) | |
| 153 (define-key help-mode-map "v" 'describe-variable-at-point) | |
| 154 (define-key help-mode-map "i" 'Info-elisp-ref) | |
| 155 (define-key help-mode-map "c" 'customize-variable) | |
| 156 (define-key help-mode-map [tab] 'help-next-symbol) | |
| 157 (define-key help-mode-map [(shift tab)] 'help-prev-symbol) | |
| 3368 | 158 (define-key help-mode-map [return] 'help-find-source-or-scroll-up) |
| 159 (define-key help-mode-map [button2] 'help-mouse-find-source-or-track) | |
| 428 | 160 (define-key help-mode-map "n" 'help-next-section) |
| 161 (define-key help-mode-map "p" 'help-prev-section) | |
| 162 | |
| 1123 | 163 (define-derived-mode temp-buffer-mode view-major-mode "Temp" |
| 164 "Major mode for viewing temporary buffers. | |
| 165 Exit using \\<temp-buffer-mode-map>\\[help-mode-quit]. | |
| 166 | |
| 167 Entry to this mode runs the normal hook `temp-buffer-mode-hook'. | |
| 168 Commands: | |
| 169 \\{temp-buffer-mode-map}" | |
| 170 ) | |
| 171 | |
| 172 (define-key temp-buffer-mode-map "q" 'help-mode-quit) | |
| 173 (define-key temp-buffer-mode-map "Q" 'help-mode-bury) | |
| 174 | |
| 428 | 175 (defun describe-function-at-point () |
| 176 "Describe directly the function at point in the other window." | |
| 177 (interactive) | |
| 178 (let ((symb (function-at-point))) | |
| 179 (when symb | |
| 180 (describe-function symb)))) | |
| 181 | |
| 182 (defun describe-variable-at-point () | |
| 183 "Describe directly the variable at point in the other window." | |
| 184 (interactive) | |
| 185 (let ((symb (variable-at-point))) | |
| 186 (when symb | |
| 187 (describe-variable symb)))) | |
| 188 | |
| 189 (defun help-next-symbol () | |
| 190 "Move point to the next quoted symbol." | |
| 191 (interactive) | |
| 192 (search-forward "`" nil t)) | |
| 193 | |
| 194 (defun help-prev-symbol () | |
| 195 "Move point to the previous quoted symbol." | |
| 196 (interactive) | |
| 197 (search-backward "'" nil t)) | |
| 198 | |
| 199 (defun help-next-section () | |
| 200 "Move point to the next quoted symbol." | |
| 201 (interactive) | |
| 202 (search-forward-regexp "^\\w+:" nil t)) | |
| 203 | |
| 204 (defun help-prev-section () | |
| 205 "Move point to the previous quoted symbol." | |
| 206 (interactive) | |
| 207 (search-backward-regexp "^\\w+:" nil t)) | |
| 208 | |
| 209 (defun help-mode-bury () | |
| 210 "Bury the help buffer, possibly restoring the previous window configuration." | |
| 211 (interactive) | |
| 212 (help-mode-quit t)) | |
| 213 | |
| 214 (defun help-mode-quit (&optional bury) | |
| 215 "Exit from help mode, possibly restoring the previous window configuration. | |
| 216 If the optional argument BURY is non-nil, the help buffer is buried, | |
| 217 otherwise it is killed." | |
| 218 (interactive) | |
| 219 (let ((buf (current-buffer))) | |
| 442 | 220 (cond (help-window-config |
| 221 (set-window-configuration help-window-config)) | |
| 428 | 222 ((not (one-window-p)) |
| 223 (delete-window))) | |
| 224 (if bury | |
| 225 (bury-buffer buf) | |
| 226 (kill-buffer buf)))) | |
| 227 | |
| 228 (defun help-quit () | |
| 229 (interactive) | |
| 230 nil) | |
| 231 | |
| 771 | 232 (define-obsolete-function-alias 'deprecated-help-command 'help-for-help) |
| 428 | 233 |
| 234 ;;(define-key global-map 'backspace 'deprecated-help-command) | |
| 235 | |
| 771 | 236 (defconst tutorial-supported-languages |
| 237 '( | |
| 238 ("Croatian" hr iso-8859-2) | |
| 239 ("Czech" cs iso-8859-2) | |
| 240 ("Dutch" nl iso-8859-1) | |
| 241 ("English" nil raw-text) | |
| 242 ("French" fr iso-8859-1) | |
| 243 ("German" de iso-8859-1) | |
| 244 ("Norwegian" no iso-8859-1) | |
| 245 ("Polish" pl iso-8859-2) | |
| 246 ("Romanian" ro iso-8859-2) | |
| 247 ("Slovak" sk iso-8859-2) | |
| 248 ("Slovenian" sl iso-8859-2) | |
| 249 ("Spanish" es iso-8859-1) | |
| 250 ("Swedish" se iso-8859-1) | |
| 251 ) | |
| 252 "Alist of supported languages in TUTORIAL files. | |
| 253 Add languages here, as more are translated.") | |
| 254 | |
| 255 ;; TUTORIAL arg is XEmacs addition | |
| 256 (defun help-with-tutorial (&optional tutorial language) | |
| 257 "Select the XEmacs learn-by-doing tutorial. | |
| 258 Optional arg TUTORIAL specifies the tutorial file; if not specified or | |
| 259 if this command is invoked interactively, the tutorial appropriate to | |
| 260 the current language environment is used. If there is no tutorial | |
| 261 written in that language, or if this version of XEmacs has no | |
| 262 international (Mule) support, the English-language tutorial is used. | |
| 263 With a prefix argument, you are asked to select which language." | |
| 264 (interactive "i\nP") | |
| 265 (when (and language (consp language)) | |
| 266 (setq language | |
| 267 (if (featurep 'mule) | |
| 268 (or (declare-fboundp (read-language-name 'tutorial "Language: ")) | |
| 269 (error "No tutorial file of the specified language")) | |
| 270 (let ((completion-ignore-case t)) | |
| 271 (completing-read "Language: " | |
| 272 tutorial-supported-languages nil t))))) | |
| 273 (or language | |
| 274 (setq language | |
| 275 (if (featurep 'mule) (declare-boundp current-language-environment) | |
| 276 "English"))) | |
| 277 (or tutorial | |
| 278 (setq tutorial | |
| 279 (cond ((featurep 'mule) | |
| 280 (or (declare-fboundp (get-language-info language 'tutorial)) | |
| 281 "TUTORIAL")) | |
| 282 ((equal language "English") "TUTORIAL") | |
| 283 (t (format "TUTORIAL.%s" | |
| 284 (cadr (assoc language | |
| 285 tutorial-supported-languages))))))) | |
| 286 (let ((file (expand-file-name tutorial "~"))) | |
| 287 (delete-other-windows) | |
| 288 (let ((buffer (or (get-file-buffer file) | |
| 289 (create-file-buffer file))) | |
| 290 (window-configuration (current-window-configuration))) | |
| 291 (condition-case error-data | |
| 292 (progn | |
| 293 (switch-to-buffer buffer) | |
| 294 (setq buffer-file-name file) | |
| 295 (setq default-directory (expand-file-name "~/")) | |
| 296 (setq buffer-auto-save-file-name nil) | |
| 297 ;; Because of non-Mule users, TUTORIALs are not coded | |
| 298 ;; independently, so we must guess the coding according to | |
| 299 ;; the language. | |
| 300 (let ((coding-system-for-read | |
| 301 (if (featurep 'mule) | |
| 302 (with-fboundp 'get-language-info | |
| 303 (or (get-language-info language | |
| 304 'tutorial-coding-system) | |
| 305 (car (get-language-info language | |
| 306 'coding-system)))) | |
| 307 (nth 2 (assoc language tutorial-supported-languages))))) | |
| 308 (insert-file-contents (locate-data-file tutorial))) | |
| 309 (goto-char (point-min)) | |
| 310 ;; [The 'didactic' blank lines: possibly insert blank lines | |
| 311 ;; around <<nya nya nya>> and replace << >> with [ ].] No more | |
| 312 ;; didactic blank lines. It was just a bad idea, anyway. I | |
| 313 ;; rewrote the TUTORIAL so it doesn't need them. However, some | |
| 314 ;; tutorials in other languages haven't yet been updated. #### | |
| 315 ;; Delete this code when they're all updated. | |
| 316 (if (re-search-forward "^<<.+>>" nil t) | |
| 317 (let ((n (- (window-height (selected-window)) | |
| 318 (count-lines (point-min) (point-at-bol)) | |
| 319 6))) | |
| 320 (if (< n 12) | |
| 321 (progn (beginning-of-line) (kill-line)) | |
| 322 ;; Some people get confused by the large gap | |
| 323 (delete-backward-char 2) | |
| 324 (insert "]") | |
| 325 (beginning-of-line) | |
| 326 (save-excursion | |
| 327 (delete-char 2) | |
| 328 (insert "[")) | |
| 329 (newline (/ n 2)) | |
| 330 (next-line 1) | |
| 331 (newline (- n (/ n 2)))))) | |
| 332 (goto-char (point-min)) | |
| 333 (set-buffer-modified-p nil)) | |
| 334 ;; TUTORIAL was not found: kill the buffer and restore the | |
| 335 ;; window configuration. | |
| 336 (file-error (kill-buffer buffer) | |
| 337 (set-window-configuration window-configuration) | |
| 338 ;; Now, signal the error | |
| 339 (signal (car error-data) (cdr error-data))))))) | |
| 428 | 340 |
| 341 ;; used by describe-key, describe-key-briefly, insert-key-binding, etc. | |
| 342 (defun key-or-menu-binding (key &optional menu-flag) | |
| 343 "Return the command invoked by KEY. | |
| 344 Like `key-binding', but handles menu events and toolbar presses correctly. | |
| 345 KEY is any value returned by `next-command-event'. | |
| 346 MENU-FLAG is a symbol that should be set to t if KEY is a menu event, | |
| 444 | 347 or nil otherwise." |
| 428 | 348 (let (defn) |
| 349 (and menu-flag (set menu-flag nil)) | |
| 350 ;; If the key typed was really a menu selection, grab the form out | |
| 351 ;; of the event object and intuit the function that would be called, | |
| 352 ;; and describe that instead. | |
| 353 (if (and (vectorp key) (= 1 (length key)) | |
| 354 (or (misc-user-event-p (aref key 0)) | |
| 355 (eq (car-safe (aref key 0)) 'menu-selection))) | |
| 356 (let ((event (aref key 0))) | |
| 357 (setq defn (if (eventp event) | |
| 358 (list (event-function event) (event-object event)) | |
| 359 (cdr event))) | |
| 360 (and menu-flag (set menu-flag t)) | |
| 361 (when (eq (car defn) 'eval) | |
| 362 (setq defn (car (cdr defn)))) | |
| 363 (when (eq (car-safe defn) 'call-interactively) | |
| 364 (setq defn (car (cdr defn)))) | |
| 365 (when (and (consp defn) (null (cdr defn))) | |
| 366 (setq defn (car defn)))) | |
| 367 ;; else | |
| 368 (setq defn (key-binding key))) | |
| 369 ;; kludge: if a toolbar button was pressed on, try to find the | |
| 370 ;; binding of the toolbar button. | |
| 371 (if (and (eq defn 'press-toolbar-button) | |
| 372 (vectorp key) | |
| 373 (button-press-event-p (aref key (1- (length key))))) | |
| 374 ;; wait for the button release. We're on shaky ground here ... | |
| 375 (let ((event (next-command-event)) | |
| 376 button) | |
| 377 (if (and (button-release-event-p event) | |
| 378 (event-over-toolbar-p event) | |
| 379 (eq 'release-and-activate-toolbar-button | |
| 380 (key-binding (vector event))) | |
| 381 (setq button (event-toolbar-button event))) | |
| 382 (toolbar-button-callback button) | |
| 383 ;; if anything went wrong, try returning the binding of | |
| 384 ;; the button-up event, of the original binding | |
| 385 (or (key-or-menu-binding (vector event)) | |
| 386 defn))) | |
| 387 ;; no toolbar kludge | |
| 388 defn) | |
| 389 )) | |
| 390 | |
| 391 (defun describe-key-briefly (key &optional insert) | |
| 392 "Print the name of the function KEY invokes. KEY is a string. | |
| 393 If INSERT (the prefix arg) is non-nil, insert the message in the buffer." | |
| 394 (interactive "kDescribe key briefly: \nP") | |
| 395 (let ((standard-output (if insert (current-buffer) t)) | |
| 396 defn menup) | |
| 397 (setq defn (key-or-menu-binding key 'menup)) | |
| 398 (if (or (null defn) (integerp defn)) | |
| 399 (princ (format "%s is undefined" (key-description key))) | |
| 400 ;; If it's a keyboard macro which trivially invokes another command, | |
| 401 ;; document that instead. | |
| 402 (if (or (stringp defn) (vectorp defn)) | |
| 403 (setq defn (or (key-binding defn) | |
| 404 defn))) | |
| 405 (let ((last-event (and (vectorp key) | |
| 406 (aref key (1- (length key)))))) | |
| 407 (princ (format (cond (insert | |
| 408 "%s (%s)") | |
| 409 ((or (button-press-event-p last-event) | |
| 410 (button-release-event-p last-event)) | |
| 411 (gettext "%s at that spot runs the command %s")) | |
| 412 (t | |
| 413 (gettext "%s runs the command %s"))) | |
| 414 ;; This used to say 'This menu item' but it | |
| 415 ;; could also be a scrollbar event. We can't | |
| 416 ;; distinguish at the moment. | |
| 417 (if menup | |
| 418 (if insert "item" "This item") | |
| 419 (key-description key)) | |
| 420 (if (symbolp defn) defn (prin1-to-string defn)))))))) | |
| 421 | |
| 422 ;; #### this is a horrible piece of shit function that should | |
| 423 ;; not exist. In FSF 19.30 this function has gotten three times | |
| 424 ;; as long and has tons and tons of dumb shit checking | |
| 425 ;; special-display-buffer-names and such crap. I absolutely | |
| 426 ;; refuse to insert that Ebolification here. I wanted to delete | |
| 427 ;; this function entirely but Mly bitched. | |
| 428 ;; | |
| 429 ;; If your user-land code calls this function, rewrite it to | |
| 430 ;; call with-displaying-help-buffer. | |
| 431 | |
| 432 (defun print-help-return-message (&optional function) | |
| 433 "Display or return message saying how to restore windows after help command. | |
| 434 Computes a message and applies the optional argument FUNCTION to it. | |
| 435 If FUNCTION is nil, applies `message' to it, thus printing it." | |
| 436 (and (not (get-buffer-window standard-output)) | |
| 437 (funcall | |
| 438 (or function 'message) | |
| 439 (concat | |
| 440 (substitute-command-keys | |
| 441 (if (one-window-p t) | |
| 442 (if pop-up-windows | |
| 443 (gettext "Type \\[delete-other-windows] to remove help window.") | |
| 444 (gettext "Type \\[switch-to-buffer] RET to remove help window.")) | |
| 445 (gettext "Type \\[switch-to-buffer-other-window] RET to restore the other window."))) | |
| 446 (substitute-command-keys | |
| 447 (gettext " \\[scroll-other-window] to scroll the help.")))))) | |
| 448 | |
| 449 (defcustom help-selects-help-window t | |
| 450 "*If nil, use the \"old Emacs\" behavior for Help buffers. | |
| 451 This just displays the buffer in another window, rather than selecting | |
| 452 the window." | |
| 453 :type 'boolean | |
| 454 :group 'help-appearance) | |
| 455 | |
| 456 (defcustom help-max-help-buffers 10 | |
| 457 "*Maximum help buffers to allow before they start getting killed. | |
| 458 If this is a positive integer, before a help buffer is displayed | |
| 459 by `with-displaying-help-buffer', any excess help buffers which | |
| 460 are not being displayed are first killed. Otherwise, if it is | |
| 461 zero or nil, only one help buffer, \"*Help*\" is ever used." | |
| 462 :type '(choice integer (const :tag "None" nil)) | |
| 463 :group 'help-appearance) | |
| 464 | |
| 465 (defvar help-buffer-list nil | |
| 466 "List of help buffers used by `help-register-and-maybe-prune-excess'") | |
| 467 | |
| 468 (defun help-register-and-maybe-prune-excess (newbuf) | |
| 2030 | 469 "Register help buffer named NEWBUF and possibly kill excess ones." |
| 470 ;; don't let client code pass us bogus NEWBUF---if it gets in the list, | |
| 471 ;; help can become unusable | |
| 472 (unless (stringp newbuf) | |
| 473 (error 'wrong-type-argument "help buffer name must be string" newbuf)) | |
| 428 | 474 ;; remove new buffer from list |
| 475 (setq help-buffer-list (remove newbuf help-buffer-list)) | |
| 476 ;; maybe kill excess help buffers | |
| 477 (if (and (integerp help-max-help-buffers) | |
| 478 (> (length help-buffer-list) help-max-help-buffers)) | |
| 479 (let ((keep-list nil) | |
| 480 (num-kill (- (length help-buffer-list) | |
| 481 help-max-help-buffers))) | |
| 482 (while help-buffer-list | |
| 483 (let ((buf (car help-buffer-list))) | |
| 484 (if (and (or (equal buf newbuf) (get-buffer buf)) | |
| 485 (string-match "^*Help" buf) | |
| 486 (save-excursion (set-buffer buf) | |
| 487 (eq major-mode 'help-mode))) | |
| 488 (if (and (>= num-kill (length help-buffer-list)) | |
| 489 (not (get-buffer-window buf t t))) | |
| 490 (kill-buffer buf) | |
| 491 (setq keep-list (cons buf keep-list))))) | |
| 492 (setq help-buffer-list (cdr help-buffer-list))) | |
| 493 (setq help-buffer-list (nreverse keep-list)))) | |
| 494 ;; push new buffer | |
| 495 (setq help-buffer-list (cons newbuf help-buffer-list))) | |
| 496 | |
| 497 (defvar help-buffer-prefix-string "Help" | |
| 498 "Initial string to use in constructing help buffer names. | |
| 2030 | 499 You should never set this directly, only let-bind it.") |
| 428 | 500 |
| 501 (defun help-buffer-name (name) | |
| 502 "Return a name for a Help buffer using string NAME for context." | |
| 503 (if (and (integerp help-max-help-buffers) | |
| 504 (> help-max-help-buffers 0) | |
| 505 (stringp name)) | |
| 506 (if help-buffer-prefix-string | |
| 507 (format "*%s: %s*" help-buffer-prefix-string name) | |
| 508 (format "*%s*" name)) | |
| 509 (format "*%s*" help-buffer-prefix-string))) | |
| 510 | |
| 863 | 511 ;; with-displaying-help-buffer |
| 428 | 512 |
| 513 ;; #### Should really be a macro to eliminate the requirement of | |
| 514 ;; caller to code a lambda form in THUNK -- mrb | |
| 515 | |
| 516 ;; #### BEFORE you rush to make this a macro, think about backward | |
| 517 ;; compatibility. The right way would be to create a macro with | |
| 518 ;; another name (which is a shame, because w-d-h-b is a perfect name | |
| 519 ;; for a macro) that uses with-displaying-help-buffer internally. | |
| 520 | |
| 442 | 521 (defcustom mode-for-help 'help-mode |
| 522 "*Mode that help buffers are put into.") | |
| 523 | |
| 1123 | 524 (defcustom mode-for-temp-buffer 'temp-buffer-mode |
| 525 "*Mode that help buffers are put into.") | |
| 526 | |
| 442 | 527 (defvar help-sticky-window nil |
| 528 ;; Window into which help buffers will be displayed, rather than | |
| 529 ;; always searching for a new one. This is INTERNAL and liable to | |
| 530 ;; change its interface and/or name at any moment. It should be | |
| 531 ;; bound, not set. | |
| 532 ) | |
| 533 | |
| 534 (defvar help-window-config nil) | |
| 535 | |
| 536 (make-variable-buffer-local 'help-window-config) | |
| 537 (put 'help-window-config 'permanent-local t) | |
| 538 | |
| 1123 | 539 (defmacro with-displaying-temp-buffer (name &rest body) |
| 2030 | 540 "Make a help buffer with given NAME and evaluate BODY, sending stdout there. |
| 1123 | 541 |
| 542 Use this function for displaying information in temporary buffers, where the | |
| 543 user will typically view the information and then exit using | |
| 544 \\<temp-buffer-mode-map>\\[help-mode-quit]. | |
| 863 | 545 |
| 2030 | 546 On exit from this form, the buffer is put into the mode specified in |
| 547 `mode-for-temp-buffer' and displayed, typically in a popup window. Ie, | |
| 548 the buffer is a scratchpad which is displayed all at once in formatted | |
| 549 form. | |
| 550 | |
| 551 N.B. Write to this buffer with functions like `princ', not `insert'." | |
| 1123 | 552 `(let* ((winconfig (current-window-configuration)) |
| 553 (was-one-window (one-window-p)) | |
| 554 (buffer-name ,name) | |
| 555 (help-not-visible | |
| 556 (not (and (windows-of-buffer buffer-name) ;shortcut | |
| 557 (memq (selected-frame) | |
| 558 (mapcar 'window-frame | |
| 559 (windows-of-buffer buffer-name))))))) | |
| 428 | 560 (help-register-and-maybe-prune-excess buffer-name) |
| 442 | 561 ;; if help-sticky-window is bogus or deleted, get rid of it. |
| 562 (if (and help-sticky-window (or (not (windowp help-sticky-window)) | |
| 563 (not (window-live-p help-sticky-window)))) | |
| 564 (setq help-sticky-window nil)) | |
| 565 (prog1 | |
| 566 (let ((temp-buffer-show-function | |
| 567 (if help-sticky-window | |
| 568 #'(lambda (buffer) | |
| 569 (set-window-buffer help-sticky-window buffer)) | |
| 570 temp-buffer-show-function))) | |
| 571 (with-output-to-temp-buffer buffer-name | |
| 1123 | 572 (prog1 (progn ,@body) |
| 442 | 573 (save-excursion |
| 574 (set-buffer standard-output) | |
| 1123 | 575 (funcall mode-for-temp-buffer))))) |
| 428 | 576 (let ((helpwin (get-buffer-window buffer-name))) |
| 577 (when helpwin | |
| 1123 | 578 ;; If the temp buffer is already displayed on this |
| 442 | 579 ;; frame, don't override the previous configuration |
| 580 (when help-not-visible | |
| 581 (with-current-buffer (window-buffer helpwin) | |
| 582 (setq help-window-config winconfig))) | |
| 428 | 583 (when help-selects-help-window |
| 584 (select-window helpwin)) | |
| 585 (cond ((eq helpwin (selected-window)) | |
| 586 (display-message 'command | |
| 1123 | 587 (substitute-command-keys "Type \\[help-mode-quit] to remove window, \\[scroll-up] to scroll the text."))) |
| 428 | 588 (was-one-window |
| 589 (display-message 'command | |
| 1123 | 590 (substitute-command-keys "Type \\[delete-other-windows] to remove window, \\[scroll-other-window] to scroll the text."))) |
| 428 | 591 (t |
| 592 (display-message 'command | |
| 1123 | 593 (substitute-command-keys "Type \\[switch-to-buffer-other-window] to restore the other window, \\[scroll-other-window] to scroll the text."))))))))) |
| 594 | |
| 595 (put 'with-displaying-temp-buffer 'lisp-indent-function 1) | |
| 596 | |
| 597 (defun with-displaying-help-buffer (thunk &optional name) | |
| 598 "Form which makes a help buffer with given NAME and evaluates BODY there. | |
| 599 The actual name of the buffer is generated by the function `help-buffer-name'. | |
| 600 | |
| 601 Use this function for displaying help when C-h something is pressed or | |
| 602 in similar situations. Do *not* use it when you are displaying a help | |
| 603 message and then prompting for input in the minibuffer -- this macro | |
| 604 usually selects the help buffer, which is not what you want in those | |
| 605 situations." | |
| 606 (let ((mode-for-temp-buffer mode-for-help)) | |
| 607 (with-displaying-temp-buffer (help-buffer-name name) | |
| 608 (funcall thunk)))) | |
| 428 | 609 |
| 610 (defun describe-key (key) | |
| 611 "Display documentation of the function invoked by KEY. | |
| 612 KEY is a string, or vector of events. | |
| 613 When called interactively, KEY may also be a menu selection." | |
| 614 (interactive "kDescribe key: ") | |
| 615 (let ((defn (key-or-menu-binding key)) | |
| 616 (key-string (key-description key))) | |
| 617 (if (or (null defn) (integerp defn)) | |
| 618 (message "%s is undefined" key-string) | |
| 619 (with-displaying-help-buffer | |
| 620 (lambda () | |
| 621 (princ key-string) | |
| 622 (princ " runs ") | |
| 623 (if (symbolp defn) | |
| 624 (princ (format "`%s'" defn)) | |
| 625 (princ defn)) | |
| 626 (princ "\n\n") | |
| 627 (cond ((or (stringp defn) (vectorp defn)) | |
| 628 (let ((cmd (key-binding defn))) | |
| 629 (if (not cmd) | |
| 630 (princ "a keyboard macro") | |
| 631 (progn | |
| 632 (princ "a keyboard macro which runs the command ") | |
| 633 (princ cmd) | |
| 634 (princ ":\n\n") | |
| 635 (if (documentation cmd) (princ (documentation cmd))))))) | |
| 636 ((and (consp defn) (not (eq 'lambda (car-safe defn)))) | |
| 637 (let ((describe-function-show-arglist nil)) | |
| 638 (describe-function-1 (car defn)))) | |
| 639 ((symbolp defn) | |
| 640 (describe-function-1 defn)) | |
| 641 ((documentation defn) | |
| 642 (princ (documentation defn))) | |
| 643 (t | |
| 644 (princ "not documented")))) | |
| 645 (format "key `%s'" key-string))))) | |
| 646 | |
| 647 (defun describe-mode () | |
| 648 "Display documentation of current major mode and minor modes. | |
| 649 For this to work correctly for a minor mode, the mode's indicator variable | |
| 650 \(listed in `minor-mode-alist') must also be a function whose documentation | |
| 651 describes the minor mode." | |
| 652 (interactive) | |
| 653 (with-displaying-help-buffer | |
| 654 (lambda () | |
| 655 ;; XEmacs change: print the major-mode documentation before | |
| 656 ;; the minor modes. | |
| 657 (princ mode-name) | |
| 658 (princ " mode:\n") | |
| 659 (princ (documentation major-mode)) | |
| 660 (princ "\n\n----\n\n") | |
| 661 (let ((minor-modes minor-mode-alist)) | |
| 662 (while minor-modes | |
| 663 (let* ((minor-mode (car (car minor-modes))) | |
| 664 (indicator (car (cdr (car minor-modes))))) | |
| 665 ;; Document a minor mode if it is listed in minor-mode-alist, | |
| 666 ;; bound locally in this buffer, non-nil, and has a function | |
| 667 ;; definition. | |
| 668 (if (and (boundp minor-mode) | |
| 669 (symbol-value minor-mode) | |
| 670 (fboundp minor-mode)) | |
| 671 (let ((pretty-minor-mode minor-mode)) | |
| 672 (if (string-match "-mode\\'" (symbol-name minor-mode)) | |
| 673 (setq pretty-minor-mode | |
| 674 (capitalize | |
| 675 (substring (symbol-name minor-mode) | |
| 676 0 (match-beginning 0))))) | |
| 677 (while (and (consp indicator) (extentp (car indicator))) | |
| 678 (setq indicator (cdr indicator))) | |
| 679 (while (and indicator (symbolp indicator)) | |
| 680 (setq indicator (symbol-value indicator))) | |
| 732 | 681 (princ (format "%s minor mode (%s):\n" |
| 682 pretty-minor-mode | |
| 683 (if indicator | |
| 684 (format "indicator%s" indicator) | |
| 685 "no indicator"))) | |
| 428 | 686 (princ (documentation minor-mode)) |
| 687 (princ "\n\n----\n\n")))) | |
| 688 (setq minor-modes (cdr minor-modes))))) | |
| 689 (format "%s mode" mode-name))) | |
| 690 | |
| 691 ;; So keyboard macro definitions are documented correctly | |
| 692 (fset 'defining-kbd-macro (symbol-function 'start-kbd-macro)) | |
| 693 | |
| 462 | 694 ;; view a read-only file intelligently |
| 695 (defun Help-find-file (file) | |
| 696 (if (fboundp 'view-file) | |
| 697 (view-file file) | |
| 698 (find-file-read-only file) | |
| 699 (goto-char (point-min)))) | |
| 700 | |
| 428 | 701 (defun describe-distribution () |
| 702 "Display info on how to obtain the latest version of XEmacs." | |
| 703 (interactive) | |
| 2537 | 704 (save-window-excursion |
| 705 (info) | |
| 706 (Info-find-node "xemacs-faq" "Q1.1.1")) | |
| 707 (switch-to-buffer "*info*")) | |
| 428 | 708 |
| 709 (defun describe-beta () | |
| 710 "Display info on how to deal with Beta versions of XEmacs." | |
| 711 (interactive) | |
| 2537 | 712 (save-window-excursion |
| 713 (info "(beta)Top")) | |
| 714 (switch-to-buffer "*info*")) | |
| 428 | 715 |
| 716 (defun describe-copying () | |
| 717 "Display info on how you may redistribute copies of XEmacs." | |
| 718 (interactive) | |
| 462 | 719 (Help-find-file (locate-data-file "COPYING"))) |
| 428 | 720 |
| 721 (defun describe-pointer () | |
| 722 "Show a list of all defined mouse buttons, and their definitions." | |
| 723 (interactive) | |
| 724 (describe-bindings nil t)) | |
| 725 | |
| 726 (defun describe-no-warranty () | |
| 727 "Display info on all the kinds of warranty XEmacs does NOT have." | |
| 728 (interactive) | |
| 729 (describe-copying) | |
| 730 (let (case-fold-search) | |
| 731 (search-forward "NO WARRANTY") | |
| 732 (recenter 0))) | |
| 733 | |
| 734 (defun describe-bindings (&optional prefix mouse-only-p) | |
| 735 "Show a list of all defined keys, and their definitions. | |
| 736 The list is put in a buffer, which is displayed. | |
| 444 | 737 If optional first argument PREFIX is supplied, only commands |
| 738 which start with that sequence of keys are described. | |
| 739 If optional second argument MOUSE-ONLY-P (prefix arg, interactively) | |
| 740 is non-nil then only the mouse bindings are displayed." | |
| 428 | 741 (interactive (list nil current-prefix-arg)) |
| 742 (with-displaying-help-buffer | |
| 743 (lambda () | |
| 744 (describe-bindings-1 prefix mouse-only-p)) | |
| 745 (format "bindings for %s" major-mode))) | |
| 746 | |
| 747 (defun describe-bindings-1 (&optional prefix mouse-only-p) | |
| 748 (let ((heading (if mouse-only-p | |
| 749 (gettext "button binding\n------ -------\n") | |
| 750 (gettext "key binding\n--- -------\n"))) | |
| 751 (buffer (current-buffer)) | |
| 752 (minor minor-mode-map-alist) | |
| 430 | 753 (extent-maps (mapcar-extents |
| 754 'extent-keymap | |
| 755 nil (current-buffer) (point) (point) nil 'keymap)) | |
| 428 | 756 (local (current-local-map)) |
| 757 (shadow '())) | |
| 758 (set-buffer standard-output) | |
| 430 | 759 (while extent-maps |
| 760 (insert "Bindings for Text Region:\n" | |
| 761 heading) | |
| 762 (describe-bindings-internal | |
| 763 (car extent-maps) nil shadow prefix mouse-only-p) | |
| 764 (insert "\n") | |
| 765 (setq shadow (cons (car extent-maps) shadow) | |
| 766 extent-maps (cdr extent-maps))) | |
| 428 | 767 (while minor |
| 768 (let ((sym (car (car minor))) | |
| 769 (map (cdr (car minor)))) | |
| 770 (if (symbol-value-in-buffer sym buffer nil) | |
| 771 (progn | |
| 772 (insert (format "Minor Mode Bindings for `%s':\n" | |
| 773 sym) | |
| 774 heading) | |
| 775 (describe-bindings-internal map nil shadow prefix mouse-only-p) | |
| 776 (insert "\n") | |
| 777 (setq shadow (cons map shadow)))) | |
| 778 (setq minor (cdr minor)))) | |
| 779 (if local | |
| 780 (progn | |
| 781 (insert "Local Bindings:\n" heading) | |
| 782 (describe-bindings-internal local nil shadow prefix mouse-only-p) | |
| 783 (insert "\n") | |
| 784 (setq shadow (cons local shadow)))) | |
| 771 | 785 (if (console-on-window-system-p) |
| 786 (progn | |
| 787 (insert "Global Window-System-Only Bindings:\n" heading) | |
| 788 (describe-bindings-internal global-window-system-map nil | |
| 789 shadow prefix mouse-only-p) | |
| 790 (push global-window-system-map shadow)) | |
| 791 (insert "Global TTY-Only Bindings:\n" heading) | |
| 792 (describe-bindings-internal global-tty-map nil | |
| 793 shadow prefix mouse-only-p) | |
| 794 (push global-tty-map shadow)) | |
| 795 (insert "\nGlobal Bindings:\n" heading) | |
| 428 | 796 (describe-bindings-internal (current-global-map) |
| 797 nil shadow prefix mouse-only-p) | |
| 798 (when (and prefix function-key-map (not mouse-only-p)) | |
| 799 (insert "\nFunction key map translations:\n" heading) | |
| 800 (describe-bindings-internal function-key-map nil nil | |
| 801 prefix mouse-only-p)) | |
| 802 (set-buffer buffer) | |
| 803 standard-output)) | |
| 804 | |
| 805 (defun describe-prefix-bindings () | |
| 806 "Describe the bindings of the prefix used to reach this command. | |
| 807 The prefix described consists of all but the last event | |
| 808 of the key sequence that ran this command." | |
| 809 (interactive) | |
| 810 (let* ((key (this-command-keys)) | |
| 811 (prefix (make-vector (1- (length key)) nil)) | |
| 812 i) | |
| 813 (setq i 0) | |
| 814 (while (< i (length prefix)) | |
| 815 (aset prefix i (aref key i)) | |
| 816 (setq i (1+ i))) | |
| 817 (with-displaying-help-buffer | |
| 818 (lambda () | |
| 819 (princ "Key bindings starting with ") | |
| 820 (princ (key-description prefix)) | |
| 821 (princ ":\n\n") | |
| 822 (describe-bindings-1 prefix nil)) | |
| 823 (format "%s prefix" (key-description prefix))))) | |
| 824 | |
| 825 ;; Make C-h after a prefix, when not specifically bound, | |
| 826 ;; run describe-prefix-bindings. | |
| 827 (setq prefix-help-command 'describe-prefix-bindings) | |
| 828 | |
| 829 (defun describe-installation () | |
| 830 "Display a buffer showing information about this XEmacs was compiled." | |
| 831 (interactive) | |
| 4246 | 832 (if (and-boundp 'Installation-string |
| 833 (stringp Installation-string)) | |
| 428 | 834 (with-displaying-help-buffer |
| 835 (lambda () | |
| 4246 | 836 (princ Installation-string)) |
| 428 | 837 "Installation") |
| 4246 | 838 (error 'unimplemented "No Installation information available."))) |
| 428 | 839 |
| 840 (defun view-emacs-news () | |
| 841 "Display info on recent changes to XEmacs." | |
| 842 (interactive) | |
| 2986 | 843 (Help-find-file (expand-file-name "NEWS" data-directory))) |
| 428 | 844 |
| 3074 | 845 (defun view-xemacs-problems () |
| 846 "Display known problems with XEmacs." | |
| 847 (interactive) | |
| 848 (Help-find-file (expand-file-name "PROBLEMS" data-directory))) | |
| 849 | |
| 428 | 850 (defun xemacs-www-page () |
| 851 "Go to the XEmacs World Wide Web page." | |
| 852 (interactive) | |
| 776 | 853 (if-fboundp 'browse-url |
| 442 | 854 (browse-url "http://www.xemacs.org/") |
| 428 | 855 (error "xemacs-www-page requires browse-url"))) |
| 856 | |
| 857 (defun xemacs-www-faq () | |
| 858 "View the latest and greatest XEmacs FAQ using the World Wide Web." | |
| 859 (interactive) | |
| 776 | 860 (if-fboundp 'browse-url |
| 442 | 861 (browse-url "http://www.xemacs.org/faq/index.html") |
| 428 | 862 (error "xemacs-www-faq requires browse-url"))) |
| 863 | |
| 864 (defun xemacs-local-faq () | |
| 865 "View the local copy of the XEmacs FAQ. | |
| 866 If you have access to the World Wide Web, you should use `xemacs-www-faq' | |
| 867 instead, to ensure that you get the most up-to-date information." | |
| 868 (interactive) | |
| 869 (save-window-excursion | |
| 870 (info) | |
| 871 (Info-find-node "xemacs-faq" "Top")) | |
| 872 (switch-to-buffer "*info*")) | |
| 873 | |
| 462 | 874 (defun view-sample-init-el () |
| 875 "Display the sample init.el file." | |
| 876 (interactive) | |
| 877 (Help-find-file (locate-data-file "sample.init.el"))) | |
| 878 | |
| 428 | 879 (defcustom view-lossage-key-count 100 |
| 880 "*Number of keys `view-lossage' shows. | |
| 881 The maximum number of available keys is governed by `recent-keys-ring-size'." | |
| 882 :type 'integer | |
| 883 :group 'help) | |
| 884 | |
| 885 (defcustom view-lossage-message-count 100 | |
| 886 "*Number of minibuffer messages `view-lossage' shows." | |
| 887 :type 'integer | |
| 888 :group 'help) | |
| 889 | |
| 890 (defun print-recent-messages (n) | |
| 891 "Print N most recent messages to standard-output, most recent first. | |
| 892 If N is nil, all messages will be printed." | |
| 793 | 893 (clear-message) ;; make sure current message goes into log |
| 428 | 894 (save-excursion |
| 895 (let ((buffer (get-buffer-create " *Message-Log*")) | |
| 896 oldpoint extent) | |
| 897 (goto-char (point-max buffer) buffer) | |
| 898 (set-buffer standard-output) | |
| 899 (while (and (not (bobp buffer)) | |
| 900 (or (null n) (>= (decf n) 0))) | |
| 901 (setq oldpoint (point buffer)) | |
| 902 (setq extent (extent-at oldpoint buffer | |
| 903 'message-multiline nil 'before)) | |
| 904 ;; If the message was multiline, move all the way to the | |
| 905 ;; beginning. | |
| 906 (if extent | |
| 907 (goto-char (extent-start-position extent) buffer) | |
| 908 (forward-line -1 buffer)) | |
| 909 (insert-buffer-substring buffer (point buffer) oldpoint))))) | |
| 910 | |
| 793 | 911 (defun view-warnings () |
| 912 "Display warnings issued." | |
| 913 (interactive) | |
| 914 (with-displaying-help-buffer | |
| 915 (lambda () | |
| 916 (let ((buf (get-buffer "*Warnings*"))) | |
| 917 (when buf | |
| 918 (save-excursion | |
| 919 (set-buffer standard-output) | |
| 920 (map-extents | |
| 921 #'(lambda (extent arg) | |
| 922 (goto-char (point-min)) | |
| 923 (insert (extent-string extent))) | |
| 924 buf))))) | |
| 925 "warnings")) | |
| 926 | |
| 927 (defun view-lossage (&optional no-keys) | |
| 428 | 928 "Display recent input keystrokes and recent minibuffer messages. |
| 929 The number of keys shown is controlled by `view-lossage-key-count'. | |
| 1038 | 930 The number of messages shown is controlled by `view-lossage-message-count'. |
| 931 | |
| 932 If optional arg NO-KEYS (prefix arg, interactively) is non-nil, | |
| 933 then recent input keystrokes output is omitted." | |
| 934 (interactive "P") | |
| 428 | 935 (with-displaying-help-buffer |
| 936 (lambda () | |
| 793 | 937 (unless no-keys |
| 938 (princ (key-description (recent-keys view-lossage-key-count))) | |
| 939 (save-excursion | |
| 940 (set-buffer standard-output) | |
| 941 (goto-char (point-min)) | |
| 942 (insert "Recent keystrokes:\n\n") | |
| 943 (while (progn (move-to-column 50) (not (eobp))) | |
| 944 (search-forward " " nil t) | |
| 945 (insert "\n"))) | |
| 946 (princ "\n\n\n")) | |
| 947 ;; Copy the messages from " *Message-Log*", reversing their order and | |
| 948 ;; handling multiline messages correctly. | |
| 949 (princ "Recent minibuffer messages (most recent first):\n\n") | |
| 428 | 950 (print-recent-messages view-lossage-message-count)) |
| 951 "lossage")) | |
| 952 | |
| 953 (define-function 'help 'help-for-help) | |
| 954 | |
| 955 (make-help-screen help-for-help | |
| 956 "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:" | |
| 502 | 957 (concat |
| 958 "Type a Help option: | |
| 428 | 959 \(Use SPC or DEL to scroll through this text. Type \\<help-map>\\[help-quit] to exit the Help command.) |
| 960 | |
| 502 | 961 Help on key bindings: |
| 962 | |
| 963 \\[describe-bindings] Table of all key bindings. | |
| 964 \\[describe-key-briefly] Type a key sequence or select a menu item; | |
| 965 it displays the corresponding command name. | |
| 966 \\[describe-key] Type a key sequence or select a menu item; | |
| 967 it displays the documentation for the command bound to that key. | |
| 968 (Terser but more up-to-date than what's in the manual.) | |
| 969 \\[Info-goto-emacs-key-command-node] Type a key sequence or select a menu item; | |
| 970 it jumps to the full documentation in the XEmacs User's Manual | |
| 971 for the corresponding command. | |
| 972 \\[view-lossage] Recent input keystrokes and minibuffer messages. | |
| 973 \\[describe-mode] Documentation of current major and minor modes. | |
| 974 \\[describe-pointer] Table of all mouse-button bindings. | |
| 975 \\[where-is] Type a command name; it displays which keystrokes invoke that command. | |
| 976 | |
| 977 Help on functions and variables: | |
| 978 | |
| 428 | 979 \\[hyper-apropos] Type a substring; it shows a hypertext list of |
| 980 functions and variables that contain that substring. | |
| 502 | 981 \\[command-apropos] Older version of apropos; superseded by previous command. |
| 982 \\[apropos-documentation] Type a substring; it shows a hypertext list of | |
| 983 functions and variables containing that substring anywhere | |
| 984 in their documentation. | |
| 985 \\[Info-goto-emacs-command-node] Type a command name; it jumps to the full documentation | |
| 986 in the XEmacs User's Manual. | |
| 987 \\[describe-function] Type a command or function name; it shows its documentation. | |
| 988 (Terser but more up-to-date than what's in the manual.) | |
| 989 \\[Info-elisp-ref] Type a function name; it jumps to the full documentation | |
| 990 in the XEmacs Lisp Reference Manual. | |
| 991 \\[Info-search-index-in-xemacs-and-lispref] Type a substring; it looks it up in the indices of both | |
| 992 the XEmacs User's Manual and the XEmacs Lisp Reference Manual. | |
| 993 It jumps to the first match (preferring an exact match); you | |
| 994 can use `\\<Info-mode-map>\\[Info-index-next]\\<help-map>' to successively visit other matches. | |
| 995 \\[describe-variable] Type a variable name; it displays its documentation and value. | |
| 996 | |
| 997 Miscellaneous: | |
| 998 | |
| 999 " | |
| 1000 (if (string-match "beta" emacs-version) | |
| 1001 "\\[describe-beta] Special considerations about running a beta version of XEmacs. | |
| 1002 " | |
| 1003 "") | |
| 1004 " | |
| 3074 | 1005 \\[view-xemacs-problems] Known problems. |
| 428 | 1006 \\[customize] Customize Emacs options. |
| 502 | 1007 \\[describe-distribution] How to obtain XEmacs. |
| 1008 \\[describe-last-error] Information about the most recent error. | |
| 428 | 1009 \\[xemacs-local-faq] Local copy of the XEmacs FAQ. |
| 1010 \\[info] Info documentation reader. | |
| 1011 \\[Info-query] Type an Info file name; it displays it in Info reader. | |
| 502 | 1012 \\[describe-copying] XEmacs copying permission (General Public License). |
| 428 | 1013 \\[view-emacs-news] News of recent XEmacs changes. |
| 1014 \\[finder-by-keyword] Type a topic keyword; it finds matching packages. | |
| 1015 \\[describe-syntax] Contents of syntax table with explanations. | |
| 502 | 1016 \\[view-sample-init-el] View the sample init.el that comes with XEmacs. |
| 428 | 1017 \\[help-with-tutorial] XEmacs learn-by-doing tutorial. |
| 502 | 1018 \\[describe-no-warranty] Information on absence of warranty for XEmacs." |
| 1019 ) | |
| 428 | 1020 help-map) |
| 1021 | |
| 1022 (defun function-called-at-point () | |
| 1023 "Return the function which is called by the list containing point. | |
| 1024 If that gives no function, return the function whose name is around point. | |
| 1025 If that doesn't give a function, return nil." | |
| 1026 (or (ignore-errors | |
| 1027 (save-excursion | |
| 1028 (save-restriction | |
| 1029 (narrow-to-region (max (point-min) (- (point) 1000)) | |
| 1030 (point-max)) | |
| 1031 (backward-up-list 1) | |
| 1032 (forward-char 1) | |
| 1033 (let (obj) | |
| 1034 (setq obj (read (current-buffer))) | |
| 1035 (and (symbolp obj) (fboundp obj) obj))))) | |
| 1036 (ignore-errors | |
| 1037 (with-syntax-table emacs-lisp-mode-syntax-table | |
| 1038 (save-excursion | |
| 1039 (or (not (zerop (skip-syntax-backward "_w"))) | |
| 1040 (eq (char-syntax (char-after (point))) ?w) | |
| 1041 (eq (char-syntax (char-after (point))) ?_) | |
| 1042 (forward-sexp -1)) | |
| 1043 (skip-chars-forward "`'") | |
| 1044 (let ((obj (read (current-buffer)))) | |
| 1045 (and (symbolp obj) (fboundp obj) obj))))))) | |
| 1046 | |
| 1047 (defun function-at-point () | |
| 1048 "Return the function whose name is around point. | |
| 1049 If that gives no function, return the function which is called by the | |
| 1050 list containing point. If that doesn't give a function, return nil." | |
| 1051 (or (ignore-errors | |
| 1052 (with-syntax-table emacs-lisp-mode-syntax-table | |
| 1053 (save-excursion | |
| 1054 (or (not (zerop (skip-syntax-backward "_w"))) | |
| 1055 (eq (char-syntax (char-after (point))) ?w) | |
| 1056 (eq (char-syntax (char-after (point))) ?_) | |
| 1057 (forward-sexp -1)) | |
| 1058 (skip-chars-forward "`'") | |
| 1059 (let ((obj (read (current-buffer)))) | |
| 1060 (and (symbolp obj) (fboundp obj) obj))))) | |
| 1061 (ignore-errors | |
| 1062 (save-excursion | |
| 1063 (save-restriction | |
| 1064 (narrow-to-region (max (point-min) (- (point) 1000)) | |
| 1065 (point-max)) | |
| 1066 (backward-up-list 1) | |
| 1067 (forward-char 1) | |
| 1068 (let (obj) | |
| 1069 (setq obj (read (current-buffer))) | |
| 1070 (and (symbolp obj) (fboundp obj) obj))))))) | |
| 1071 | |
| 442 | 1072 (defun function-at-event (event) |
| 1073 "Return the function whose name is around the position of EVENT. | |
| 1074 EVENT should be a mouse event. When calling from a popup or context menu, | |
| 1075 use `last-popup-menu-event' to find out where the mouse was clicked. | |
| 1076 \(You cannot use (interactive \"e\"), unfortunately. This returns a | |
| 1077 misc-user event.) | |
| 1078 | |
| 1079 If the event contains no position, or the position is not over text, or | |
| 1080 there is no function around that point, nil is returned." | |
| 1081 (if (and event (event-buffer event) (event-point event)) | |
| 1082 (save-excursion | |
| 1083 (set-buffer (event-buffer event)) | |
| 1084 (goto-char (event-point event)) | |
| 1085 (function-at-point)))) | |
| 1086 | |
| 428 | 1087 ;; Default to nil for the non-hackers? Not until we find a way to |
| 1088 ;; distinguish hackers from non-hackers automatically! | |
| 1089 (defcustom describe-function-show-arglist t | |
|
4695
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1090 "*If non-nil, describe-function will show the function's arglist." |
| 428 | 1091 :type 'boolean |
| 1092 :group 'help-appearance) | |
| 1093 | |
| 3368 | 1094 (define-obsolete-function-alias |
| 1095 ;; Moved to using the version in loadhist.el | |
| 1096 'describe-function-find-symbol | |
| 1097 'symbol-file) | |
| 428 | 1098 |
| 1099 (define-obsolete-function-alias | |
| 1100 'describe-function-find-file | |
| 3368 | 1101 'symbol-file) |
| 428 | 1102 |
| 1103 (defun describe-function (function) | |
| 1104 "Display the full documentation of FUNCTION (a symbol). | |
| 1105 When run interactively, it defaults to any function found by | |
| 1106 `function-at-point'." | |
| 1107 (interactive | |
| 1108 (let* ((fn (function-at-point)) | |
| 1109 (val (let ((enable-recursive-minibuffers t)) | |
| 1110 (completing-read | |
| 1111 (if fn | |
| 1112 (format (gettext "Describe function (default %s): ") | |
| 1113 fn) | |
| 1114 (gettext "Describe function: ")) | |
| 430 | 1115 obarray 'fboundp t nil 'function-history |
| 1116 (symbol-name fn))))) | |
| 1117 (list (intern val)))) | |
| 428 | 1118 (with-displaying-help-buffer |
| 1119 (lambda () | |
| 1120 (describe-function-1 function) | |
| 1121 ;; Return the text we displayed. | |
| 1122 (buffer-string nil nil standard-output)) | |
| 1123 (format "function `%s'" function))) | |
| 1124 | |
| 1125 (defun function-obsolete-p (function) | |
| 1126 "Return non-nil if FUNCTION is obsolete." | |
| 1127 (not (null (get function 'byte-obsolete-info)))) | |
| 1128 | |
| 1129 (defun function-obsoleteness-doc (function) | |
| 1130 "If FUNCTION is obsolete, return a string describing this." | |
| 1131 (let ((obsolete (get function 'byte-obsolete-info))) | |
| 1132 (if obsolete | |
| 1133 (format "Obsolete; %s" | |
| 1134 (if (stringp (car obsolete)) | |
| 1135 (car obsolete) | |
| 1136 (format "use `%s' instead." (car obsolete))))))) | |
| 1137 | |
| 1138 (defun function-compatible-p (function) | |
| 1139 "Return non-nil if FUNCTION is present for Emacs compatibility." | |
| 1140 (not (null (get function 'byte-compatible-info)))) | |
| 1141 | |
| 1142 (defun function-compatibility-doc (function) | |
| 1143 "If FUNCTION is Emacs compatible, return a string describing this." | |
| 1144 (let ((compatible (get function 'byte-compatible-info))) | |
| 1145 (if compatible | |
| 1146 (format "Emacs Compatible; %s" | |
| 1147 (if (stringp (car compatible)) | |
| 1148 (car compatible) | |
| 1149 (format "use `%s' instead." (car compatible))))))) | |
| 1150 | |
| 1151 ;Here are all the possibilities below spelled out, for the benefit | |
| 1152 ;of the I18N3 snarfer. | |
| 1153 ; | |
| 1154 ;(gettext "a built-in function") | |
| 1155 ;(gettext "an interactive built-in function") | |
| 1156 ;(gettext "a built-in macro") | |
| 1157 ;(gettext "an interactive built-in macro") | |
| 1158 ;(gettext "a compiled Lisp function") | |
| 1159 ;(gettext "an interactive compiled Lisp function") | |
| 1160 ;(gettext "a compiled Lisp macro") | |
| 1161 ;(gettext "an interactive compiled Lisp macro") | |
| 1162 ;(gettext "a Lisp function") | |
| 1163 ;(gettext "an interactive Lisp function") | |
| 1164 ;(gettext "a Lisp macro") | |
| 1165 ;(gettext "an interactive Lisp macro") | |
| 1166 ;(gettext "an autoloaded Lisp function") | |
| 1167 ;(gettext "an interactive autoloaded Lisp function") | |
| 1168 ;(gettext "an autoloaded Lisp macro") | |
| 1169 ;(gettext "an interactive autoloaded Lisp macro") | |
| 1170 | |
| 1171 ;; taken out of `describe-function-1' | |
| 1172 (defun function-arglist (function) | |
| 1173 "Return a string giving the argument list of FUNCTION. | |
| 1174 For example: | |
| 1175 | |
| 1176 (function-arglist 'function-arglist) | |
|
4694
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1177 => \"(function-arglist FUNCTION)\" |
| 428 | 1178 |
| 1179 This function is used by `describe-function-1' to list function | |
| 1180 arguments in the standard Lisp style." | |
| 440 | 1181 (let* ((fnc (indirect-function function)) |
| 1182 (fndef (if (eq (car-safe fnc) 'macro) | |
| 1183 (cdr fnc) | |
| 1184 fnc)) | |
| 428 | 1185 (arglist |
| 440 | 1186 (cond ((compiled-function-p fndef) |
| 1187 (compiled-function-arglist fndef)) | |
| 1188 ((eq (car-safe fndef) 'lambda) | |
| 1189 (nth 1 fndef)) | |
|
4695
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1190 ((or (subrp fndef) (eq 'autoload (car-safe fndef))) |
| 440 | 1191 (let* ((doc (documentation function)) |
| 3065 | 1192 (args (and doc |
| 1193 (string-match | |
|
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4601
diff
changeset
|
1194 "[\n\t ]*\narguments: ?(\\([^)]*\\))\n?\\'" |
| 440 | 1195 doc) |
|
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4601
diff
changeset
|
1196 (match-string 1 doc))) |
|
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4601
diff
changeset
|
1197 (args (and args (replace-in-string args |
|
4671
e9b88e997479
Deal with arglist newlines better, #'function-arglist, #'function-documentation
Aidan Kehoe <kehoea@parhasard.net>
parents:
4642
diff
changeset
|
1198 "[ ]*\\\\\n[ \t]*" |
|
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4601
diff
changeset
|
1199 " " t)))) |
| 440 | 1200 ;; If there are no arguments documented for the |
| 1201 ;; subr, rather don't print anything. | |
| 1202 (cond ((null args) t) | |
| 1203 ((equal args "") nil) | |
| 1204 (args)))) | |
|
4694
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1205 (t t))) |
|
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1206 (print-gensym nil)) |
| 428 | 1207 (cond ((listp arglist) |
| 1208 (prin1-to-string | |
|
4694
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1209 (cons function (loop |
|
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1210 for arg in arglist |
|
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1211 collect (if (memq arg '(&optional &rest)) |
|
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1212 arg |
|
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1213 (make-symbol (upcase (symbol-name |
|
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1214 arg)))))) |
|
2ac296807b88
Don't needlessly intern symbols, #'function-arglist, #'cl-function-arglist
Aidan Kehoe <kehoea@parhasard.net>
parents:
4671
diff
changeset
|
1215 |
| 428 | 1216 t)) |
| 1217 ((stringp arglist) | |
| 1218 (format "(%s %s)" function arglist))))) | |
| 1219 | |
| 1220 (defun function-documentation (function &optional strip-arglist) | |
| 1221 "Return a string giving the documentation for FUNCTION, if any. | |
| 1222 If the optional argument STRIP-ARGLIST is non-nil, remove the arglist | |
| 1223 part of the documentation of internal subroutines." | |
| 1224 (let ((doc (condition-case nil | |
| 1225 (or (documentation function) | |
| 1226 (gettext "not documented")) | |
| 2275 | 1227 (void-function "(alias for undefined function)") |
| 1228 (error "(unexpected error from `documention')")))) | |
|
4695
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1229 (when (and strip-arglist |
|
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1230 (string-match "[\n\t ]*\narguments: ?(\\([^)]*\\))\n?\\'" doc)) |
|
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1231 (setq doc (substring doc 0 (match-beginning 0))) |
|
fee33ab25966
Add arglist info for autoloaded functions and macros.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4694
diff
changeset
|
1232 (and (zerop (length doc)) (setq doc (gettext "not documented")))) |
| 428 | 1233 doc)) |
| 442 | 1234 |
| 462 | 1235 ;; replacement for `princ' that puts the text in the specified face, |
| 1236 ;; if possible | |
| 1237 (defun Help-princ-face (object face) | |
| 1238 (cond ((bufferp standard-output) | |
| 464 | 1239 (let ((opoint (point standard-output))) |
| 1240 (princ object) | |
| 1241 (put-nonduplicable-text-property opoint (point standard-output) | |
| 1242 'face face standard-output))) | |
| 1243 ((markerp standard-output) | |
| 1244 (let ((buf (marker-buffer standard-output)) | |
| 1245 (pos (marker-position standard-output))) | |
| 1246 (princ object) | |
| 1247 (put-nonduplicable-text-property | |
| 1248 pos (marker-position standard-output) 'face face buf))) | |
| 1779 | 1249 (t (princ object)))) |
| 462 | 1250 |
| 1251 ;; replacement for `prin1' that puts the text in the specified face, | |
| 1252 ;; if possible | |
| 1253 (defun Help-prin1-face (object face) | |
| 1254 (cond ((bufferp standard-output) | |
| 464 | 1255 (let ((opoint (point standard-output))) |
| 1256 (prin1 object) | |
| 1257 (put-nonduplicable-text-property opoint (point standard-output) | |
| 1258 'face face standard-output))) | |
| 1259 ((markerp standard-output) | |
| 1260 (let ((buf (marker-buffer standard-output)) | |
| 1261 (pos (marker-position standard-output))) | |
| 1262 (prin1 object) | |
| 1263 (put-nonduplicable-text-property | |
| 1264 pos (marker-position standard-output) 'face face buf))) | |
| 1779 | 1265 (t (prin1 object)))) |
| 462 | 1266 |
| 442 | 1267 (defvar help-symbol-regexp |
| 1268 (let ((sym-char "[+a-zA-Z0-9_:*]") | |
| 1269 (sym-char-no-dash "[-+a-zA-Z0-9_:*]")) | |
| 1270 (concat "\\(" | |
| 1271 ;; a symbol with a - in it. | |
| 1272 "\\<\\(" sym-char-no-dash "+\\(-" sym-char-no-dash "+\\)+\\)\\>" | |
| 1273 "\\|" | |
| 1274 "`\\(" sym-char "+\\)'" | |
| 1275 "\\)"))) | |
| 1276 | |
| 1277 (defun help-symbol-run-function-1 (ev ex fun) | |
| 1278 (let ((help-sticky-window | |
| 1279 ;; if we were called from a help buffer, make sure the new help | |
| 1280 ;; goes in the same window. | |
| 1281 (if (and (event-buffer ev) | |
| 1282 (symbol-value-in-buffer 'help-window-config | |
| 1283 (event-buffer ev))) | |
| 1284 (event-window ev) | |
| 1285 help-sticky-window))) | |
| 1286 (funcall fun (extent-property ex 'help-symbol)))) | |
| 1287 | |
| 1288 (defun help-symbol-run-function (fun) | |
| 1289 (let ((ex (extent-at-event last-popup-menu-event 'help-symbol))) | |
| 1290 (when ex | |
| 1291 (help-symbol-run-function-1 last-popup-menu-event ex fun)))) | |
| 1292 | |
| 1293 (defvar help-symbol-function-context-menu | |
| 462 | 1294 '(["View %_Documentation" (help-symbol-run-function 'describe-function)] |
| 4103 | 1295 ["Find %_Function Source" (help-symbol-run-function 'find-function) |
| 1296 (fboundp #'find-function)] | |
| 462 | 1297 ["Find %_Tag" (help-symbol-run-function 'find-tag)] |
| 442 | 1298 )) |
| 1299 | |
| 1300 (defvar help-symbol-variable-context-menu | |
| 462 | 1301 '(["View %_Documentation" (help-symbol-run-function 'describe-variable)] |
| 4103 | 1302 ["Find %_Variable Source" (help-symbol-run-function 'find-variable) |
| 1303 (fboundp #'find-variable)] | |
| 462 | 1304 ["Find %_Tag" (help-symbol-run-function 'find-tag)] |
| 442 | 1305 )) |
| 1306 | |
| 1307 (defvar help-symbol-function-and-variable-context-menu | |
| 462 | 1308 '(["View Function %_Documentation" (help-symbol-run-function |
| 442 | 1309 'describe-function)] |
| 1310 ["View Variable D%_ocumentation" (help-symbol-run-function | |
| 1311 'describe-variable)] | |
| 4103 | 1312 ["Find %_Function Source" (help-symbol-run-function 'find-function) |
| 1313 (fboundp #'find-function)] | |
| 1314 ["Find %_Variable Source" (help-symbol-run-function 'find-variable) | |
| 1315 (fboundp #'find-variable)] | |
| 462 | 1316 ["Find %_Tag" (help-symbol-run-function 'find-tag)] |
| 442 | 1317 )) |
| 1318 | |
| 1319 (defun frob-help-extents (buffer) | |
| 1320 ;; Look through BUFFER, starting at the buffer's point and continuing | |
| 1321 ;; till end of file, and find documented functions and variables. | |
| 1322 ;; any such symbol found is tagged with an extent, that sets up these | |
| 1323 ;; properties: | |
| 1324 ;; 1. mouse-face is 'highlight (so the extent gets highlighted on mouse over) | |
| 1325 ;; 2. help-symbol is the name of the symbol. | |
| 464 | 1326 ;; 3. face is 'hyper-apropos-hyperlink. |
| 462 | 1327 ;; 4. context-menu is a list of context menu items, specific to whether |
| 442 | 1328 ;; the symbol is a function, variable, or both. |
| 462 | 1329 ;; 5. activate-function will cause the function or variable to be described, |
| 442 | 1330 ;; replacing the existing help contents. |
| 1331 (save-excursion | |
| 1332 (set-buffer buffer) | |
| 1333 (let (b e name) | |
| 1334 (while (re-search-forward help-symbol-regexp nil t) | |
| 1335 (setq b (or (match-beginning 2) (match-beginning 4))) | |
| 1336 (setq e (or (match-end 2) (match-end 4))) | |
| 1337 (setq name (buffer-substring b e)) | |
| 1338 (let* ((sym (intern-soft name)) | |
| 1339 (var (and sym (boundp sym) | |
| 1340 (documentation-property sym | |
| 1341 'variable-documentation t))) | |
| 1342 (fun (and sym (fboundp sym) | |
| 2275 | 1343 (condition-case nil |
| 1344 (documentation sym t) | |
| 1345 (void-function "(alias for undefined function)") | |
| 1346 (error "(unexpected error from `documention')"))))) | |
| 442 | 1347 (when (or var fun) |
| 1348 (let ((ex (make-extent b e))) | |
| 622 | 1349 (require 'hyper-apropos) |
| 3368 | 1350 |
| 442 | 1351 (set-extent-property ex 'mouse-face 'highlight) |
| 1352 (set-extent-property ex 'help-symbol sym) | |
| 464 | 1353 (set-extent-property ex 'face 'hyper-apropos-hyperlink) |
| 442 | 1354 (set-extent-property |
| 1355 ex 'context-menu | |
| 1356 (cond ((and var fun) | |
| 1357 help-symbol-function-and-variable-context-menu) | |
| 1358 (var help-symbol-variable-context-menu) | |
| 1359 (fun help-symbol-function-context-menu))) | |
| 1360 (set-extent-property | |
| 1361 ex 'activate-function | |
| 1362 (if fun | |
| 1363 #'(lambda (ev ex) | |
| 1364 (help-symbol-run-function-1 ev ex 'describe-function)) | |
| 1365 #'(lambda (ev ex) | |
| 1366 (help-symbol-run-function-1 ev ex 'describe-variable)))) | |
| 1367 ))))))) ;; 11 parentheses! | |
| 428 | 1368 |
| 1369 (defun describe-function-1 (function &optional nodoc) | |
| 1370 "This function does the work for `describe-function'." | |
| 462 | 1371 (princ "`") |
| 1372 ;; (Help-princ-face function 'font-lock-function-name-face) overkill | |
| 1373 (princ function) | |
| 1374 (princ "' is ") | |
| 428 | 1375 (let* ((def function) |
|
4595
a1a8728fec10
Distinguish between special forms and subrs, #'describe-function-1.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4535
diff
changeset
|
1376 aliases file-name kbd-macro-p fndef macrop) |
| 428 | 1377 (while (and (symbolp def) (fboundp def)) |
| 1378 (when (not (eq def function)) | |
| 1379 (setq aliases | |
| 1380 (if aliases | |
| 1381 ;; I18N3 Need gettext due to concat | |
| 1382 (concat aliases | |
| 1383 (format | |
| 1384 "\n which is an alias for `%s', " | |
| 1385 (symbol-name def))) | |
| 1386 (format "an alias for `%s', " (symbol-name def))))) | |
| 1387 (setq def (symbol-function def))) | |
| 1388 (if (and (fboundp 'compiled-function-annotation) | |
| 1389 (compiled-function-p def)) | |
| 502 | 1390 (setq file-name (declare-fboundp (compiled-function-annotation def)))) |
| 428 | 1391 (if (eq 'macro (car-safe def)) |
| 1392 (setq fndef (cdr def) | |
| 1393 file-name (and (compiled-function-p (cdr def)) | |
| 1394 (fboundp 'compiled-function-annotation) | |
| 502 | 1395 (declare-fboundp |
| 1396 (compiled-function-annotation (cdr def)))) | |
| 428 | 1397 macrop t) |
| 1398 (setq fndef def)) | |
| 1399 (if aliases (princ aliases)) | |
| 1400 (let ((int #'(lambda (string an-p macro-p) | |
| 1401 (princ (format | |
| 1402 (gettext (concat | |
| 1403 (cond ((commandp def) | |
| 1404 "an interactive ") | |
| 1405 (an-p "an ") | |
| 1406 (t "a ")) | |
| 1407 "%s" | |
|
4595
a1a8728fec10
Distinguish between special forms and subrs, #'describe-function-1.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4535
diff
changeset
|
1408 (cond |
|
a1a8728fec10
Distinguish between special forms and subrs, #'describe-function-1.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4535
diff
changeset
|
1409 ((eq 'neither macro-p) |
|
a1a8728fec10
Distinguish between special forms and subrs, #'describe-function-1.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4535
diff
changeset
|
1410 "") |
|
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4601
diff
changeset
|
1411 (macro-p " macro") |
|
4595
a1a8728fec10
Distinguish between special forms and subrs, #'describe-function-1.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4535
diff
changeset
|
1412 (t " function")))) |
| 428 | 1413 string))))) |
| 1414 (cond ((or (stringp def) (vectorp def)) | |
| 1415 (princ "a keyboard macro.") | |
| 1416 (setq kbd-macro-p t)) | |
|
4595
a1a8728fec10
Distinguish between special forms and subrs, #'describe-function-1.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4535
diff
changeset
|
1417 ((special-form-p fndef) |
|
a1a8728fec10
Distinguish between special forms and subrs, #'describe-function-1.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4535
diff
changeset
|
1418 (funcall int "built-in special form" nil 'neither)) |
| 428 | 1419 ((subrp fndef) |
| 1420 (funcall int "built-in" nil macrop)) | |
| 1421 ((compiled-function-p fndef) | |
| 1422 (funcall int "compiled Lisp" nil macrop)) | |
| 1423 ((eq (car-safe fndef) 'lambda) | |
| 1424 (funcall int "Lisp" nil macrop)) | |
| 1425 ((eq (car-safe def) 'autoload) | |
| 1426 (funcall int "autoloaded Lisp" t (elt def 4))) | |
| 1427 ((and (symbolp def) (not (fboundp def))) | |
| 1428 (princ "a symbol with a void (unbound) function definition.")) | |
| 1429 (t | |
| 1430 nil))) | |
| 1431 (princ "\n") | |
| 1432 (or file-name | |
|
4535
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1433 (setq file-name (symbol-file function 'defun))) |
| 3368 | 1434 (when file-name |
| 1435 (princ " -- loaded from \"") | |
| 1436 (if (not (bufferp standard-output)) | |
| 1437 (princ file-name) | |
| 1438 (let ((opoint (point standard-output)) | |
| 1439 e) | |
| 1440 (require 'hyper-apropos) | |
| 1441 (princ file-name) | |
| 1442 (setq e (make-extent opoint (point standard-output) | |
| 1443 standard-output)) | |
| 1444 (set-extent-property e 'face 'hyper-apropos-hyperlink) | |
| 1445 (set-extent-property e 'mouse-face 'highlight) | |
| 1446 (set-extent-property e 'find-function-symbol function))) | |
| 1447 (princ "\"\n")) | |
| 428 | 1448 (if describe-function-show-arglist |
| 1449 (let ((arglist (function-arglist function))) | |
| 1450 (when arglist | |
| 464 | 1451 (require 'hyper-apropos) |
| 1452 (Help-princ-face arglist 'hyper-apropos-documentation) | |
| 428 | 1453 (terpri)))) |
| 1454 (terpri) | |
| 1455 (cond (kbd-macro-p | |
| 1456 (princ "These characters are executed:\n\n\t") | |
| 1457 (princ (key-description def)) | |
| 1458 (cond ((setq def (key-binding def)) | |
| 1459 (princ (format "\n\nwhich executes the command `%s'.\n\n" | |
| 1460 def)) | |
| 1461 (describe-function-1 def)))) | |
| 1462 (nodoc nil) | |
| 1463 (t | |
| 1464 ;; tell the user about obsoleteness. | |
| 1465 ;; If the function is obsolete and is aliased, don't | |
| 1466 ;; even bother to report the documentation, as a further | |
| 1467 ;; encouragement to use the new function. | |
| 1468 (let ((obsolete (function-obsoleteness-doc function)) | |
| 1469 (compatible (function-compatibility-doc function))) | |
| 1470 (when obsolete | |
| 1471 (princ obsolete) | |
| 1472 (terpri) | |
| 1473 (terpri)) | |
| 1474 (when compatible | |
| 1475 (princ compatible) | |
| 1476 (terpri) | |
| 1477 (terpri)) | |
| 1478 (unless (and obsolete aliases) | |
| 1479 (let ((doc (function-documentation function t))) | |
| 1480 (princ "Documentation:\n") | |
| 442 | 1481 (let ((oldp (point standard-output)) |
| 1482 newp) | |
| 1483 (princ doc) | |
| 1484 (setq newp (point standard-output)) | |
| 1485 (goto-char oldp standard-output) | |
| 1486 (frob-help-extents standard-output) | |
| 1487 (goto-char newp standard-output)) | |
| 428 | 1488 (unless (or (equal doc "") |
| 1489 (eq ?\n (aref doc (1- (length doc))))) | |
|
4335
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1490 (terpri))) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1491 (when (commandp function) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1492 (princ "\nInvoked with:\n") |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1493 (let ((global-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1494 (where-is-internal function global-map)) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1495 (global-tty-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1496 (where-is-internal function global-tty-map)) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1497 (global-window-system-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1498 (where-is-internal function global-window-system-map))) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1499 (if (or global-binding global-tty-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1500 global-window-system-binding) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1501 (if (and (equal global-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1502 global-tty-binding) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1503 (equal global-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1504 global-window-system-binding)) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1505 (princ |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1506 (substitute-command-keys |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1507 (format "\n\\[%s]" function))) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1508 (when (and global-window-system-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1509 (not (equal global-window-system-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1510 global-binding))) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1511 (princ |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1512 (format |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1513 "\n%s\n -- under window systems\n" |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1514 (mapconcat #'key-description |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1515 global-window-system-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1516 ", ")))) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1517 (when (and global-tty-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1518 (not (equal global-tty-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1519 global-binding))) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1520 (princ |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1521 (format |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1522 "\n%s\n -- under TTYs\n" |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1523 (mapconcat #'key-description |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1524 global-tty-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1525 ", ")))) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1526 (when global-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1527 (princ |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1528 (format |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1529 "\n%s\n -- generally (that is, unless\ |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1530 overridden by TTY- or |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1531 window-system-specific mappings)\n" |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1532 (mapconcat #'key-description |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1533 global-binding |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1534 ", "))))) |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1535 (princ (substitute-command-keys |
|
4ba890988caa
Within #'describe-function, say what commands are bound to.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4246
diff
changeset
|
1536 (format "\n\\[%s]" function)))))))))))) |
| 428 | 1537 |
| 1538 ;;; [Obnoxious, whining people who complain very LOUDLY on Usenet | |
| 1539 ;;; are binding this to keys.] | |
| 1540 (defun describe-function-arglist (function) | |
| 1541 (interactive (list (or (function-at-point) | |
| 1542 (error "no function call at point")))) | |
| 1543 (message nil) | |
| 1544 (message (function-arglist function))) | |
| 1545 | |
| 1546 (defun variable-at-point () | |
| 1547 (ignore-errors | |
| 1548 (with-syntax-table emacs-lisp-mode-syntax-table | |
| 1549 (save-excursion | |
| 1550 (or (not (zerop (skip-syntax-backward "_w"))) | |
| 1551 (eq (char-syntax (char-after (point))) ?w) | |
| 1552 (eq (char-syntax (char-after (point))) ?_) | |
| 1553 (forward-sexp -1)) | |
| 1554 (skip-chars-forward "'") | |
| 1555 (let ((obj (read (current-buffer)))) | |
| 1556 (and (symbolp obj) (boundp obj) obj)))))) | |
| 1557 | |
| 442 | 1558 (defun variable-at-event (event) |
| 1559 "Return the variable whose name is around the position of EVENT. | |
| 1560 EVENT should be a mouse event. When calling from a popup or context menu, | |
| 1561 use `last-popup-menu-event' to find out where the mouse was clicked. | |
| 1562 \(You cannot use (interactive \"e\"), unfortunately. This returns a | |
| 1563 misc-user event.) | |
| 1564 | |
| 1565 If the event contains no position, or the position is not over text, or | |
| 1566 there is no variable around that point, nil is returned." | |
| 1567 (if (and event (event-buffer event) (event-point event)) | |
| 1568 (save-excursion | |
| 1569 (set-buffer (event-buffer event)) | |
| 1570 (goto-char (event-point event)) | |
| 1571 (variable-at-point)))) | |
| 1572 | |
| 428 | 1573 (defun variable-obsolete-p (variable) |
| 1574 "Return non-nil if VARIABLE is obsolete." | |
| 1575 (not (null (get variable 'byte-obsolete-variable)))) | |
| 1576 | |
| 1577 (defun variable-obsoleteness-doc (variable) | |
| 1578 "If VARIABLE is obsolete, return a string describing this." | |
| 1579 (let ((obsolete (get variable 'byte-obsolete-variable))) | |
| 1580 (if obsolete | |
| 1581 (format "Obsolete; %s" | |
| 1582 (if (stringp obsolete) | |
| 1583 obsolete | |
| 1584 (format "use `%s' instead." obsolete)))))) | |
| 1585 | |
| 1586 (defun variable-compatible-p (variable) | |
| 1587 "Return non-nil if VARIABLE is Emacs compatible." | |
| 1588 (not (null (get variable 'byte-compatible-variable)))) | |
| 1589 | |
| 1590 (defun variable-compatibility-doc (variable) | |
| 1591 "If VARIABLE is Emacs compatible, return a string describing this." | |
| 1592 (let ((compatible (get variable 'byte-compatible-variable))) | |
| 1593 (if compatible | |
| 1594 (format "Emacs Compatible; %s" | |
| 1595 (if (stringp compatible) | |
| 1596 compatible | |
| 1597 (format "use `%s' instead." compatible)))))) | |
| 1598 | |
| 1599 (defun built-in-variable-doc (variable) | |
| 1600 "Return a string describing whether VARIABLE is built-in." | |
| 1601 (let ((type (built-in-variable-type variable))) | |
| 1602 (case type | |
| 1603 (integer "a built-in integer variable") | |
| 1604 (const-integer "a built-in constant integer variable") | |
| 1605 (boolean "a built-in boolean variable") | |
| 1606 (const-boolean "a built-in constant boolean variable") | |
| 1607 (object "a simple built-in variable") | |
| 1608 (const-object "a simple built-in constant variable") | |
| 1609 (const-specifier "a built-in constant specifier variable") | |
| 1610 (current-buffer "a built-in buffer-local variable") | |
| 1611 (const-current-buffer "a built-in constant buffer-local variable") | |
| 1612 (default-buffer "a built-in default buffer-local variable") | |
| 1613 (selected-console "a built-in console-local variable") | |
| 1614 (const-selected-console "a built-in constant console-local variable") | |
| 1615 (default-console "a built-in default console-local variable") | |
| 1616 (t | |
| 1617 (if type "an unknown type of built-in variable?" | |
| 1618 "a variable declared in Lisp"))))) | |
| 1619 | |
| 1620 (defun describe-variable (variable) | |
| 1621 "Display the full documentation of VARIABLE (a symbol)." | |
| 1622 (interactive | |
| 1623 (let* ((v (variable-at-point)) | |
| 1624 (val (let ((enable-recursive-minibuffers t)) | |
| 1625 (completing-read | |
| 1626 (if v | |
| 1627 (format "Describe variable (default %s): " v) | |
| 1628 (gettext "Describe variable: ")) | |
| 430 | 1629 obarray 'boundp t nil 'variable-history |
| 1630 (symbol-name v))))) | |
| 1631 (list (intern val)))) | |
| 428 | 1632 (with-displaying-help-buffer |
| 1633 (lambda () | |
| 1634 (let ((origvar variable) | |
| 1635 aliases) | |
| 1636 (let ((print-escape-newlines t)) | |
| 462 | 1637 (princ "`") |
| 1638 ;; (Help-princ-face (symbol-name variable) | |
| 502 | 1639 ;; 'font-lock-variable-name-face) overkill |
| 462 | 1640 (princ (symbol-name variable)) |
| 1641 (princ "' is ") | |
| 428 | 1642 (while (variable-alias variable) |
| 1643 (let ((newvar (variable-alias variable))) | |
| 1644 (if aliases | |
| 1645 ;; I18N3 Need gettext due to concat | |
| 1646 (setq aliases | |
| 1647 (concat aliases | |
| 1648 (format "\n which is an alias for `%s'," | |
| 1649 (symbol-name newvar)))) | |
| 1650 (setq aliases | |
| 1651 (format "an alias for `%s'," | |
| 1652 (symbol-name newvar)))) | |
| 1653 (setq variable newvar))) | |
| 1654 (if aliases | |
| 1655 (princ (format "%s" aliases))) | |
| 1656 (princ (built-in-variable-doc variable)) | |
| 1657 (princ ".\n") | |
| 3368 | 1658 (require 'hyper-apropos) |
|
4535
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
4506
diff
changeset
|
1659 (let ((file-name (symbol-file variable 'defvar)) |
| 3368 | 1660 opoint e) |
| 1661 (when file-name | |
| 1662 (princ " -- loaded from \"") | |
| 1663 (if (not (bufferp standard-output)) | |
| 1664 (princ file-name) | |
| 1665 (setq opoint (point standard-output)) | |
| 1666 (princ file-name) | |
| 1667 (setq e (make-extent opoint (point standard-output) | |
| 1668 standard-output)) | |
| 1669 (set-extent-property e 'face 'hyper-apropos-hyperlink) | |
| 1670 (set-extent-property e 'mouse-face 'highlight) | |
| 1671 (set-extent-property e 'find-variable-symbol variable)) | |
| 1672 (princ"\"\n"))) | |
| 428 | 1673 (princ "\nValue: ") |
| 464 | 1674 (if (not (boundp variable)) |
| 1675 (Help-princ-face "void\n" 'hyper-apropos-documentation) | |
| 1676 (Help-prin1-face (symbol-value variable) | |
| 1677 'hyper-apropos-documentation) | |
| 428 | 1678 (terpri)) |
| 1679 (terpri) | |
| 1680 (cond ((local-variable-p variable (current-buffer)) | |
| 1681 (let* ((void (cons nil nil)) | |
| 1682 (def (condition-case nil | |
| 1683 (default-value variable) | |
| 1684 (error void)))) | |
| 1685 (princ "This value is specific to the current buffer.\n") | |
| 1686 (if (local-variable-p variable nil) | |
| 1687 (princ "(Its value is local to each buffer.)\n")) | |
| 1688 (terpri) | |
| 1689 (if (if (eq def void) | |
| 1690 (boundp variable) | |
| 1691 (not (eq (symbol-value variable) def))) | |
| 1692 ;; #### I18N3 doesn't localize properly! | |
| 1693 (progn (princ "Default-value: ") | |
| 1694 (if (eq def void) | |
| 1695 (princ "void\n") | |
| 1696 (prin1 def) | |
| 1697 (terpri)) | |
| 1698 (terpri))))) | |
| 1699 ((local-variable-p variable (current-buffer) t) | |
| 1700 (princ "Setting it would make its value buffer-local.\n\n")))) | |
| 1701 (princ "Documentation:") | |
| 1702 (terpri) | |
| 1703 (let ((doc (documentation-property variable 'variable-documentation)) | |
| 1704 (obsolete (variable-obsoleteness-doc origvar)) | |
| 1705 (compatible (variable-compatibility-doc origvar))) | |
| 1706 (when obsolete | |
| 1707 (princ obsolete) | |
| 1708 (terpri) | |
| 1709 (terpri)) | |
| 1710 (when compatible | |
| 1711 (princ compatible) | |
| 1712 (terpri) | |
| 1713 (terpri)) | |
| 1714 ;; don't bother to print anything if variable is obsolete and aliased. | |
| 1715 (when (or (not obsolete) (not aliases)) | |
| 1716 (if doc | |
| 1717 ;; note: documentation-property calls substitute-command-keys. | |
| 442 | 1718 (let ((oldp (point standard-output)) |
| 1719 newp) | |
| 1720 (princ doc) | |
| 1721 (setq newp (point standard-output)) | |
| 1722 (goto-char oldp standard-output) | |
| 1723 (frob-help-extents standard-output) | |
| 1724 (goto-char newp standard-output)) | |
| 428 | 1725 (princ "not documented as a variable.")))) |
| 1726 (terpri))) | |
| 1727 (format "variable `%s'" variable))) | |
| 1728 | |
| 1729 (defun sorted-key-descriptions (keys &optional separator) | |
| 1730 "Sort and separate the key descriptions for KEYS. | |
| 1731 The sorting is done by length (shortest bindings first), and the bindings | |
| 1732 are separated with SEPARATOR (\", \" by default)." | |
| 1733 (mapconcat 'key-description | |
| 1734 (sort keys #'(lambda (x y) | |
| 1735 (< (length x) (length y)))) | |
| 1736 (or separator ", "))) | |
| 1737 | |
| 1738 (defun where-is (definition &optional insert) | |
| 1739 "Print message listing key sequences that invoke specified command. | |
| 1740 Argument is a command definition, usually a symbol with a function definition. | |
| 1741 When run interactively, it defaults to any function found by | |
| 1742 `function-at-point'. | |
| 1743 If INSERT (the prefix arg) is non-nil, insert the message in the buffer." | |
| 1744 (interactive | |
| 1745 (let ((fn (function-at-point)) | |
| 1746 (enable-recursive-minibuffers t) | |
| 1747 val) | |
| 1748 (setq val (read-command | |
| 1749 (if fn (format "Where is command (default %s): " fn) | |
| 456 | 1750 "Where is command: ") |
| 1751 (and fn (symbol-name fn)))) | |
| 428 | 1752 (list (if (equal (symbol-name val) "") |
| 1753 fn val) | |
| 1754 current-prefix-arg))) | |
| 1755 (let ((keys (where-is-internal definition))) | |
| 1756 (if keys | |
| 1757 (if insert | |
| 1758 (princ (format "%s (%s)" (sorted-key-descriptions keys) | |
| 1759 definition) (current-buffer)) | |
| 1760 (message "%s is on %s" definition (sorted-key-descriptions keys))) | |
| 1761 (if insert | |
| 1762 (princ (format (if (commandp definition) "M-x %s RET" | |
| 1763 "M-: (%s ...)") definition) (current-buffer)) | |
| 1764 (message "%s is not on any keys" definition)))) | |
| 1765 nil) | |
| 1766 | |
| 1767 ;; `locate-library' moved to "packages.el" | |
| 1768 | |
| 1769 | |
| 1770 ;; Functions ported from C into Lisp in XEmacs | |
| 1771 | |
| 1772 (defun describe-syntax () | |
| 1773 "Describe the syntax specifications in the syntax table. | |
| 1774 The descriptions are inserted in a buffer, which is then displayed." | |
| 1775 (interactive) | |
| 1776 (with-displaying-help-buffer | |
| 1777 (lambda () | |
| 1778 ;; defined in syntax.el | |
| 1779 (describe-syntax-table (syntax-table) standard-output)) | |
| 1780 (format "syntax-table for %s" major-mode))) | |
| 1781 | |
| 1782 (defun list-processes () | |
| 1783 "Display a list of all processes. | |
| 1784 \(Any processes listed as Exited or Signaled are actually eliminated | |
| 1785 after the listing is made.)" | |
| 1786 (interactive) | |
| 1787 (with-output-to-temp-buffer "*Process List*" | |
| 1788 (set-buffer standard-output) | |
| 1789 (buffer-disable-undo standard-output) | |
| 1790 (make-local-variable 'truncate-lines) | |
| 1791 (setq truncate-lines t) | |
| 1792 ;; 00000000001111111111222222222233333333334444444444 | |
| 1793 ;; 01234567890123456789012345678901234567890123456789 | |
| 1794 ;; rewritten for I18N3. This one should stay rewritten | |
| 1795 ;; so that the dashes will line up properly. | |
| 1796 (princ "Proc Status Buffer Tty Command\n---- ------ ------ --- -------\n") | |
| 1797 (let ((tail (process-list))) | |
| 1798 (while tail | |
| 1799 (let* ((p (car tail)) | |
| 1800 (pid (process-id p)) | |
| 1801 (s (process-status p))) | |
| 1802 (setq tail (cdr tail)) | |
| 1803 (princ (format "%-13s" (process-name p))) | |
| 1804 (princ s) | |
| 1805 (if (and (eq s 'exit) (/= (process-exit-status p) 0)) | |
| 1806 (princ (format " %d" (process-exit-status p)))) | |
| 1807 (if (memq s '(signal exit closed)) | |
| 1808 ;; Do delete-exited-processes' work | |
| 1809 (delete-process p)) | |
| 1810 (indent-to 22 1) ;#### | |
| 1811 (let ((b (process-buffer p))) | |
| 1812 (cond ((not b) | |
| 1813 (princ "(none)")) | |
| 1814 ((not (buffer-name b)) | |
| 1815 (princ "(killed)")) | |
| 1816 (t | |
| 1817 (princ (buffer-name b))))) | |
| 1818 (indent-to 37 1) ;#### | |
| 1819 (let ((tn (process-tty-name p))) | |
| 1820 (cond ((not tn) | |
| 1821 (princ "(none)")) | |
| 1822 (t | |
| 1823 (princ (format "%s" tn))))) | |
| 1824 (indent-to 49 1) ;#### | |
| 1825 (if (not (integerp pid)) | |
| 1826 (progn | |
| 1827 (princ "network stream connection ") | |
| 1828 (princ (car pid)) | |
| 1829 (princ "@") | |
| 1830 (princ (cdr pid))) | |
| 1831 (let ((cmd (process-command p))) | |
| 1832 (while cmd | |
| 1833 (princ (car cmd)) | |
| 1834 (setq cmd (cdr cmd)) | |
| 1835 (if cmd (princ " "))))) | |
| 1836 (terpri)))))) | |
| 1837 | |
| 440 | 1838 ;; Stop gap for 21.0 until we do help-char etc properly. |
| 428 | 1839 (defun help-keymap-with-help-key (keymap form) |
| 1840 "Return a copy of KEYMAP with an help-key binding according to help-char | |
| 1841 invoking FORM like help-form. An existing binding is not overridden. | |
| 1842 If FORM is nil then no binding is made." | |
| 1843 (let ((map (copy-keymap keymap)) | |
| 1844 (key (if (characterp help-char) | |
| 1845 (vector (character-to-event help-char)) | |
| 1846 help-char))) | |
| 1847 (when (and form key (not (lookup-key map key))) | |
| 1848 (define-key map key | |
| 1849 `(lambda () (interactive) (help-print-help-form ,form)))) | |
| 1850 map)) | |
| 1851 | |
| 1852 (defun help-print-help-form (form) | |
| 1853 (let ((string (eval form))) | |
| 1854 (if (stringp string) | |
| 1855 (with-displaying-help-buffer | |
| 1856 (insert string))))) | |
| 1857 | |
| 3368 | 1858 (defun help-find-source-or-scroll-up (&optional pos) |
| 1859 "Follow any cross reference to source code; if none, scroll up. " | |
| 1860 (interactive "d") | |
| 1861 (let ((e (extent-at pos nil 'find-function-symbol))) | |
| 4103 | 1862 (if (and-fboundp #'find-function e) |
| 1863 (with-fboundp #'find-function | |
| 1864 (find-function (extent-property e 'find-function-symbol))) | |
| 3368 | 1865 (setq e (extent-at pos nil 'find-variable-symbol)) |
| 4103 | 1866 (if (and-fboundp #'find-variable e) |
| 1867 (with-fboundp #'find-variable | |
| 1868 (find-variable (extent-property e 'find-variable-symbol))) | |
| 1869 (scroll-up 1))))) | |
| 3368 | 1870 |
| 1871 (defun help-mouse-find-source-or-track (event) | |
| 1872 "Follow any cross reference to source code under the mouse; | |
| 1873 if none, call mouse-track. " | |
| 1874 (interactive "e") | |
| 1875 (mouse-set-point event) | |
| 1876 (let ((e (extent-at (point) nil 'find-function-symbol))) | |
| 4103 | 1877 (if (and-fboundp #'find-function e) |
| 1878 (with-fboundp #'find-function | |
| 1879 (find-function (extent-property e 'find-function-symbol))) | |
| 3368 | 1880 (setq e (extent-at (point) nil 'find-variable-symbol)) |
| 4103 | 1881 (if (and-fboundp #'find-variable e) |
| 1882 (with-fboundp #'find-variable | |
| 1883 (find-variable (extent-property e 'find-variable-symbol))) | |
| 3368 | 1884 (mouse-track event))))) |
| 1885 | |
|
4506
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1886 (define-minor-mode temp-buffer-resize-mode |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1887 "Toggle the mode which makes windows smaller for temporary buffers. |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1888 With prefix argument ARG, turn the resizing of windows displaying temporary |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1889 buffers on if ARG is positive or off otherwise. |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1890 This makes the window the right height for its contents, but never |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1891 less than `window-min-height' nor a higher proportion of its frame than |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1892 `temp-buffer-max-height'. (Note the differing semantics of the latter |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1893 versus GNU Emacs, where `temp-buffer-max-height' is an integer number of |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1894 lines.) |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1895 This applies to `help', `apropos' and `completion' buffers, and some others." |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1896 :global t :group 'help |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1897 ;; XEmacs; our implementation of this is very different. |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1898 (setq temp-buffer-shrink-to-fit temp-buffer-resize-mode)) |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1899 |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1900 ;; GNU name for this function. |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1901 (defalias 'resize-temp-buffer-window 'shrink-window-if-larger-than-buffer) |
|
bd28481bb0e1
Port #'window-buffer-height, #'fit-window-to-buffer, & window, buf, functions.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4443
diff
changeset
|
1902 |
| 428 | 1903 ;;; help.el ends here |
