Mercurial > emacs
comparison lisp/apropos.el @ 12640:d194c63cb75c
Add latest changes of old library and some more.
(apropos): Only show unbound symbols when do-all
(apropos-documentation-check-elc-file): new copied function.
(apropos-command): also use `apropos-do-all' when called as function.
(apropos-print-doc): renamed from `apropos-print-documentation', i
is numeric index, replaces parameter tem.
(apropos-macrop): new function.
(apropos-print): use it to differentiate macros.
(apropos-symbol-face, apropos-keybinding-face, apropos-label-face)
(apropos-property-face, apropos-match-face): new variables
replace and extend the effect of `apropos-use-faces'.
(apropos-safe-documentation): renames `safe-documentation', also
returns a cons.
(apropos-regexp, apropos-files-scanned, apropos-accumulator)
(apropos-item): new variables to prevent compiler warnings.
(apropos-value-internal, apropos-documentation-internal): new fns.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Sat, 22 Jul 1995 15:17:54 +0000 |
parents | 9fb6a9b6658b |
children | 0bfd3ae57234 |
comparison
equal
deleted
inserted
replaced
12639:1410ce7c4fab | 12640:d194c63cb75c |
---|---|
42 ;;; Added fast-command-apropos. | 42 ;;; Added fast-command-apropos. |
43 ;; Changed doc strings to comments for helping functions. | 43 ;; Changed doc strings to comments for helping functions. |
44 ;;; Made doc file buffer read-only, buried it. | 44 ;;; Made doc file buffer read-only, buried it. |
45 ;; Only call substitute-command-keys if do-all set. | 45 ;; Only call substitute-command-keys if do-all set. |
46 | 46 |
47 ;; Optionally use faces to make the output more legible. | 47 ;; Optionally use configurable faces to make the output more legible. |
48 ;; Differentiate between command and function. | 48 ;; Differentiate between command, function and macro. |
49 ;; Apropos-command (ex command-apropos) does cmd and optionally user var. | 49 ;; Apropos-command (ex command-apropos) does cmd and optionally user var. |
50 ;; Apropos shows all 3 aspects of symbols (fn, var and plist) | 50 ;; Apropos shows all 3 aspects of symbols (fn, var and plist) |
51 ;; Apropos-documentation (ex super-apropos) now finds all it should. | 51 ;; Apropos-documentation (ex super-apropos) now finds all it should. |
52 ;; New apropos-value snoops through all values and optionally plists. | 52 ;; New apropos-value snoops through all values and optionally plists. |
53 ;; Reading DOC file doesn't load nroff. | 53 ;; Reading DOC file doesn't load nroff. |
60 (defvar apropos-do-all nil | 60 (defvar apropos-do-all nil |
61 "*Whether the apropos commands should do more. | 61 "*Whether the apropos commands should do more. |
62 Slows them down more or less. Set this non-nil if you have a fast machine.") | 62 Slows them down more or less. Set this non-nil if you have a fast machine.") |
63 | 63 |
64 | 64 |
65 (defvar apropos-use-faces window-system | 65 (defvar apropos-symbol-face (if window-system 'bold) |
66 "*Whether the apropos commands display output using bold and italic. | 66 "*Face for symbol name in apropos output or `nil'. |
67 This looks good, but slows down the commands several times.") | |
68 | |
69 (defvar apropos-keybinding-face (if window-system 'underline) | |
70 "*Face for keybinding display in apropos output or `nil'. | |
71 This looks good, but slows down the commands several times.") | |
72 | |
73 (defvar apropos-label-face (if window-system 'italic) | |
74 "*Face for label (Command, Variable ...) in apropos output or `nil'. | |
75 If this is `nil' no mouse highlighting occurs. | |
76 This looks good, but slows down the commands several times. | |
77 When this is a face name, as it is initially, it gets transformed to a | |
78 text-property list for efficiency.") | |
79 | |
80 (defvar apropos-property-face (if window-system 'bold-italic) | |
81 "*Face for property name in apropos output or `nil'. | |
82 This looks good, but slows down the commands several times.") | |
83 | |
84 (defvar apropos-match-face (if window-system 'highlight) | |
85 "*Face for matching part in apropos-documentation/value output or `nil'. | |
67 This looks good, but slows down the commands several times.") | 86 This looks good, but slows down the commands several times.") |
68 | 87 |
69 | 88 |
70 (defvar apropos-local-map | 89 (defvar apropos-local-map |
71 (let ((map (make-sparse-keymap))) | 90 (let ((map (make-sparse-keymap))) |
74 (define-key map [down-mouse-2] nil) | 93 (define-key map [down-mouse-2] nil) |
75 map) | 94 map) |
76 "Local map active when displaying apropos output.") | 95 "Local map active when displaying apropos output.") |
77 | 96 |
78 | 97 |
79 | 98 (defvar apropos-regexp nil |
80 ;;;###autoload (fset 'command-apropos 'apropos-command) | 99 "Regexp used in current apropos run.") |
100 | |
101 (defvar apropos-files-scanned () | |
102 "List of elc files already scanned in current run of `apropos-documentaion'.") | |
103 | |
104 (defvar apropos-accumulator () | |
105 "Alist of symbols already found in current apropos run.") | |
106 | |
107 (defvar apropos-item () | |
108 "Current item in or for apropos-accumulator.") | |
109 | |
110 ;; For auld lang syne: | |
81 ;;;###autoload | 111 ;;;###autoload |
82 (defun apropos-command (regexp &optional do-all) | 112 (fset 'command-apropos 'apropos-command) |
113 ;;;###autoload | |
114 (defun apropos-command (apropos-regexp &optional do-all) | |
83 "Shows commands (interactively callable functions) that match REGEXP. | 115 "Shows commands (interactively callable functions) that match REGEXP. |
84 With optional prefix ARG or if `apropos-do-all' is non-nil, also show | 116 With optional prefix ARG or if `apropos-do-all' is non-nil, also show |
85 variables." | 117 variables." |
86 (interactive (list (read-string (concat "Apropos command " | 118 (interactive (list (read-string (concat "Apropos command " |
87 (if (or current-prefix-arg | 119 (if (or current-prefix-arg |
88 apropos-do-all) | 120 apropos-do-all) |
89 "or variable ") | 121 "or variable ") |
90 "(regexp): ")) | 122 "(regexp): ")) |
91 (or current-prefix-arg apropos-do-all))) | 123 current-prefix-arg)) |
92 (let ((message | 124 (let ((message |
93 (let ((standard-output (get-buffer-create "*Help*"))) | 125 (let ((standard-output (get-buffer-create "*Help*"))) |
94 (print-help-return-message 'identity)))) | 126 (print-help-return-message 'identity)))) |
127 (or do-all (setq do-all apropos-do-all)) | |
128 (setq apropos-accumulator | |
129 (apropos-internal apropos-regexp | |
130 (if do-all | |
131 (lambda (symbol) (or (commandp symbol) | |
132 (user-variable-p symbol))) | |
133 'commandp))) | |
95 (if (apropos-print | 134 (if (apropos-print |
96 regexp | |
97 (apropos-internal regexp | |
98 (if do-all | |
99 (lambda (x) (or (commandp x) | |
100 (user-variable-p x))) | |
101 'commandp)) | |
102 t | 135 t |
103 (lambda (p) | 136 (lambda (p) |
104 (let (doc symbol) | 137 (let (doc symbol) |
105 (while p | 138 (while p |
106 (setcar p (list | 139 (setcar p (list |
118 (setq p (cdr p))))) | 151 (setq p (cdr p))))) |
119 nil) | 152 nil) |
120 (and message (message message))))) | 153 (and message (message message))))) |
121 | 154 |
122 | 155 |
123 | |
124 ;;;###autoload | 156 ;;;###autoload |
125 (defun apropos (regexp &optional do-all) | 157 (defun apropos (apropos-regexp &optional do-all) |
126 "Show all symbols whose names match REGEXP. | 158 "Show all bound symbols whose names match REGEXP. |
127 With optional prefix ARG or if `apropos-do-all' is non-nil, also show key | 159 With optional prefix ARG or if `apropos-do-all' is non-nil, also show unbound |
128 bindings, which is a little more time-consuming. | 160 symbols and key bindings, which is a little more time-consuming. |
129 Returns list of symbols and documentation found." | 161 Returns list of symbols and documentation found." |
130 (interactive "sApropos symbol (regexp): \nP") | 162 (interactive "sApropos symbol (regexp): \nP") |
163 (setq apropos-accumulator | |
164 (apropos-internal apropos-regexp | |
165 (and (not do-all) | |
166 (not apropos-do-all) | |
167 (lambda (symbol) | |
168 (or (fboundp symbol) | |
169 (boundp symbol) | |
170 (symbol-plist symbol)))))) | |
131 (apropos-print | 171 (apropos-print |
132 regexp (apropos-internal regexp) | 172 (or do-all apropos-do-all) |
133 (or apropos-do-all do-all) | |
134 (lambda (p) | 173 (lambda (p) |
135 (let (symbol doc) | 174 (let (symbol doc) |
136 (while p | 175 (while p |
137 (setcar p (list | 176 (setcar p (list |
138 (setq symbol (car p)) | 177 (setq symbol (car p)) |
152 (concat doc " properties"))))) | 191 (concat doc " properties"))))) |
153 (setq p (cdr p))))) | 192 (setq p (cdr p))))) |
154 nil)) | 193 nil)) |
155 | 194 |
156 | 195 |
157 | |
158 ;;;###autoload | 196 ;;;###autoload |
159 (defun apropos-value (regexp &optional do-all) | 197 (defun apropos-value (apropos-regexp &optional do-all) |
160 "Show all symbols whose value's printed image matches REGEXP. | 198 "Show all symbols whose value's printed image matches REGEXP. |
161 With optional prefix ARG or if `apropos-do-all' is non-nil, also looks | 199 With optional prefix ARG or if `apropos-do-all' is non-nil, also looks |
162 at the function and at the names and values of properties. | 200 at the function and at the names and values of properties. |
163 Returns list of symbols and documentation found." | 201 Returns list of symbols and values found." |
164 (interactive "sApropos value (regexp): \nP") | 202 (interactive "sApropos value (regexp): \nP") |
165 (setq do-all (or apropos-do-all do-all)) | 203 (or do-all (setq do-all apropos-do-all)) |
166 (apropos-print | 204 (setq apropos-accumulator ()) |
167 regexp | 205 (let (f v p) |
168 (let (accumulator f v p) | |
169 (mapatoms | 206 (mapatoms |
170 (lambda (symbol) | 207 (lambda (symbol) |
171 (setq f nil v nil p nil) | 208 (setq f nil v nil p nil) |
172 (or (memq symbol '(regexp do-all accumulator symbol v pl p)) | 209 (or (memq symbol '(apropos-regexp do-all apropos-accumulator |
173 (if (boundp symbol) | 210 symbol f v p)) |
174 (setq v (prin1-to-string (symbol-value symbol)) | 211 (setq v (apropos-value-internal 'boundp symbol 'symbol-value))) |
175 v (if (string-match regexp v) v)))) | |
176 (if do-all | 212 (if do-all |
177 (progn | 213 (setq f (apropos-value-internal 'fboundp symbol 'symbol-function) |
178 (if (fboundp symbol) | 214 p (apropos-format-plist symbol "\n " t))) |
179 (setq f (prin1-to-string (symbol-function symbol)) | |
180 f (if (string-match regexp f) f))) | |
181 (setq p (apropos-format-plist symbol "\n " regexp)))) | |
182 ;; (if p-out (insert p-out)) | |
183 (if (or f v p) | 215 (if (or f v p) |
184 (setq accumulator (cons (list symbol f v p) accumulator))))) | 216 (setq apropos-accumulator (cons (list symbol f v p) |
185 accumulator) | 217 apropos-accumulator)))))) |
186 nil nil t)) | 218 (apropos-print nil nil t)) |
187 | |
188 | |
189 (defun apropos-format-plist (pl sep &optional regexp) | |
190 (setq pl (symbol-plist pl)) | |
191 (let (p p-out) | |
192 (while pl | |
193 (setq p (format "%s %S" (car pl) (nth 1 pl))) | |
194 (if (string-match (or regexp "") p) | |
195 (if apropos-use-faces | |
196 (put-text-property 0 (length (symbol-name (car pl))) | |
197 'face 'bold-italic p)) | |
198 (setq p nil)) | |
199 (if p (setq p-out (concat p-out (if p-out sep) p))) | |
200 (setq pl (nthcdr 2 pl))) | |
201 p-out)) | |
202 | |
203 | 219 |
204 | 220 |
205 ;;;###autoload | 221 ;;;###autoload |
206 (defun apropos-documentation (regexp &optional do-all) | 222 (defun apropos-documentation (apropos-regexp &optional do-all) |
207 "Show symbols whose names or documentation contain matches for REGEXP. | 223 "Show symbols whose names or documentation contain matches for REGEXP. |
208 With optional prefix ARG or if `apropos-do-all' is non-nil, also use | 224 With optional prefix ARG or if `apropos-do-all' is non-nil, also use |
209 documentation that is not stored in the documentation file and show key | 225 documentation that is not stored in the documentation file and show key |
210 bindings. | 226 bindings. |
211 Returns list of symbols and documentation found." | 227 Returns list of symbols and documentation found." |
212 (interactive "sApropos documentation (regexp): \nP") | 228 (interactive "sApropos documentation (regexp): \nP") |
213 (setq do-all (or apropos-do-all do-all)) | 229 (or do-all (setq do-all apropos-do-all)) |
214 (let (accumulator fn-doc var-doc item) | 230 (setq apropos-accumulator () apropos-files-scanned ()) |
215 (setq accumulator (apropos-documentation-check-doc-file regexp)) | 231 (let ((standard-input (get-buffer-create " apropos-temp")) |
216 (if do-all | 232 f v) |
217 (mapatoms | 233 (unwind-protect |
218 (lambda (symbol) | 234 (save-excursion |
219 (setq fn-doc (safe-documentation symbol) | 235 (set-buffer standard-input) |
220 var-doc (get symbol 'variable-documentation)) | 236 (apropos-documentation-check-doc-file) |
221 (if (numberp var-doc) | 237 (if do-all |
222 (setq var-doc nil)) | 238 (mapatoms |
223 (if (string-match regexp (symbol-name symbol)) | 239 (lambda (symbol) |
224 () | 240 (setq f (apropos-safe-documentation symbol) |
225 (if fn-doc | 241 v (get symbol 'variable-documentation) |
226 (or (string-match regexp fn-doc) | 242 v (if (integerp v) nil v)) |
227 (setq fn-doc nil))) | 243 (or (string-match apropos-regexp (symbol-name symbol)) |
228 (if var-doc | 244 (setq f (apropos-documentation-internal f) |
229 (or (string-match regexp var-doc) | 245 v (apropos-documentation-internal v))) |
230 (setq var-doc nil)))) | 246 (if (or f v) |
231 (if (or fn-doc var-doc) | 247 (if (setq apropos-item |
232 (if (setq item (cdr (assq symbol accumulator))) | 248 (cdr (assq symbol apropos-accumulator))) |
233 (progn | 249 (progn |
234 (if fn-doc | 250 (if f |
235 (setcar item fn-doc)) | 251 (setcar apropos-item f)) |
236 (if var-doc | 252 (if v |
237 (setcar (cdr item) var-doc))) | 253 (setcar (cdr apropos-item) v))) |
238 (setq accumulator | 254 (setq apropos-accumulator |
239 (cons (list symbol fn-doc var-doc) | 255 (cons (list symbol f v) |
240 accumulator))))))) | 256 apropos-accumulator))))))) |
241 (apropos-print regexp accumulator do-all nil t))) | 257 (apropos-print do-all nil t)) |
258 (kill-buffer standard-input)))) | |
242 | 259 |
243 | 260 |
244 | 261 (defun apropos-value-internal (predicate symbol function) |
245 ;; Finds all documentation related to REGEXP in internal-doc-file-name. | 262 (if (funcall predicate symbol) |
246 ;; Returns an alist of form ((symbol fn-doc var-doc) ...). | 263 (progn |
247 | 264 (setq symbol (prin1-to-string (funcall function symbol))) |
248 (defun apropos-documentation-check-doc-file (regexp) | 265 (if (string-match apropos-regexp symbol) |
249 (let ((doc-buffer (get-buffer-create " *apropos-doc*")) | 266 (progn |
250 ;; item is already let | 267 (if apropos-match-face |
251 type symbol sym-list) | 268 (put-text-property (match-beginning 0) (match-end 0) |
252 (set-buffer doc-buffer) | 269 'face apropos-match-face |
253 (goto-char (point-min)) | 270 symbol)) |
254 (if (eobp) | 271 symbol))))) |
255 (insert-file-contents (concat doc-directory internal-doc-file-name))) | 272 |
256 (while (re-search-forward regexp nil t) | 273 (defun apropos-documentation-internal (doc) |
274 (if (consp doc) | |
275 (apropos-documentation-check-elc-file (car doc)) | |
276 (and doc | |
277 (string-match apropos-regexp doc) | |
278 (progn | |
279 (if apropos-match-face | |
280 (put-text-property (match-beginning 0) | |
281 (match-end 0) | |
282 'face apropos-match-face | |
283 (setq doc (copy-sequence doc)))) | |
284 doc)))) | |
285 | |
286 (defun apropos-format-plist (pl sep &optional compare) | |
287 (setq pl (symbol-plist pl)) | |
288 (let (p p-out) | |
289 (while pl | |
290 (setq p (format "%s %S" (car pl) (nth 1 pl))) | |
291 (if (or (not compare) (string-match apropos-regexp p)) | |
292 (if apropos-property-face | |
293 (put-text-property 0 (length (symbol-name (car pl))) | |
294 'face apropos-property-face p)) | |
295 (setq p nil)) | |
296 (if p | |
297 (progn | |
298 (and compare apropos-match-face | |
299 (put-text-property (match-beginning 0) (match-end 0) | |
300 'face apropos-match-face | |
301 p)) | |
302 (setq p-out (concat p-out (if p-out sep) p)))) | |
303 (setq pl (nthcdr 2 pl))) | |
304 p-out)) | |
305 | |
306 | |
307 ;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name. | |
308 | |
309 (defun apropos-documentation-check-doc-file () | |
310 (let (type symbol beg end) | |
311 (insert-file-contents (concat doc-directory internal-doc-file-name)) | |
312 (while (re-search-forward apropos-regexp nil t) | |
313 (setq beg (match-beginning 0) | |
314 end (point)) | |
257 (search-backward "\C-_") | 315 (search-backward "\C-_") |
258 (or (setq type (if (eq ?F (char-after (1+ (point)))) | 316 (if (> (point) beg) |
259 1 ;function documentation | 317 () |
260 2) ;variable documentation | 318 (or (setq type (if (eq ?F (char-after (1+ (point)))) |
261 symbol (progn | 319 1 ;function documentation |
262 (forward-char 2) | 320 2) ;variable documentation |
263 (read doc-buffer)) | 321 symbol (prog2 |
264 doc (buffer-substring | 322 (forward-char 2) |
265 (1+ (point)) | 323 (read)) |
266 (if (search-forward "\C-_" nil 'move) | 324 beg (- beg (point) 1) |
267 (1- (point)) | 325 end (- end (point) 1) |
268 (point))) | 326 doc (buffer-substring |
269 item (assq symbol sym-list)) | 327 (1+ (point)) |
270 (setq item (list symbol nil nil) | 328 (if (search-forward "\C-_" nil 'move) |
271 sym-list (cons item sym-list))) | 329 (1- (point)) |
272 (setcar (nthcdr type item) doc)) | 330 (point))) |
273 sym-list)) | 331 apropos-item (assq symbol apropos-accumulator)) |
274 | 332 (setq apropos-item (list symbol nil nil) |
275 | 333 apropos-accumulator (cons apropos-item apropos-accumulator))) |
276 | 334 (and apropos-match-face |
277 ;; This function is misnamed, it is simply a variety of the original | 335 (>= beg 0) |
278 ;; that might be handled easier and more efficiently by that with a flag. | 336 (put-text-property beg end 'face apropos-match-face doc)) |
279 ;; Otherwise it might be inlined above. | 337 (setcar (nthcdr type apropos-item) doc))))) |
280 | 338 |
281 (defun safe-documentation (function) | 339 (defun apropos-documentation-check-elc-file (file) |
340 (if (member file apropos-files-scanned) | |
341 nil | |
342 (let (symbol doc beg end end1 this-is-a-variable) | |
343 (setq apropos-files-scanned (cons file apropos-files-scanned)) | |
344 (erase-buffer) | |
345 (insert-file-contents file) | |
346 (while (search-forward "\n#@" nil t) | |
347 ;; Read the comment length, and advance over it. | |
348 (setq end (read) | |
349 beg (point) | |
350 end (+ (point) end 1)) | |
351 (if (re-search-forward apropos-regexp end t) | |
352 (progn | |
353 (goto-char end) | |
354 (setq doc (buffer-substring (1+ beg) (- end 2)) | |
355 end1 (- (match-end 0) beg 1) | |
356 beg (- (match-beginning 0) beg 1) | |
357 this-is-a-variable (looking-at "(defvar\\|(defconst") | |
358 symbol (progn | |
359 (skip-chars-forward "(a-z") | |
360 (forward-char 1) | |
361 (read)) | |
362 symbol (if (consp symbol) | |
363 (nth 1 symbol) | |
364 symbol)) | |
365 (if (if this-is-a-variable | |
366 (get symbol 'variable-documentation) | |
367 (and (fboundp symbol) (apropos-safe-documentation symbol))) | |
368 (progn | |
369 (or (setq 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 end1 'face apropos-match-face | |
375 doc)) | |
376 (setcar (nthcdr (if this-is-a-variable 2 1) | |
377 apropos-item) | |
378 doc))))) | |
379 (goto-char end))))) | |
380 | |
381 | |
382 | |
383 (defun apropos-safe-documentation (function) | |
282 "Like documentation, except it avoids calling `get_doc_string'. | 384 "Like documentation, except it avoids calling `get_doc_string'. |
283 Will return nil instead." | 385 Will return nil instead." |
284 (while (and function (symbolp function)) | 386 (while (and function (symbolp function)) |
285 (setq function (if (fboundp function) | 387 (setq function (if (fboundp function) |
286 (symbol-function function)))) | 388 (symbol-function function)))) |
287 (if (eq (car-safe function) 'macro) | 389 (if (eq (car-safe function) 'macro) |
288 (setq function (cdr function))) | 390 (setq function (cdr function))) |
289 (setq function (if (byte-code-function-p function) | 391 (setq function (if (byte-code-function-p function) |
290 (condition-case nil | 392 (if (> (length function) 4) |
291 (aref function 4) | 393 (aref function 4)) |
292 (error)) | 394 (if (eq (car-safe function) 'autoload) |
293 (if (memq (car-safe function) '(lambda autoload)) | 395 (nth 2 function) |
294 (nth 2 function)))) | 396 (if (eq (car-safe function) 'lambda) |
295 (if (stringp function) | 397 (if (stringp (nth 2 function)) |
296 function)) | 398 (nth 2 function) |
297 | 399 (if (stringp (nth 3 function)) |
298 | 400 (nth 3 function))))))) |
299 | 401 (if (integerp function) |
300 (defun apropos-print (regexp apropos-result do-keys doc-fn spacing) | 402 nil |
301 "Output result of various appropos commands with REGEXP. | 403 function)) |
302 APROPOS-RESULT is a list. Optional DOC-FN is called for each element | 404 |
303 of apropos-result and may modify it resulting in (symbol fn-doc | 405 |
406 | |
407 (defun apropos-print (do-keys doc-fn spacing) | |
408 "Output result of various apropos commands with `apropos-regexp'. | |
409 APROPOS-ACCUMULATOR is a list. Optional DOC-FN is called for each element | |
410 of apropos-accumulator and may modify it resulting in (symbol fn-doc | |
304 var-doc [plist-doc]). Returns sorted list of symbols and documentation | 411 var-doc [plist-doc]). Returns sorted list of symbols and documentation |
305 found." | 412 found." |
306 (if (null apropos-result) | 413 (if (null apropos-accumulator) |
307 (message "No apropos matches for `%s'" regexp) | 414 (message "No apropos matches for `%s'" apropos-regexp) |
308 (if doc-fn | 415 (if doc-fn |
309 (funcall doc-fn apropos-result)) | 416 (funcall doc-fn apropos-accumulator)) |
310 (setq apropos-result | 417 (setq apropos-accumulator |
311 (sort apropos-result (lambda (a b) | 418 (sort apropos-accumulator (lambda (a b) |
312 (string-lessp (car a) (car b))))) | 419 (string-lessp (car a) (car b))))) |
420 (and apropos-label-face | |
421 (symbolp apropos-label-face) | |
422 (setq apropos-label-face `(face ,apropos-label-face | |
423 mouse-face highlight))) | |
313 (with-output-to-temp-buffer "*Help*" | 424 (with-output-to-temp-buffer "*Help*" |
314 (let ((p apropos-result) | 425 (let ((p apropos-accumulator) |
315 (old-buffer (current-buffer)) | 426 (old-buffer (current-buffer)) |
316 symbol item tem point1 point2) | 427 symbol item point1 point2) |
317 (save-excursion | 428 (save-excursion |
318 (set-buffer standard-output) | 429 (set-buffer standard-output) |
319 (if window-system | 430 (if window-system |
320 (insert (substitute-command-keys | 431 (insert (substitute-command-keys |
321 "Click \\<apropos-local-map>\\[apropos-mouse-follow] to get full documentation.\n"))) | 432 "Click \\<apropos-local-map>\\[apropos-mouse-follow] to get full documentation.\n"))) |
322 (insert (substitute-command-keys | 433 (insert (substitute-command-keys |
323 "In this buffer, type \\<apropos-local-map>\\[apropos-follow] to get full documentation.\n\n")) | 434 "In this buffer, type \\<apropos-local-map>\\[apropos-follow] to get full documentation.\n\n")) |
324 (while (consp p) | 435 (while (consp p) |
325 (or (not spacing) (bobp) (terpri)) | 436 (or (not spacing) (bobp) (terpri)) |
326 (setq item (car p) | 437 (setq apropos-item (car p) |
327 symbol (car item) | 438 symbol (car apropos-item) |
328 p (cdr p) | 439 p (cdr p) |
329 point1 (point)) | 440 point1 (point)) |
330 (princ symbol) ;print symbol name | 441 (princ symbol) ;print symbol name |
331 (setq point2 (point)) | 442 (setq point2 (point)) |
332 ;; don't calculate key-bindings unless needed | 443 ;; don't calculate key-bindings unless needed |
333 (and do-keys | 444 (and do-keys |
334 (commandp symbol) | 445 (commandp symbol) |
335 (indent-to 30 1) | 446 (indent-to 30 1) |
336 (princ (if (setq tem (save-excursion | 447 (insert |
337 (set-buffer old-buffer) | 448 (if (setq item (save-excursion |
338 (where-is-internal symbol))) | 449 (set-buffer old-buffer) |
339 (mapconcat 'key-description tem ", ") | 450 (where-is-internal symbol))) |
340 "(not bound to any keys)"))) | 451 (mapconcat |
452 (if apropos-keybinding-face | |
453 (lambda (key) | |
454 (setq key (key-description key)) | |
455 (put-text-property 0 (length key) | |
456 'face apropos-keybinding-face | |
457 key) | |
458 key) | |
459 'key-description) | |
460 item ", ") | |
461 "(not bound to any keys)"))) | |
341 (terpri) | 462 (terpri) |
342 ;; only now so we don't propagate text attributes all over | 463 ;; only now so we don't propagate text attributes all over |
343 (put-text-property point1 (1+ point1) 'item | 464 (put-text-property point1 (1+ point1) 'item |
344 (if (or (nth 1 item) (nth 2 item) (nth 3 item)) | 465 (if (eval `(or ,@(cdr apropos-item))) |
345 (car item) | 466 (car apropos-item) |
346 item)) | 467 apropos-item)) |
347 (if apropos-use-faces | 468 (if apropos-symbol-face |
348 (put-text-property point1 point2 'face 'bold)) | 469 (put-text-property point1 point2 'face apropos-symbol-face)) |
349 (apropos-print-documentation 'describe-function (nth 1 item) | 470 (apropos-print-doc 'describe-function 1 |
350 (if (commandp symbol) | 471 (if (commandp symbol) |
351 "Command: " | 472 "Command" |
352 "Function: ") | 473 (if (apropos-macrop symbol) |
353 do-keys) | 474 "Macro" |
354 (apropos-print-documentation 'describe-variable (nth 2 item) | 475 "Function")) |
355 "Variable: " do-keys) | 476 do-keys) |
356 (apropos-print-documentation 'apropos-describe-plist (nth 3 item) | 477 (apropos-print-doc 'describe-variable 2 |
357 "Plist: " nil)) | 478 "Variable" do-keys) |
479 (apropos-print-doc 'apropos-describe-plist 3 | |
480 "Plist" nil)) | |
358 (put-text-property 1 (point) 'local-map apropos-local-map))))) | 481 (put-text-property 1 (point) 'local-map apropos-local-map))))) |
359 apropos-result) | 482 (prog1 apropos-accumulator |
360 | 483 (setq apropos-accumulator ()))) ; permit gc |
361 | 484 |
362 (defun apropos-print-documentation (action tem str do-keys) | 485 |
363 (if tem | 486 (defun apropos-macrop (symbol) |
487 "T if SYMBOL is a Lisp macro." | |
488 (and (fboundp symbol) | |
489 (consp (setq symbol | |
490 (symbol-function symbol))) | |
491 (or (eq (car symbol) 'macro) | |
492 (if (eq (car symbol) 'autoload) | |
493 (memq (nth 4 symbol) | |
494 '(macro t)))))) | |
495 | |
496 | |
497 (defun apropos-print-doc (action i str do-keys) | |
498 (if (stringp (setq i (nth i apropos-item))) | |
364 (progn | 499 (progn |
365 (insert " ") | 500 (insert " ") |
366 (put-text-property (- (point) 2) (1- (point)) | 501 (put-text-property (- (point) 2) (1- (point)) |
367 'action action) | 502 'action action) |
368 (princ str) | 503 (insert str ": ") |
369 (if apropos-use-faces | 504 (if apropos-label-face |
370 (add-text-properties (- (point) (length str)) | 505 (add-text-properties (- (point) (length str) 2) |
371 (1- (point)) | 506 (1- (point)) |
372 '(face italic | 507 apropos-label-face)) |
373 mouse-face highlight))) | 508 (insert (if do-keys (substitute-command-keys i) i)) |
374 (insert (if do-keys (substitute-command-keys tem) tem)))) | 509 (or (bolp) (terpri))))) |
375 (or (bolp) (terpri))) | |
376 | |
377 | 510 |
378 | 511 |
379 (defun apropos-mouse-follow (event) | 512 (defun apropos-mouse-follow (event) |
380 (interactive "e") | 513 (interactive "e") |
381 (let ((other (if (eq (current-buffer) (get-buffer "*Help*")) | 514 (let ((other (if (eq (current-buffer) (get-buffer "*Help*")) |
382 () | 515 () |
383 (current-buffer)))) | 516 (current-buffer)))) |
384 (set-buffer (window-buffer (posn-window (event-start event)))) | 517 (set-buffer (window-buffer (posn-window (event-start event)))) |
385 (goto-char (posn-point (event-start event))) | 518 (goto-char (posn-point (event-start event))) |
386 ;; somehow when clicking with the point in another window, doesn't undo | 519 ;; somehow when clicking with the point in another window, undoes badly |
387 (undo-boundary) | 520 (undo-boundary) |
388 (apropos-follow other))) | 521 (apropos-follow other))) |
389 | 522 |
390 | 523 |
391 (defun apropos-follow (&optional other) | 524 (defun apropos-follow (&optional other) |
425 (with-output-to-temp-buffer "*Help*" | 558 (with-output-to-temp-buffer "*Help*" |
426 (set-buffer standard-output) | 559 (set-buffer standard-output) |
427 (princ "Symbol ") | 560 (princ "Symbol ") |
428 (prin1 symbol) | 561 (prin1 symbol) |
429 (princ "'s plist is\n (") | 562 (princ "'s plist is\n (") |
430 (if apropos-use-faces | 563 (if apropos-symbol-face |
431 (put-text-property 8 (- (point) 14) 'face 'bold)) | 564 (put-text-property 8 (- (point) 14) 'face apropos-symbol-face)) |
432 (insert (apropos-format-plist symbol "\n ")) | 565 (insert (apropos-format-plist symbol "\n ")) |
433 (princ ")"))) | 566 (princ ")"))) |
434 | 567 |
435 ;;; apropos.el ends here | 568 ;;; apropos.el ends here |