Mercurial > emacs
annotate lisp/apropos.el @ 10282:84c786359b07
(super-apropos, super-apropos-check-doc-file)
(super-apropos-accumulate): Vars item, fn-doc and var-doc renamed
to apropos-item, apropos-fn-doc and apropos-var-doc.
(apropos-item, apropos-var-doc, apropos-fn-doc)
(apropos-accumulate, apropos-regexp): New defvars.
(super-apropos): Bind apropos-regexp to regexp.
(super-apropos-accumulate): Use apropos-regexp.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 29 Dec 1994 01:46:34 +0000 |
parents | 58037e770f67 |
children | 1d1c5ea9eb86 |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
444
diff
changeset
|
1 ;;; apropos.el --- faster apropos commands. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
444
diff
changeset
|
2 |
7300 | 3 ;; Copyright (C) 1989, 1994 Free Software Foundation, Inc. |
845 | 4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
5 ;; Author: Joe Wells <jbw@bigbird.bu.edu> |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1894
diff
changeset
|
6 ;; Keywords: help |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
7 |
367 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
367 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
24 ;;; Commentary: |
367 | 25 |
26 ;; The ideas for this package were derived from the C code in | |
27 ;; src/keymap.c and elsewhere. The functions in this file should | |
28 ;; always be byte-compiled for speed. Someone should rewrite this in | |
29 ;; C (as part of src/keymap.c) for speed. | |
30 | |
31 ;; The idea for super-apropos is based on the original implementation | |
32 ;; by Lynn Slater <lrs@esl.com>. | |
33 | |
34 ;; History: | |
35 ;; Fixed bug, current-local-map can return nil. | |
36 ;; Change, doesn't calculate key-bindings unless needed. | |
37 ;; Added super-apropos capability, changed print functions. | |
38 ;; Made fast-apropos and super-apropos share code. | |
39 ;; Sped up fast-apropos again. | |
40 ;; Added apropos-do-all option. | |
41 ;; Added fast-command-apropos. | |
42 ;; Changed doc strings to comments for helping functions. | |
43 ;; Made doc file buffer read-only, buried it. | |
44 ;; Only call substitute-command-keys if do-all set. | |
45 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
46 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
47 |
367 | 48 (defvar apropos-do-all nil |
49 "*Whether `apropos' and `super-apropos' should do everything that they can. | |
50 Makes them run 2 or 3 times slower. Set this non-nil if you have a fast | |
51 machine.") | |
52 | |
53 ;;;###autoload | |
9213
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
54 (defun apropos (regexp &optional do-all pred no-header) |
367 | 55 "Show all symbols whose names contain matches for REGEXP. |
6264
f1fa434c9090
(apropos, super-apropos): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6263
diff
changeset
|
56 If optional argument DO-ALL is non-nil (prefix argument if interactive), |
f1fa434c9090
(apropos, super-apropos): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6263
diff
changeset
|
57 or if `apropos-do-all' is non-nil, does more (time-consuming) work such as |
367 | 58 showing key bindings. Optional argument PRED is called with each symbol, and |
59 if it returns nil, the symbol is not shown. | |
60 | |
9213
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
61 Optional argument NO-HEADER means don't print `Function:' or `Variable:' |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
62 in the output. |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
63 |
367 | 64 Returns list of symbols and documentation found." |
65 (interactive "sApropos (regexp): \nP") | |
66 (setq do-all (or apropos-do-all do-all)) | |
67 (let ((apropos-accumulate (apropos-internal regexp pred))) | |
68 (if (null apropos-accumulate) | |
69 (message "No apropos matches for `%s'" regexp) | |
70 (apropos-get-doc apropos-accumulate) | |
71 (with-output-to-temp-buffer "*Help*" | |
9213
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
72 (apropos-print-matches apropos-accumulate regexp nil |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
73 do-all no-header))) |
367 | 74 apropos-accumulate)) |
75 | |
76 ;; Takes LIST of symbols and adds documentation. Modifies LIST in place. | |
77 ;; Resulting alist is of form ((symbol fn-doc var-doc) ...). Should only be | |
78 ;; called by apropos. Returns LIST. | |
79 | |
80 (defun apropos-get-doc (list) | |
81 (let ((p list) | |
82 fn-doc var-doc symbol) | |
83 (while (consp p) | |
84 (setq symbol (car p) | |
85 fn-doc (and (fboundp symbol) | |
86 (documentation symbol)) | |
87 var-doc (documentation-property symbol 'variable-documentation) | |
88 fn-doc (and fn-doc | |
89 (substring fn-doc 0 (string-match "\n" fn-doc))) | |
90 var-doc (and var-doc | |
91 (substring var-doc 0 (string-match "\n" var-doc)))) | |
92 (setcar p (list symbol fn-doc var-doc)) | |
93 (setq p (cdr p))) | |
94 list)) | |
95 | |
10282
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
96 ;; Variables bound by super-apropos and used by its subroutines. |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
97 ;; It would be good to say what each one is for, but I don't know -- rms. |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
98 (defvar apropos-item) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
99 (defvar apropos-var-doc) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
100 (defvar apropos-fn-doc) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
101 (defvar apropos-accumulate) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
102 (defvar apropos-regexp |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
103 "Within `super-apropos', this holds the REGEXP argument.") |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
104 |
367 | 105 ;;;###autoload |
106 (defun super-apropos (regexp &optional do-all) | |
107 "Show symbols whose names/documentation contain matches for REGEXP. | |
6264
f1fa434c9090
(apropos, super-apropos): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6263
diff
changeset
|
108 If optional argument DO-ALL is non-nil (prefix argument if interactive), |
f1fa434c9090
(apropos, super-apropos): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6263
diff
changeset
|
109 or if `apropos-do-all' is non-nil, does more (time-consuming) work such as |
367 | 110 showing key bindings and documentation that is not stored in the documentation |
111 file. | |
112 | |
113 Returns list of symbols and documentation found." | |
114 (interactive "sSuper Apropos: \nP") | |
115 (setq do-all (or apropos-do-all do-all)) | |
10282
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
116 (let ((apropos-regexp regexp) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
117 apropos-accumulate apropos-fn-doc apropos-var-doc apropos-item) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
118 (setq apropos-accumulate (super-apropos-check-doc-file apropos-regexp)) |
367 | 119 (if (null apropos-accumulate) |
10282
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
120 (message "No apropos matches for `%s'" apropos-regexp) |
367 | 121 (if do-all (mapatoms 'super-apropos-accumulate)) |
122 (with-output-to-temp-buffer "*Help*" | |
123 (apropos-print-matches apropos-accumulate nil t do-all))) | |
124 apropos-accumulate)) | |
125 | |
126 ;; Finds all documentation related to REGEXP in internal-doc-file-name. | |
127 ;; Returns an alist of form ((symbol fn-doc var-doc) ...). | |
128 | |
129 (defun super-apropos-check-doc-file (regexp) | |
6263
f2b01e6e4a1f
(super-apropos-check-doc-file): Use doc-directory instead of data-directory.
Karl Heuer <kwzh@gnu.org>
parents:
5928
diff
changeset
|
130 (let* ((doc-file (concat doc-directory internal-doc-file-name)) |
6853
581a72b47b19
(super-apropos-check-doc-file): Force Fundamental mode.
Richard M. Stallman <rms@gnu.org>
parents:
6525
diff
changeset
|
131 (doc-buffer |
581a72b47b19
(super-apropos-check-doc-file): Force Fundamental mode.
Richard M. Stallman <rms@gnu.org>
parents:
6525
diff
changeset
|
132 ;; Force fundamental mode for the DOC file. |
581a72b47b19
(super-apropos-check-doc-file): Force Fundamental mode.
Richard M. Stallman <rms@gnu.org>
parents:
6525
diff
changeset
|
133 (let (auto-mode-alist) |
581a72b47b19
(super-apropos-check-doc-file): Force Fundamental mode.
Richard M. Stallman <rms@gnu.org>
parents:
6525
diff
changeset
|
134 (find-file-noselect doc-file t))) |
367 | 135 type symbol doc sym-list) |
136 (save-excursion | |
137 (set-buffer doc-buffer) | |
138 ;; a user said he might accidentally edit the doc file | |
139 (setq buffer-read-only t) | |
140 (bury-buffer doc-buffer) | |
141 (goto-char (point-min)) | |
142 (while (re-search-forward regexp nil t) | |
143 (search-backward "\C-_") | |
144 (setq type (if (eq ?F (char-after (1+ (point)))) | |
145 1 ;function documentation | |
146 2) ;variable documentation | |
147 symbol (progn | |
148 (forward-char 2) | |
149 (read doc-buffer)) | |
150 doc (buffer-substring | |
151 (point) | |
152 (progn | |
153 (if (search-forward "\C-_" nil 'move) | |
154 (1- (point)) | |
155 (point)))) | |
10282
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
156 apropos-item (assq symbol sym-list)) |
5366
9fb443ed4acf
(super-apropos-check-doc-file): Verify that the doc
Richard M. Stallman <rms@gnu.org>
parents:
5297
diff
changeset
|
157 (and (if (= type 1) |
5928
0a2c25c9400c
(super-apropos-check-doc-file): Don't attempt to retrieve function
Karl Heuer <kwzh@gnu.org>
parents:
5366
diff
changeset
|
158 (and (fboundp symbol) (documentation symbol)) |
5366
9fb443ed4acf
(super-apropos-check-doc-file): Verify that the doc
Richard M. Stallman <rms@gnu.org>
parents:
5297
diff
changeset
|
159 (documentation-property symbol 'variable-documentation)) |
10282
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
160 (or apropos-item |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
161 (setq apropos-item (list symbol nil nil) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
162 sym-list (cons apropos-item sym-list))) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
163 (setcar (nthcdr type apropos-item) doc)))) |
367 | 164 sym-list)) |
165 | |
166 ;; This is passed as the argument to map-atoms, so it is called once for every | |
167 ;; symbol in obarray. Takes one argument SYMBOL, and finds any memory-resident | |
10282
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
168 ;; documentation on that symbol if it matches a variable regexp. |
367 | 169 |
170 (defun super-apropos-accumulate (symbol) | |
10282
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
171 (cond ((string-match apropos-regexp (symbol-name symbol)) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
172 (setq apropos-item (apropos-get-accum-item symbol)) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
173 (setcar (cdr apropos-item) (or (safe-documentation symbol) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
174 (nth 1 apropos-item))) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
175 (setcar (nthcdr 2 apropos-item) (or (safe-documentation-property symbol) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
176 (nth 2 apropos-item)))) |
367 | 177 (t |
10282
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
178 (and (setq apropos-fn-doc (safe-documentation symbol)) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
179 (string-match apropos-regexp apropos-fn-doc) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
180 (setcar (cdr (apropos-get-accum-item symbol)) apropos-fn-doc)) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
181 (and (setq apropos-var-doc (safe-documentation-property symbol)) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
182 (string-match apropos-regexp apropos-var-doc) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
183 (setcar (nthcdr 2 (apropos-get-accum-item symbol)) |
84c786359b07
(super-apropos, super-apropos-check-doc-file)
Richard M. Stallman <rms@gnu.org>
parents:
10162
diff
changeset
|
184 apropos-var-doc)))) |
367 | 185 nil) |
186 | |
187 ;; Prints the symbols and documentation in alist MATCHES of form ((symbol | |
188 ;; fn-doc var-doc) ...). Uses optional argument REGEXP to speed up searching | |
189 ;; for keybindings. The names of all symbols in MATCHES must match REGEXP. | |
190 ;; Displays in the buffer pointed to by standard-output. Optional argument | |
191 ;; SPACING means put blank lines in between each symbol's documentation. | |
192 ;; Optional argument DO-ALL means do more time-consuming work, specifically, | |
193 ;; consulting key bindings. Should only be called within a | |
194 ;; with-output-to-temp-buffer. | |
195 | |
9213
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
196 (defun apropos-print-matches (matches &optional regexp |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
197 spacing do-all no-header) |
367 | 198 (setq matches (sort matches (function |
199 (lambda (a b) | |
200 (string-lessp (car a) (car b)))))) | |
201 (let ((p matches) | |
202 (old-buffer (current-buffer)) | |
2946
1f24ead69a2f
(apropos-print-matches): Bind tem.
Richard M. Stallman <rms@gnu.org>
parents:
2937
diff
changeset
|
203 item keys-done symbol tem) |
367 | 204 (save-excursion |
205 (set-buffer standard-output) | |
206 (or matches (princ "No matches found.")) | |
207 (while (consp p) | |
208 (setq item (car p) | |
209 symbol (car item) | |
210 p (cdr p)) | |
211 (or (not spacing) (bobp) (terpri)) | |
212 (princ symbol) ;print symbol name | |
213 ;; don't calculate key-bindings unless needed | |
214 (cond ((and do-all (commandp symbol) (not keys-done)) | |
215 (save-excursion | |
216 (set-buffer old-buffer) | |
217 (apropos-match-keys matches regexp)) | |
218 (setq keys-done t))) | |
219 (cond ((and do-all | |
220 (or (setq tem (nthcdr 3 item)) | |
221 (commandp symbol))) | |
222 (indent-to 30 1) | |
223 (if tem | |
224 (princ (mapconcat 'key-description tem ", ")) | |
225 (princ "(not bound to any keys)")))) | |
226 (terpri) | |
227 (cond ((setq tem (nth 1 item)) | |
9213
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
228 (let ((substed (if do-all (substitute-command-keys tem) tem))) |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
229 (if no-header |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
230 (princ " ") |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
231 (princ " Function: ") |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
232 (if (> (length substed) 67) |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
233 (princ "\n "))) |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
234 (princ substed)))) |
367 | 235 (or (bolp) (terpri)) |
236 (cond ((setq tem (nth 2 item)) | |
9213
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
237 (let ((substed (if do-all (substitute-command-keys tem) tem))) |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
238 (if no-header |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
239 (princ " ") |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
240 (princ " Variable: ") |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
241 (if (> (length substed) 67) |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
242 (princ "\n "))) |
177bb6670a97
(apropos-print-matches): Add newline after
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
243 (princ substed)))) |
9860
49a20a98c276
(apropos-print-matches): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
9213
diff
changeset
|
244 (or (bolp) (terpri))) |
49a20a98c276
(apropos-print-matches): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
9213
diff
changeset
|
245 (help-mode))) |
367 | 246 t) |
247 | |
248 ;; Find key bindings for symbols that are cars in ALIST. Optionally, first | |
249 ;; match the symbol name against REGEXP. Modifies ALIST in place. Each key | |
250 ;; binding is added as a string to the end of the list in ALIST whose car is | |
251 ;; the corresponding symbol. The pointer to ALIST is returned. | |
252 | |
253 (defun apropos-match-keys (alist &optional regexp) | |
254 (let* ((current-local-map (current-local-map)) | |
10162
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
255 ;; Get a list of the top-level maps now active. |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
256 (top-maps |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
257 (if overriding-local-map |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
258 (list overriding-local-map (current-global-map)) |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
259 (append (current-minor-mode-maps) |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
260 (if current-local-map |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
261 (list current-local-map (current-global-map)) |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
262 (list (current-global-map)))))) |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
263 ;; Turn that into a list of all the maps including submaps. |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
264 (maps (apply 'append (mapcar 'accessible-keymaps top-maps))) |
367 | 265 map ;map we are now inspecting |
266 sequence ;key sequence to reach map | |
267 i ;index into vector map | |
268 command ;what is bound to current keys | |
269 key ;last key to reach command | |
270 local ;local binding for sequence + key | |
271 item) ;symbol data item in alist | |
272 ;; examine all reachable keymaps | |
273 (while (consp maps) | |
274 (setq map (cdr (car maps)) | |
275 sequence (car (car maps)) ;keys to reach this map | |
276 maps (cdr maps)) | |
2937
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
277 ;; Skip the leading `keymap', doc string, etc. |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
278 (if (eq (car map) 'keymap) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
279 (setq map (cdr map))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
280 (while (stringp (car-safe map)) |
367 | 281 (setq map (cdr map))) |
10162
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
282 |
2937
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
283 (while (consp map) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
284 (cond ((consp (car map)) |
367 | 285 (setq command (cdr (car map)) |
2937
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
286 key (car (car map))) |
10162
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
287 ;; Skip any menu prompt and help string in this key binding. |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
288 (while (and (consp command) (stringp (car command))) |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
289 (setq command (cdr command))) |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
290 ;; Skip any cached equivalent key. |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
291 (and (consp command) |
58037e770f67
(apropos-match-keys): Handle menu bindings with cached equivalent keys.
Richard M. Stallman <rms@gnu.org>
parents:
9860
diff
changeset
|
292 (consp (car command)) |
2937
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
293 (setq command (cdr command))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
294 ;; if is a symbol, and matches optional regexp, and is a car |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
295 ;; in alist, and is not shadowed by a different local binding, |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
296 ;; record it |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
297 (and (symbolp command) |
5297
969ebd50eb72
(apropos-match-keys): If REGEXP is nil, always act as if it matched.
Richard M. Stallman <rms@gnu.org>
parents:
3563
diff
changeset
|
298 (if regexp |
969ebd50eb72
(apropos-match-keys): If REGEXP is nil, always act as if it matched.
Richard M. Stallman <rms@gnu.org>
parents:
3563
diff
changeset
|
299 (string-match regexp (symbol-name command)) |
969ebd50eb72
(apropos-match-keys): If REGEXP is nil, always act as if it matched.
Richard M. Stallman <rms@gnu.org>
parents:
3563
diff
changeset
|
300 t) |
2937
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
301 (setq item (assq command alist)) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
302 (if (or (vectorp sequence) (not (integerp key))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
303 (setq key (vconcat sequence (vector key))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
304 (setq key (concat sequence (char-to-string key)))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
305 ;; checking if shadowed by local binding. |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
306 ;; either no local map, no local binding, or runs off the |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
307 ;; binding tree (number), or is the same binding |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
308 (or (not current-local-map) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
309 (not (setq local (lookup-key current-local-map key))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
310 (numberp local) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
311 (eq command local)) |
6525
7e1e1ccc238c
(apropos-match-keys): Skip duplicate keybindings.
Karl Heuer <kwzh@gnu.org>
parents:
6329
diff
changeset
|
312 ;; check if this binding is already recorded |
7e1e1ccc238c
(apropos-match-keys): Skip duplicate keybindings.
Karl Heuer <kwzh@gnu.org>
parents:
6329
diff
changeset
|
313 ;; (this can happen due to inherited keymaps) |
7e1e1ccc238c
(apropos-match-keys): Skip duplicate keybindings.
Karl Heuer <kwzh@gnu.org>
parents:
6329
diff
changeset
|
314 (not (member key (nthcdr 3 item))) |
2937
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
315 ;; add this key binding to the item in alist |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
316 (nconc item (cons key nil)))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
317 ((vectorp (car map)) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
318 (let ((i 0) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
319 (vec (car map)) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
320 (len (length (car map)))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
321 (while (< i len) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
322 (setq command (aref vec i)) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
323 (setq key i) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
324 ;; Skip any menu prompt in this key binding. |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
325 (and (consp command) (symbolp (cdr command)) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
326 (setq command (cdr command))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
327 ;; This is the same as the code in the previous case. |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
328 (and (symbolp command) |
5297
969ebd50eb72
(apropos-match-keys): If REGEXP is nil, always act as if it matched.
Richard M. Stallman <rms@gnu.org>
parents:
3563
diff
changeset
|
329 (if regexp |
969ebd50eb72
(apropos-match-keys): If REGEXP is nil, always act as if it matched.
Richard M. Stallman <rms@gnu.org>
parents:
3563
diff
changeset
|
330 (string-match regexp (symbol-name command)) |
969ebd50eb72
(apropos-match-keys): If REGEXP is nil, always act as if it matched.
Richard M. Stallman <rms@gnu.org>
parents:
3563
diff
changeset
|
331 t) |
2937
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
332 (setq item (assq command alist)) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
333 (if (or (vectorp sequence) (not (integerp key))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
334 (setq key (vconcat sequence (vector key))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
335 (setq key (concat sequence (char-to-string key)))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
336 ;; checking if shadowed by local binding. |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
337 ;; either no local map, no local binding, or runs off the |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
338 ;; binding tree (number), or is the same binding |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
339 (or (not current-local-map) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
340 (not (setq local (lookup-key current-local-map key))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
341 (numberp local) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
342 (eq command local)) |
6525
7e1e1ccc238c
(apropos-match-keys): Skip duplicate keybindings.
Karl Heuer <kwzh@gnu.org>
parents:
6329
diff
changeset
|
343 ;; check if this binding is already recorded |
7e1e1ccc238c
(apropos-match-keys): Skip duplicate keybindings.
Karl Heuer <kwzh@gnu.org>
parents:
6329
diff
changeset
|
344 ;; (this can happen due to inherited keymaps) |
7e1e1ccc238c
(apropos-match-keys): Skip duplicate keybindings.
Karl Heuer <kwzh@gnu.org>
parents:
6329
diff
changeset
|
345 (not (member key (nthcdr 3 item))) |
2937
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
346 ;; add this key binding to the item in alist |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
347 (nconc item (cons key nil))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
348 (setq i (1+ i)))))) |
e38ff71093b5
(apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
349 (setq map (cdr map))))) |
367 | 350 alist) |
351 | |
352 ;; Get an alist item in alist apropos-accumulate whose car is SYMBOL. Creates | |
353 ;; the item if not already present. Modifies apropos-accumulate in place. | |
354 | |
355 (defun apropos-get-accum-item (symbol) | |
356 (or (assq symbol apropos-accumulate) | |
357 (progn | |
358 (setq apropos-accumulate | |
359 (cons (list symbol nil nil) apropos-accumulate)) | |
360 (assq symbol apropos-accumulate)))) | |
361 | |
362 (defun safe-documentation (function) | |
363 "Like documentation, except it avoids calling `get_doc_string'. | |
364 Will return nil instead." | |
365 (while (symbolp function) | |
366 (setq function (if (fboundp function) | |
367 (symbol-function function) | |
368 0))) | |
3563
804e4f30b7ce
(safe-documentation): Don't crash on byte-compiled macro.
Richard M. Stallman <rms@gnu.org>
parents:
2946
diff
changeset
|
369 (if (eq (car-safe function) 'macro) |
804e4f30b7ce
(safe-documentation): Don't crash on byte-compiled macro.
Richard M. Stallman <rms@gnu.org>
parents:
2946
diff
changeset
|
370 (setq function (cdr function))) |
367 | 371 (if (not (consp function)) |
372 nil | |
373 (if (not (memq (car function) '(lambda autoload))) | |
374 nil | |
375 (setq function (nth 2 function)) | |
376 (if (stringp function) | |
377 function | |
378 nil)))) | |
379 | |
380 (defun safe-documentation-property (symbol) | |
381 "Like documentation-property, except it avoids calling `get_doc_string'. | |
382 Will return nil instead." | |
383 (setq symbol (get symbol 'variable-documentation)) | |
384 (if (numberp symbol) | |
385 nil | |
386 symbol)) | |
387 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
444
diff
changeset
|
388 ;;; apropos.el ends here |