(byte-decompile-bytecode-1):
[bpt/emacs.git] / lisp / apropos.el
CommitLineData
3925e76d 1;;; apropos.el --- apropos commands for users and programmers.
c0274f38 2
3925e76d 3;; Copyright (C) 1989, 1994, 1995 Free Software Foundation, Inc.
9750e079 4
e5167999 5;; Author: Joe Wells <jbw@bigbird.bu.edu>
3925e76d 6;; Rewritten: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389
e9571d2a 7;; Keywords: help
e5167999 8
6f8e447f
RS
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
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
6f8e447f
RS
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
b578f267
EN
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.
6f8e447f 25
e5167999 26;;; Commentary:
6f8e447f
RS
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.
3925e76d
KH
40;;; Made fast-apropos and super-apropos share code.
41;;; Sped up fast-apropos again.
6f8e447f 42;; Added apropos-do-all option.
3925e76d 43;;; Added fast-command-apropos.
6f8e447f 44;; Changed doc strings to comments for helping functions.
3925e76d 45;;; Made doc file buffer read-only, buried it.
6f8e447f
RS
46;; Only call substitute-command-keys if do-all set.
47
645c4f6a
KH
48;; Optionally use configurable faces to make the output more legible.
49;; Differentiate between command, function and macro.
3925e76d
KH
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
e5167999
ER
58;;; Code:
59
ddd2f740
RS
60(defgroup apropos nil
61 "Apropos commands for users and programmers"
62 :group 'Help
63 :prefix "apropos")
64
3925e76d 65;; I see a degradation of maybe 10-20% only.
ddd2f740 66(defcustom apropos-do-all nil
3925e76d 67 "*Whether the apropos commands should do more.
ddd2f740
RS
68
69Slows them down more or less. Set this non-nil if you have a fast machine."
70 :group 'apropos
71 :type 'boolean)
3925e76d
KH
72
73
ddd2f740
RS
74(defcustom apropos-symbol-face (if window-system 'bold)
75 "*Face for symbol name in apropos output or `nil'.
76This looks good, but slows down the commands several times."
77 :group 'apropos
78 :type 'face)
645c4f6a 79
ddd2f740 80(defcustom apropos-keybinding-face (if window-system 'underline)
645c4f6a 81 "*Face for keybinding display in apropos output or `nil'.
ddd2f740
RS
82This looks good, but slows down the commands several times."
83 :group 'apropos
84 :type 'face)
645c4f6a 85
ddd2f740 86(defcustom apropos-label-face (if window-system 'italic)
645c4f6a
KH
87 "*Face for label (Command, Variable ...) in apropos output or `nil'.
88If this is `nil' no mouse highlighting occurs.
89This looks good, but slows down the commands several times.
90When this is a face name, as it is initially, it gets transformed to a
ddd2f740
RS
91text-property list for efficiency."
92 :group 'apropos
93 :type 'face)
645c4f6a 94
ddd2f740 95(defcustom apropos-property-face (if window-system 'bold-italic)
645c4f6a 96 "*Face for property name in apropos output or `nil'.
ddd2f740
RS
97This looks good, but slows down the commands several times."
98 :group 'apropos
99 :type 'face)
645c4f6a 100
ddd2f740 101(defcustom apropos-match-face (if window-system 'secondary-selection)
645c4f6a 102 "*Face for matching part in apropos-documentation/value output or `nil'.
ddd2f740
RS
103This looks good, but slows down the commands several times."
104 :group 'apropos
105 :type 'face)
3925e76d 106
6f8e447f 107
26a4a227 108(defvar apropos-mode-map
3925e76d
KH
109 (let ((map (make-sparse-keymap)))
110 (define-key map "\C-m" 'apropos-follow)
5b23b5e4
RS
111 (define-key map " " 'scroll-up)
112 (define-key map "\177" 'scroll-down)
113 (define-key map "q" 'quit-window)
3925e76d
KH
114 (define-key map [mouse-2] 'apropos-mouse-follow)
115 (define-key map [down-mouse-2] nil)
116 map)
26a4a227 117 "Keymap used in Apropos mode.")
4de5599d 118
3925e76d 119
645c4f6a
KH
120(defvar apropos-regexp nil
121 "Regexp used in current apropos run.")
122
123(defvar apropos-files-scanned ()
1259a080 124 "List of elc files already scanned in current run of `apropos-documentation'.")
645c4f6a
KH
125
126(defvar apropos-accumulator ()
127 "Alist of symbols already found in current apropos run.")
3925e76d 128
645c4f6a
KH
129(defvar apropos-item ()
130 "Current item in or for apropos-accumulator.")
131\f
26a4a227
KH
132(defun apropos-mode ()
133 "Major mode for following hyperlinks in output of apropos commands.
134
135\\{apropos-mode-map}"
136 (interactive)
137 (kill-all-local-variables)
138 (use-local-map apropos-mode-map)
139 (setq major-mode 'apropos-mode
140 mode-name "Apropos"))
141
f38fd610
RS
142;;;###autoload
143(defun apropos-variable (regexp)
144 (interactive (list (read-string "Apropos variable (regexp): ")))
145 (apropos-command regexp nil t))
26a4a227 146
645c4f6a
KH
147;; For auld lang syne:
148;;;###autoload
149(fset 'command-apropos 'apropos-command)
6f8e447f 150;;;###autoload
f38fd610 151(defun apropos-command (apropos-regexp &optional do-all just-vars)
3ccee345
KH
152 "Show commands (interactively callable functions) that match REGEXP.
153With optional prefix ARG, or if `apropos-do-all' is non-nil, also show
f38fd610
RS
154variables. If JUST-VARS is non-nil, show only variables."
155 (interactive (list (read-string (concat
156 "Apropos command "
157 (if (or current-prefix-arg
158 apropos-do-all)
159 "or variable ")
160 "(regexp): "))
645c4f6a 161 current-prefix-arg))
3925e76d 162 (let ((message
26a4a227 163 (let ((standard-output (get-buffer-create "*Apropos*")))
3925e76d 164 (print-help-return-message 'identity))))
645c4f6a
KH
165 (or do-all (setq do-all apropos-do-all))
166 (setq apropos-accumulator
167 (apropos-internal apropos-regexp
168 (if do-all
169 (lambda (symbol) (or (commandp symbol)
170 (user-variable-p symbol)))
f38fd610
RS
171 (if just-vars 'user-variable-p
172 'commandp))))
dea22c45
RS
173 (let ((tem apropos-accumulator))
174 (while tem
175 (if (get (car tem) 'apropos-inhibit)
176 (setq apropos-accumulator (delq (car tem) apropos-accumulator)))
177 (setq tem (cdr tem))))
3925e76d 178 (if (apropos-print
3925e76d
KH
179 t
180 (lambda (p)
181 (let (doc symbol)
182 (while p
183 (setcar p (list
184 (setq symbol (car p))
f38fd610
RS
185 (if (or do-all (not just-vars))
186 (if (commandp symbol)
187 (if (setq doc (documentation symbol t))
188 (substring doc 0 (string-match "\n" doc))
189 "(not documented)")))
3925e76d
KH
190 (and do-all
191 (user-variable-p symbol)
192 (if (setq doc (documentation-property
193 symbol 'variable-documentation t))
194 (substring doc 0
195 (string-match "\n" doc))))))
196 (setq p (cdr p)))))
197 nil)
198 (and message (message message)))))
199
200
3925e76d 201;;;###autoload
645c4f6a
KH
202(defun apropos (apropos-regexp &optional do-all)
203 "Show all bound symbols whose names match REGEXP.
204With optional prefix ARG or if `apropos-do-all' is non-nil, also show unbound
205symbols and key bindings, which is a little more time-consuming.
6f8e447f 206Returns list of symbols and documentation found."
3925e76d 207 (interactive "sApropos symbol (regexp): \nP")
645c4f6a
KH
208 (setq apropos-accumulator
209 (apropos-internal apropos-regexp
210 (and (not do-all)
211 (not apropos-do-all)
212 (lambda (symbol)
213 (or (fboundp symbol)
214 (boundp symbol)
5edc67d3 215 (facep symbol)
645c4f6a 216 (symbol-plist symbol))))))
dea22c45
RS
217 (let ((tem apropos-accumulator))
218 (while tem
219 (if (get (car tem) 'apropos-inhibit)
220 (setq apropos-accumulator (delq (car tem) apropos-accumulator)))
221 (setq tem (cdr tem))))
3925e76d 222 (apropos-print
645c4f6a 223 (or do-all apropos-do-all)
3925e76d 224 (lambda (p)
d69e3b68 225 (let (symbol doc properties)
3925e76d
KH
226 (while p
227 (setcar p (list
228 (setq symbol (car p))
d69e3b68
KH
229 (when (fboundp symbol)
230 (if (setq doc (documentation symbol t))
231 (substring doc 0 (string-match "\n" doc))
232 "(not documented)"))
233 (when (boundp symbol)
234 (if (setq doc (documentation-property
235 symbol 'variable-documentation t))
236 (substring doc 0 (string-match "\n" doc))
237 "(not documented)"))
238 (when (setq properties (symbol-plist symbol))
239 (setq doc (list (car properties)))
240 (while (setq properties (cdr (cdr properties)))
241 (setq doc (cons (car properties) doc)))
5edc67d3
RS
242 (mapconcat #'symbol-name (nreverse doc) " "))
243 (when (get symbol 'widget-type)
244 (if (setq doc (documentation-property
245 symbol 'widget-documentation t))
246 (substring doc 0
247 (string-match "\n" doc))
248 "(not documented)"))
249 (when (facep symbol)
250 (if (setq doc (documentation-property
251 symbol 'face-documentation t))
252 (substring doc 0
253 (string-match "\n" doc))
2be7e3fa
RS
254 "(not documented)"))
255 (when (get symbol 'custom-group)
256 (if (setq doc (documentation-property
257 symbol 'group-documentation t))
258 (substring doc 0
259 (string-match "\n" doc))
5edc67d3 260 "(not documented)"))))
3925e76d
KH
261 (setq p (cdr p)))))
262 nil))
263
264
6f8e447f 265;;;###autoload
645c4f6a 266(defun apropos-value (apropos-regexp &optional do-all)
3925e76d
KH
267 "Show all symbols whose value's printed image matches REGEXP.
268With optional prefix ARG or if `apropos-do-all' is non-nil, also looks
269at the function and at the names and values of properties.
645c4f6a 270Returns list of symbols and values found."
3925e76d 271 (interactive "sApropos value (regexp): \nP")
645c4f6a
KH
272 (or do-all (setq do-all apropos-do-all))
273 (setq apropos-accumulator ())
274 (let (f v p)
3925e76d
KH
275 (mapatoms
276 (lambda (symbol)
277 (setq f nil v nil p nil)
645c4f6a
KH
278 (or (memq symbol '(apropos-regexp do-all apropos-accumulator
279 symbol f v p))
280 (setq v (apropos-value-internal 'boundp symbol 'symbol-value)))
3925e76d 281 (if do-all
645c4f6a
KH
282 (setq f (apropos-value-internal 'fboundp symbol 'symbol-function)
283 p (apropos-format-plist symbol "\n " t)))
3925e76d 284 (if (or f v p)
645c4f6a
KH
285 (setq apropos-accumulator (cons (list symbol f v p)
286 apropos-accumulator))))))
287 (apropos-print nil nil t))
3925e76d
KH
288
289
645c4f6a
KH
290;;;###autoload
291(defun apropos-documentation (apropos-regexp &optional do-all)
26a4a227 292 "Show symbols whose documentation contain matches for REGEXP.
645c4f6a
KH
293With optional prefix ARG or if `apropos-do-all' is non-nil, also use
294documentation that is not stored in the documentation file and show key
295bindings.
296Returns list of symbols and documentation found."
297 (interactive "sApropos documentation (regexp): \nP")
298 (or do-all (setq do-all apropos-do-all))
299 (setq apropos-accumulator () apropos-files-scanned ())
300 (let ((standard-input (get-buffer-create " apropos-temp"))
301 f v)
302 (unwind-protect
303 (save-excursion
304 (set-buffer standard-input)
305 (apropos-documentation-check-doc-file)
306 (if do-all
307 (mapatoms
308 (lambda (symbol)
309 (setq f (apropos-safe-documentation symbol)
26a4a227
KH
310 v (get symbol 'variable-documentation))
311 (if (integerp v) (setq v))
312 (setq f (apropos-documentation-internal f)
313 v (apropos-documentation-internal v))
645c4f6a
KH
314 (if (or f v)
315 (if (setq apropos-item
316 (cdr (assq symbol apropos-accumulator)))
317 (progn
318 (if f
319 (setcar apropos-item f))
320 (if v
321 (setcar (cdr apropos-item) v)))
322 (setq apropos-accumulator
323 (cons (list symbol f v)
324 apropos-accumulator)))))))
26a4a227 325 (apropos-print nil nil t))
645c4f6a
KH
326 (kill-buffer standard-input))))
327
328\f
329(defun apropos-value-internal (predicate symbol function)
330 (if (funcall predicate symbol)
331 (progn
332 (setq symbol (prin1-to-string (funcall function symbol)))
333 (if (string-match apropos-regexp symbol)
334 (progn
335 (if apropos-match-face
336 (put-text-property (match-beginning 0) (match-end 0)
337 'face apropos-match-face
338 symbol))
339 symbol)))))
340
341(defun apropos-documentation-internal (doc)
342 (if (consp doc)
343 (apropos-documentation-check-elc-file (car doc))
344 (and doc
345 (string-match apropos-regexp doc)
346 (progn
347 (if apropos-match-face
348 (put-text-property (match-beginning 0)
349 (match-end 0)
350 'face apropos-match-face
351 (setq doc (copy-sequence doc))))
352 doc))))
353
354(defun apropos-format-plist (pl sep &optional compare)
3925e76d
KH
355 (setq pl (symbol-plist pl))
356 (let (p p-out)
357 (while pl
358 (setq p (format "%s %S" (car pl) (nth 1 pl)))
645c4f6a
KH
359 (if (or (not compare) (string-match apropos-regexp p))
360 (if apropos-property-face
3925e76d 361 (put-text-property 0 (length (symbol-name (car pl)))
645c4f6a 362 'face apropos-property-face p))
3925e76d 363 (setq p nil))
645c4f6a
KH
364 (if p
365 (progn
366 (and compare apropos-match-face
367 (put-text-property (match-beginning 0) (match-end 0)
368 'face apropos-match-face
369 p))
370 (setq p-out (concat p-out (if p-out sep) p))))
3925e76d
KH
371 (setq pl (nthcdr 2 pl)))
372 p-out))
373
6f8e447f 374
645c4f6a 375;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name.
3925e76d 376
645c4f6a 377(defun apropos-documentation-check-doc-file ()
26a4a227
KH
378 (let (type symbol (sepa 2) sepb beg end)
379 (insert ?\^_)
380 (backward-char)
645c4f6a 381 (insert-file-contents (concat doc-directory internal-doc-file-name))
26a4a227
KH
382 (forward-char)
383 (while (save-excursion
384 (setq sepb (search-forward "\^_"))
385 (not (eobp)))
386 (beginning-of-line 2)
387 (if (save-restriction
388 (narrow-to-region (point) (1- sepb))
389 (re-search-forward apropos-regexp nil t))
390 (progn
391 (setq beg (match-beginning 0)
392 end (point))
393 (goto-char (1+ sepa))
394 (or (setq type (if (eq ?F (preceding-char))
395 1 ; function documentation
396 2) ; variable documentation
397 symbol (read)
398 beg (- beg (point) 1)
399 end (- end (point) 1)
400 doc (buffer-substring (1+ (point)) (1- sepb))
401 apropos-item (assq symbol apropos-accumulator))
402 (setq apropos-item (list symbol nil nil)
403 apropos-accumulator (cons apropos-item
404 apropos-accumulator)))
405 (if apropos-match-face
406 (put-text-property beg end 'face apropos-match-face doc))
407 (setcar (nthcdr type apropos-item) doc)))
408 (setq sepa (goto-char sepb)))))
645c4f6a
KH
409
410(defun apropos-documentation-check-elc-file (file)
411 (if (member file apropos-files-scanned)
412 nil
26a4a227 413 (let (symbol doc beg end this-is-a-variable)
645c4f6a
KH
414 (setq apropos-files-scanned (cons file apropos-files-scanned))
415 (erase-buffer)
416 (insert-file-contents file)
417 (while (search-forward "\n#@" nil t)
418 ;; Read the comment length, and advance over it.
419 (setq end (read)
26a4a227
KH
420 beg (1+ (point))
421 end (+ (point) end -1))
422 (forward-char)
423 (if (save-restriction
424 ;; match ^ and $ relative to doc string
425 (narrow-to-region beg end)
426 (re-search-forward apropos-regexp nil t))
645c4f6a 427 (progn
26a4a227
KH
428 (goto-char (+ end 2))
429 (setq doc (buffer-substring beg end)
430 end (- (match-end 0) beg)
431 beg (- (match-beginning 0) beg)
432 this-is-a-variable (looking-at "(def\\(var\\|const\\) ")
645c4f6a
KH
433 symbol (progn
434 (skip-chars-forward "(a-z")
26a4a227 435 (forward-char)
645c4f6a
KH
436 (read))
437 symbol (if (consp symbol)
438 (nth 1 symbol)
439 symbol))
440 (if (if this-is-a-variable
441 (get symbol 'variable-documentation)
442 (and (fboundp symbol) (apropos-safe-documentation symbol)))
443 (progn
444 (or (setq apropos-item (assq symbol apropos-accumulator))
445 (setq apropos-item (list symbol nil nil)
446 apropos-accumulator (cons apropos-item
447 apropos-accumulator)))
448 (if apropos-match-face
26a4a227 449 (put-text-property beg end 'face apropos-match-face
645c4f6a
KH
450 doc))
451 (setcar (nthcdr (if this-is-a-variable 2 1)
452 apropos-item)
26a4a227 453 doc)))))))))
645c4f6a
KH
454
455
456
457(defun apropos-safe-documentation (function)
6f8e447f
RS
458 "Like documentation, except it avoids calling `get_doc_string'.
459Will return nil instead."
3925e76d 460 (while (and function (symbolp function))
6f8e447f 461 (setq function (if (fboundp function)
3925e76d 462 (symbol-function function))))
d2e1218f
RS
463 (if (eq (car-safe function) 'macro)
464 (setq function (cdr function)))
3925e76d 465 (setq function (if (byte-code-function-p function)
645c4f6a
KH
466 (if (> (length function) 4)
467 (aref function 4))
468 (if (eq (car-safe function) 'autoload)
469 (nth 2 function)
470 (if (eq (car-safe function) 'lambda)
471 (if (stringp (nth 2 function))
472 (nth 2 function)
473 (if (stringp (nth 3 function))
474 (nth 3 function)))))))
475 (if (integerp function)
476 nil
477 function))
478
479
480
481(defun apropos-print (do-keys doc-fn spacing)
482 "Output result of various apropos commands with `apropos-regexp'.
483APROPOS-ACCUMULATOR is a list. Optional DOC-FN is called for each element
484of apropos-accumulator and may modify it resulting in (symbol fn-doc
3925e76d
KH
485var-doc [plist-doc]). Returns sorted list of symbols and documentation
486found."
645c4f6a
KH
487 (if (null apropos-accumulator)
488 (message "No apropos matches for `%s'" apropos-regexp)
3925e76d 489 (if doc-fn
645c4f6a
KH
490 (funcall doc-fn apropos-accumulator))
491 (setq apropos-accumulator
492 (sort apropos-accumulator (lambda (a b)
26a4a227 493 (string-lessp (car a) (car b)))))
645c4f6a
KH
494 (and apropos-label-face
495 (symbolp apropos-label-face)
496 (setq apropos-label-face `(face ,apropos-label-face
497 mouse-face highlight)))
09e32aaf 498 (with-output-to-temp-buffer "*Apropos*"
645c4f6a 499 (let ((p apropos-accumulator)
3925e76d 500 (old-buffer (current-buffer))
645c4f6a 501 symbol item point1 point2)
26a4a227
KH
502 (set-buffer standard-output)
503 (apropos-mode)
504 (if window-system
1f64403f
EN
505 (insert "If you move the mouse over text that changes color,\n"
506 (substitute-command-keys
3787cf2c 507 "you can click \\[apropos-mouse-follow] to get more information.\n")))
26a4a227
KH
508 (insert (substitute-command-keys
509 "In this buffer, type \\[apropos-follow] to get full documentation.\n\n"))
510 (while (consp p)
511 (or (not spacing) (bobp) (terpri))
512 (setq apropos-item (car p)
513 symbol (car apropos-item)
514 p (cdr p)
515 point1 (point))
516 (princ symbol) ; print symbol name
517 (setq point2 (point))
98ce2330 518 ;; Calculate key-bindings if we want them.
26a4a227
KH
519 (and do-keys
520 (commandp symbol)
521 (indent-to 30 1)
98ce2330
RS
522 (if (let ((keys
523 (save-excursion
524 (set-buffer old-buffer)
525 (where-is-internal symbol)))
526 filtered)
527 ;; Copy over the list of key sequences,
528 ;; omitting any that contain a buffer or a frame.
529 (while keys
530 (let ((key (car keys))
531 (i 0)
532 loser)
533 (while (< i (length key))
534 (if (or (framep (aref key i))
535 (bufferp (aref key i)))
536 (setq loser t))
537 (setq i (1+ i)))
538 (or loser
539 (setq filtered (cons key filtered))))
540 (setq keys (cdr keys)))
541 (setq item filtered))
542 ;; Convert the remaining keys to a string and insert.
543 (insert
26a4a227 544 (mapconcat
98ce2330
RS
545 (lambda (key)
546 (setq key (key-description key))
547 (if apropos-keybinding-face
26a4a227
KH
548 (put-text-property 0 (length key)
549 'face apropos-keybinding-face
98ce2330
RS
550 key))
551 key)
552 item ", "))
82fbaa5e
RS
553 (insert "M-x")
554 (put-text-property (- (point) 3) (point)
555 'face apropos-keybinding-face)
556 (insert " " (symbol-name symbol) " ")
557 (insert "RET")
558 (put-text-property (- (point) 3) (point)
559 'face apropos-keybinding-face)))
26a4a227
KH
560 (terpri)
561 ;; only now so we don't propagate text attributes all over
562 (put-text-property point1 point2 'item
563 (if (eval `(or ,@(cdr apropos-item)))
564 (car apropos-item)
565 apropos-item))
566 (if apropos-symbol-face
567 (put-text-property point1 point2 'face apropos-symbol-face))
568 (apropos-print-doc 'describe-function 1
569 (if (commandp symbol)
570 "Command"
571 (if (apropos-macrop symbol)
572 "Macro"
573 "Function"))
8d7f1de3 574 t)
5edc67d3
RS
575 (if (get symbol 'custom-type)
576 (apropos-print-doc 'customize-variable-other-window 2
8d7f1de3 577 "User Option" t)
5edc67d3 578 (apropos-print-doc 'describe-variable 2
8d7f1de3
RS
579 "Variable" t))
580 (apropos-print-doc 'customize-group-other-window 6 "Group" t)
581 (apropos-print-doc 'customize-face-other-window 5 "Face" t)
582 (apropos-print-doc 'widget-browse-other-window 4 "Widget" t)
26a4a227
KH
583 (apropos-print-doc 'apropos-describe-plist 3
584 "Plist" nil)))))
645c4f6a
KH
585 (prog1 apropos-accumulator
586 (setq apropos-accumulator ()))) ; permit gc
587
3925e76d 588
645c4f6a
KH
589(defun apropos-macrop (symbol)
590 "T if SYMBOL is a Lisp macro."
591 (and (fboundp symbol)
592 (consp (setq symbol
593 (symbol-function symbol)))
594 (or (eq (car symbol) 'macro)
595 (if (eq (car symbol) 'autoload)
596 (memq (nth 4 symbol)
597 '(macro t))))))
3925e76d 598
645c4f6a
KH
599
600(defun apropos-print-doc (action i str do-keys)
601 (if (stringp (setq i (nth i apropos-item)))
3925e76d
KH
602 (progn
603 (insert " ")
604 (put-text-property (- (point) 2) (1- (point))
605 'action action)
645c4f6a
KH
606 (insert str ": ")
607 (if apropos-label-face
608 (add-text-properties (- (point) (length str) 2)
3925e76d 609 (1- (point))
645c4f6a
KH
610 apropos-label-face))
611 (insert (if do-keys (substitute-command-keys i) i))
612 (or (bolp) (terpri)))))
3925e76d
KH
613
614
615(defun apropos-mouse-follow (event)
616 (interactive "e")
26a4a227 617 (let ((other (if (eq (current-buffer) (get-buffer "*Apropos*"))
3925e76d
KH
618 ()
619 (current-buffer))))
17ef0353
RS
620 (save-excursion
621 (set-buffer (window-buffer (posn-window (event-start event))))
622 (goto-char (posn-point (event-start event)))
623 (or (and (not (eobp)) (get-text-property (point) 'mouse-face))
624 (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face))
625 (error "There is nothing to follow here"))
17ef0353 626 (apropos-follow other))))
3925e76d
KH
627
628
629(defun apropos-follow (&optional other)
630 (interactive)
17ef0353
RS
631 (let* (;; Properties are always found at the beginning of the line.
632 (bol (save-excursion (beginning-of-line) (point)))
633 ;; If there is no `item' property here, look behind us.
634 (item (get-text-property bol 'item))
635 (item-at (if item nil (previous-single-property-change bol 'item)))
636 ;; Likewise, if there is no `action' property here, look in front.
637 (action (get-text-property bol 'action))
638 (action-at (if action nil (next-single-property-change bol 'action))))
639 (and (null item) item-at
640 (setq item (get-text-property (1- item-at) 'item)))
641 (and (null action) action-at
642 (setq action (get-text-property action-at 'action)))
643 (if (not (and item action))
0a812366 644 (error "There is nothing to follow here"))
17ef0353
RS
645 (if (consp item) (error "There is nothing to follow in `%s'" (car item)))
646 (if other (set-buffer other))
647 (funcall action item)))
3925e76d
KH
648
649
650
651(defun apropos-describe-plist (symbol)
652 "Display a pretty listing of SYMBOL's plist."
653 (with-output-to-temp-buffer "*Help*"
654 (set-buffer standard-output)
655 (princ "Symbol ")
656 (prin1 symbol)
657 (princ "'s plist is\n (")
645c4f6a
KH
658 (if apropos-symbol-face
659 (put-text-property 8 (- (point) 14) 'face apropos-symbol-face))
3925e76d 660 (insert (apropos-format-plist symbol "\n "))
26a4a227
KH
661 (princ ")")
662 (print-help-return-message)))
6f8e447f 663
896546cd
RS
664(provide 'apropos)
665
c0274f38 666;;; apropos.el ends here