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