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