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