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