Mercurial > hg > xemacs-beta
annotate lisp/apropos.el @ 5885:c8bbb32fe124
Always return a string, #'current-message.
lisp/ChangeLog addition:
2015-04-04 Aidan Kehoe <kehoea@parhasard.net>
* gutter-items.el (append-progress-feedback):
* gutter-items.el (abort-progress-feedback):
Correct comments in both these functions, it's the progress stack
being adjusted, not the message stack.
* simple.el (message-stack):
Describe my recent change in the structure of this.
* simple.el (current-message):
Adjust the implementation of this to always return the string
displayed.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 04 Apr 2015 13:49:30 +0100 |
parents | bbe4146603db |
children |
rev | line source |
---|---|
428 | 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 ;; Maintainer: SL Baur <steve@xemacs.org> | |
8 ;; Keywords: help | |
9 | |
10 ;; This file is part of XEmacs. | |
11 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
12 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
13 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
14 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
15 ;; option) any later version. |
428 | 16 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
17 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
19 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
20 ;; for more details. |
428 | 21 |
22 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5182
diff
changeset
|
23 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 24 |
25 ;;; Synched up with: Last synched with FSF 19.34, diverged since. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; The ideas for this package were derived from the C code in | |
30 ;; src/keymap.c and elsewhere. The functions in this file should | |
31 ;; always be byte-compiled for speed. Someone should rewrite this in | |
32 ;; C (as part of src/keymap.c) for speed. | |
33 | |
34 ;; The idea for super-apropos is based on the original implementation | |
35 ;; by Lynn Slater <lrs@esl.com>. | |
36 | |
37 ;;; ChangeLog: | |
38 | |
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. | |
63 ;; [sb -- FSF protects the face declarations with `if window-system' | |
64 ;; I see no reason why we should do so] | |
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 ;; XEmacs addition | |
502 | 70 (defvar apropos-symbol-face (if-boundp 'font-lock-keyword-face |
428 | 71 font-lock-keyword-face |
72 'bold) | |
73 "*Face for symbol name in apropos output or `nil'. | |
74 This looks good, but slows down the commands several times.") | |
75 | |
76 ;; XEmacs addition | |
502 | 77 (defvar apropos-keybinding-face (if-boundp 'font-lock-string-face |
428 | 78 font-lock-string-face |
79 'underline) | |
80 "*Face for keybinding display in apropos output or `nil'. | |
81 This looks good, but slows down the commands several times.") | |
82 | |
83 ;; XEmacs addition | |
502 | 84 (defvar apropos-label-face (if-boundp 'font-lock-comment-face |
428 | 85 font-lock-comment-face |
86 'italic) | |
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 | |
93 ;; XEmacs addition | |
502 | 94 (defvar apropos-property-face (if-boundp 'font-lock-variable-name-face |
428 | 95 font-lock-variable-name-face |
96 'bold-italic) | |
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))) | |
107 (define-key map [(control m)] 'apropos-follow) | |
430 | 108 (define-key map [return] 'apropos-follow) |
428 | 109 (define-key map [(button2up)] 'apropos-mouse-follow) |
110 (define-key map [(button2)] 'undefined) | |
111 map) | |
112 "Keymap used in Apropos mode.") | |
113 | |
114 | |
115 (defvar apropos-regexp nil | |
116 "Regexp used in current apropos run.") | |
117 | |
118 (defvar apropos-files-scanned () | |
119 "List of elc files already scanned in current run of `apropos-documentation'.") | |
120 | |
121 (defvar apropos-accumulator () | |
122 "Alist of symbols already found in current apropos run.") | |
123 | |
124 (defvar apropos-item () | |
125 "Current item in or for apropos-accumulator.") | |
126 | |
127 (defvar apropos-mode-hook nil) ; XEmacs | |
128 | |
129 (defun apropos-mode () | |
130 "Major mode for following hyperlinks in output of apropos commands. | |
131 | |
132 \\{apropos-mode-map}" | |
133 (interactive) | |
134 (kill-all-local-variables) | |
135 (use-local-map apropos-mode-map) | |
136 (setq major-mode 'apropos-mode | |
137 mode-name "Apropos") | |
138 (run-hooks 'apropos-mode-hook)) ; XEmacs | |
139 | |
140 | |
141 ;; For auld lang syne: | |
142 ;;;###autoload | |
143 (fset 'command-apropos 'apropos-command) | |
144 | |
145 ;;;###autoload | |
146 (defun apropos-command (apropos-regexp &optional do-all) | |
147 "Shows commands (interactively callable functions) that match REGEXP. | |
148 With optional prefix ARG or if `apropos-do-all' is non-nil, also show | |
149 variables." | |
150 ;; XEmacs: All code related to special treatment of buffer has been removed | |
151 (interactive (list (read-string (concat "Apropos command " | |
152 (if (or current-prefix-arg | |
153 apropos-do-all) | |
154 "or variable ") | |
155 "(regexp): ")) | |
156 current-prefix-arg)) | |
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 (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) | |
2275 | 176 (condition-case nil |
177 (documentation symbol t) | |
178 (void-function "(aliased to undefined function)") | |
179 (error "(unexpected error from `documention')")))) | |
5882
bbe4146603db
Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
180 (subseq doc 0 (position ?\n doc)) |
428 | 181 "(not documented)")) |
182 (and do-all | |
183 (user-variable-p symbol) | |
184 (if (setq doc | |
185 (or | |
186 ;; XEmacs change: if obsolete, | |
187 ;; only mention that. | |
188 (variable-obsoleteness-doc symbol) | |
189 (documentation-property | |
190 symbol 'variable-documentation t))) | |
5882
bbe4146603db
Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
191 (subseq doc 0 (position ?\n doc)))))) |
428 | 192 (setq p (cdr p))))) |
193 nil)) | |
194 | |
195 | |
196 ;;;###autoload | |
197 (defun apropos (apropos-regexp &optional do-all) | |
198 "Show all bound symbols whose names match REGEXP. | |
199 With optional prefix ARG or if `apropos-do-all' is non-nil, also show unbound | |
200 symbols and key bindings, which is a little more time-consuming. | |
201 Returns list of symbols and documentation found." | |
202 (interactive "sApropos symbol (regexp): \nP") | |
203 ;; XEmacs change: hitting ENTER by mistake is a common mess-up and | |
204 ;; shouldn't make Emacs hang for a long time trying to list all symbols. | |
205 (or (> (length apropos-regexp) 0) | |
206 (error "Must pass non-empty regexp to `apropos'")) | |
207 (setq apropos-accumulator | |
208 (apropos-internal apropos-regexp | |
209 (and (not do-all) | |
210 (not apropos-do-all) | |
211 (lambda (symbol) | |
212 (or (fboundp symbol) | |
213 (boundp symbol) | |
214 (find-face symbol) | |
215 (symbol-plist symbol)))))) | |
216 (apropos-print | |
217 (or do-all apropos-do-all) | |
218 (lambda (p) | |
219 (let (symbol doc) | |
220 (while p | |
221 (setcar p (list | |
222 (setq symbol (car p)) | |
223 (if (fboundp symbol) | |
224 (if (setq doc | |
225 ;; XEmacs change: if obsolete, | |
226 ;; only mention that. | |
227 (or (function-obsoleteness-doc symbol) | |
2275 | 228 (condition-case nil |
229 (documentation symbol t) | |
230 (void-function "(aliased to undefined function)") | |
231 (error "(unexpected error from `documention')")))) | |
5882
bbe4146603db
Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
232 (subseq doc 0 (position ?\n doc)) |
428 | 233 "(not documented)")) |
234 (if (boundp symbol) | |
235 (if (setq doc | |
236 (or | |
237 ;; XEmacs change: if obsolete, | |
238 ;; only mention that. | |
239 (variable-obsoleteness-doc symbol) | |
240 (documentation-property | |
241 symbol 'variable-documentation t))) | |
5882
bbe4146603db
Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
242 (subseq doc 0 (position ?\n doc)) |
428 | 243 "(not documented)")) |
244 (if (setq doc (symbol-plist symbol)) | |
245 (if (eq (/ (length doc) 2) 1) | |
246 (format "1 property (%s)" (car doc)) | |
247 (format "%d properties" (/ (length doc) 2)))) | |
248 (if (get symbol 'widget-type) | |
249 (if (setq doc (documentation-property | |
250 symbol 'widget-documentation t)) | |
5882
bbe4146603db
Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
251 (subseq doc 0 (position ?\n doc)) |
428 | 252 "(not documented)")) |
253 (if (find-face symbol) | |
254 (if (setq doc (face-doc-string symbol)) | |
5882
bbe4146603db
Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
255 (subseq doc 0 (position ?\n doc)) |
428 | 256 "(not documented)")) |
257 (when (get symbol 'custom-group) | |
258 (if (setq doc (documentation-property | |
259 symbol 'group-documentation t)) | |
5882
bbe4146603db
Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
260 (subseq doc 0 (position ?\n doc)) |
428 | 261 "(not documented)")))) |
262 (setq p (cdr p))))) | |
263 nil)) | |
264 | |
265 | |
266 ;;;###autoload | |
267 (defun apropos-value (apropos-regexp &optional do-all) | |
268 "Show all symbols whose value's printed image matches REGEXP. | |
269 With optional prefix ARG or if `apropos-do-all' is non-nil, also looks | |
270 at the function and at the names and values of properties. | |
271 Returns list of symbols and values found." | |
272 (interactive "sApropos value (regexp): \nP") | |
273 (or do-all (setq do-all apropos-do-all)) | |
274 (setq apropos-accumulator ()) | |
275 (let (f v p) | |
276 (mapatoms | |
277 (lambda (symbol) | |
278 (setq f nil v nil p nil) | |
279 (or (memq symbol '(apropos-regexp do-all apropos-accumulator | |
280 symbol f v p)) | |
281 (setq v (apropos-value-internal 'boundp symbol 'symbol-value))) | |
282 (if do-all | |
283 (setq f (apropos-value-internal 'fboundp symbol 'symbol-function) | |
284 p (apropos-format-plist symbol "\n " t))) | |
285 (if (or f v p) | |
286 (setq apropos-accumulator (cons (list symbol f v p) | |
287 apropos-accumulator)))))) | |
288 (apropos-print nil nil t)) | |
289 | |
290 | |
291 ;;;###autoload | |
292 (defun apropos-documentation (apropos-regexp &optional do-all) | |
293 "Show symbols whose documentation contain matches for REGEXP. | |
294 With optional prefix ARG or if `apropos-do-all' is non-nil, also use | |
295 documentation that is not stored in the documentation file and show key | |
296 bindings. | |
297 Returns list of symbols and documentation found." | |
298 (interactive "sApropos documentation (regexp): \nP") | |
299 (or do-all (setq do-all apropos-do-all)) | |
300 (setq apropos-accumulator () apropos-files-scanned ()) | |
301 (let ((standard-input (get-buffer-create " apropos-temp")) | |
302 f v) | |
303 (unwind-protect | |
304 (save-excursion | |
305 (set-buffer standard-input) | |
306 (apropos-documentation-check-doc-file) | |
307 (if do-all | |
308 (mapatoms | |
309 (lambda (symbol) | |
310 (setq f (apropos-safe-documentation symbol) | |
311 v (get symbol 'variable-documentation)) | |
312 (when (integerp v) (setq v nil)) | |
313 (setq f (apropos-documentation-internal f) | |
314 v (apropos-documentation-internal v)) | |
315 (if (or f v) | |
316 (if (setq apropos-item | |
317 (cdr (assq symbol apropos-accumulator))) | |
318 (progn | |
319 (if f | |
320 (setcar apropos-item f)) | |
321 (if v | |
322 (setcar (cdr apropos-item) v))) | |
323 (setq apropos-accumulator | |
324 (cons (list symbol f v) | |
325 apropos-accumulator))))))) | |
326 (apropos-print nil nil t)) | |
327 (kill-buffer standard-input)))) | |
328 | |
329 | |
330 (defun apropos-value-internal (predicate symbol function) | |
331 (if (funcall predicate symbol) | |
332 (progn | |
333 (setq symbol (prin1-to-string (funcall function symbol))) | |
334 (if (string-match apropos-regexp symbol) | |
335 (progn | |
336 (if apropos-match-face | |
337 (put-text-property (match-beginning 0) (match-end 0) | |
338 'face apropos-match-face | |
339 symbol)) | |
340 symbol))))) | |
341 | |
342 (defun apropos-documentation-internal (doc) | |
343 (if (consp doc) | |
344 (apropos-documentation-check-elc-file (car doc)) | |
345 (and doc | |
346 (string-match apropos-regexp doc) | |
347 (progn | |
348 (if apropos-match-face | |
349 (put-text-property (match-beginning 0) | |
350 (match-end 0) | |
351 'face apropos-match-face | |
352 (setq doc (copy-sequence doc)))) | |
353 doc)))) | |
354 | |
355 (defun apropos-format-plist (pl sep &optional compare) | |
356 (setq pl (symbol-plist pl)) | |
357 (let (p p-out) | |
358 (while pl | |
359 (setq p (format "%s %S" (car pl) (nth 1 pl))) | |
360 (if (or (not compare) (string-match apropos-regexp p)) | |
361 (if apropos-property-face | |
362 (put-text-property 0 (length (symbol-name (car pl))) | |
363 'face apropos-property-face p)) | |
364 (setq p nil)) | |
365 (if p | |
366 (progn | |
367 (and compare apropos-match-face | |
368 (put-text-property (match-beginning 0) (match-end 0) | |
369 'face apropos-match-face | |
370 p)) | |
371 (setq p-out (concat p-out (if p-out sep) p)))) | |
372 (setq pl (nthcdr 2 pl))) | |
373 p-out)) | |
374 | |
375 | |
376 ;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name. | |
377 | |
378 (defun apropos-documentation-check-doc-file () | |
444 | 379 (let (type symbol (sepa 2) sepb start end doc) |
428 | 380 (insert ?\^_) |
381 (backward-char) | |
382 (insert-file-contents (concat doc-directory internal-doc-file-name)) | |
383 (forward-char) | |
384 (while (save-excursion | |
385 (setq sepb (search-forward "\^_")) | |
386 (not (eobp))) | |
387 (beginning-of-line 2) | |
388 (if (save-restriction | |
389 (narrow-to-region (point) (1- sepb)) | |
390 (re-search-forward apropos-regexp nil t)) | |
391 (progn | |
444 | 392 (setq start (match-beginning 0) |
428 | 393 end (point)) |
394 (goto-char (1+ sepa)) | |
395 (or (setq type (if (eq ?F (preceding-char)) | |
396 1 ; function documentation | |
397 2) ; variable documentation | |
398 symbol (read) | |
444 | 399 start (- start (point) 1) |
428 | 400 end (- end (point) 1) |
401 doc (buffer-substring (1+ (point)) (1- sepb)) | |
402 apropos-item (assq symbol apropos-accumulator)) | |
403 (setq apropos-item (list symbol nil nil) | |
404 apropos-accumulator (cons apropos-item | |
405 apropos-accumulator))) | |
406 (if apropos-match-face | |
444 | 407 (put-text-property start end 'face apropos-match-face doc)) |
428 | 408 (setcar (nthcdr type apropos-item) doc))) |
409 (setq sepa (goto-char sepb))))) | |
410 | |
411 (defun apropos-documentation-check-elc-file (file) | |
412 (if (member file apropos-files-scanned) | |
413 nil | |
444 | 414 (let (symbol doc start end this-is-a-variable) |
428 | 415 (setq apropos-files-scanned (cons file apropos-files-scanned)) |
416 (erase-buffer) | |
417 (insert-file-contents file) | |
418 (while (search-forward "\n#@" nil t) | |
419 ;; Read the comment length, and advance over it. | |
420 (setq end (read) | |
444 | 421 start (1+ (point)) |
428 | 422 end (+ (point) end -1)) |
423 (forward-char) | |
424 (if (save-restriction | |
425 ;; match ^ and $ relative to doc string | |
444 | 426 (narrow-to-region start end) |
428 | 427 (re-search-forward apropos-regexp nil t)) |
428 (progn | |
429 (goto-char (+ end 2)) | |
444 | 430 (setq doc (buffer-substring start end) |
431 end (- (match-end 0) start) | |
432 start (- (match-beginning 0) start) | |
428 | 433 this-is-a-variable (looking-at "(def\\(var\\|const\\) ") |
434 symbol (progn | |
435 (skip-chars-forward "(a-z") | |
436 (forward-char) | |
437 (read)) | |
438 symbol (if (consp symbol) | |
439 (nth 1 symbol) | |
440 symbol)) | |
441 (if (if this-is-a-variable | |
442 (get symbol 'variable-documentation) | |
443 (and (fboundp symbol) (apropos-safe-documentation symbol))) | |
444 (progn | |
445 (or (setq apropos-item (assq symbol apropos-accumulator)) | |
446 (setq apropos-item (list symbol nil nil) | |
447 apropos-accumulator (cons apropos-item | |
448 apropos-accumulator))) | |
449 (if apropos-match-face | |
444 | 450 (put-text-property start end 'face apropos-match-face |
428 | 451 doc)) |
452 (setcar (nthcdr (if this-is-a-variable 2 1) | |
453 apropos-item) | |
454 doc))))))))) | |
455 | |
456 | |
457 | |
458 (defun apropos-safe-documentation (function) | |
459 "Like documentation, except it avoids calling `get_doc_string'. | |
460 Will return nil instead." | |
461 (while (and function (symbolp function)) | |
462 (setq function (if (fboundp function) | |
463 (symbol-function function)))) | |
464 (if (eq (car-safe function) 'macro) | |
465 (setq function (cdr function))) | |
466 ;; XEmacs change from: (setq function (if (byte-code-function-p function) | |
467 (setq function (if (compiled-function-p function) | |
776 | 468 (if-fboundp 'compiled-function-doc-string |
428 | 469 (compiled-function-doc-string function) |
470 (if (> (length function) 4) | |
471 (aref function 4))) | |
472 (if (eq (car-safe function) 'autoload) | |
473 (nth 2 function) | |
474 (if (eq (car-safe function) 'lambda) | |
475 (if (stringp (nth 2 function)) | |
476 (nth 2 function) | |
477 (if (stringp (nth 3 function)) | |
478 (nth 3 function))))))) | |
479 (if (integerp function) | |
480 nil | |
481 function)) | |
482 | |
483 | |
484 | |
485 (defun apropos-print (do-keys doc-fn spacing) | |
486 "Output result of various apropos commands with `apropos-regexp'. | |
487 APROPOS-ACCUMULATOR is a list. Optional DOC-FN is called for each element | |
488 of apropos-accumulator and may modify it resulting in (symbol fn-doc | |
489 var-doc [plist-doc]). Returns sorted list of symbols and documentation | |
490 found." | |
491 (if (null apropos-accumulator) | |
492 (message "No apropos matches for `%s'" apropos-regexp) | |
493 (if doc-fn | |
494 (funcall doc-fn apropos-accumulator)) | |
495 (setq apropos-accumulator | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2275
diff
changeset
|
496 (sort* apropos-accumulator #'string-lessp :key #'car)) |
428 | 497 (and apropos-label-face |
498 (or (symbolp apropos-label-face) | |
499 (facep apropos-label-face)) ; XEmacs | |
500 (setq apropos-label-face `(face ,apropos-label-face | |
501 mouse-face highlight))) | |
502 (let ((help-buffer-prefix-string "Apropos")) | |
503 (with-displaying-help-buffer | |
504 (lambda () | |
505 (with-current-buffer standard-output | |
506 (run-hooks 'apropos-mode-hook) | |
507 (let ((p apropos-accumulator) | |
508 (old-buffer (current-buffer)) | |
509 symbol item point1 point2) | |
430 | 510 ;; Mostly useless but to provide better keymap |
511 ;; explanation. help-mode-map will be used instead. | |
512 (use-local-map apropos-mode-map) | |
428 | 513 ;; XEmacs change from (if window-system |
514 (if (device-on-window-system-p) | |
515 (progn | |
516 (princ "If you move the mouse over text that changes color,\n") | |
517 (princ (substitute-command-keys | |
518 "you can click \\[apropos-mouse-follow] to get more information.\n")))) | |
519 (princ (substitute-command-keys | |
520 "Type \\[apropos-follow] in this buffer to get full documentation.\n\n")) | |
521 (while (consp p) | |
522 (or (not spacing) (bobp) (terpri)) | |
523 (setq apropos-item (car p) | |
524 symbol (car apropos-item) | |
525 p (cdr p) | |
526 point1 (point)) | |
527 (princ symbol) ; print symbol name | |
528 (setq point2 (point)) | |
529 ;; Calculate key-bindings if we want them. | |
530 (and do-keys | |
531 (commandp symbol) | |
532 (indent-to 30 1) | |
533 (if (let ((keys | |
534 (save-excursion | |
535 (set-buffer old-buffer) | |
536 (where-is-internal symbol))) | |
537 filtered) | |
538 ;; Copy over the list of key sequences, | |
539 ;; omitting any that contain a buffer or a frame. | |
540 (while keys | |
541 (let ((key (car keys)) | |
542 (i 0) | |
543 loser) | |
544 (while (< i (length key)) | |
545 (if (or (framep (aref key i)) | |
546 (bufferp (aref key i))) | |
547 (setq loser t)) | |
548 (setq i (1+ i))) | |
549 (or loser | |
550 (setq filtered (cons key filtered)))) | |
551 (setq keys (cdr keys))) | |
552 (setq item filtered)) | |
553 ;; Convert the remaining keys to a string and insert. | |
554 (princ | |
555 (mapconcat | |
556 (lambda (key) | |
557 (setq key (key-description key)) | |
558 (if apropos-keybinding-face | |
559 (put-text-property 0 (length key) | |
560 'face apropos-keybinding-face | |
561 key)) | |
562 key) | |
563 item ", ")) | |
564 (princ "Type ") | |
565 (princ "M-x") | |
566 (put-text-property (- (point) 3) (point) | |
567 'face apropos-keybinding-face) | |
568 (princ (format " %s " (symbol-name symbol))) | |
569 (princ "RET") | |
570 (put-text-property (- (point) 3) (point) | |
571 'face apropos-keybinding-face))) | |
572 (terpri) | |
573 ;; only now so we don't propagate text attributes all over | |
574 (put-text-property point1 point2 'item | |
575 (if (eval `(or ,@(cdr apropos-item))) | |
576 (car apropos-item) | |
577 apropos-item)) | |
578 (if apropos-symbol-face | |
579 (put-text-property point1 point2 'face apropos-symbol-face)) | |
430 | 580 ;; Add text-property on symbol, too. |
581 (put-text-property point1 point2 'keymap apropos-mode-map) | |
428 | 582 (apropos-print-doc 'describe-function 1 |
583 (if (commandp symbol) | |
584 "Command" | |
585 (if (apropos-macrop symbol) | |
586 "Macro" | |
587 "Function")) | |
588 do-keys) | |
589 (if (get symbol 'custom-type) | |
590 (apropos-print-doc 'customize-variable-other-window 2 | |
591 "User Option" do-keys) | |
592 (apropos-print-doc 'describe-variable 2 | |
593 "Variable" do-keys)) | |
594 (apropos-print-doc 'customize-other-window 6 "Group" do-keys) | |
595 (apropos-print-doc 'customize-face-other-window 5 "Face" do-keys) | |
596 (apropos-print-doc 'widget-browse-other-window 4 "Widget" do-keys) | |
597 (apropos-print-doc 'apropos-describe-plist 3 | |
598 "Plist" nil))))) | |
599 apropos-regexp)) | |
600 (prog1 apropos-accumulator | |
601 (setq apropos-accumulator ())))) ; permit gc | |
602 | |
603 | |
604 (defun apropos-macrop (symbol) | |
605 "Return t if SYMBOL is a Lisp macro." | |
606 (and (fboundp symbol) | |
607 (consp (setq symbol | |
608 (symbol-function symbol))) | |
609 (or (eq (car symbol) 'macro) | |
610 (if (eq (car symbol) 'autoload) | |
611 (memq (nth 4 symbol) | |
612 '(macro t)))))) | |
613 | |
614 | |
615 (defun apropos-print-doc (action i str do-keys) | |
616 (with-current-buffer standard-output | |
617 (if (stringp (setq i (nth i apropos-item))) | |
618 (progn | |
619 (insert " ") | |
620 (put-text-property (- (point) 2) (1- (point)) | |
621 'action action) | |
622 (insert str ": ") | |
623 (if apropos-label-face | |
624 (add-text-properties (- (point) (length str) 2) | |
625 (1- (point)) | |
626 apropos-label-face)) | |
627 (add-text-properties (- (point) (length str) 2) | |
628 (1- (point)) | |
629 (list 'keymap apropos-mode-map)) | |
630 (insert (if do-keys (substitute-command-keys i) i)) | |
631 (or (bolp) (terpri)))))) | |
632 | |
633 (defun apropos-mouse-follow (event) | |
634 (interactive "e") | |
635 ;; XEmacs change: We're using the standard help buffer code now, don't | |
636 ;; do special tricks about trying to preserve current-buffer about mouse | |
637 ;; clicks. | |
638 | |
639 (save-excursion | |
640 ;; XEmacs change from: | |
641 ;; (set-buffer (window-buffer (posn-window (event-start event)))) | |
642 ;; (goto-char (posn-point (event-start event))) | |
643 (set-buffer (event-buffer event)) | |
644 (goto-char (event-closest-point event)) | |
645 ;; XEmacs change: following code seems useless | |
646 ;;(or (and (not (eobp)) (get-text-property (point) 'mouse-face)) | |
647 ;; (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face)) | |
648 ;; (error "There is nothing to follow here")) | |
649 (apropos-follow))) | |
650 | |
651 | |
652 (defun apropos-follow (&optional other) | |
653 (interactive) | |
654 (let* (;; Properties are always found at the beginning of the line. | |
655 (bol (save-excursion (beginning-of-line) (point))) | |
656 ;; If there is no `item' property here, look behind us. | |
657 (item (get-text-property bol 'item)) | |
658 (item-at (if item nil (previous-single-property-change bol 'item))) | |
659 ;; Likewise, if there is no `action' property here, look in front. | |
660 (action (get-text-property bol 'action)) | |
661 (action-at (if action nil (next-single-property-change bol 'action)))) | |
662 (and (null item) item-at | |
663 (setq item (get-text-property (1- item-at) 'item))) | |
664 (and (null action) action-at | |
665 (setq action (get-text-property action-at 'action))) | |
666 (if (not (and item action)) | |
667 (error "There is nothing to follow here")) | |
668 (if (consp item) (error "There is nothing to follow in `%s'" (car item))) | |
669 (if other (set-buffer other)) | |
670 (funcall action item))) | |
671 | |
672 | |
673 | |
674 (defun apropos-describe-plist (symbol) | |
675 "Display a pretty listing of SYMBOL's plist." | |
676 (let ((help-buffer-prefix-string "Apropos-plist")) | |
677 (with-displaying-help-buffer | |
678 (lambda () | |
679 (run-hooks 'apropos-mode-hook) | |
680 (princ "Symbol ") | |
681 (prin1 symbol) | |
682 (princ "'s plist is\n (") | |
683 (with-current-buffer standard-output | |
684 (if apropos-symbol-face | |
685 (put-text-property 8 (- (point) 14) 'face apropos-symbol-face))) | |
686 (princ (apropos-format-plist symbol "\n ")) | |
687 (princ ")") | |
688 (terpri) | |
689 (print-help-return-message)) | |
690 (symbol-name symbol)))) | |
691 | |
692 (provide 'apropos) ; XEmacs | |
693 | |
694 ;;; apropos.el ends here |