* viper-ex.el: Patch by Samuel Padgett. Copyright papers received.
[emacs.git] / lisp / apropos.el
blob0fa0e83b82db8b33cade77cb4c9ad97c7f50bec8
1 ;;; apropos.el --- apropos commands for users and programmers
3 ;; Copyright (C) 1989, 1994, 1995, 2001 Free Software Foundation, Inc.
5 ;; Author: Joe Wells <jbw@bigbird.bu.edu>
6 ;; Rewritten: Daniel Pfeiffer <occitan@esperanto.org>
7 ;; Keywords: help
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it 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.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;; The ideas for this package were derived from the C code in
29 ;; src/keymap.c and elsewhere. The functions in this file should
30 ;; always be byte-compiled for speed. Someone should rewrite this in
31 ;; C (as part of src/keymap.c) for speed.
33 ;; The idea for super-apropos is based on the original implementation
34 ;; by Lynn Slater <lrs@esl.com>.
36 ;; History:
37 ;; Fixed bug, current-local-map can return nil.
38 ;; Change, doesn't calculate key-bindings unless needed.
39 ;; Added super-apropos capability, changed print functions.
40 ;;; Made fast-apropos and super-apropos share code.
41 ;;; Sped up fast-apropos again.
42 ;; Added apropos-do-all option.
43 ;;; Added fast-command-apropos.
44 ;; Changed doc strings to comments for helping functions.
45 ;;; Made doc file buffer read-only, buried it.
46 ;; Only call substitute-command-keys if do-all set.
48 ;; Optionally use configurable faces to make the output more legible.
49 ;; Differentiate between command, function and macro.
50 ;; Apropos-command (ex command-apropos) does cmd and optionally user var.
51 ;; Apropos shows all 3 aspects of symbols (fn, var and plist)
52 ;; Apropos-documentation (ex super-apropos) now finds all it should.
53 ;; New apropos-value snoops through all values and optionally plists.
54 ;; Reading DOC file doesn't load nroff.
55 ;; Added hypertext following of documentation, mouse-2 on variable gives value
56 ;; from buffer in active window.
58 ;;; Code:
60 (require 'button)
62 (defgroup apropos nil
63 "Apropos commands for users and programmers"
64 :group 'help
65 :prefix "apropos")
67 ;; I see a degradation of maybe 10-20% only.
68 (defcustom apropos-do-all nil
69 "*Whether the apropos commands should do more.
71 Slows them down more or less. Set this non-nil if you have a fast machine."
72 :group 'apropos
73 :type 'boolean)
76 (defcustom apropos-symbol-face 'bold
77 "*Face for symbol name in Apropos output, or nil for none."
78 :group 'apropos
79 :type 'face)
81 (defcustom apropos-keybinding-face 'underline
82 "*Face for lists of keybinding in Apropos output, or nil for none."
83 :group 'apropos
84 :type 'face)
86 (defcustom apropos-label-face 'italic
87 "*Face for label (`Command', `Variable' ...) in Apropos output.
88 A value of nil means don't use any special font for them, and also
89 turns off mouse highlighting."
90 :group 'apropos
91 :type 'face)
93 (defcustom apropos-property-face 'bold-italic
94 "*Face for property name in apropos output, or nil for none."
95 :group 'apropos
96 :type 'face)
98 (defcustom apropos-match-face 'secondary-selection
99 "*Face for matching text in Apropos documentation/value, or nil for none.
100 This applies when you look for matches in the documentation or variable value
101 for the regexp; the part that matches gets displayed in this font."
102 :group 'apropos
103 :type 'face)
106 (defvar apropos-mode-map
107 (let ((map (make-sparse-keymap)))
108 (set-keymap-parent map button-buffer-map)
109 ;; Use `apropos-follow' instead of just using the button
110 ;; definition of RET, so that users can use it anywhere in an
111 ;; apropos item, not just on top of a button.
112 (define-key map "\C-m" 'apropos-follow)
113 (define-key map " " 'scroll-up)
114 (define-key map "\177" 'scroll-down)
115 (define-key map "q" 'quit-window)
116 map)
117 "Keymap used in Apropos mode.")
119 (defvar apropos-mode-hook nil
120 "*Hook run when mode is turned on.")
122 (defvar apropos-regexp nil
123 "Regexp used in current apropos run.")
125 (defvar apropos-files-scanned ()
126 "List of elc files already scanned in current run of `apropos-documentation'.")
128 (defvar apropos-accumulator ()
129 "Alist of symbols already found in current apropos run.")
131 (defvar apropos-item ()
132 "Current item in or for `apropos-accumulator'.")
135 ;;; Button types used by apropos
137 (define-button-type 'apropos-symbol
138 'face apropos-symbol-face
139 'help-echo "mouse-2, RET: Display more help on this symbol"
140 'action #'apropos-symbol-button-display-help
141 'skip t)
143 (defun apropos-symbol-button-display-help (button)
144 "Display further help for the `apropos-symbol' button BUTTON."
145 (button-activate
146 (or (apropos-next-label-button (button-start button))
147 (error "There is nothing to follow for `%s'" (button-label button)))))
149 (define-button-type 'apropos-function
150 'apropos-label "Function"
151 'action (lambda (button)
152 (describe-function (button-get button 'apropos-symbol)))
153 'help-echo "mouse-2, RET: Display more help on this function")
154 (define-button-type 'apropos-macro
155 'apropos-label "Macro"
156 'action (lambda (button)
157 (describe-function (button-get button 'apropos-symbol)))
158 'help-echo "mouse-2, RET: Display more help on this macro")
159 (define-button-type 'apropos-command
160 'apropos-label "Command"
161 'action (lambda (button)
162 (describe-function (button-get button 'apropos-symbol)))
163 'help-echo "mouse-2, RET: Display more help on this command")
165 ;; We used to use `customize-variable-other-window' instead for a
166 ;; customizable variable, but that is slow. It is better to show an
167 ;; ordinary help buffer and let the user click on the customization
168 ;; button in that buffer, if he wants to.
169 ;; Likewise for `customize-face-other-window'.
170 (define-button-type 'apropos-variable
171 'apropos-label "Variable"
172 'help-echo "mouse-2, RET: Display more help on this variable"
173 'action (lambda (button)
174 (describe-variable (button-get button 'apropos-symbol))))
176 (define-button-type 'apropos-face
177 'apropos-label "Face"
178 'help-echo "mouse-2, RET: Display more help on this face"
179 'action (lambda (button)
180 (describe-face (button-get button 'apropos-symbol))))
182 (define-button-type 'apropos-group
183 'apropos-label "Group"
184 'help-echo "mouse-2, RET: Display more help on this group"
185 'action (lambda (button)
186 (customize-variable-other-window
187 (button-get button 'apropos-symbol))))
189 (define-button-type 'apropos-widget
190 'apropos-label "Widget"
191 'help-echo "mouse-2, RET: Display more help on this widget"
192 'action (lambda (button)
193 (widget-browse-other-window (button-get button 'apropos-symbol))))
195 (define-button-type 'apropos-plist
196 'apropos-label "Plist"
197 'help-echo "mouse-2, RET: Display more help on this plist"
198 'action (lambda (button)
199 (apropos-describe-plist (button-get button 'apropos-symbol))))
201 (defun apropos-next-label-button (pos)
202 "Return the next apropos label button after POS, or nil if there's none.
203 Will also return nil if more than one `apropos-symbol' button is encountered
204 before finding a label."
205 (let* ((button (next-button pos t))
206 (already-hit-symbol nil)
207 (label (and button (button-get button 'apropos-label)))
208 (type (and button (button-get button 'type))))
209 (while (and button
210 (not label)
211 (or (not (eq type 'apropos-symbol))
212 (not already-hit-symbol)))
213 (when (eq type 'apropos-symbol)
214 (setq already-hit-symbol t))
215 (setq button (next-button (button-start button)))
216 (when button
217 (setq label (button-get button 'apropos-label))
218 (setq type (button-get button 'type))))
219 (and label button)))
222 ;;;###autoload
223 (define-derived-mode apropos-mode fundamental-mode "Apropos"
224 "Major mode for following hyperlinks in output of apropos commands.
226 \\{apropos-mode-map}")
228 ;;;###autoload
229 (defun apropos-variable (regexp &optional do-all)
230 "Show user variables that match REGEXP.
231 With optional prefix DO-ALL or if `apropos-do-all' is non-nil, also show
232 normal variables."
233 (interactive (list (read-string
234 (concat "Apropos "
235 (if (or current-prefix-arg apropos-do-all)
236 "variable"
237 "user option")
238 " (regexp): "))
239 current-prefix-arg))
240 (apropos-command regexp nil
241 (if (or do-all apropos-do-all)
242 #'(lambda (symbol)
243 (and (boundp symbol)
244 (get symbol 'variable-documentation)))
245 'user-variable-p)))
247 ;; For auld lang syne:
248 ;;;###autoload
249 (fset 'command-apropos 'apropos-command)
250 ;;;###autoload
251 (defun apropos-command (apropos-regexp &optional do-all var-predicate)
252 "Show commands (interactively callable functions) that match APROPOS-REGEXP.
253 With optional prefix DO-ALL, or if `apropos-do-all' is non-nil, also show
254 noninteractive functions.
256 If VAR-PREDICATE is non-nil, show only variables, and only those that
257 satisfy the predicate VAR-PREDICATE."
258 (interactive (list (read-string (concat
259 "Apropos command "
260 (if (or current-prefix-arg
261 apropos-do-all)
262 "or function ")
263 "(regexp): "))
264 current-prefix-arg))
265 (let ((message
266 (let ((standard-output (get-buffer-create "*Apropos*")))
267 (print-help-return-message 'identity))))
268 (or do-all (setq do-all apropos-do-all))
269 (setq apropos-accumulator
270 (apropos-internal apropos-regexp
271 (or var-predicate
272 (if do-all 'functionp 'commandp))))
273 (let ((tem apropos-accumulator))
274 (while tem
275 (if (get (car tem) 'apropos-inhibit)
276 (setq apropos-accumulator (delq (car tem) apropos-accumulator)))
277 (setq tem (cdr tem))))
278 (let ((p apropos-accumulator)
279 doc symbol)
280 (while p
281 (setcar p (list
282 (setq symbol (car p))
283 (unless var-predicate
284 (if (functionp symbol)
285 (if (setq doc (documentation symbol t))
286 (substring doc 0 (string-match "\n" doc))
287 "(not documented)")))
288 (and var-predicate
289 (funcall var-predicate symbol)
290 (if (setq doc (documentation-property
291 symbol 'variable-documentation t))
292 (substring doc 0
293 (string-match "\n" doc))))))
294 (setq p (cdr p))))
295 (and (apropos-print t nil)
296 message
297 (message message))))
300 ;;;###autoload
301 (defun apropos (apropos-regexp &optional do-all)
302 "Show all bound symbols whose names match APROPOS-REGEXP.
303 With optional prefix DO-ALL or if `apropos-do-all' is non-nil, also
304 show unbound symbols and key bindings, which is a little more
305 time-consuming. Returns list of symbols and documentation found."
306 (interactive "sApropos symbol (regexp): \nP")
307 (setq apropos-accumulator
308 (apropos-internal apropos-regexp
309 (and (not do-all)
310 (not apropos-do-all)
311 (lambda (symbol)
312 (or (fboundp symbol)
313 (boundp symbol)
314 (facep symbol)
315 (symbol-plist symbol))))))
316 (let ((tem apropos-accumulator))
317 (while tem
318 (if (get (car tem) 'apropos-inhibit)
319 (setq apropos-accumulator (delq (car tem) apropos-accumulator)))
320 (setq tem (cdr tem))))
321 (let ((p apropos-accumulator)
322 symbol doc properties)
323 (while p
324 (setcar p (list
325 (setq symbol (car p))
326 (when (fboundp symbol)
327 (if (setq doc (condition-case nil
328 (documentation symbol t)
329 (void-function
330 "(alias for undefined function)")))
331 (substring doc 0 (string-match "\n" doc))
332 "(not documented)"))
333 (when (boundp symbol)
334 (if (setq doc (documentation-property
335 symbol 'variable-documentation t))
336 (substring doc 0 (string-match "\n" doc))
337 "(not documented)"))
338 (when (setq properties (symbol-plist symbol))
339 (setq doc (list (car properties)))
340 (while (setq properties (cdr (cdr properties)))
341 (setq doc (cons (car properties) doc)))
342 (mapconcat #'symbol-name (nreverse doc) " "))
343 (when (get symbol 'widget-type)
344 (if (setq doc (documentation-property
345 symbol 'widget-documentation t))
346 (substring doc 0
347 (string-match "\n" doc))
348 "(not documented)"))
349 (when (facep symbol)
350 (if (setq doc (documentation-property
351 symbol 'face-documentation t))
352 (substring doc 0
353 (string-match "\n" doc))
354 "(not documented)"))
355 (when (get symbol 'custom-group)
356 (if (setq doc (documentation-property
357 symbol 'group-documentation t))
358 (substring doc 0
359 (string-match "\n" doc))
360 "(not documented)"))))
361 (setq p (cdr p))))
362 (apropos-print
363 (or do-all apropos-do-all)
364 nil))
367 ;;;###autoload
368 (defun apropos-value (apropos-regexp &optional do-all)
369 "Show all symbols whose value's printed image matches APROPOS-REGEXP.
370 With optional prefix DO-ALL or if `apropos-do-all' is non-nil, also looks
371 at the function and at the names and values of properties.
372 Returns list of symbols and values found."
373 (interactive "sApropos value (regexp): \nP")
374 (or do-all (setq do-all apropos-do-all))
375 (setq apropos-accumulator ())
376 (let (f v p)
377 (mapatoms
378 (lambda (symbol)
379 (setq f nil v nil p nil)
380 (or (memq symbol '(apropos-regexp do-all apropos-accumulator
381 symbol f v p))
382 (setq v (apropos-value-internal 'boundp symbol 'symbol-value)))
383 (if do-all
384 (setq f (apropos-value-internal 'fboundp symbol 'symbol-function)
385 p (apropos-format-plist symbol "\n " t)))
386 (if (or f v p)
387 (setq apropos-accumulator (cons (list symbol f v p)
388 apropos-accumulator))))))
389 (apropos-print nil "\n----------------\n"))
392 ;;;###autoload
393 (defun apropos-documentation (apropos-regexp &optional do-all)
394 "Show symbols whose documentation contain matches for APROPOS-REGEXP.
395 With optional prefix DO-ALL or if `apropos-do-all' is non-nil, also use
396 documentation that is not stored in the documentation file and show key
397 bindings.
398 Returns list of symbols and documentation found."
399 (interactive "sApropos documentation (regexp): \nP")
400 (or do-all (setq do-all apropos-do-all))
401 (setq apropos-accumulator () apropos-files-scanned ())
402 (let ((standard-input (get-buffer-create " apropos-temp"))
403 f v)
404 (unwind-protect
405 (save-excursion
406 (set-buffer standard-input)
407 (apropos-documentation-check-doc-file)
408 (if do-all
409 (mapatoms
410 (lambda (symbol)
411 (setq f (apropos-safe-documentation symbol)
412 v (get symbol 'variable-documentation))
413 (if (integerp v) (setq v))
414 (setq f (apropos-documentation-internal f)
415 v (apropos-documentation-internal v))
416 (if (or f v)
417 (if (setq apropos-item
418 (cdr (assq symbol apropos-accumulator)))
419 (progn
420 (if f
421 (setcar apropos-item f))
422 (if v
423 (setcar (cdr apropos-item) v)))
424 (setq apropos-accumulator
425 (cons (list symbol f v)
426 apropos-accumulator)))))))
427 (apropos-print nil "\n----------------\n"))
428 (kill-buffer standard-input))))
431 (defun apropos-value-internal (predicate symbol function)
432 (if (funcall predicate symbol)
433 (progn
434 (setq symbol (prin1-to-string (funcall function symbol)))
435 (if (string-match apropos-regexp symbol)
436 (progn
437 (if apropos-match-face
438 (put-text-property (match-beginning 0) (match-end 0)
439 'face apropos-match-face
440 symbol))
441 symbol)))))
443 (defun apropos-documentation-internal (doc)
444 (if (consp doc)
445 (apropos-documentation-check-elc-file (car doc))
446 (and doc
447 (string-match apropos-regexp doc)
448 (progn
449 (if apropos-match-face
450 (put-text-property (match-beginning 0)
451 (match-end 0)
452 'face apropos-match-face
453 (setq doc (copy-sequence doc))))
454 doc))))
456 (defun apropos-format-plist (pl sep &optional compare)
457 (setq pl (symbol-plist pl))
458 (let (p p-out)
459 (while pl
460 (setq p (format "%s %S" (car pl) (nth 1 pl)))
461 (if (or (not compare) (string-match apropos-regexp p))
462 (if apropos-property-face
463 (put-text-property 0 (length (symbol-name (car pl)))
464 'face apropos-property-face p))
465 (setq p nil))
466 (if p
467 (progn
468 (and compare apropos-match-face
469 (put-text-property (match-beginning 0) (match-end 0)
470 'face apropos-match-face
472 (setq p-out (concat p-out (if p-out sep) p))))
473 (setq pl (nthcdr 2 pl)))
474 p-out))
477 ;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name.
479 (defun apropos-documentation-check-doc-file ()
480 (let (type symbol (sepa 2) sepb beg end)
481 (insert ?\^_)
482 (backward-char)
483 (insert-file-contents (concat doc-directory internal-doc-file-name))
484 (forward-char)
485 (while (save-excursion
486 (setq sepb (search-forward "\^_"))
487 (not (eobp)))
488 (beginning-of-line 2)
489 (if (save-restriction
490 (narrow-to-region (point) (1- sepb))
491 (re-search-forward apropos-regexp nil t))
492 (progn
493 (setq beg (match-beginning 0)
494 end (point))
495 (goto-char (1+ sepa))
496 (or (setq type (if (eq ?F (preceding-char))
497 1 ; function documentation
498 2) ; variable documentation
499 symbol (read)
500 beg (- beg (point) 1)
501 end (- end (point) 1)
502 doc (buffer-substring (1+ (point)) (1- sepb))
503 apropos-item (assq symbol apropos-accumulator))
504 (setq apropos-item (list symbol nil nil)
505 apropos-accumulator (cons apropos-item
506 apropos-accumulator)))
507 (if apropos-match-face
508 (put-text-property beg end 'face apropos-match-face doc))
509 (setcar (nthcdr type apropos-item) doc)))
510 (setq sepa (goto-char sepb)))))
512 (defun apropos-documentation-check-elc-file (file)
513 (if (member file apropos-files-scanned)
515 (let (symbol doc beg end this-is-a-variable)
516 (setq apropos-files-scanned (cons file apropos-files-scanned))
517 (erase-buffer)
518 (insert-file-contents file)
519 (while (search-forward "\n#@" nil t)
520 ;; Read the comment length, and advance over it.
521 (setq end (read)
522 beg (1+ (point))
523 end (+ (point) end -1))
524 (forward-char)
525 (if (save-restriction
526 ;; match ^ and $ relative to doc string
527 (narrow-to-region beg end)
528 (re-search-forward apropos-regexp nil t))
529 (progn
530 (goto-char (+ end 2))
531 (setq doc (buffer-substring beg end)
532 end (- (match-end 0) beg)
533 beg (- (match-beginning 0) beg)
534 this-is-a-variable (looking-at "(def\\(var\\|const\\) ")
535 symbol (progn
536 (skip-chars-forward "(a-z")
537 (forward-char)
538 (read))
539 symbol (if (consp symbol)
540 (nth 1 symbol)
541 symbol))
542 (if (if this-is-a-variable
543 (get symbol 'variable-documentation)
544 (and (fboundp symbol) (apropos-safe-documentation symbol)))
545 (progn
546 (or (setq apropos-item (assq symbol apropos-accumulator))
547 (setq apropos-item (list symbol nil nil)
548 apropos-accumulator (cons apropos-item
549 apropos-accumulator)))
550 (if apropos-match-face
551 (put-text-property beg end 'face apropos-match-face
552 doc))
553 (setcar (nthcdr (if this-is-a-variable 2 1)
554 apropos-item)
555 doc)))))))))
559 (defun apropos-safe-documentation (function)
560 "Like `documentation', except it avoids calling `get_doc_string'.
561 Will return nil instead."
562 (while (and function (symbolp function))
563 (setq function (if (fboundp function)
564 (symbol-function function))))
565 (if (eq (car-safe function) 'macro)
566 (setq function (cdr function)))
567 (setq function (if (byte-code-function-p function)
568 (if (> (length function) 4)
569 (aref function 4))
570 (if (eq (car-safe function) 'autoload)
571 (nth 2 function)
572 (if (eq (car-safe function) 'lambda)
573 (if (stringp (nth 2 function))
574 (nth 2 function)
575 (if (stringp (nth 3 function))
576 (nth 3 function)))))))
577 (if (integerp function)
579 function))
582 (defun apropos-print (do-keys spacing)
583 "Output result of apropos searching into buffer `*Apropos*'.
584 The value of `apropos-accumulator' is the list of items to output.
585 Each element should have the format (SYMBOL FN-DOC VAR-DOC [PLIST-DOC]).
586 The return value is the list that was in `apropos-accumulator', sorted
587 alphabetically by symbol name; but this function also sets
588 `apropos-accumulator' to nil before returning.
590 If SPACING is non-nil, it should be a string;
591 separate items with that string."
592 (if (null apropos-accumulator)
593 (message "No apropos matches for `%s'" apropos-regexp)
594 (setq apropos-accumulator
595 (sort apropos-accumulator (lambda (a b)
596 (string-lessp (car a) (car b)))))
597 (with-output-to-temp-buffer "*Apropos*"
598 (let ((p apropos-accumulator)
599 (old-buffer (current-buffer))
600 symbol item)
601 (set-buffer standard-output)
602 (apropos-mode)
603 (if (display-mouse-p)
604 (insert "If moving the mouse over text changes the text's color,\n"
605 (substitute-command-keys
606 "you can click \\[push-button] on that text to get more information.\n")))
607 (insert "In this buffer, go to the name of the command, or function,"
608 " or variable,\n"
609 (substitute-command-keys
610 "and type \\[apropos-follow] to get full documentation.\n\n"))
611 (while (consp p)
612 (when (and spacing (not (bobp)))
613 (princ spacing))
614 (setq apropos-item (car p)
615 symbol (car apropos-item)
616 p (cdr p))
617 (insert-text-button (symbol-name symbol)
618 'type 'apropos-symbol
619 ;; Can't use default, since user may have
620 ;; changed the variable!
621 ;; Just say `no' to variables containing faces!
622 'face apropos-symbol-face)
623 ;; Calculate key-bindings if we want them.
624 (and do-keys
625 (commandp symbol)
626 (indent-to 30 1)
627 (if (let ((keys
628 (save-excursion
629 (set-buffer old-buffer)
630 (where-is-internal symbol)))
631 filtered)
632 ;; Copy over the list of key sequences,
633 ;; omitting any that contain a buffer or a frame.
634 (while keys
635 (let ((key (car keys))
636 (i 0)
637 loser)
638 (while (< i (length key))
639 (if (or (framep (aref key i))
640 (bufferp (aref key i)))
641 (setq loser t))
642 (setq i (1+ i)))
643 (or loser
644 (setq filtered (cons key filtered))))
645 (setq keys (cdr keys)))
646 (setq item filtered))
647 ;; Convert the remaining keys to a string and insert.
648 (insert
649 (mapconcat
650 (lambda (key)
651 (setq key (condition-case ()
652 (key-description key)
653 (error)))
654 (if apropos-keybinding-face
655 (put-text-property 0 (length key)
656 'face apropos-keybinding-face
657 key))
658 key)
659 item ", "))
660 (insert "M-x")
661 (put-text-property (- (point) 3) (point)
662 'face apropos-keybinding-face)
663 (insert " " (symbol-name symbol) " ")
664 (insert "RET")
665 (put-text-property (- (point) 3) (point)
666 'face apropos-keybinding-face)))
667 (terpri)
668 (apropos-print-doc 1
669 (if (commandp symbol)
670 'apropos-command
671 (if (apropos-macrop symbol)
672 'apropos-macro
673 'apropos-function))
675 (apropos-print-doc 2 'apropos-variable t)
676 (apropos-print-doc 6 'apropos-group t)
677 (apropos-print-doc 5 'apropos-face t)
678 (apropos-print-doc 4 'apropos-widget t)
679 (apropos-print-doc 3 'apropos-plist nil))
680 (setq buffer-read-only t))))
681 (prog1 apropos-accumulator
682 (setq apropos-accumulator ()))) ; permit gc
685 (defun apropos-macrop (symbol)
686 "T if SYMBOL is a Lisp macro."
687 (and (fboundp symbol)
688 (consp (setq symbol
689 (symbol-function symbol)))
690 (or (eq (car symbol) 'macro)
691 (if (eq (car symbol) 'autoload)
692 (memq (nth 4 symbol)
693 '(macro t))))))
696 (defun apropos-print-doc (i type do-keys)
697 (if (stringp (setq i (nth i apropos-item)))
698 (progn
699 (insert " ")
700 (insert-text-button (button-type-get type 'apropos-label)
701 'type type
702 ;; Can't use the default button face, since
703 ;; user may have changed the variable!
704 ;; Just say `no' to variables containing faces!
705 'face apropos-label-face
706 'apropos-symbol (car apropos-item))
707 (insert ": ")
708 (insert (if do-keys (substitute-command-keys i) i))
709 (or (bolp) (terpri)))))
712 (defun apropos-follow ()
713 "Invokes any button at point, otherwise invokes the nearest label button."
714 (interactive)
715 (button-activate
716 (or (apropos-next-label-button (line-beginning-position))
717 (error "There is nothing to follow here"))))
720 (defun apropos-describe-plist (symbol)
721 "Display a pretty listing of SYMBOL's plist."
722 (with-output-to-temp-buffer "*Help*"
723 (set-buffer standard-output)
724 (princ "Symbol ")
725 (prin1 symbol)
726 (princ "'s plist is\n (")
727 (if apropos-symbol-face
728 (put-text-property 8 (- (point) 14) 'face apropos-symbol-face))
729 (insert (apropos-format-plist symbol "\n "))
730 (princ ")")
731 (print-help-return-message)))
734 (provide 'apropos)
736 ;;; apropos.el ends here