Comment.
[bpt/emacs.git] / lisp / apropos.el
CommitLineData
e8af40ee 1;;; apropos.el --- apropos commands for users and programmers
c0274f38 2
0d30b337 3;; Copyright (C) 1989, 1994, 1995, 2001, 2002, 2003, 2004,
409cc4a3 4;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
9750e079 5
e5167999 6;; Author: Joe Wells <jbw@bigbird.bu.edu>
ae212837 7;; Rewritten: Daniel Pfeiffer <occitan@esperanto.org>
e9571d2a 8;; Keywords: help
e5167999 9
6f8e447f
RS
10;; This file is part of GNU Emacs.
11
eb3fa2cf 12;; GNU Emacs is free software: you can redistribute it and/or modify
6f8e447f 13;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
6f8e447f
RS
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
eb3fa2cf 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
6f8e447f 24
e5167999 25;;; Commentary:
6f8e447f
RS
26
27;; The ideas for this package were derived from the C code in
28;; src/keymap.c and elsewhere. The functions in this file should
29;; always be byte-compiled for speed. Someone should rewrite this in
30;; C (as part of src/keymap.c) for speed.
31
32;; The idea for super-apropos is based on the original implementation
33;; by Lynn Slater <lrs@esl.com>.
34
35;; History:
36;; Fixed bug, current-local-map can return nil.
37;; Change, doesn't calculate key-bindings unless needed.
38;; Added super-apropos capability, changed print functions.
3925e76d
KH
39;;; Made fast-apropos and super-apropos share code.
40;;; Sped up fast-apropos again.
6f8e447f 41;; Added apropos-do-all option.
3925e76d 42;;; Added fast-command-apropos.
6f8e447f 43;; Changed doc strings to comments for helping functions.
3925e76d 44;;; Made doc file buffer read-only, buried it.
6f8e447f
RS
45;; Only call substitute-command-keys if do-all set.
46
645c4f6a
KH
47;; Optionally use configurable faces to make the output more legible.
48;; Differentiate between command, function and macro.
3925e76d
KH
49;; Apropos-command (ex command-apropos) does cmd and optionally user var.
50;; Apropos shows all 3 aspects of symbols (fn, var and plist)
51;; Apropos-documentation (ex super-apropos) now finds all it should.
52;; New apropos-value snoops through all values and optionally plists.
53;; Reading DOC file doesn't load nroff.
54;; Added hypertext following of documentation, mouse-2 on variable gives value
55;; from buffer in active window.
56
e5167999
ER
57;;; Code:
58
851befd4 59(require 'button)
caa8e7aa 60(eval-when-compile (require 'cl))
851befd4 61
ddd2f740 62(defgroup apropos nil
32463e4d 63 "Apropos commands for users and programmers."
c906e3ab 64 :group 'help
ddd2f740
RS
65 :prefix "apropos")
66
3925e76d 67;; I see a degradation of maybe 10-20% only.
ddd2f740 68(defcustom apropos-do-all nil
671c04d9 69 "Whether the apropos commands should do more.
ddd2f740
RS
70
71Slows them down more or less. Set this non-nil if you have a fast machine."
72 :group 'apropos
73 :type 'boolean)
3925e76d
KH
74
75
07eeca5d 76(defcustom apropos-symbol-face 'bold
671c04d9 77 "Face for symbol name in Apropos output, or nil for none."
ddd2f740
RS
78 :group 'apropos
79 :type 'face)
645c4f6a 80
07eeca5d 81(defcustom apropos-keybinding-face 'underline
671c04d9 82 "Face for lists of keybinding in Apropos output, or nil for none."
ddd2f740
RS
83 :group 'apropos
84 :type 'face)
645c4f6a 85
671c04d9
SM
86(defcustom apropos-label-face '(italic variable-pitch)
87 "Face for label (`Command', `Variable' ...) in Apropos output.
07eeca5d
RS
88A value of nil means don't use any special font for them, and also
89turns off mouse highlighting."
ddd2f740
RS
90 :group 'apropos
91 :type 'face)
645c4f6a 92
07eeca5d 93(defcustom apropos-property-face 'bold-italic
671c04d9 94 "Face for property name in apropos output, or nil for none."
ddd2f740
RS
95 :group 'apropos
96 :type 'face)
645c4f6a 97
5248b3e3 98(defcustom apropos-match-face 'match
671c04d9 99 "Face for matching text in Apropos documentation/value, or nil for none.
07eeca5d 100This applies when you look for matches in the documentation or variable value
0820b753 101for the pattern; the part that matches gets displayed in this font."
ddd2f740
RS
102 :group 'apropos
103 :type 'face)
3925e76d 104
ab765ff7 105(defcustom apropos-sort-by-scores nil
671c04d9 106 "Non-nil means sort matches by scores; best match is shown first.
0820b753
KS
107This applies to all `apropos' commands except `apropos-documentation'.
108If value is `verbose', the computed score is shown for each match."
30aab741 109 :group 'apropos
0820b753
KS
110 :type '(choice (const :tag "off" nil)
111 (const :tag "on" t)
112 (const :tag "show scores" verbose)))
113
114(defcustom apropos-documentation-sort-by-scores t
115 "*Non-nil means sort matches by scores; best match is shown first.
116This applies to `apropos-documentation' only.
117If value is `verbose', the computed score is shown for each match."
118 :group 'apropos
119 :type '(choice (const :tag "off" nil)
120 (const :tag "on" t)
121 (const :tag "show scores" verbose)))
6f8e447f 122
26a4a227 123(defvar apropos-mode-map
3925e76d 124 (let ((map (make-sparse-keymap)))
e517f56d
MB
125 (set-keymap-parent map button-buffer-map)
126 ;; Use `apropos-follow' instead of just using the button
127 ;; definition of RET, so that users can use it anywhere in an
128 ;; apropos item, not just on top of a button.
3925e76d 129 (define-key map "\C-m" 'apropos-follow)
5b23b5e4
RS
130 (define-key map " " 'scroll-up)
131 (define-key map "\177" 'scroll-down)
132 (define-key map "q" 'quit-window)
3925e76d 133 map)
26a4a227 134 "Keymap used in Apropos mode.")
4de5599d 135
45f485a6 136(defvar apropos-mode-hook nil
671c04d9 137 "Hook run when mode is turned on.")
3925e76d 138
fe8bc3fa 139(defvar apropos-pattern nil
0820b753
KS
140 "Apropos pattern as entered by user.")
141
142(defvar apropos-pattern-quoted nil
c6b19225 143 "Apropos pattern passed through `regexp-quote'.")
0820b753
KS
144
145(defvar apropos-words ()
146 "Current list of apropos words extracted from `apropos-pattern'.")
645c4f6a 147
0820b753
KS
148(defvar apropos-all-words ()
149 "Current list of words and synonyms.")
7dbffb1c 150
0820b753
KS
151(defvar apropos-regexp nil
152 "Regexp used in current apropos run.")
153
154(defvar apropos-all-words-regexp nil
7dbffb1c
KS
155 "Regexp matching apropos-all-words.")
156
645c4f6a 157(defvar apropos-files-scanned ()
1259a080 158 "List of elc files already scanned in current run of `apropos-documentation'.")
645c4f6a
KH
159
160(defvar apropos-accumulator ()
161 "Alist of symbols already found in current apropos run.")
3925e76d 162
645c4f6a 163(defvar apropos-item ()
7a5348db 164 "Current item in or for `apropos-accumulator'.")
e517f56d 165
7dbffb1c
KS
166(defvar apropos-synonyms '(
167 ("find" "open" "edit")
168 ("kill" "cut")
f4517e51
KS
169 ("yank" "paste")
170 ("region" "selection"))
7dbffb1c 171 "List of synonyms known by apropos.
5e24ee14 172Each element is a list of words where the first word is the standard Emacs
7dbffb1c
KS
173term, and the rest of the words are alternative terms.")
174
e517f56d
MB
175\f
176;;; Button types used by apropos
177
178(define-button-type 'apropos-symbol
179 'face apropos-symbol-face
894e460c 180 'help-echo "mouse-2, RET: Display more help on this symbol"
d8fac801 181 'follow-link t
60f4c0c8 182 'action #'apropos-symbol-button-display-help)
e517f56d
MB
183
184(defun apropos-symbol-button-display-help (button)
185 "Display further help for the `apropos-symbol' button BUTTON."
186 (button-activate
187 (or (apropos-next-label-button (button-start button))
188 (error "There is nothing to follow for `%s'" (button-label button)))))
189
894e460c
MB
190(define-button-type 'apropos-function
191 'apropos-label "Function"
1d69bd9b 192 'apropos-short-label "f"
d8fac801
KS
193 'help-echo "mouse-2, RET: Display more help on this function"
194 'follow-link t
894e460c 195 'action (lambda (button)
d8fac801
KS
196 (describe-function (button-get button 'apropos-symbol))))
197
894e460c
MB
198(define-button-type 'apropos-macro
199 'apropos-label "Macro"
1d69bd9b 200 'apropos-short-label "m"
d8fac801
KS
201 'help-echo "mouse-2, RET: Display more help on this macro"
202 'follow-link t
894e460c 203 'action (lambda (button)
d8fac801
KS
204 (describe-function (button-get button 'apropos-symbol))))
205
894e460c
MB
206(define-button-type 'apropos-command
207 'apropos-label "Command"
1d69bd9b 208 'apropos-short-label "c"
d8fac801
KS
209 'help-echo "mouse-2, RET: Display more help on this command"
210 'follow-link t
894e460c 211 'action (lambda (button)
d8fac801 212 (describe-function (button-get button 'apropos-symbol))))
7cfedc97 213
894e460c
MB
214;; We used to use `customize-variable-other-window' instead for a
215;; customizable variable, but that is slow. It is better to show an
216;; ordinary help buffer and let the user click on the customization
217;; button in that buffer, if he wants to.
218;; Likewise for `customize-face-other-window'.
219(define-button-type 'apropos-variable
220 'apropos-label "Variable"
1d69bd9b 221 'apropos-short-label "v"
894e460c 222 'help-echo "mouse-2, RET: Display more help on this variable"
d8fac801 223 'follow-link t
894e460c
MB
224 'action (lambda (button)
225 (describe-variable (button-get button 'apropos-symbol))))
226
227(define-button-type 'apropos-face
228 'apropos-label "Face"
1d69bd9b 229 'apropos-short-label "F"
894e460c 230 'help-echo "mouse-2, RET: Display more help on this face"
d8fac801 231 'follow-link t
894e460c
MB
232 'action (lambda (button)
233 (describe-face (button-get button 'apropos-symbol))))
234
235(define-button-type 'apropos-group
236 'apropos-label "Group"
1d69bd9b 237 'apropos-short-label "g"
894e460c 238 'help-echo "mouse-2, RET: Display more help on this group"
d8fac801 239 'follow-link t
894e460c 240 'action (lambda (button)
2d37b91e 241 (customize-group-other-window
894e460c
MB
242 (button-get button 'apropos-symbol))))
243
244(define-button-type 'apropos-widget
245 'apropos-label "Widget"
1d69bd9b 246 'apropos-short-label "w"
894e460c 247 'help-echo "mouse-2, RET: Display more help on this widget"
d8fac801 248 'follow-link t
894e460c
MB
249 'action (lambda (button)
250 (widget-browse-other-window (button-get button 'apropos-symbol))))
251
252(define-button-type 'apropos-plist
253 'apropos-label "Plist"
1d69bd9b 254 'apropos-short-label "p"
894e460c 255 'help-echo "mouse-2, RET: Display more help on this plist"
d8fac801 256 'follow-link t
894e460c
MB
257 'action (lambda (button)
258 (apropos-describe-plist (button-get button 'apropos-symbol))))
e517f56d 259
2e3d43ac
SM
260(define-button-type 'apropos-library
261 'help-echo "mouse-2, RET: Display more help on this library"
262 'follow-link t
263 'action (lambda (button)
264 (apropos-library (button-get button 'apropos-symbol))))
265
e517f56d 266(defun apropos-next-label-button (pos)
a11a4e9f 267 "Return the next apropos label button after POS, or nil if there's none.
e517f56d
MB
268Will also return nil if more than one `apropos-symbol' button is encountered
269before finding a label."
a101302b 270 (let* ((button (next-button pos t))
e517f56d 271 (already-hit-symbol nil)
3b8c60f1
MB
272 (label (and button (button-get button 'apropos-label)))
273 (type (and button (button-get button 'type))))
e517f56d 274 (while (and button
3b8c60f1
MB
275 (not label)
276 (or (not (eq type 'apropos-symbol))
e517f56d 277 (not already-hit-symbol)))
3b8c60f1 278 (when (eq type 'apropos-symbol)
e517f56d
MB
279 (setq already-hit-symbol t))
280 (setq button (next-button (button-start button)))
281 (when button
3b8c60f1
MB
282 (setq label (button-get button 'apropos-label))
283 (setq type (button-get button 'type))))
284 (and label button)))
e517f56d 285
645c4f6a 286\f
7dbffb1c
KS
287(defun apropos-words-to-regexp (words wild)
288 "Make regexp matching any two of the words in WORDS."
289 (concat "\\("
290 (mapconcat 'identity words "\\|")
80f5d2ef 291 "\\)"
71296446 292 (if (cdr words)
80f5d2ef
AS
293 (concat wild
294 "\\("
7dbffb1c
KS
295 (mapconcat 'identity words "\\|")
296 "\\)")
297 "")))
298
0820b753
KS
299;;;###autoload
300(defun apropos-read-pattern (subject)
301 "Read an apropos pattern, either a word list or a regexp.
302Returns the user pattern, either a list of words which are matched
303literally, or a string which is used as a regexp to search for.
304
305SUBJECT is a string that is included in the prompt to identify what
306kind of objects to search."
307 (let ((pattern
308 (read-string (concat "Apropos " subject " (word list or regexp): "))))
309 (if (string-equal (regexp-quote pattern) pattern)
310 ;; Split into words
311 (split-string pattern "[ \t]+")
312 pattern)))
313
314(defun apropos-parse-pattern (pattern)
315 "Rewrite a list of words to a regexp matching all permutations.
3fefda51
KS
316If PATTERN is a string, that means it is already a regexp.
317This updates variables `apropos-pattern', `apropos-pattern-quoted',
318`apropos-regexp', `apropos-words', and `apropos-all-words-regexp'."
0820b753
KS
319 (setq apropos-words nil
320 apropos-all-words nil)
321 (if (consp pattern)
7dbffb1c
KS
322 ;; We don't actually make a regexp matching all permutations.
323 ;; Instead, for e.g. "a b c", we make a regexp matching
324 ;; any combination of two or more words like this:
325 ;; (a|b|c).*(a|b|c) which may give some false matches,
326 ;; but as long as it also gives the right ones, that's ok.
0820b753
KS
327 (let ((words pattern))
328 (setq apropos-pattern (mapconcat 'identity pattern " ")
329 apropos-pattern-quoted (regexp-quote apropos-pattern))
7dbffb1c
KS
330 (dolist (word words)
331 (let ((syn apropos-synonyms) (s word) (a word))
332 (while syn
333 (if (member word (car syn))
334 (progn
335 (setq a (mapconcat 'identity (car syn) "\\|"))
336 (if (member word (cdr (car syn)))
337 (setq s a))
338 (setq syn nil))
339 (setq syn (cdr syn))))
340 (setq apropos-words (cons s apropos-words)
341 apropos-all-words (cons a apropos-all-words))))
3fefda51
KS
342 (setq apropos-all-words-regexp
343 (apropos-words-to-regexp apropos-all-words ".+"))
344 (setq apropos-regexp
345 (apropos-words-to-regexp apropos-words ".*?")))
0820b753
KS
346 (setq apropos-pattern-quoted (regexp-quote pattern)
347 apropos-all-words-regexp pattern
3fefda51
KS
348 apropos-pattern pattern
349 apropos-regexp pattern)))
0820b753 350
7dbffb1c
KS
351
352(defun apropos-calc-scores (str words)
353 "Return apropos scores for string STR matching WORDS.
354Value is a list of offsets of the words into the string."
0820b753 355 (let (scores i)
7dbffb1c
KS
356 (if words
357 (dolist (word words scores)
358 (if (setq i (string-match word str))
359 (setq scores (cons i scores))))
360 ;; Return list of start and end position of regexp
347a20b8 361 (and (string-match apropos-pattern str)
0820b753 362 (list (match-beginning 0) (match-end 0))))))
7dbffb1c
KS
363
364(defun apropos-score-str (str)
365 "Return apropos score for string STR."
366 (if str
0820b753
KS
367 (let* ((l (length str))
368 (score (- (/ l 10))))
7dbffb1c 369 (dolist (s (apropos-calc-scores str apropos-all-words) score)
d5857a96 370 (setq score (+ score 1000 (/ (* (- l s) 1000) l)))))
7dbffb1c
KS
371 0))
372
373(defun apropos-score-doc (doc)
374 "Return apropos score for documentation string DOC."
b7a2a696
LK
375 (let ((l (length doc)))
376 (if (> l 0)
0820b753
KS
377 (let ((score 0) i)
378 (when (setq i (string-match apropos-pattern-quoted doc))
379 (setq score 10000))
b7a2a696
LK
380 (dolist (s (apropos-calc-scores doc apropos-all-words) score)
381 (setq score (+ score 50 (/ (* (- l s) 50) l)))))
382 0)))
71296446 383
7dbffb1c
KS
384(defun apropos-score-symbol (symbol &optional weight)
385 "Return apropos score for SYMBOL."
386 (setq symbol (symbol-name symbol))
387 (let ((score 0)
0820b753 388 (l (length symbol)))
7dbffb1c
KS
389 (dolist (s (apropos-calc-scores symbol apropos-words) (* score (or weight 3)))
390 (setq score (+ score (- 60 l) (/ (* (- l s) 60) l))))))
391
d2b30292
KS
392(defun apropos-true-hit (str words)
393 "Return t if STR is a genuine hit.
394This may fail if only one of the keywords is matched more than once.
395This requires that at least 2 keywords (unless only one was given)."
396 (or (not str)
397 (not words)
398 (not (cdr words))
399 (> (length (apropos-calc-scores str words)) 1)))
400
401(defun apropos-false-hit-symbol (symbol)
402 "Return t if SYMBOL is not really matched by the current keywords."
403 (not (apropos-true-hit (symbol-name symbol) apropos-words)))
404
405(defun apropos-false-hit-str (str)
406 "Return t if STR is not really matched by the current keywords."
407 (not (apropos-true-hit str apropos-words)))
408
409(defun apropos-true-hit-doc (doc)
410 "Return t if DOC is really matched by the current keywords."
411 (apropos-true-hit doc apropos-all-words))
412
38ab866c 413(define-derived-mode apropos-mode fundamental-mode "Apropos"
26a4a227
KH
414 "Major mode for following hyperlinks in output of apropos commands.
415
38ab866c 416\\{apropos-mode-map}")
26a4a227 417
1d69bd9b
SM
418(defvar apropos-multi-type t
419 "If non-nil, this apropos query concerns multiple types.
420This is used to decide whether to print the result's type or not.")
421
f38fd610 422;;;###autoload
0820b753
KS
423(defun apropos-variable (pattern &optional do-all)
424 "Show user variables that match PATTERN.
425PATTERN can be a word, a list of words (separated by spaces),
426or a regexp (using some regexp special characters). If it is a word,
427search for matches for that word as a substring. If it is a list of words,
428search for matches for any two (or more) of those words.
429
430With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also show
05942d06 431normal variables."
0820b753
KS
432 (interactive (list (apropos-read-pattern
433 (if (or current-prefix-arg apropos-do-all)
434 "variable" "user option"))
05942d06 435 current-prefix-arg))
0820b753 436 (apropos-command pattern nil
cd00fd36 437 (if (or do-all apropos-do-all)
05942d06
RS
438 #'(lambda (symbol)
439 (and (boundp symbol)
440 (get symbol 'variable-documentation)))
441 'user-variable-p)))
26a4a227 442
645c4f6a
KH
443;; For auld lang syne:
444;;;###autoload
82e736c1 445(defalias 'command-apropos 'apropos-command)
6f8e447f 446;;;###autoload
0820b753
KS
447(defun apropos-command (pattern &optional do-all var-predicate)
448 "Show commands (interactively callable functions) that match PATTERN.
449PATTERN can be a word, a list of words (separated by spaces),
fe8bc3fa
RS
450or a regexp (using some regexp special characters). If it is a word,
451search for matches for that word as a substring. If it is a list of words,
452search for matches for any two (or more) of those words.
453
0820b753 454With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also show
9a909b3c 455noninteractive functions.
05942d06 456
9a909b3c 457If VAR-PREDICATE is non-nil, show only variables, and only those that
0820b753
KS
458satisfy the predicate VAR-PREDICATE.
459
460When called from a Lisp program, a string PATTERN is used as a regexp,
461while a list of strings is used as a word list."
462 (interactive (list (apropos-read-pattern
463 (if (or current-prefix-arg apropos-do-all)
464 "command or function" "command"))
645c4f6a 465 current-prefix-arg))
3fefda51 466 (apropos-parse-pattern pattern)
c851bcec 467 (let ((message
26a4a227 468 (let ((standard-output (get-buffer-create "*Apropos*")))
3925e76d 469 (print-help-return-message 'identity))))
645c4f6a
KH
470 (or do-all (setq do-all apropos-do-all))
471 (setq apropos-accumulator
0820b753 472 (apropos-internal apropos-regexp
cd00fd36 473 (or var-predicate
554fde6e
SM
474 ;; We used to use `functionp' here, but this
475 ;; rules out macros. `fboundp' rules in
476 ;; keymaps, but it seems harmless.
477 (if do-all 'fboundp 'commandp))))
dea22c45
RS
478 (let ((tem apropos-accumulator))
479 (while tem
d2b30292
KS
480 (if (or (get (car tem) 'apropos-inhibit)
481 (apropos-false-hit-symbol (car tem)))
dea22c45
RS
482 (setq apropos-accumulator (delq (car tem) apropos-accumulator)))
483 (setq tem (cdr tem))))
a9155e87 484 (let ((p apropos-accumulator)
7dbffb1c 485 doc symbol score)
a9155e87
KH
486 (while p
487 (setcar p (list
488 (setq symbol (car p))
7dbffb1c 489 (setq score (apropos-score-symbol symbol))
a9155e87 490 (unless var-predicate
554fde6e 491 (if (fboundp symbol)
7cb78ecd 492 (if (setq doc (ignore-errors (documentation symbol t)))
7dbffb1c 493 (progn
71296446 494 (setq score (+ score (apropos-score-doc doc)))
7dbffb1c 495 (substring doc 0 (string-match "\n" doc)))
a9155e87
KH
496 "(not documented)")))
497 (and var-predicate
498 (funcall var-predicate symbol)
499 (if (setq doc (documentation-property
500 symbol 'variable-documentation t))
7dbffb1c
KS
501 (progn
502 (setq score (+ score (apropos-score-doc doc)))
503 (substring doc 0
504 (string-match "\n" doc)))))))
505 (setcar (cdr (car p)) score)
a9155e87 506 (setq p (cdr p))))
1d69bd9b
SM
507 (and (let ((apropos-multi-type do-all))
508 (apropos-print t nil nil t))
a9155e87 509 message
8a26c165 510 (message "%s" message))))
3925e76d
KH
511
512
3925e76d 513;;;###autoload
914b40da
RS
514(defun apropos-documentation-property (symbol property raw)
515 "Like (documentation-property SYMBOL PROPERTY RAW) but handle errors."
516 (condition-case ()
517 (let ((doc (documentation-property symbol property raw)))
518 (if doc (substring doc 0 (string-match "\n" doc))
519 "(not documented)"))
520 (error "(error retrieving documentation)")))
521
5760219d
JPW
522
523;;;###autoload
0820b753 524(defun apropos (pattern &optional do-all)
2a4ec7e1
RS
525 "Show all meaningful Lisp symbols whose names match PATTERN.
526Symbols are shown if they are defined as functions, variables, or
527faces, or if they have nonempty property lists.
528
0820b753 529PATTERN can be a word, a list of words (separated by spaces),
fe8bc3fa
RS
530or a regexp (using some regexp special characters). If it is a word,
531search for matches for that word as a substring. If it is a list of words,
532search for matches for any two (or more) of those words.
533
543e570f
RS
534With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil,
535consider all symbols (if they match PATTERN).
536
537Returns list of symbols and documentation found."
0820b753
KS
538 (interactive (list (apropos-read-pattern "symbol")
539 current-prefix-arg))
3fefda51 540 (apropos-parse-pattern pattern)
caa8e7aa 541 (apropos-symbols-internal
0820b753 542 (apropos-internal apropos-regexp
543e570f
RS
543 (and (not do-all)
544 (not apropos-do-all)
545 (lambda (symbol)
546 (or (fboundp symbol)
547 (boundp symbol)
548 (facep symbol)
549 (symbol-plist symbol)))))
caa8e7aa
SM
550 (or do-all apropos-do-all)))
551
2e3d43ac
SM
552(defun apropos-library-button (sym)
553 (if (null sym)
554 "<nothing>"
555 (let ((name (copy-sequence (symbol-name sym))))
556 (make-text-button name nil
557 'type 'apropos-library
558 'face apropos-symbol-face
559 'apropos-symbol name)
560 name)))
561
562;;;###autoload
563(defun apropos-library (file)
564 "List the variables and functions defined by library FILE.
565FILE should be one of the libraries currently loaded and should
566thus be found in `load-history'."
567 (interactive
568 (let ((libs
569 (nconc (delq nil
570 (mapcar
571 (lambda (l)
572 (setq l (file-name-nondirectory l))
573 (while
574 (not (equal (setq l (file-name-sans-extension l))
575 l)))
576 l)
577 (mapcar 'car load-history)))
578 (mapcar 'car load-history))))
579 (list (completing-read "Describe library: " libs nil t))))
580 (let ((symbols nil)
581 ;; (autoloads nil)
582 (provides nil)
583 (requires nil)
584 (lh-entry (assoc file load-history)))
585 (unless lh-entry
586 ;; `file' may be the "shortname".
587 (let ((lh load-history)
588 (re (concat "\\(?:\\`\\|[\\/]\\)" (regexp-quote file)
589 "\\(\\.\\|\\'\\)")))
590 (while (and lh (null lh-entry))
591 (if (string-match re (caar lh))
592 (setq lh-entry (car lh))
593 (setq lh (cdr lh)))))
594 (unless lh-entry (error "Unknown library `%s'" file)))
595 (dolist (x (cdr lh-entry))
596 (case (car-safe x)
597 ;; (autoload (push (cdr x) autoloads))
598 (require (push (cdr x) requires))
599 (provide (push (cdr x) provides))
600 (t (push (or (cdr-safe x) x) symbols))))
601 (let ((apropos-pattern "")) ;Dummy binding for apropos-symbols-internal.
602 (apropos-symbols-internal
603 symbols apropos-do-all
604 (concat
605 (format "Library `%s' provides: %s\nand requires: %s"
606 file
607 (mapconcat 'apropos-library-button
608 (or provides '(nil)) " and ")
609 (mapconcat 'apropos-library-button
610 (or requires '(nil)) " and ")))))))
611
caa8e7aa
SM
612(defun apropos-symbols-internal (symbols keys &optional text)
613 ;; Filter out entries that are marked as apropos-inhibit.
614 (let ((all nil))
615 (dolist (symbol symbols)
616 (unless (get symbol 'apropos-inhibit)
617 (push symbol all)))
618 (setq symbols all))
619 (let ((apropos-accumulator
620 (mapcar
621 (lambda (symbol)
622 (let (doc properties)
623 (list
624 symbol
625 (apropos-score-symbol symbol)
626 (when (fboundp symbol)
627 (if (setq doc (condition-case nil
628 (documentation symbol t)
629 (void-function
630 "(alias for undefined function)")
631 (error
632 "(can't retrieve function documentation)")))
633 (substring doc 0 (string-match "\n" doc))
634 "(not documented)"))
635 (when (boundp symbol)
636 (apropos-documentation-property
914b40da 637 symbol 'variable-documentation t))
a9155e87
KH
638 (when (setq properties (symbol-plist symbol))
639 (setq doc (list (car properties)))
640 (while (setq properties (cdr (cdr properties)))
641 (setq doc (cons (car properties) doc)))
642 (mapconcat #'symbol-name (nreverse doc) " "))
643 (when (get symbol 'widget-type)
914b40da
RS
644 (apropos-documentation-property
645 symbol 'widget-documentation t))
caa8e7aa
SM
646 (when (facep symbol)
647 (apropos-documentation-property
648 symbol 'face-documentation t))
649 (when (get symbol 'custom-group)
914b40da 650 (apropos-documentation-property
caa8e7aa
SM
651 symbol 'group-documentation t)))))
652 symbols)))
653 (apropos-print keys nil text)))
3925e76d
KH
654
655
6f8e447f 656;;;###autoload
0820b753 657(defun apropos-value (pattern &optional do-all)
2a4ec7e1 658 "Show all symbols whose value's printed representation matches PATTERN.
0820b753 659PATTERN can be a word, a list of words (separated by spaces),
fe8bc3fa
RS
660or a regexp (using some regexp special characters). If it is a word,
661search for matches for that word as a substring. If it is a list of words,
662search for matches for any two (or more) of those words.
663
0820b753 664With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also looks
3925e76d 665at the function and at the names and values of properties.
645c4f6a 666Returns list of symbols and values found."
0820b753
KS
667 (interactive (list (apropos-read-pattern "value")
668 current-prefix-arg))
3fefda51 669 (apropos-parse-pattern pattern)
645c4f6a
KH
670 (or do-all (setq do-all apropos-do-all))
671 (setq apropos-accumulator ())
672 (let (f v p)
3925e76d
KH
673 (mapatoms
674 (lambda (symbol)
675 (setq f nil v nil p nil)
0820b753
KS
676 (or (memq symbol '(apropos-regexp
677 apropos-pattern apropos-all-words-regexp
7dbffb1c
KS
678 apropos-words apropos-all-words
679 do-all apropos-accumulator
680 symbol f v p))
645c4f6a 681 (setq v (apropos-value-internal 'boundp symbol 'symbol-value)))
3925e76d 682 (if do-all
645c4f6a
KH
683 (setq f (apropos-value-internal 'fboundp symbol 'symbol-function)
684 p (apropos-format-plist symbol "\n " t)))
d2b30292
KS
685 (if (apropos-false-hit-str v)
686 (setq v nil))
687 (if (apropos-false-hit-str f)
688 (setq f nil))
689 (if (apropos-false-hit-str p)
690 (setq p nil))
3925e76d 691 (if (or f v p)
71296446 692 (setq apropos-accumulator (cons (list symbol
7dbffb1c
KS
693 (+ (apropos-score-str f)
694 (apropos-score-str v)
695 (apropos-score-str p))
696 f v p)
645c4f6a 697 apropos-accumulator))))))
1d69bd9b
SM
698 (let ((apropos-multi-type do-all))
699 (apropos-print nil "\n----------------\n")))
3925e76d
KH
700
701
645c4f6a 702;;;###autoload
0820b753 703(defun apropos-documentation (pattern &optional do-all)
2a4ec7e1 704 "Show symbols whose documentation contains matches for PATTERN.
0820b753 705PATTERN can be a word, a list of words (separated by spaces),
fe8bc3fa
RS
706or a regexp (using some regexp special characters). If it is a word,
707search for matches for that word as a substring. If it is a list of words,
708search for matches for any two (or more) of those words.
709
0820b753 710With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also use
645c4f6a
KH
711documentation that is not stored in the documentation file and show key
712bindings.
713Returns list of symbols and documentation found."
0820b753
KS
714 (interactive (list (apropos-read-pattern "documentation")
715 current-prefix-arg))
3fefda51 716 (apropos-parse-pattern pattern)
645c4f6a
KH
717 (or do-all (setq do-all apropos-do-all))
718 (setq apropos-accumulator () apropos-files-scanned ())
719 (let ((standard-input (get-buffer-create " apropos-temp"))
0820b753 720 (apropos-sort-by-scores apropos-documentation-sort-by-scores)
7dbffb1c 721 f v sf sv)
645c4f6a
KH
722 (unwind-protect
723 (save-excursion
724 (set-buffer standard-input)
725 (apropos-documentation-check-doc-file)
726 (if do-all
727 (mapatoms
728 (lambda (symbol)
729 (setq f (apropos-safe-documentation symbol)
26a4a227
KH
730 v (get symbol 'variable-documentation))
731 (if (integerp v) (setq v))
732 (setq f (apropos-documentation-internal f)
733 v (apropos-documentation-internal v))
7dbffb1c
KS
734 (setq sf (apropos-score-doc f)
735 sv (apropos-score-doc v))
645c4f6a
KH
736 (if (or f v)
737 (if (setq apropos-item
738 (cdr (assq symbol apropos-accumulator)))
739 (progn
740 (if f
7dbffb1c
KS
741 (progn
742 (setcar (nthcdr 1 apropos-item) f)
743 (setcar apropos-item (+ (car apropos-item) sf))))
645c4f6a 744 (if v
7dbffb1c
KS
745 (progn
746 (setcar (nthcdr 2 apropos-item) v)
747 (setcar apropos-item (+ (car apropos-item) sv)))))
645c4f6a 748 (setq apropos-accumulator
71296446 749 (cons (list symbol
7dbffb1c
KS
750 (+ (apropos-score-symbol symbol 2) sf sv)
751 f v)
645c4f6a 752 apropos-accumulator)))))))
0820b753 753 (apropos-print nil "\n----------------\n" nil t))
645c4f6a
KH
754 (kill-buffer standard-input))))
755
756\f
757(defun apropos-value-internal (predicate symbol function)
758 (if (funcall predicate symbol)
759 (progn
760 (setq symbol (prin1-to-string (funcall function symbol)))
0820b753 761 (if (string-match apropos-regexp symbol)
645c4f6a
KH
762 (progn
763 (if apropos-match-face
764 (put-text-property (match-beginning 0) (match-end 0)
765 'face apropos-match-face
766 symbol))
767 symbol)))))
768
769(defun apropos-documentation-internal (doc)
770 (if (consp doc)
771 (apropos-documentation-check-elc-file (car doc))
0820b753
KS
772 (if (and doc
773 (string-match apropos-all-words-regexp doc)
774 (apropos-true-hit-doc doc))
775 (when apropos-match-face
776 (setq doc (substitute-command-keys (copy-sequence doc)))
777 (if (or (string-match apropos-pattern-quoted doc)
778 (string-match apropos-all-words-regexp doc))
779 (put-text-property (match-beginning 0)
780 (match-end 0)
781 'face apropos-match-face doc))
782 doc))))
645c4f6a
KH
783
784(defun apropos-format-plist (pl sep &optional compare)
3925e76d
KH
785 (setq pl (symbol-plist pl))
786 (let (p p-out)
787 (while pl
788 (setq p (format "%s %S" (car pl) (nth 1 pl)))
0820b753 789 (if (or (not compare) (string-match apropos-regexp p))
645c4f6a 790 (if apropos-property-face
3925e76d 791 (put-text-property 0 (length (symbol-name (car pl)))
645c4f6a 792 'face apropos-property-face p))
3925e76d 793 (setq p nil))
645c4f6a
KH
794 (if p
795 (progn
796 (and compare apropos-match-face
797 (put-text-property (match-beginning 0) (match-end 0)
798 'face apropos-match-face
799 p))
800 (setq p-out (concat p-out (if p-out sep) p))))
3925e76d
KH
801 (setq pl (nthcdr 2 pl)))
802 p-out))
803
6f8e447f 804
0820b753 805;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name.
3925e76d 806
645c4f6a 807(defun apropos-documentation-check-doc-file ()
0820b753 808 (let (type symbol (sepa 2) sepb)
26a4a227
KH
809 (insert ?\^_)
810 (backward-char)
645c4f6a 811 (insert-file-contents (concat doc-directory internal-doc-file-name))
26a4a227
KH
812 (forward-char)
813 (while (save-excursion
814 (setq sepb (search-forward "\^_"))
815 (not (eobp)))
816 (beginning-of-line 2)
817 (if (save-restriction
818 (narrow-to-region (point) (1- sepb))
0820b753 819 (re-search-forward apropos-all-words-regexp nil t))
26a4a227 820 (progn
26a4a227 821 (goto-char (1+ sepa))
d2b30292
KS
822 (setq type (if (eq ?F (preceding-char))
823 2 ; function documentation
824 3) ; variable documentation
825 symbol (read)
d2b30292
KS
826 doc (buffer-substring (1+ (point)) (1- sepb)))
827 (when (apropos-true-hit-doc doc)
828 (or (and (setq apropos-item (assq symbol apropos-accumulator))
829 (setcar (cdr apropos-item)
0820b753 830 (apropos-score-doc doc)))
71296446 831 (setq apropos-item (list symbol
d2b30292
KS
832 (+ (apropos-score-symbol symbol 2)
833 (apropos-score-doc doc))
834 nil nil)
835 apropos-accumulator (cons apropos-item
836 apropos-accumulator)))
0820b753
KS
837 (when apropos-match-face
838 (setq doc (substitute-command-keys doc))
839 (if (or (string-match apropos-pattern-quoted doc)
840 (string-match apropos-all-words-regexp doc))
841 (put-text-property (match-beginning 0)
842 (match-end 0)
843 'face apropos-match-face doc)))
d2b30292 844 (setcar (nthcdr type apropos-item) doc))))
26a4a227 845 (setq sepa (goto-char sepb)))))
645c4f6a
KH
846
847(defun apropos-documentation-check-elc-file (file)
848 (if (member file apropos-files-scanned)
849 nil
26a4a227 850 (let (symbol doc beg end this-is-a-variable)
645c4f6a
KH
851 (setq apropos-files-scanned (cons file apropos-files-scanned))
852 (erase-buffer)
853 (insert-file-contents file)
854 (while (search-forward "\n#@" nil t)
855 ;; Read the comment length, and advance over it.
856 (setq end (read)
26a4a227
KH
857 beg (1+ (point))
858 end (+ (point) end -1))
859 (forward-char)
860 (if (save-restriction
861 ;; match ^ and $ relative to doc string
862 (narrow-to-region beg end)
0820b753 863 (re-search-forward apropos-all-words-regexp nil t))
645c4f6a 864 (progn
26a4a227
KH
865 (goto-char (+ end 2))
866 (setq doc (buffer-substring beg end)
867 end (- (match-end 0) beg)
d2b30292
KS
868 beg (- (match-beginning 0) beg))
869 (when (apropos-true-hit-doc doc)
870 (setq this-is-a-variable (looking-at "(def\\(var\\|const\\) ")
871 symbol (progn
872 (skip-chars-forward "(a-z")
873 (forward-char)
874 (read))
875 symbol (if (consp symbol)
876 (nth 1 symbol)
877 symbol))
878 (if (if this-is-a-variable
879 (get symbol 'variable-documentation)
880 (and (fboundp symbol) (apropos-safe-documentation symbol)))
881 (progn
882 (or (and (setq apropos-item (assq symbol apropos-accumulator))
883 (setcar (cdr apropos-item)
884 (+ (cadr apropos-item) (apropos-score-doc doc))))
885 (setq apropos-item (list symbol
886 (+ (apropos-score-symbol symbol 2)
887 (apropos-score-doc doc))
888 nil nil)
889 apropos-accumulator (cons apropos-item
890 apropos-accumulator)))
0820b753
KS
891 (when apropos-match-face
892 (setq doc (substitute-command-keys doc))
893 (if (or (string-match apropos-pattern-quoted doc)
894 (string-match apropos-all-words-regexp doc))
895 (put-text-property (match-beginning 0)
896 (match-end 0)
897 'face apropos-match-face doc)))
d2b30292
KS
898 (setcar (nthcdr (if this-is-a-variable 3 2)
899 apropos-item)
900 doc))))))))))
645c4f6a
KH
901
902
903
904(defun apropos-safe-documentation (function)
7a5348db 905 "Like `documentation', except it avoids calling `get_doc_string'.
6f8e447f 906Will return nil instead."
3925e76d 907 (while (and function (symbolp function))
6f8e447f 908 (setq function (if (fboundp function)
3925e76d 909 (symbol-function function))))
d2e1218f
RS
910 (if (eq (car-safe function) 'macro)
911 (setq function (cdr function)))
3925e76d 912 (setq function (if (byte-code-function-p function)
645c4f6a
KH
913 (if (> (length function) 4)
914 (aref function 4))
915 (if (eq (car-safe function) 'autoload)
916 (nth 2 function)
917 (if (eq (car-safe function) 'lambda)
918 (if (stringp (nth 2 function))
919 (nth 2 function)
920 (if (stringp (nth 3 function))
921 (nth 3 function)))))))
922 (if (integerp function)
923 nil
924 function))
925
1d69bd9b
SM
926(defcustom apropos-compact-layout nil
927 "If non-nil, use a single line per binding."
928 :type 'boolean)
645c4f6a 929
0820b753 930(defun apropos-print (do-keys spacing &optional text nosubst)
a9155e87
KH
931 "Output result of apropos searching into buffer `*Apropos*'.
932The value of `apropos-accumulator' is the list of items to output.
71296446 933Each element should have the format
7dbffb1c 934 (SYMBOL SCORE FN-DOC VAR-DOC [PLIST-DOC WIDGET-DOC FACE-DOC GROUP-DOC]).
a9155e87
KH
935The return value is the list that was in `apropos-accumulator', sorted
936alphabetically by symbol name; but this function also sets
9cc84e31
RS
937`apropos-accumulator' to nil before returning.
938
caa8e7aa
SM
939If SPACING is non-nil, it should be a string; separate items with that string.
940If non-nil TEXT is a string that will be printed as a heading."
645c4f6a 941 (if (null apropos-accumulator)
0820b753 942 (message "No apropos matches for `%s'" apropos-pattern)
645c4f6a 943 (setq apropos-accumulator
30aab741
RS
944 (sort apropos-accumulator
945 (lambda (a b)
946 ;; Don't sort by score if user can't see the score.
947 ;; It would be confusing. -- rms.
ab765ff7 948 (if apropos-sort-by-scores
30aab741
RS
949 (or (> (cadr a) (cadr b))
950 (and (= (cadr a) (cadr b))
951 (string-lessp (car a) (car b))))
952 (string-lessp (car a) (car b))))))
09e32aaf 953 (with-output-to-temp-buffer "*Apropos*"
645c4f6a 954 (let ((p apropos-accumulator)
3925e76d 955 (old-buffer (current-buffer))
e517f56d 956 symbol item)
26a4a227
KH
957 (set-buffer standard-output)
958 (apropos-mode)
a2ee7919 959 (if (display-mouse-p)
8d33699b
EZ
960 (insert
961 "If moving the mouse over text changes the text's color, "
962 "you can click\n"
963 "mouse-2 (second button from right) on that text to "
964 "get more information.\n"))
53a7d078 965 (insert "In this buffer, go to the name of the command, or function,"
d94d5b5a
EZ
966 " or variable,\n"
967 (substitute-command-keys
968 "and type \\[apropos-follow] to get full documentation.\n\n"))
caa8e7aa 969 (if text (insert text "\n\n"))
671c04d9 970 (dolist (apropos-item p)
9cc84e31
RS
971 (when (and spacing (not (bobp)))
972 (princ spacing))
671c04d9 973 (setq symbol (car apropos-item))
0820b753
KS
974 ;; Insert dummy score element for backwards compatibility with 21.x
975 ;; apropos-item format.
976 (if (not (numberp (cadr apropos-item)))
977 (setq apropos-item
978 (cons (car apropos-item)
979 (cons nil (cdr apropos-item)))))
e517f56d
MB
980 (insert-text-button (symbol-name symbol)
981 'type 'apropos-symbol
60f4c0c8 982 'skip apropos-multi-type
e517f56d
MB
983 ;; Can't use default, since user may have
984 ;; changed the variable!
985 ;; Just say `no' to variables containing faces!
986 'face apropos-symbol-face)
0820b753
KS
987 (if (and (eq apropos-sort-by-scores 'verbose)
988 (cadr apropos-item))
7dbffb1c 989 (insert " (" (number-to-string (cadr apropos-item)) ") "))
98ce2330 990 ;; Calculate key-bindings if we want them.
1d69bd9b
SM
991 (unless apropos-compact-layout
992 (and do-keys
993 (commandp symbol)
994 (not (eq symbol 'self-insert-command))
995 (indent-to 30 1)
996 (if (let ((keys
997 (with-current-buffer old-buffer
998 (where-is-internal symbol)))
999 filtered)
1000 ;; Copy over the list of key sequences,
1001 ;; omitting any that contain a buffer or a frame.
1002 ;; FIXME: Why omit keys that contain buffers and
1003 ;; frames? This looks like a bad workaround rather
1004 ;; than a proper fix. Does anybod know what problem
1005 ;; this is trying to address? --Stef
1006 (dolist (key keys)
1007 (let ((i 0)
1008 loser)
1009 (while (< i (length key))
1010 (if (or (framep (aref key i))
1011 (bufferp (aref key i)))
1012 (setq loser t))
1013 (setq i (1+ i)))
1014 (or loser
1015 (push key filtered))))
1016 (setq item filtered))
1017 ;; Convert the remaining keys to a string and insert.
1018 (insert
1019 (mapconcat
1020 (lambda (key)
1021 (setq key (condition-case ()
1022 (key-description key)
1023 (error)))
1024 (if apropos-keybinding-face
1025 (put-text-property 0 (length key)
1026 'face apropos-keybinding-face
1027 key))
1028 key)
1029 item ", "))
1030 (insert "M-x ... RET")
1031 (when apropos-keybinding-face
1032 (put-text-property (- (point) 11) (- (point) 8)
1033 'face apropos-keybinding-face)
1034 (put-text-property (- (point) 3) (point)
1035 'face apropos-keybinding-face))))
1036 (terpri))
7dbffb1c 1037 (apropos-print-doc 2
26a4a227 1038 (if (commandp symbol)
894e460c 1039 'apropos-command
26a4a227 1040 (if (apropos-macrop symbol)
894e460c
MB
1041 'apropos-macro
1042 'apropos-function))
0820b753
KS
1043 (not nosubst))
1044 (apropos-print-doc 3 'apropos-variable (not nosubst))
7dbffb1c
KS
1045 (apropos-print-doc 7 'apropos-group t)
1046 (apropos-print-doc 6 'apropos-face t)
1047 (apropos-print-doc 5 'apropos-widget t)
1048 (apropos-print-doc 4 'apropos-plist nil))
1d69bd9b
SM
1049 (set (make-local-variable 'truncate-partial-width-windows) t)
1050 (set (make-local-variable 'truncate-lines) t)
a9155e87 1051 (setq buffer-read-only t))))
645c4f6a
KH
1052 (prog1 apropos-accumulator
1053 (setq apropos-accumulator ()))) ; permit gc
1054
645c4f6a 1055(defun apropos-macrop (symbol)
b965722b 1056 "Return t if SYMBOL is a Lisp macro."
645c4f6a
KH
1057 (and (fboundp symbol)
1058 (consp (setq symbol
1059 (symbol-function symbol)))
1060 (or (eq (car symbol) 'macro)
1061 (if (eq (car symbol) 'autoload)
1062 (memq (nth 4 symbol)
1063 '(macro t))))))
3925e76d 1064
645c4f6a 1065
894e460c 1066(defun apropos-print-doc (i type do-keys)
671c04d9 1067 (when (stringp (setq i (nth i apropos-item)))
1d69bd9b
SM
1068 (if apropos-compact-layout
1069 (insert (propertize "\t" 'display '(space :align-to 32)) " ")
1070 (insert " "))
60f4c0c8
CY
1071 (if (null apropos-multi-type)
1072 ;; If the query is only for a single type, there's no point
1073 ;; writing it over and over again. Insert a blank button, and
1074 ;; put the 'apropos-label property there (needed by
1075 ;; apropos-symbol-button-display-help).
1076 (insert-text-button
1077 " " 'type type 'skip t
1078 'face 'default 'apropos-symbol (car apropos-item))
1d69bd9b
SM
1079 (insert-text-button
1080 (if apropos-compact-layout
1081 (button-type-get type 'apropos-label)
1082 (format "<%s>" (button-type-get type 'apropos-short-label)))
1083 'type type
1084 ;; Can't use the default button face, since user may have changed the
1085 ;; variable! Just say `no' to variables containing faces!
1086 'face apropos-label-face
1087 'apropos-symbol (car apropos-item))
1088 (insert (if apropos-compact-layout " " ": ")))
60f4c0c8 1089 (insert (if do-keys (substitute-command-keys i) i))
671c04d9 1090 (or (bolp) (terpri))))
3925e76d 1091
e517f56d
MB
1092(defun apropos-follow ()
1093 "Invokes any button at point, otherwise invokes the nearest label button."
3925e76d 1094 (interactive)
e517f56d
MB
1095 (button-activate
1096 (or (apropos-next-label-button (line-beginning-position))
1097 (error "There is nothing to follow here"))))
3925e76d
KH
1098
1099
1100(defun apropos-describe-plist (symbol)
1101 "Display a pretty listing of SYMBOL's plist."
caa8e7aa 1102 (help-setup-xref (list 'apropos-describe-plist symbol) (interactive-p))
c6808785 1103 (with-help-window (help-buffer)
3925e76d
KH
1104 (set-buffer standard-output)
1105 (princ "Symbol ")
1106 (prin1 symbol)
1107 (princ "'s plist is\n (")
645c4f6a 1108 (if apropos-symbol-face
caa8e7aa
SM
1109 (put-text-property (+ (point-min) 7) (- (point) 14)
1110 'face apropos-symbol-face))
3925e76d 1111 (insert (apropos-format-plist symbol "\n "))
c6808785 1112 (princ ")")))
6f8e447f 1113
e517f56d 1114
896546cd
RS
1115(provide 'apropos)
1116
cbee283d 1117;; arch-tag: d56fa2ac-e56b-4ce3-84ff-852f9c0dc66e
c0274f38 1118;;; apropos.el ends here