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