annotate lisp/apropos.el @ 5759:e4bd64404a43

(X_IO_BUG): Defined.
author Richard M. Stallman <rms@gnu.org>
date Thu, 03 Feb 1994 06:07:47 +0000
parents 9fb443ed4acf
children 0a2c25c9400c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
3 ;; Copyright (C) 1989 Free Software Foundation, Inc.
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
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
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
24 ;;; Commentary:
367
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; The ideas for this package were derived from the C code in
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; src/keymap.c and elsewhere. The functions in this file should
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; always be byte-compiled for speed. Someone should rewrite this in
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; C (as part of src/keymap.c) for speed.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; The idea for super-apropos is based on the original implementation
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; by Lynn Slater <lrs@esl.com>.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; History:
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; Fixed bug, current-local-map can return nil.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; Change, doesn't calculate key-bindings unless needed.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; Added super-apropos capability, changed print functions.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; Made fast-apropos and super-apropos share code.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; Sped up fast-apropos again.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; Added apropos-do-all option.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; Added fast-command-apropos.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; Changed doc strings to comments for helping functions.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; Made doc file buffer read-only, buried it.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; Only call substitute-command-keys if do-all set.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (defvar apropos-do-all nil
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 "*Whether `apropos' and `super-apropos' should do everything that they can.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 Makes them run 2 or 3 times slower. Set this non-nil if you have a fast
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 machine.")
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; If there isn't already a lisp variable named internal-doc-file-name, create
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; it and document it. This is so the code will work right after RMS adds
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; internal-doc-file-name.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;(or (boundp 'internal-doc-file-name)
444
4cec2e6d4f9e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 367
diff changeset
57 ; (setq internal-doc-file-name (concat data-directory "DOC")))
367
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;(or (documentation-property 'internal-doc-file-name 'variable-documentation)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ; (put 'internal-doc-file-name 'variable-documentation
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ; "The complete pathname of the documentation file that contains all
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;documentation for functions and variables defined before Emacs is dumped."))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;;###autoload
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (defun apropos (regexp &optional do-all pred)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 "Show all symbols whose names contain matches for REGEXP.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 If optional argument DO-ALL is non-nil, does more (time-consuming) work such as
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 showing key bindings. Optional argument PRED is called with each symbol, and
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 if it returns nil, the symbol is not shown.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 Returns list of symbols and documentation found."
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (interactive "sApropos (regexp): \nP")
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (setq do-all (or apropos-do-all do-all))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (let ((apropos-accumulate (apropos-internal regexp pred)))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (if (null apropos-accumulate)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (message "No apropos matches for `%s'" regexp)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (apropos-get-doc apropos-accumulate)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (with-output-to-temp-buffer "*Help*"
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (apropos-print-matches apropos-accumulate regexp nil do-all)))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 apropos-accumulate))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; If "C-h a" still has its original binding of command-apropos, change it to
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; use fast-command-apropos. I don't use substitute-key-definition because
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; it's slow.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;(if (eq 'command-apropos (lookup-key help-map "a"))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ; (define-key help-map "a" 'fast-command-apropos))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; Takes LIST of symbols and adds documentation. Modifies LIST in place.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; Resulting alist is of form ((symbol fn-doc var-doc) ...). Should only be
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; called by apropos. Returns LIST.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (defun apropos-get-doc (list)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (let ((p list)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 fn-doc var-doc symbol)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (while (consp p)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (setq symbol (car p)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 fn-doc (and (fboundp symbol)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (documentation symbol))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 var-doc (documentation-property symbol 'variable-documentation)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 fn-doc (and fn-doc
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (substring fn-doc 0 (string-match "\n" fn-doc)))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 var-doc (and var-doc
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (substring var-doc 0 (string-match "\n" var-doc))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (setcar p (list symbol fn-doc var-doc))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (setq p (cdr p)))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 list))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;;;###autoload
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (defun super-apropos (regexp &optional do-all)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 "Show symbols whose names/documentation contain matches for REGEXP.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 If optional argument DO-ALL is non-nil, does more (time-consuming) work such as
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 showing key bindings and documentation that is not stored in the documentation
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 file.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 Returns list of symbols and documentation found."
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (interactive "sSuper Apropos: \nP")
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (setq do-all (or apropos-do-all do-all))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (let (apropos-accumulate fn-doc var-doc item)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (setq apropos-accumulate (super-apropos-check-doc-file regexp))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (if (null apropos-accumulate)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (message "No apropos matches for `%s'" regexp)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (if do-all (mapatoms 'super-apropos-accumulate))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (with-output-to-temp-buffer "*Help*"
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (apropos-print-matches apropos-accumulate nil t do-all)))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 apropos-accumulate))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;; Finds all documentation related to REGEXP in internal-doc-file-name.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;; Returns an alist of form ((symbol fn-doc var-doc) ...).
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (defun super-apropos-check-doc-file (regexp)
1894
73a56a618d25 (super-apropos-check-doc-file): Look for DOC file in proper directory.
Richard M. Stallman <rms@gnu.org>
parents: 1734
diff changeset
130 (let* ((doc-file (concat data-directory internal-doc-file-name))
73a56a618d25 (super-apropos-check-doc-file): Look for DOC file in proper directory.
Richard M. Stallman <rms@gnu.org>
parents: 1734
diff changeset
131 (doc-buffer (find-file-noselect doc-file t))
73a56a618d25 (super-apropos-check-doc-file): Look for DOC file in proper directory.
Richard M. Stallman <rms@gnu.org>
parents: 1734
diff changeset
132 ;; (doc-buffer (or (get-file-buffer doc-file)
73a56a618d25 (super-apropos-check-doc-file): Look for DOC file in proper directory.
Richard M. Stallman <rms@gnu.org>
parents: 1734
diff changeset
133 ;; (find-file-noselect doc-file)))
367
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 type symbol doc sym-list)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (save-excursion
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (set-buffer doc-buffer)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;; a user said he might accidentally edit the doc file
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (setq buffer-read-only t)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (bury-buffer doc-buffer)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (goto-char (point-min))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (while (re-search-forward regexp nil t)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (search-backward "\C-_")
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (setq type (if (eq ?F (char-after (1+ (point))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 1 ;function documentation
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 2) ;variable documentation
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 symbol (progn
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (forward-char 2)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (read doc-buffer))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 doc (buffer-substring
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (point)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (progn
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (if (search-forward "\C-_" nil 'move)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (1- (point))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (point))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 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
156 (and (if (= type 1)
9fb443ed4acf (super-apropos-check-doc-file): Verify that the doc
Richard M. Stallman <rms@gnu.org>
parents: 5297
diff changeset
157 (documentation symbol)
9fb443ed4acf (super-apropos-check-doc-file): Verify that the doc
Richard M. Stallman <rms@gnu.org>
parents: 5297
diff changeset
158 (documentation-property symbol 'variable-documentation))
9fb443ed4acf (super-apropos-check-doc-file): Verify that the doc
Richard M. Stallman <rms@gnu.org>
parents: 5297
diff changeset
159 (or item
9fb443ed4acf (super-apropos-check-doc-file): Verify that the doc
Richard M. Stallman <rms@gnu.org>
parents: 5297
diff changeset
160 (setq item (list symbol nil nil)
9fb443ed4acf (super-apropos-check-doc-file): Verify that the doc
Richard M. Stallman <rms@gnu.org>
parents: 5297
diff changeset
161 sym-list (cons item sym-list)))
9fb443ed4acf (super-apropos-check-doc-file): Verify that the doc
Richard M. Stallman <rms@gnu.org>
parents: 5297
diff changeset
162 (setcar (nthcdr type item) doc))))
367
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 sym-list))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 ;; This is passed as the argument to map-atoms, so it is called once for every
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; symbol in obarray. Takes one argument SYMBOL, and finds any memory-resident
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;; documentation on that symbol if it matches a variable regexp. WARNING: this
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 ;; function depends on the symbols fn-doc var-doc regexp and item being bound
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;; correctly when it is called!"
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (defun super-apropos-accumulate (symbol)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (cond ((string-match regexp (symbol-name symbol))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (setq item (apropos-get-accum-item symbol))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (setcar (cdr item) (or (safe-documentation symbol)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (nth 1 item)))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (setcar (nthcdr 2 item) (or (safe-documentation-property symbol)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (nth 2 item))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (t
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (and (setq fn-doc (safe-documentation symbol))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (string-match regexp fn-doc)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (setcar (cdr (apropos-get-accum-item symbol)) fn-doc))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (and (setq var-doc (safe-documentation-property symbol))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (string-match regexp var-doc)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (setcar (nthcdr 2 (apropos-get-accum-item symbol)) var-doc))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 nil)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 ;; Prints the symbols and documentation in alist MATCHES of form ((symbol
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 ;; fn-doc var-doc) ...). Uses optional argument REGEXP to speed up searching
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;; for keybindings. The names of all symbols in MATCHES must match REGEXP.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;; Displays in the buffer pointed to by standard-output. Optional argument
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ;; SPACING means put blank lines in between each symbol's documentation.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;; Optional argument DO-ALL means do more time-consuming work, specifically,
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ;; consulting key bindings. Should only be called within a
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ;; with-output-to-temp-buffer.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (defun apropos-print-matches (matches &optional regexp spacing do-all)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (setq matches (sort matches (function
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (lambda (a b)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (string-lessp (car a) (car b))))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (let ((p matches)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (old-buffer (current-buffer))
2946
1f24ead69a2f (apropos-print-matches): Bind tem.
Richard M. Stallman <rms@gnu.org>
parents: 2937
diff changeset
202 item keys-done symbol tem)
367
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (save-excursion
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (set-buffer standard-output)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (or matches (princ "No matches found."))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (while (consp p)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (setq item (car p)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 symbol (car item)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 p (cdr p))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (or (not spacing) (bobp) (terpri))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (princ symbol) ;print symbol name
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 ;; don't calculate key-bindings unless needed
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (cond ((and do-all (commandp symbol) (not keys-done))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (save-excursion
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (set-buffer old-buffer)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (apropos-match-keys matches regexp))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (setq keys-done t)))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (cond ((and do-all
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (or (setq tem (nthcdr 3 item))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (commandp symbol)))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (indent-to 30 1)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (if tem
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (princ (mapconcat 'key-description tem ", "))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (princ "(not bound to any keys)"))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (terpri)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (cond ((setq tem (nth 1 item))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (princ " Function: ")
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (princ (if do-all (substitute-command-keys tem) tem))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (or (bolp) (terpri))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (cond ((setq tem (nth 2 item))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (princ " Variable: ")
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (princ (if do-all (substitute-command-keys tem) tem))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (or (bolp) (terpri)))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 t)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ;; Find key bindings for symbols that are cars in ALIST. Optionally, first
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 ;; match the symbol name against REGEXP. Modifies ALIST in place. Each key
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 ;; binding is added as a string to the end of the list in ALIST whose car is
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 ;; the corresponding symbol. The pointer to ALIST is returned.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (defun apropos-match-keys (alist &optional regexp)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (let* ((current-local-map (current-local-map))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (maps (append (and current-local-map
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (accessible-keymaps current-local-map))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (accessible-keymaps (current-global-map))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 map ;map we are now inspecting
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 sequence ;key sequence to reach map
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 i ;index into vector map
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 command ;what is bound to current keys
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 key ;last key to reach command
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 local ;local binding for sequence + key
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 item) ;symbol data item in alist
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 ;; examine all reachable keymaps
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (while (consp maps)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (setq map (cdr (car maps))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 sequence (car (car maps)) ;keys to reach this map
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 maps (cdr maps))
2937
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
258 ;; 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
259 (if (eq (car map) 'keymap)
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
260 (setq map (cdr map)))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
261 (while (stringp (car-safe map))
367
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (setq map (cdr map)))
2937
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
263 (while (consp map)
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
264 (cond ((consp (car map))
367
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (setq command (cdr (car map))
2937
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
266 key (car (car map)))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
267 ;; 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
268 (and (consp command) (symbolp (cdr command))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
269 (setq command (cdr command)))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
270 ;; 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
271 ;; 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
272 ;; record it
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
273 (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
274 (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
275 (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
276 t)
2937
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
277 (setq item (assq command alist))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
278 (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
279 (setq key (vconcat sequence (vector key)))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
280 (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
281 ;; checking if shadowed by local binding.
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
282 ;; 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
283 ;; 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
284 (or (not current-local-map)
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
285 (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
286 (numberp local)
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
287 (eq command local))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
288 ;; 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
289 (nconc item (cons key nil))))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
290 ((vectorp (car map))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
291 (let ((i 0)
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
292 (vec (car map))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
293 (len (length (car map))))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
294 (while (< i len)
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
295 (setq command (aref vec i))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
296 (setq key i)
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
297 ;; 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
298 (and (consp command) (symbolp (cdr command))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
299 (setq command (cdr command)))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
300 ;; 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
301 (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
302 (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
303 (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
304 t)
2937
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
305 (setq item (assq command alist))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
306 (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
307 (setq key (vconcat sequence (vector key)))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
308 (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
309 ;; checking if shadowed by local binding.
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
310 ;; 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
311 ;; 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
312 (or (not current-local-map)
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
313 (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
314 (numberp local)
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
315 (eq command local))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
316 ;; 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
317 (nconc item (cons key nil)))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
318 (setq i (1+ i))))))
e38ff71093b5 (apropos-match-keys): Handle modern keymap structure.
Richard M. Stallman <rms@gnu.org>
parents: 2247
diff changeset
319 (setq map (cdr map)))))
367
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 alist)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 ;; Get an alist item in alist apropos-accumulate whose car is SYMBOL. Creates
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ;; the item if not already present. Modifies apropos-accumulate in place.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (defun apropos-get-accum-item (symbol)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (or (assq symbol apropos-accumulate)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (progn
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (setq apropos-accumulate
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (cons (list symbol nil nil) apropos-accumulate))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (assq symbol apropos-accumulate))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (defun safe-documentation (function)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 "Like documentation, except it avoids calling `get_doc_string'.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 Will return nil instead."
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (while (symbolp function)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (setq function (if (fboundp function)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (symbol-function function)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 0)))
3563
804e4f30b7ce (safe-documentation): Don't crash on byte-compiled macro.
Richard M. Stallman <rms@gnu.org>
parents: 2946
diff changeset
339 (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
340 (setq function (cdr function)))
367
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (if (not (consp function))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 nil
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (if (not (memq (car function) '(lambda autoload)))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 nil
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (setq function (nth 2 function))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (if (stringp function)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 function
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 nil))))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (defun safe-documentation-property (symbol)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 "Like documentation-property, except it avoids calling `get_doc_string'.
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 Will return nil instead."
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (setq symbol (get symbol 'variable-documentation))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (if (numberp symbol)
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 nil
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 symbol))
6c230193acf9 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 444
diff changeset
358 ;;; apropos.el ends here