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