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