Mercurial > hg > xemacs-beta
annotate lisp/apropos.el @ 5327:d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
src/ChangeLog addition:
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
Move the heavy lifting from cl-seq.el to C, finally making those
functions first-class XEmacs citizens, with circularity checking,
built-in support for tests other than #'eql, and as much
compatibility with current Common Lisp as Paul Dietz' tests require.
* fns.c (check_eq_nokey, check_eq_key, check_eql_nokey)
(check_eql_key, check_equal_nokey, check_equal_key)
(check_equalp_nokey, check_equalp_key, check_string_match_nokey)
(check_string_match_key, check_other_nokey, check_other_key)
(check_if_nokey, check_if_key, check_match_eq_key)
(check_match_eql_key, check_match_equal_key)
(check_match_equalp_key, check_match_other_key): New. These are
basically to provide function pointers to be used by Lisp
functions that take TEST, TEST-NOT and KEY arguments.
(get_check_match_function_1, get_check_test_function)
(get_check_match_function): These functions work out which of the
previous list of functions to use, given the keywords supplied by
the user.
(count_with_tail): New. This is the bones of #'count.
(list_count_from_end, string_count_from_end): Utility functions
for #'count.
(Fcount): New, moved from cl-seq.el.
(list_position_cons_before): New. The implementation of #'member*,
and important in implementing various other functions.
(FmemberX, Fadjoin, FassocX, FrassocX, Fposition, Ffind)
(FdeleteX, FremoveX, Fdelete_duplicates, Fremove_duplicates)
(Fnsubstitute, Fsubstitute, Fsublis, Fnsublis, Fsubst, Fnsubst)
(Ftree_equal, Fmismatch, Fsearch, Fintersection, Fnintersection)
(Fsubsetp, Fset_difference, Fnset_difference, Fnunion, Funion)
(Fset_exclusive_or, Fnset_exclusive_or): New, moved here from
cl-seq.el.
(position): New. The implementation of #'find and #'position.
(list_delete_duplicates_from_end, subst, sublis, nsublis)
(tree_equal, mismatch_from_end, mismatch_list_list)
(mismatch_list_string, mismatch_list_array)
(mismatch_string_array, mismatch_string_string)
(mismatch_array_array, get_mismatch_func): Helper C functions for
the Lisp-visible functions.
(venn, nvenn): New. The implementation of the main Lisp functions that
treat lists as sets.
lisp/ChangeLog addition:
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* cl-seq.el:
Move the heavy lifting from this file to C. Dump the
cl-parsing-keywords macro, but don't use defun* for the functions
we define that do take keywords, dynamic scope lossage makes that
not practical.
* subr.el (sort, fillarray): Move these aliases here.
(map-plist): #'nsublis is now built-in, but at this point #'eql
isn't necessarily available as a test; use #'eq.
* obsolete.el (cl-delete-duplicates): Make this available for old
compiler macros and old code.
(memql): Document that this is equivalent to #'member*, and worse.
* cl.el (adjoin, subst): Removed. These are in C.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Thu, 30 Dec 2010 01:59:52 +0000 |
parents | 2e528066e2fc |
children | 308d34e9f07d |
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 | |
12 ;; XEmacs is free software; you can redistribute it and/or modify it | |
13 ;; under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; XEmacs is distributed in the hope that it will be useful, but | |
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 ;; General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
613 | 23 ;; along with XEmacs; see the file COPYING. If not, write to the |
428 | 24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Synched up with: Last synched with FSF 19.34, diverged since. | |
28 | |
29 ;;; Commentary: | |
30 | |
31 ;; The ideas for this package were derived from the C code in | |
32 ;; src/keymap.c and elsewhere. The functions in this file should | |
33 ;; always be byte-compiled for speed. Someone should rewrite this in | |
34 ;; C (as part of src/keymap.c) for speed. | |
35 | |
36 ;; The idea for super-apropos is based on the original implementation | |
37 ;; by Lynn Slater <lrs@esl.com>. | |
38 | |
39 ;;; ChangeLog: | |
40 | |
41 ;; Fixed bug, current-local-map can return nil. | |
42 ;; Change, doesn't calculate key-bindings unless needed. | |
43 ;; Added super-apropos capability, changed print functions. | |
44 ;;; Made fast-apropos and super-apropos share code. | |
45 ;;; Sped up fast-apropos again. | |
46 ;; Added apropos-do-all option. | |
47 ;;; Added fast-command-apropos. | |
48 ;; Changed doc strings to comments for helping functions. | |
49 ;;; Made doc file buffer read-only, buried it. | |
50 ;; Only call substitute-command-keys if do-all set. | |
51 | |
52 ;; Optionally use configurable faces to make the output more legible. | |
53 ;; Differentiate between command, function and macro. | |
54 ;; Apropos-command (ex command-apropos) does cmd and optionally user var. | |
55 ;; Apropos shows all 3 aspects of symbols (fn, var and plist) | |
56 ;; Apropos-documentation (ex super-apropos) now finds all it should. | |
57 ;; New apropos-value snoops through all values and optionally plists. | |
58 ;; Reading DOC file doesn't load nroff. | |
59 ;; Added hypertext following of documentation, mouse-2 on variable gives value | |
60 ;; from buffer in active window. | |
61 | |
62 ;;; Code: | |
63 | |
64 ;; I see a degradation of maybe 10-20% only. | |
65 ;; [sb -- FSF protects the face declarations with `if window-system' | |
66 ;; I see no reason why we should do so] | |
67 (defvar apropos-do-all nil | |
68 "*Whether the apropos commands should do more. | |
69 Slows them down more or less. Set this non-nil if you have a fast machine.") | |
70 | |
71 ;; XEmacs addition | |
502 | 72 (defvar apropos-symbol-face (if-boundp 'font-lock-keyword-face |
428 | 73 font-lock-keyword-face |
74 'bold) | |
75 "*Face for symbol name in apropos output or `nil'. | |
76 This looks good, but slows down the commands several times.") | |
77 | |
78 ;; XEmacs addition | |
502 | 79 (defvar apropos-keybinding-face (if-boundp 'font-lock-string-face |
428 | 80 font-lock-string-face |
81 'underline) | |
82 "*Face for keybinding display in apropos output or `nil'. | |
83 This looks good, but slows down the commands several times.") | |
84 | |
85 ;; XEmacs addition | |
502 | 86 (defvar apropos-label-face (if-boundp 'font-lock-comment-face |
428 | 87 font-lock-comment-face |
88 'italic) | |
89 "*Face for label (Command, Variable ...) in apropos output or `nil'. | |
90 If this is `nil' no mouse highlighting occurs. | |
91 This looks good, but slows down the commands several times. | |
92 When this is a face name, as it is initially, it gets transformed to a | |
93 text-property list for efficiency.") | |
94 | |
95 ;; XEmacs addition | |
502 | 96 (defvar apropos-property-face (if-boundp 'font-lock-variable-name-face |
428 | 97 font-lock-variable-name-face |
98 'bold-italic) | |
99 "*Face for property name in apropos output or `nil'. | |
100 This looks good, but slows down the commands several times.") | |
101 | |
102 (defvar apropos-match-face 'secondary-selection | |
103 "*Face for matching part in apropos-documentation/value output or `nil'. | |
104 This looks good, but slows down the commands several times.") | |
105 | |
106 | |
107 (defvar apropos-mode-map | |
108 (let ((map (make-sparse-keymap))) | |
109 (define-key map [(control m)] 'apropos-follow) | |
430 | 110 (define-key map [return] 'apropos-follow) |
428 | 111 (define-key map [(button2up)] 'apropos-mouse-follow) |
112 (define-key map [(button2)] 'undefined) | |
113 map) | |
114 "Keymap used in Apropos mode.") | |
115 | |
116 | |
117 (defvar apropos-regexp nil | |
118 "Regexp used in current apropos run.") | |
119 | |
120 (defvar apropos-files-scanned () | |
121 "List of elc files already scanned in current run of `apropos-documentation'.") | |
122 | |
123 (defvar apropos-accumulator () | |
124 "Alist of symbols already found in current apropos run.") | |
125 | |
126 (defvar apropos-item () | |
127 "Current item in or for apropos-accumulator.") | |
128 | |
129 (defvar apropos-mode-hook nil) ; XEmacs | |
130 | |
131 (defun apropos-mode () | |
132 "Major mode for following hyperlinks in output of apropos commands. | |
133 | |
134 \\{apropos-mode-map}" | |
135 (interactive) | |
136 (kill-all-local-variables) | |
137 (use-local-map apropos-mode-map) | |
138 (setq major-mode 'apropos-mode | |
139 mode-name "Apropos") | |
140 (run-hooks 'apropos-mode-hook)) ; XEmacs | |
141 | |
142 | |
143 ;; For auld lang syne: | |
144 ;;;###autoload | |
145 (fset 'command-apropos 'apropos-command) | |
146 | |
147 ;;;###autoload | |
148 (defun apropos-command (apropos-regexp &optional do-all) | |
149 "Shows commands (interactively callable functions) that match REGEXP. | |
150 With optional prefix ARG or if `apropos-do-all' is non-nil, also show | |
151 variables." | |
152 ;; XEmacs: All code related to special treatment of buffer has been removed | |
153 (interactive (list (read-string (concat "Apropos command " | |
154 (if (or current-prefix-arg | |
155 apropos-do-all) | |
156 "or variable ") | |
157 "(regexp): ")) | |
158 current-prefix-arg)) | |
159 (or do-all (setq do-all apropos-do-all)) | |
160 (setq apropos-accumulator | |
161 (apropos-internal apropos-regexp | |
162 (if do-all | |
163 (lambda (symbol) (or (commandp symbol) | |
164 (user-variable-p symbol))) | |
165 'commandp))) | |
166 (apropos-print | |
167 t | |
168 (lambda (p) | |
169 (let (doc symbol) | |
170 (while p | |
171 (setcar p (list | |
172 (setq symbol (car p)) | |
173 (if (commandp symbol) | |
174 (if (setq doc | |
175 ;; XEmacs change: if obsolete, | |
176 ;; only mention that. | |
177 (or (function-obsoleteness-doc symbol) | |
2275 | 178 (condition-case nil |
179 (documentation symbol t) | |
180 (void-function "(aliased to undefined function)") | |
181 (error "(unexpected error from `documention')")))) | |
428 | 182 (substring doc 0 (string-match "\n" doc)) |
183 "(not documented)")) | |
184 (and do-all | |
185 (user-variable-p symbol) | |
186 (if (setq doc | |
187 (or | |
188 ;; XEmacs change: if obsolete, | |
189 ;; only mention that. | |
190 (variable-obsoleteness-doc symbol) | |
191 (documentation-property | |
192 symbol 'variable-documentation t))) | |
193 (substring doc 0 | |
194 (string-match "\n" doc)))))) | |
195 (setq p (cdr p))))) | |
196 nil)) | |
197 | |
198 | |
199 ;;;###autoload | |
200 (defun apropos (apropos-regexp &optional do-all) | |
201 "Show all bound symbols whose names match REGEXP. | |
202 With optional prefix ARG or if `apropos-do-all' is non-nil, also show unbound | |
203 symbols and key bindings, which is a little more time-consuming. | |
204 Returns list of symbols and documentation found." | |
205 (interactive "sApropos symbol (regexp): \nP") | |
206 ;; XEmacs change: hitting ENTER by mistake is a common mess-up and | |
207 ;; shouldn't make Emacs hang for a long time trying to list all symbols. | |
208 (or (> (length apropos-regexp) 0) | |
209 (error "Must pass non-empty regexp to `apropos'")) | |
210 (setq apropos-accumulator | |
211 (apropos-internal apropos-regexp | |
212 (and (not do-all) | |
213 (not apropos-do-all) | |
214 (lambda (symbol) | |
215 (or (fboundp symbol) | |
216 (boundp symbol) | |
217 (find-face symbol) | |
218 (symbol-plist symbol)))))) | |
219 (apropos-print | |
220 (or do-all apropos-do-all) | |
221 (lambda (p) | |
222 (let (symbol doc) | |
223 (while p | |
224 (setcar p (list | |
225 (setq symbol (car p)) | |
226 (if (fboundp symbol) | |
227 (if (setq doc | |
228 ;; XEmacs change: if obsolete, | |
229 ;; only mention that. | |
230 (or (function-obsoleteness-doc symbol) | |
2275 | 231 (condition-case nil |
232 (documentation symbol t) | |
233 (void-function "(aliased to undefined function)") | |
234 (error "(unexpected error from `documention')")))) | |
428 | 235 (substring doc 0 (string-match "\n" doc)) |
236 "(not documented)")) | |
237 (if (boundp symbol) | |
238 (if (setq doc | |
239 (or | |
240 ;; XEmacs change: if obsolete, | |
241 ;; only mention that. | |
242 (variable-obsoleteness-doc symbol) | |
243 (documentation-property | |
244 symbol 'variable-documentation t))) | |
245 (substring doc 0 | |
246 (string-match "\n" doc)) | |
247 "(not documented)")) | |
248 (if (setq doc (symbol-plist symbol)) | |
249 (if (eq (/ (length doc) 2) 1) | |
250 (format "1 property (%s)" (car doc)) | |
251 (format "%d properties" (/ (length doc) 2)))) | |
252 (if (get symbol 'widget-type) | |
253 (if (setq doc (documentation-property | |
254 symbol 'widget-documentation t)) | |
255 (substring doc 0 | |
256 (string-match "\n" doc)) | |
257 "(not documented)")) | |
258 (if (find-face symbol) | |
259 (if (setq doc (face-doc-string symbol)) | |
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))))) | |
270 nil)) | |
271 | |
272 | |
273 ;;;###autoload | |
274 (defun apropos-value (apropos-regexp &optional do-all) | |
275 "Show all symbols whose value's printed image matches REGEXP. | |
276 With optional prefix ARG or if `apropos-do-all' is non-nil, also looks | |
277 at the function and at the names and values of properties. | |
278 Returns list of symbols and values found." | |
279 (interactive "sApropos value (regexp): \nP") | |
280 (or do-all (setq do-all apropos-do-all)) | |
281 (setq apropos-accumulator ()) | |
282 (let (f v p) | |
283 (mapatoms | |
284 (lambda (symbol) | |
285 (setq f nil v nil p nil) | |
286 (or (memq symbol '(apropos-regexp do-all apropos-accumulator | |
287 symbol f v p)) | |
288 (setq v (apropos-value-internal 'boundp symbol 'symbol-value))) | |
289 (if do-all | |
290 (setq f (apropos-value-internal 'fboundp symbol 'symbol-function) | |
291 p (apropos-format-plist symbol "\n " t))) | |
292 (if (or f v p) | |
293 (setq apropos-accumulator (cons (list symbol f v p) | |
294 apropos-accumulator)))))) | |
295 (apropos-print nil nil t)) | |
296 | |
297 | |
298 ;;;###autoload | |
299 (defun apropos-documentation (apropos-regexp &optional do-all) | |
300 "Show symbols whose documentation contain matches for REGEXP. | |
301 With optional prefix ARG or if `apropos-do-all' is non-nil, also use | |
302 documentation that is not stored in the documentation file and show key | |
303 bindings. | |
304 Returns list of symbols and documentation found." | |
305 (interactive "sApropos documentation (regexp): \nP") | |
306 (or do-all (setq do-all apropos-do-all)) | |
307 (setq apropos-accumulator () apropos-files-scanned ()) | |
308 (let ((standard-input (get-buffer-create " apropos-temp")) | |
309 f v) | |
310 (unwind-protect | |
311 (save-excursion | |
312 (set-buffer standard-input) | |
313 (apropos-documentation-check-doc-file) | |
314 (if do-all | |
315 (mapatoms | |
316 (lambda (symbol) | |
317 (setq f (apropos-safe-documentation symbol) | |
318 v (get symbol 'variable-documentation)) | |
319 (when (integerp v) (setq v nil)) | |
320 (setq f (apropos-documentation-internal f) | |
321 v (apropos-documentation-internal v)) | |
322 (if (or f v) | |
323 (if (setq apropos-item | |
324 (cdr (assq symbol apropos-accumulator))) | |
325 (progn | |
326 (if f | |
327 (setcar apropos-item f)) | |
328 (if v | |
329 (setcar (cdr apropos-item) v))) | |
330 (setq apropos-accumulator | |
331 (cons (list symbol f v) | |
332 apropos-accumulator))))))) | |
333 (apropos-print nil nil t)) | |
334 (kill-buffer standard-input)))) | |
335 | |
336 | |
337 (defun apropos-value-internal (predicate symbol function) | |
338 (if (funcall predicate symbol) | |
339 (progn | |
340 (setq symbol (prin1-to-string (funcall function symbol))) | |
341 (if (string-match apropos-regexp symbol) | |
342 (progn | |
343 (if apropos-match-face | |
344 (put-text-property (match-beginning 0) (match-end 0) | |
345 'face apropos-match-face | |
346 symbol)) | |
347 symbol))))) | |
348 | |
349 (defun apropos-documentation-internal (doc) | |
350 (if (consp doc) | |
351 (apropos-documentation-check-elc-file (car doc)) | |
352 (and doc | |
353 (string-match apropos-regexp doc) | |
354 (progn | |
355 (if apropos-match-face | |
356 (put-text-property (match-beginning 0) | |
357 (match-end 0) | |
358 'face apropos-match-face | |
359 (setq doc (copy-sequence doc)))) | |
360 doc)))) | |
361 | |
362 (defun apropos-format-plist (pl sep &optional compare) | |
363 (setq pl (symbol-plist pl)) | |
364 (let (p p-out) | |
365 (while pl | |
366 (setq p (format "%s %S" (car pl) (nth 1 pl))) | |
367 (if (or (not compare) (string-match apropos-regexp p)) | |
368 (if apropos-property-face | |
369 (put-text-property 0 (length (symbol-name (car pl))) | |
370 'face apropos-property-face p)) | |
371 (setq p nil)) | |
372 (if p | |
373 (progn | |
374 (and compare apropos-match-face | |
375 (put-text-property (match-beginning 0) (match-end 0) | |
376 'face apropos-match-face | |
377 p)) | |
378 (setq p-out (concat p-out (if p-out sep) p)))) | |
379 (setq pl (nthcdr 2 pl))) | |
380 p-out)) | |
381 | |
382 | |
383 ;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name. | |
384 | |
385 (defun apropos-documentation-check-doc-file () | |
444 | 386 (let (type symbol (sepa 2) sepb start end doc) |
428 | 387 (insert ?\^_) |
388 (backward-char) | |
389 (insert-file-contents (concat doc-directory internal-doc-file-name)) | |
390 (forward-char) | |
391 (while (save-excursion | |
392 (setq sepb (search-forward "\^_")) | |
393 (not (eobp))) | |
394 (beginning-of-line 2) | |
395 (if (save-restriction | |
396 (narrow-to-region (point) (1- sepb)) | |
397 (re-search-forward apropos-regexp nil t)) | |
398 (progn | |
444 | 399 (setq start (match-beginning 0) |
428 | 400 end (point)) |
401 (goto-char (1+ sepa)) | |
402 (or (setq type (if (eq ?F (preceding-char)) | |
403 1 ; function documentation | |
404 2) ; variable documentation | |
405 symbol (read) | |
444 | 406 start (- start (point) 1) |
428 | 407 end (- end (point) 1) |
408 doc (buffer-substring (1+ (point)) (1- sepb)) | |
409 apropos-item (assq symbol apropos-accumulator)) | |
410 (setq apropos-item (list symbol nil nil) | |
411 apropos-accumulator (cons apropos-item | |
412 apropos-accumulator))) | |
413 (if apropos-match-face | |
444 | 414 (put-text-property start end 'face apropos-match-face doc)) |
428 | 415 (setcar (nthcdr type apropos-item) doc))) |
416 (setq sepa (goto-char sepb))))) | |
417 | |
418 (defun apropos-documentation-check-elc-file (file) | |
419 (if (member file apropos-files-scanned) | |
420 nil | |
444 | 421 (let (symbol doc start end this-is-a-variable) |
428 | 422 (setq apropos-files-scanned (cons file apropos-files-scanned)) |
423 (erase-buffer) | |
424 (insert-file-contents file) | |
425 (while (search-forward "\n#@" nil t) | |
426 ;; Read the comment length, and advance over it. | |
427 (setq end (read) | |
444 | 428 start (1+ (point)) |
428 | 429 end (+ (point) end -1)) |
430 (forward-char) | |
431 (if (save-restriction | |
432 ;; match ^ and $ relative to doc string | |
444 | 433 (narrow-to-region start end) |
428 | 434 (re-search-forward apropos-regexp nil t)) |
435 (progn | |
436 (goto-char (+ end 2)) | |
444 | 437 (setq doc (buffer-substring start end) |
438 end (- (match-end 0) start) | |
439 start (- (match-beginning 0) start) | |
428 | 440 this-is-a-variable (looking-at "(def\\(var\\|const\\) ") |
441 symbol (progn | |
442 (skip-chars-forward "(a-z") | |
443 (forward-char) | |
444 (read)) | |
445 symbol (if (consp symbol) | |
446 (nth 1 symbol) | |
447 symbol)) | |
448 (if (if this-is-a-variable | |
449 (get symbol 'variable-documentation) | |
450 (and (fboundp symbol) (apropos-safe-documentation symbol))) | |
451 (progn | |
452 (or (setq apropos-item (assq symbol apropos-accumulator)) | |
453 (setq apropos-item (list symbol nil nil) | |
454 apropos-accumulator (cons apropos-item | |
455 apropos-accumulator))) | |
456 (if apropos-match-face | |
444 | 457 (put-text-property start end 'face apropos-match-face |
428 | 458 doc)) |
459 (setcar (nthcdr (if this-is-a-variable 2 1) | |
460 apropos-item) | |
461 doc))))))))) | |
462 | |
463 | |
464 | |
465 (defun apropos-safe-documentation (function) | |
466 "Like documentation, except it avoids calling `get_doc_string'. | |
467 Will return nil instead." | |
468 (while (and function (symbolp function)) | |
469 (setq function (if (fboundp function) | |
470 (symbol-function function)))) | |
471 (if (eq (car-safe function) 'macro) | |
472 (setq function (cdr function))) | |
473 ;; XEmacs change from: (setq function (if (byte-code-function-p function) | |
474 (setq function (if (compiled-function-p function) | |
776 | 475 (if-fboundp 'compiled-function-doc-string |
428 | 476 (compiled-function-doc-string function) |
477 (if (> (length function) 4) | |
478 (aref function 4))) | |
479 (if (eq (car-safe function) 'autoload) | |
480 (nth 2 function) | |
481 (if (eq (car-safe function) 'lambda) | |
482 (if (stringp (nth 2 function)) | |
483 (nth 2 function) | |
484 (if (stringp (nth 3 function)) | |
485 (nth 3 function))))))) | |
486 (if (integerp function) | |
487 nil | |
488 function)) | |
489 | |
490 | |
491 | |
492 (defun apropos-print (do-keys doc-fn spacing) | |
493 "Output result of various apropos commands with `apropos-regexp'. | |
494 APROPOS-ACCUMULATOR is a list. Optional DOC-FN is called for each element | |
495 of apropos-accumulator and may modify it resulting in (symbol fn-doc | |
496 var-doc [plist-doc]). Returns sorted list of symbols and documentation | |
497 found." | |
498 (if (null apropos-accumulator) | |
499 (message "No apropos matches for `%s'" apropos-regexp) | |
500 (if doc-fn | |
501 (funcall doc-fn apropos-accumulator)) | |
502 (setq apropos-accumulator | |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
2275
diff
changeset
|
503 (sort* apropos-accumulator #'string-lessp :key #'car)) |
428 | 504 (and apropos-label-face |
505 (or (symbolp apropos-label-face) | |
506 (facep apropos-label-face)) ; XEmacs | |
507 (setq apropos-label-face `(face ,apropos-label-face | |
508 mouse-face highlight))) | |
509 (let ((help-buffer-prefix-string "Apropos")) | |
510 (with-displaying-help-buffer | |
511 (lambda () | |
512 (with-current-buffer standard-output | |
513 (run-hooks 'apropos-mode-hook) | |
514 (let ((p apropos-accumulator) | |
515 (old-buffer (current-buffer)) | |
516 symbol item point1 point2) | |
430 | 517 ;; Mostly useless but to provide better keymap |
518 ;; explanation. help-mode-map will be used instead. | |
519 (use-local-map apropos-mode-map) | |
428 | 520 ;; XEmacs change from (if window-system |
521 (if (device-on-window-system-p) | |
522 (progn | |
523 (princ "If you move the mouse over text that changes color,\n") | |
524 (princ (substitute-command-keys | |
525 "you can click \\[apropos-mouse-follow] to get more information.\n")))) | |
526 (princ (substitute-command-keys | |
527 "Type \\[apropos-follow] in this buffer to get full documentation.\n\n")) | |
528 (while (consp p) | |
529 (or (not spacing) (bobp) (terpri)) | |
530 (setq apropos-item (car p) | |
531 symbol (car apropos-item) | |
532 p (cdr p) | |
533 point1 (point)) | |
534 (princ symbol) ; print symbol name | |
535 (setq point2 (point)) | |
536 ;; Calculate key-bindings if we want them. | |
537 (and do-keys | |
538 (commandp symbol) | |
539 (indent-to 30 1) | |
540 (if (let ((keys | |
541 (save-excursion | |
542 (set-buffer old-buffer) | |
543 (where-is-internal symbol))) | |
544 filtered) | |
545 ;; Copy over the list of key sequences, | |
546 ;; omitting any that contain a buffer or a frame. | |
547 (while keys | |
548 (let ((key (car keys)) | |
549 (i 0) | |
550 loser) | |
551 (while (< i (length key)) | |
552 (if (or (framep (aref key i)) | |
553 (bufferp (aref key i))) | |
554 (setq loser t)) | |
555 (setq i (1+ i))) | |
556 (or loser | |
557 (setq filtered (cons key filtered)))) | |
558 (setq keys (cdr keys))) | |
559 (setq item filtered)) | |
560 ;; Convert the remaining keys to a string and insert. | |
561 (princ | |
562 (mapconcat | |
563 (lambda (key) | |
564 (setq key (key-description key)) | |
565 (if apropos-keybinding-face | |
566 (put-text-property 0 (length key) | |
567 'face apropos-keybinding-face | |
568 key)) | |
569 key) | |
570 item ", ")) | |
571 (princ "Type ") | |
572 (princ "M-x") | |
573 (put-text-property (- (point) 3) (point) | |
574 'face apropos-keybinding-face) | |
575 (princ (format " %s " (symbol-name symbol))) | |
576 (princ "RET") | |
577 (put-text-property (- (point) 3) (point) | |
578 'face apropos-keybinding-face))) | |
579 (terpri) | |
580 ;; only now so we don't propagate text attributes all over | |
581 (put-text-property point1 point2 'item | |
582 (if (eval `(or ,@(cdr apropos-item))) | |
583 (car apropos-item) | |
584 apropos-item)) | |
585 (if apropos-symbol-face | |
586 (put-text-property point1 point2 'face apropos-symbol-face)) | |
430 | 587 ;; Add text-property on symbol, too. |
588 (put-text-property point1 point2 'keymap apropos-mode-map) | |
428 | 589 (apropos-print-doc 'describe-function 1 |
590 (if (commandp symbol) | |
591 "Command" | |
592 (if (apropos-macrop symbol) | |
593 "Macro" | |
594 "Function")) | |
595 do-keys) | |
596 (if (get symbol 'custom-type) | |
597 (apropos-print-doc 'customize-variable-other-window 2 | |
598 "User Option" do-keys) | |
599 (apropos-print-doc 'describe-variable 2 | |
600 "Variable" do-keys)) | |
601 (apropos-print-doc 'customize-other-window 6 "Group" do-keys) | |
602 (apropos-print-doc 'customize-face-other-window 5 "Face" do-keys) | |
603 (apropos-print-doc 'widget-browse-other-window 4 "Widget" do-keys) | |
604 (apropos-print-doc 'apropos-describe-plist 3 | |
605 "Plist" nil))))) | |
606 apropos-regexp)) | |
607 (prog1 apropos-accumulator | |
608 (setq apropos-accumulator ())))) ; permit gc | |
609 | |
610 | |
611 (defun apropos-macrop (symbol) | |
612 "Return t if SYMBOL is a Lisp macro." | |
613 (and (fboundp symbol) | |
614 (consp (setq symbol | |
615 (symbol-function symbol))) | |
616 (or (eq (car symbol) 'macro) | |
617 (if (eq (car symbol) 'autoload) | |
618 (memq (nth 4 symbol) | |
619 '(macro t)))))) | |
620 | |
621 | |
622 (defun apropos-print-doc (action i str do-keys) | |
623 (with-current-buffer standard-output | |
624 (if (stringp (setq i (nth i apropos-item))) | |
625 (progn | |
626 (insert " ") | |
627 (put-text-property (- (point) 2) (1- (point)) | |
628 'action action) | |
629 (insert str ": ") | |
630 (if apropos-label-face | |
631 (add-text-properties (- (point) (length str) 2) | |
632 (1- (point)) | |
633 apropos-label-face)) | |
634 (add-text-properties (- (point) (length str) 2) | |
635 (1- (point)) | |
636 (list 'keymap apropos-mode-map)) | |
637 (insert (if do-keys (substitute-command-keys i) i)) | |
638 (or (bolp) (terpri)))))) | |
639 | |
640 (defun apropos-mouse-follow (event) | |
641 (interactive "e") | |
642 ;; XEmacs change: We're using the standard help buffer code now, don't | |
643 ;; do special tricks about trying to preserve current-buffer about mouse | |
644 ;; clicks. | |
645 | |
646 (save-excursion | |
647 ;; XEmacs change from: | |
648 ;; (set-buffer (window-buffer (posn-window (event-start event)))) | |
649 ;; (goto-char (posn-point (event-start event))) | |
650 (set-buffer (event-buffer event)) | |
651 (goto-char (event-closest-point event)) | |
652 ;; XEmacs change: following code seems useless | |
653 ;;(or (and (not (eobp)) (get-text-property (point) 'mouse-face)) | |
654 ;; (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face)) | |
655 ;; (error "There is nothing to follow here")) | |
656 (apropos-follow))) | |
657 | |
658 | |
659 (defun apropos-follow (&optional other) | |
660 (interactive) | |
661 (let* (;; Properties are always found at the beginning of the line. | |
662 (bol (save-excursion (beginning-of-line) (point))) | |
663 ;; If there is no `item' property here, look behind us. | |
664 (item (get-text-property bol 'item)) | |
665 (item-at (if item nil (previous-single-property-change bol 'item))) | |
666 ;; Likewise, if there is no `action' property here, look in front. | |
667 (action (get-text-property bol 'action)) | |
668 (action-at (if action nil (next-single-property-change bol 'action)))) | |
669 (and (null item) item-at | |
670 (setq item (get-text-property (1- item-at) 'item))) | |
671 (and (null action) action-at | |
672 (setq action (get-text-property action-at 'action))) | |
673 (if (not (and item action)) | |
674 (error "There is nothing to follow here")) | |
675 (if (consp item) (error "There is nothing to follow in `%s'" (car item))) | |
676 (if other (set-buffer other)) | |
677 (funcall action item))) | |
678 | |
679 | |
680 | |
681 (defun apropos-describe-plist (symbol) | |
682 "Display a pretty listing of SYMBOL's plist." | |
683 (let ((help-buffer-prefix-string "Apropos-plist")) | |
684 (with-displaying-help-buffer | |
685 (lambda () | |
686 (run-hooks 'apropos-mode-hook) | |
687 (princ "Symbol ") | |
688 (prin1 symbol) | |
689 (princ "'s plist is\n (") | |
690 (with-current-buffer standard-output | |
691 (if apropos-symbol-face | |
692 (put-text-property 8 (- (point) 14) 'face apropos-symbol-face))) | |
693 (princ (apropos-format-plist symbol "\n ")) | |
694 (princ ")") | |
695 (terpri) | |
696 (print-help-return-message)) | |
697 (symbol-name symbol)))) | |
698 | |
699 (provide 'apropos) ; XEmacs | |
700 | |
701 ;;; apropos.el ends here |