(exec-suffixes): Initialize to a system-dependent value.
[bpt/emacs.git] / lisp / apropos.el
1 ;;; apropos.el --- apropos commands for users and programmers
2
3 ;; Copyright (C) 1989, 1994, 1995, 2001 Free Software Foundation, Inc.
4
5 ;; Author: Joe Wells <jbw@bigbird.bu.edu>
6 ;; Rewritten: Daniel Pfeiffer <occitan@esperanto.org>
7 ;; Keywords: help
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
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.
25
26 ;;; Commentary:
27
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.
32
33 ;; The idea for super-apropos is based on the original implementation
34 ;; by Lynn Slater <lrs@esl.com>.
35
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.
47
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.
57
58 ;;; Code:
59
60 (require 'button)
61
62 (defgroup apropos nil
63 "Apropos commands for users and programmers"
64 :group 'help
65 :prefix "apropos")
66
67 ;; I see a degradation of maybe 10-20% only.
68 (defcustom apropos-do-all nil
69 "*Whether the apropos commands should do more.
70
71 Slows them down more or less. Set this non-nil if you have a fast machine."
72 :group 'apropos
73 :type 'boolean)
74
75
76 (defcustom apropos-symbol-face 'bold
77 "*Face for symbol name in Apropos output, or nil for none."
78 :group 'apropos
79 :type 'face)
80
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)
85
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)
92
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)
97
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)
104
105
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.")
118
119 (defvar apropos-mode-hook nil
120 "*Hook run when mode is turned on.")
121
122 (defvar apropos-regexp nil
123 "Regexp used in current apropos run.")
124
125 (defvar apropos-files-scanned ()
126 "List of elc files already scanned in current run of `apropos-documentation'.")
127
128 (defvar apropos-accumulator ()
129 "Alist of symbols already found in current apropos run.")
130
131 (defvar apropos-item ()
132 "Current item in or for `apropos-accumulator'.")
133
134 \f
135 ;;; Button types used by apropos
136
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)
142
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)))))
148
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")
164
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))))
175
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))))
181
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))))
188
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))))
194
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))))
200
201 (defun apropos-next-label-button (pos)
202 "Returns 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)))
220
221 \f
222 ;;;###autoload
223 (define-derived-mode apropos-mode fundamental-mode "Apropos"
224 "Major mode for following hyperlinks in output of apropos commands.
225
226 \\{apropos-mode-map}")
227
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)))
246
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.
255
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))))
298
299
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))
365
366
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 t))
390
391
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 t))
428 (kill-buffer standard-input))))
429
430 \f
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)))))
442
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))))
455
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
471 p))
472 (setq p-out (concat p-out (if p-out sep) p))))
473 (setq pl (nthcdr 2 pl)))
474 p-out))
475
476
477 ;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name.
478
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)))))
511
512 (defun apropos-documentation-check-elc-file (file)
513 (if (member file apropos-files-scanned)
514 nil
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)))))))))
556
557
558
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)
578 nil
579 function))
580
581
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."
589 (if (null apropos-accumulator)
590 (message "No apropos matches for `%s'" apropos-regexp)
591 (setq apropos-accumulator
592 (sort apropos-accumulator (lambda (a b)
593 (string-lessp (car a) (car b)))))
594 (with-output-to-temp-buffer "*Apropos*"
595 (let ((p apropos-accumulator)
596 (old-buffer (current-buffer))
597 symbol item)
598 (set-buffer standard-output)
599 (apropos-mode)
600 (if (display-mouse-p)
601 (insert "If moving the mouse over text changes the text's color,\n"
602 (substitute-command-keys
603 "you can click \\[push-button] on that text to get more information.\n")))
604 (insert "In this buffer, go to the name of the command, or function,"
605 " or variable,\n"
606 (substitute-command-keys
607 "and type \\[apropos-follow] to get full documentation.\n\n"))
608 (while (consp p)
609 (or (not spacing) (bobp) (terpri))
610 (setq apropos-item (car p)
611 symbol (car apropos-item)
612 p (cdr p))
613 (insert-text-button (symbol-name symbol)
614 'type 'apropos-symbol
615 ;; Can't use default, since user may have
616 ;; changed the variable!
617 ;; Just say `no' to variables containing faces!
618 'face apropos-symbol-face)
619 ;; Calculate key-bindings if we want them.
620 (and do-keys
621 (commandp symbol)
622 (indent-to 30 1)
623 (if (let ((keys
624 (save-excursion
625 (set-buffer old-buffer)
626 (where-is-internal symbol)))
627 filtered)
628 ;; Copy over the list of key sequences,
629 ;; omitting any that contain a buffer or a frame.
630 (while keys
631 (let ((key (car keys))
632 (i 0)
633 loser)
634 (while (< i (length key))
635 (if (or (framep (aref key i))
636 (bufferp (aref key i)))
637 (setq loser t))
638 (setq i (1+ i)))
639 (or loser
640 (setq filtered (cons key filtered))))
641 (setq keys (cdr keys)))
642 (setq item filtered))
643 ;; Convert the remaining keys to a string and insert.
644 (insert
645 (mapconcat
646 (lambda (key)
647 (setq key (condition-case ()
648 (key-description key)
649 (error)))
650 (if apropos-keybinding-face
651 (put-text-property 0 (length key)
652 'face apropos-keybinding-face
653 key))
654 key)
655 item ", "))
656 (insert "M-x")
657 (put-text-property (- (point) 3) (point)
658 'face apropos-keybinding-face)
659 (insert " " (symbol-name symbol) " ")
660 (insert "RET")
661 (put-text-property (- (point) 3) (point)
662 'face apropos-keybinding-face)))
663 (terpri)
664 (apropos-print-doc 1
665 (if (commandp symbol)
666 'apropos-command
667 (if (apropos-macrop symbol)
668 'apropos-macro
669 'apropos-function))
670 t)
671 (apropos-print-doc 2 'apropos-variable t)
672 (apropos-print-doc 6 'apropos-group t)
673 (apropos-print-doc 5 'apropos-face t)
674 (apropos-print-doc 4 'apropos-widget t)
675 (apropos-print-doc 3 'apropos-plist nil))
676 (setq buffer-read-only t))))
677 (prog1 apropos-accumulator
678 (setq apropos-accumulator ()))) ; permit gc
679
680
681 (defun apropos-macrop (symbol)
682 "T if SYMBOL is a Lisp macro."
683 (and (fboundp symbol)
684 (consp (setq symbol
685 (symbol-function symbol)))
686 (or (eq (car symbol) 'macro)
687 (if (eq (car symbol) 'autoload)
688 (memq (nth 4 symbol)
689 '(macro t))))))
690
691
692 (defun apropos-print-doc (i type do-keys)
693 (if (stringp (setq i (nth i apropos-item)))
694 (progn
695 (insert " ")
696 (insert-text-button (button-type-get type 'apropos-label)
697 'type type
698 ;; Can't use the default button face, since
699 ;; user may have changed the variable!
700 ;; Just say `no' to variables containing faces!
701 'face apropos-label-face
702 'apropos-symbol (car apropos-item))
703 (insert ": ")
704 (insert (if do-keys (substitute-command-keys i) i))
705 (or (bolp) (terpri)))))
706
707
708 (defun apropos-follow ()
709 "Invokes any button at point, otherwise invokes the nearest label button."
710 (interactive)
711 (button-activate
712 (or (apropos-next-label-button (line-beginning-position))
713 (error "There is nothing to follow here"))))
714
715
716 (defun apropos-describe-plist (symbol)
717 "Display a pretty listing of SYMBOL's plist."
718 (with-output-to-temp-buffer "*Help*"
719 (set-buffer standard-output)
720 (princ "Symbol ")
721 (prin1 symbol)
722 (princ "'s plist is\n (")
723 (if apropos-symbol-face
724 (put-text-property 8 (- (point) 14) 'face apropos-symbol-face))
725 (insert (apropos-format-plist symbol "\n "))
726 (princ ")")
727 (print-help-return-message)))
728
729
730 (provide 'apropos)
731
732 ;;; apropos.el ends here