Mercurial > emacs
annotate src/keymap.c @ 1392:ad64a94cd81c
(morecore_with_warning): Reduce warnlevel when usage drops far enough.
(memory_warnings): Renamed from malloc_init.
Don't set lim_data or warnlevel. Use start_of_data if start is 0.
[!emacs]: Don't include config.h or lisp.h;
instead, use stddef.h. Define POINTER, SIZE, EXCEEDS_LISP_PTR.
(morecore_with_warning): Use EXCEEDS_LISP_PTR.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 11 Oct 1992 20:39:15 +0000 |
parents | 02226bff1476 |
children | 929409595312 |
rev | line source |
---|---|
250 | 1 /* Manipulation of keymaps |
647 | 2 Copyright (C) 1985, 1986, 1987, 1988, 1992 Free Software Foundation, Inc. |
250 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
647 | 8 the Free Software Foundation; either version 2, or (at your option) |
250 | 9 any later version. |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
21 #include "config.h" | |
22 #include <stdio.h> | |
23 #undef NULL | |
24 #include "lisp.h" | |
25 #include "commands.h" | |
26 #include "buffer.h" | |
517 | 27 #include "keyboard.h" |
250 | 28 |
29 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
30 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
31 /* The number of elements in keymap vectors. */ |
250 | 32 #define DENSE_TABLE_SIZE (0200) |
33 | |
34 /* Actually allocate storage for these variables */ | |
35 | |
36 Lisp_Object current_global_map; /* Current global keymap */ | |
37 | |
38 Lisp_Object global_map; /* default global key bindings */ | |
39 | |
40 Lisp_Object meta_map; /* The keymap used for globally bound | |
41 ESC-prefixed default commands */ | |
42 | |
43 Lisp_Object control_x_map; /* The keymap used for globally bound | |
44 C-x-prefixed default commands */ | |
45 | |
46 /* was MinibufLocalMap */ | |
47 Lisp_Object Vminibuffer_local_map; | |
48 /* The keymap used by the minibuf for local | |
49 bindings when spaces are allowed in the | |
50 minibuf */ | |
51 | |
52 /* was MinibufLocalNSMap */ | |
53 Lisp_Object Vminibuffer_local_ns_map; | |
54 /* The keymap used by the minibuf for local | |
55 bindings when spaces are not encouraged | |
56 in the minibuf */ | |
57 | |
58 /* keymap used for minibuffers when doing completion */ | |
59 /* was MinibufLocalCompletionMap */ | |
60 Lisp_Object Vminibuffer_local_completion_map; | |
61 | |
62 /* keymap used for minibuffers when doing completion and require a match */ | |
63 /* was MinibufLocalMustMatchMap */ | |
64 Lisp_Object Vminibuffer_local_must_match_map; | |
65 | |
465 | 66 /* Alist of minor mode variables and keymaps. */ |
67 Lisp_Object Vminor_mode_map_alist; | |
68 | |
517 | 69 /* Keymap mapping ASCII function key sequences onto their preferred forms. |
70 Initialized by the terminal-specific lisp files. See DEFVAR for more | |
71 documentation. */ | |
72 Lisp_Object Vfunction_key_map; | |
73 | |
250 | 74 Lisp_Object Qkeymapp, Qkeymap; |
75 | |
76 /* A char over 0200 in a key sequence | |
77 is equivalent to prefixing with this character. */ | |
78 | |
79 extern Lisp_Object meta_prefix_char; | |
80 | |
81 void describe_map_tree (); | |
82 static Lisp_Object describe_buffer_bindings (); | |
83 static void describe_command (); | |
84 static void describe_map (); | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
85 static void describe_map_2 (); |
250 | 86 |
465 | 87 /* Keymap object support - constructors and predicates. */ |
88 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
89 DEFUN ("make-keymap", Fmake_keymap, Smake_keymap, 0, 1, 0, |
250 | 90 "Construct and return a new keymap, of the form (keymap VECTOR . ALIST).\n\ |
91 VECTOR is a 128-element vector which holds the bindings for the ASCII\n\ | |
92 characters. ALIST is an assoc-list which holds bindings for function keys,\n\ | |
93 mouse events, and any other things that appear in the input stream.\n\ | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
94 All entries in it are initially nil, meaning \"command undefined\".\n\n\ |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
95 The optional arg STRING supplies a menu name for the keymap\n\ |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
96 in case you use it as a menu with `x-popup-menu'.") |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
97 (string) |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
98 Lisp_Object string; |
250 | 99 { |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
100 Lisp_Object tail; |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
101 if (!NILP (string)) |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
102 tail = Fcons (string, Qnil); |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
103 else |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
104 tail = Qnil; |
250 | 105 return Fcons (Qkeymap, |
106 Fcons (Fmake_vector (make_number (DENSE_TABLE_SIZE), Qnil), | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
107 tail)); |
250 | 108 } |
109 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
110 DEFUN ("make-sparse-keymap", Fmake_sparse_keymap, Smake_sparse_keymap, 0, 1, 0, |
250 | 111 "Construct and return a new sparse-keymap list.\n\ |
112 Its car is `keymap' and its cdr is an alist of (CHAR . DEFINITION),\n\ | |
113 which binds the character CHAR to DEFINITION, or (SYMBOL . DEFINITION),\n\ | |
114 which binds the function key or mouse event SYMBOL to DEFINITION.\n\ | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
115 Initially the alist is nil.\n\n\ |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
116 The optional arg STRING supplies a menu name for the keymap\n\ |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
117 in case you use it as a menu with `x-popup-menu'.") |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
118 (string) |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
119 Lisp_Object string; |
250 | 120 { |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
121 if (!NILP (string)) |
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
122 return Fcons (Qkeymap, Fcons (string, Qnil)); |
250 | 123 return Fcons (Qkeymap, Qnil); |
124 } | |
125 | |
126 /* This function is used for installing the standard key bindings | |
127 at initialization time. | |
128 | |
129 For example: | |
130 | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
131 initial_define_key (control_x_map, Ctl('X'), "exchange-point-and-mark"); */ |
250 | 132 |
133 void | |
134 initial_define_key (keymap, key, defname) | |
135 Lisp_Object keymap; | |
136 int key; | |
137 char *defname; | |
138 { | |
139 store_in_keymap (keymap, make_number (key), intern (defname)); | |
140 } | |
141 | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
142 void |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
143 initial_define_lispy_key (keymap, keyname, defname) |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
144 Lisp_Object keymap; |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
145 char *keyname; |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
146 char *defname; |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
147 { |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
148 store_in_keymap (keymap, intern (keyname), intern (defname)); |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
149 } |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
150 |
250 | 151 /* Define character fromchar in map frommap as an alias for character |
152 tochar in map tomap. Subsequent redefinitions of the latter WILL | |
153 affect the former. */ | |
154 | |
155 #if 0 | |
156 void | |
157 synkey (frommap, fromchar, tomap, tochar) | |
158 struct Lisp_Vector *frommap, *tomap; | |
159 int fromchar, tochar; | |
160 { | |
161 Lisp_Object v, c; | |
162 XSET (v, Lisp_Vector, tomap); | |
163 XFASTINT (c) = tochar; | |
164 frommap->contents[fromchar] = Fcons (v, c); | |
165 } | |
166 #endif /* 0 */ | |
167 | |
168 DEFUN ("keymapp", Fkeymapp, Skeymapp, 1, 1, 0, | |
169 "Return t if ARG is a keymap.\n\ | |
362 | 170 \n\ |
171 A keymap is list (keymap . ALIST), a list (keymap VECTOR . ALIST),\n\ | |
172 or a symbol whose function definition is a keymap is itself a keymap.\n\ | |
173 ALIST elements look like (CHAR . DEFN) or (SYMBOL . DEFN);\n\ | |
174 VECTOR is a 128-element vector of bindings for ASCII characters.") | |
250 | 175 (object) |
176 Lisp_Object object; | |
177 { | |
485 | 178 return (NILP (get_keymap_1 (object, 0)) ? Qnil : Qt); |
250 | 179 } |
180 | |
181 /* Check that OBJECT is a keymap (after dereferencing through any | |
182 symbols). If it is, return it; otherwise, return nil, or signal an | |
183 error if ERROR != 0. */ | |
184 Lisp_Object | |
185 get_keymap_1 (object, error) | |
186 Lisp_Object object; | |
187 int error; | |
188 { | |
189 register Lisp_Object tem; | |
190 | |
647 | 191 tem = indirect_function (object); |
250 | 192 if (CONSP (tem) && EQ (XCONS (tem)->car, Qkeymap)) |
193 return tem; | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
194 |
250 | 195 if (error) |
196 wrong_type_argument (Qkeymapp, object); | |
465 | 197 else |
198 return Qnil; | |
250 | 199 } |
200 | |
201 Lisp_Object | |
202 get_keymap (object) | |
203 Lisp_Object object; | |
204 { | |
205 return get_keymap_1 (object, 1); | |
206 } | |
207 | |
208 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
209 /* Look up IDX in MAP. IDX may be any sort of event. |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
210 Note that this does only one level of lookup; IDX must be a single |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
211 event, not a sequence. |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
212 |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
213 If T_OK is non-zero, bindings for Qt are treated as default |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
214 bindings; any key left unmentioned by other tables and bindings is |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
215 given the binding of Qt. |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
216 |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
217 If T_OK is zero, bindings for Qt are not treated specially. */ |
250 | 218 |
219 Lisp_Object | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
220 access_keymap (map, idx, t_ok) |
250 | 221 Lisp_Object map; |
222 Lisp_Object idx; | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
223 int t_ok; |
250 | 224 { |
225 /* If idx is a list (some sort of mouse click, perhaps?), | |
226 the index we want to use is the car of the list, which | |
227 ought to be a symbol. */ | |
1315
884c3d7e7172
* keymap.c (access_keymap, store_in_keymap,
Jim Blandy <jimb@redhat.com>
parents:
1264
diff
changeset
|
228 idx = EVENT_HEAD (idx); |
250 | 229 |
230 if (XTYPE (idx) == Lisp_Int | |
231 && (XINT (idx) < 0 || XINT (idx) >= DENSE_TABLE_SIZE)) | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
232 error ("only ASCII characters may be looked up in keymaps"); |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
233 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
234 /* If idx is a symbol, it might have modifiers, which need to |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
235 be put in the canonical order. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
236 else if (XTYPE (idx) == Lisp_Symbol) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
237 idx = reorder_modifiers (idx); |
250 | 238 |
239 { | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
240 Lisp_Object tail; |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
241 Lisp_Object t_binding = Qnil; |
250 | 242 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
243 for (tail = map; CONSP (tail); tail = XCONS (tail)->cdr) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
244 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
245 Lisp_Object binding = XCONS (tail)->car; |
250 | 246 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
247 switch (XTYPE (binding)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
248 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
249 case Lisp_Cons: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
250 if (EQ (XCONS (binding)->car, idx)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
251 return XCONS (binding)->cdr; |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
252 if (t_ok && EQ (XCONS (binding)->car, Qt)) |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
253 t_binding = XCONS (binding)->cdr; |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
254 break; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
255 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
256 case Lisp_Vector: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
257 if (XVECTOR (binding)->size == DENSE_TABLE_SIZE |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
258 && XTYPE (idx) == Lisp_Int) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
259 return XVECTOR (binding)->contents[XINT (idx)]; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
260 break; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
261 } |
1264
6ba9d5aaace6
* keymap.c (access_keymap): Don't forget to QUIT while scanning
Jim Blandy <jimb@redhat.com>
parents:
1236
diff
changeset
|
262 |
6ba9d5aaace6
* keymap.c (access_keymap): Don't forget to QUIT while scanning
Jim Blandy <jimb@redhat.com>
parents:
1236
diff
changeset
|
263 QUIT; |
250 | 264 } |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
265 |
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
266 return t_binding; |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
267 } |
250 | 268 } |
269 | |
270 /* Given OBJECT which was found in a slot in a keymap, | |
271 trace indirect definitions to get the actual definition of that slot. | |
272 An indirect definition is a list of the form | |
273 (KEYMAP . INDEX), where KEYMAP is a keymap or a symbol defined as one | |
274 and INDEX is the object to look up in KEYMAP to yield the definition. | |
275 | |
276 Also if OBJECT has a menu string as the first element, | |
1160
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
277 remove that. Also remove a menu help string as second element. */ |
250 | 278 |
279 Lisp_Object | |
280 get_keyelt (object) | |
281 register Lisp_Object object; | |
282 { | |
283 while (1) | |
284 { | |
285 register Lisp_Object map, tem; | |
286 | |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
287 /* If the contents are (KEYMAP . ELEMENT), go indirect. */ |
250 | 288 map = get_keymap_1 (Fcar_safe (object), 0); |
289 tem = Fkeymapp (map); | |
485 | 290 if (!NILP (tem)) |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
291 object = access_keymap (map, Fcdr (object), 0); |
250 | 292 |
293 /* If the keymap contents looks like (STRING . DEFN), | |
294 use DEFN. | |
295 Keymap alist elements like (CHAR MENUSTRING . DEFN) | |
296 will be used by HierarKey menus. */ | |
297 else if (XTYPE (object) == Lisp_Cons | |
298 && XTYPE (XCONS (object)->car) == Lisp_String) | |
1160
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
299 { |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
300 object = XCONS (object)->cdr; |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
301 /* Also remove a menu help string, if any, |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
302 following the menu item name. */ |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
303 if (XTYPE (object) == Lisp_Cons |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
304 && XTYPE (XCONS (object)->car) == Lisp_String) |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
305 object = XCONS (object)->cdr; |
f7b55bfe1c05
(get_keyelt): Skip menu help string after menu item name.
Richard M. Stallman <rms@gnu.org>
parents:
1120
diff
changeset
|
306 } |
250 | 307 |
308 else | |
309 /* Anything else is really the value. */ | |
310 return object; | |
311 } | |
312 } | |
313 | |
314 Lisp_Object | |
315 store_in_keymap (keymap, idx, def) | |
316 Lisp_Object keymap; | |
317 register Lisp_Object idx; | |
318 register Lisp_Object def; | |
319 { | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
320 if (XTYPE (keymap) != Lisp_Cons |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
321 || ! EQ (XCONS (keymap)->car, Qkeymap)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
322 error ("attempt to define a key in a non-keymap"); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
323 |
250 | 324 /* If idx is a list (some sort of mouse click, perhaps?), |
325 the index we want to use is the car of the list, which | |
326 ought to be a symbol. */ | |
1315
884c3d7e7172
* keymap.c (access_keymap, store_in_keymap,
Jim Blandy <jimb@redhat.com>
parents:
1264
diff
changeset
|
327 idx = EVENT_HEAD (idx); |
250 | 328 |
329 if (XTYPE (idx) == Lisp_Int | |
330 && (XINT (idx) < 0 || XINT (idx) >= DENSE_TABLE_SIZE)) | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
331 error ("only ASCII characters may be used as keymap indices"); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
332 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
333 /* If idx is a symbol, it might have modifiers, which need to |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
334 be put in the canonical order. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
335 else if (XTYPE (idx) == Lisp_Symbol) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
336 idx = reorder_modifiers (idx); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
337 |
250 | 338 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
339 /* Scan the keymap for a binding of idx. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
340 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
341 Lisp_Object tail; |
250 | 342 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
343 /* The cons after which we should insert new bindings. If the |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
344 keymap has a table element, we record its position here, so new |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
345 bindings will go after it; this way, the table will stay |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
346 towards the front of the alist and character lookups in dense |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
347 keymaps will remain fast. Otherwise, this just points at the |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
348 front of the keymap. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
349 Lisp_Object insertion_point = keymap; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
350 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
351 for (tail = XCONS (keymap)->cdr; CONSP (tail); tail = XCONS (tail)->cdr) |
250 | 352 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
353 Lisp_Object elt = XCONS (tail)->car; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
354 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
355 switch (XTYPE (elt)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
356 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
357 case Lisp_Vector: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
358 if (XTYPE (idx) == Lisp_Int) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
359 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
360 XVECTOR (elt)->contents[XFASTINT (idx)] = def; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
361 return def; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
362 } |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
363 insertion_point = tail; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
364 break; |
250 | 365 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
366 case Lisp_Cons: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
367 if (EQ (idx, XCONS (elt)->car)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
368 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
369 XCONS (elt)->cdr = def; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
370 return def; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
371 } |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
372 break; |
250 | 373 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
374 case Lisp_Symbol: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
375 /* If we find a 'keymap' symbol in the spine of KEYMAP, |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
376 then we must have found the start of a second keymap |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
377 being used as the tail of KEYMAP, and a binding for IDX |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
378 should be inserted before it. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
379 if (EQ (elt, Qkeymap)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
380 goto keymap_end; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
381 break; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
382 } |
250 | 383 } |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
384 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
385 keymap_end: |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
386 /* We have scanned the entire keymap, and not found a binding for |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
387 IDX. Let's add one. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
388 XCONS (insertion_point)->cdr = |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
389 Fcons (Fcons (idx, def), XCONS (insertion_point)->cdr); |
250 | 390 } |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
391 |
250 | 392 return def; |
393 } | |
394 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
395 |
250 | 396 DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0, |
397 "Return a copy of the keymap KEYMAP.\n\ | |
398 The copy starts out with the same definitions of KEYMAP,\n\ | |
399 but changing either the copy or KEYMAP does not affect the other.\n\ | |
362 | 400 Any key definitions that are subkeymaps are recursively copied.\n\ |
401 However, a key definition which is a symbol whose definition is a keymap\n\ | |
402 is not copied.") | |
250 | 403 (keymap) |
404 Lisp_Object keymap; | |
405 { | |
406 register Lisp_Object copy, tail; | |
407 | |
408 copy = Fcopy_alist (get_keymap (keymap)); | |
409 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
410 for (tail = copy; CONSP (tail); tail = XCONS (tail)->cdr) |
250 | 411 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
412 Lisp_Object elt = XCONS (tail)->car; |
250 | 413 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
414 if (XTYPE (elt) == Lisp_Vector |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
415 && XVECTOR (elt)->size == DENSE_TABLE_SIZE) |
250 | 416 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
417 int i; |
250 | 418 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
419 elt = Fcopy_sequence (elt); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
420 XCONS (tail)->car = elt; |
250 | 421 |
422 for (i = 0; i < DENSE_TABLE_SIZE; i++) | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
423 if (XTYPE (XVECTOR (elt)->contents[i]) != Lisp_Symbol |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
424 && Fkeymapp (XVECTOR (elt)->contents[i])) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
425 XVECTOR (elt)->contents[i] = |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
426 Fcopy_keymap (XVECTOR (elt)->contents[i]); |
250 | 427 } |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
428 else if (CONSP (elt) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
429 && XTYPE (XCONS (elt)->cdr) != Lisp_Symbol |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
430 && ! NILP (Fkeymapp (XCONS (elt)->cdr))) |
250 | 431 XCONS (elt)->cdr = Fcopy_keymap (XCONS (elt)->cdr); |
432 } | |
433 | |
434 return copy; | |
435 } | |
436 | |
465 | 437 /* Simple Keymap mutators and accessors. */ |
438 | |
250 | 439 DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0, |
440 "Args KEYMAP, KEY, DEF. Define key sequence KEY, in KEYMAP, as DEF.\n\ | |
441 KEYMAP is a keymap. KEY is a string or a vector of symbols and characters\n\ | |
442 meaning a sequence of keystrokes and events.\n\ | |
443 DEF is anything that can be a key's definition:\n\ | |
444 nil (means key is undefined in this keymap),\n\ | |
445 a command (a Lisp function suitable for interactive calling)\n\ | |
446 a string (treated as a keyboard macro),\n\ | |
447 a keymap (to define a prefix key),\n\ | |
448 a symbol. When the key is looked up, the symbol will stand for its\n\ | |
449 function definition, which should at that time be one of the above,\n\ | |
450 or another symbol whose function definition is used, etc.\n\ | |
451 a cons (STRING . DEFN), meaning that DEFN is the definition\n\ | |
452 (DEFN should be a valid definition in its own right),\n\ | |
368 | 453 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP.\n\ |
454 \n\ | |
455 If KEYMAP is a sparse keymap, the pair binding KEY to DEF is added at\n\ | |
456 the front of KEYMAP.") | |
250 | 457 (keymap, key, def) |
458 register Lisp_Object keymap; | |
459 Lisp_Object key; | |
460 Lisp_Object def; | |
461 { | |
462 register int idx; | |
463 register Lisp_Object c; | |
464 register Lisp_Object tem; | |
465 register Lisp_Object cmd; | |
466 int metized = 0; | |
467 int length; | |
468 | |
469 keymap = get_keymap (keymap); | |
470 | |
471 if (XTYPE (key) != Lisp_Vector | |
472 && XTYPE (key) != Lisp_String) | |
473 key = wrong_type_argument (Qarrayp, key); | |
474 | |
475 length = Flength (key); | |
476 if (length == 0) | |
477 return Qnil; | |
478 | |
479 idx = 0; | |
480 while (1) | |
481 { | |
482 c = Faref (key, make_number (idx)); | |
483 | |
484 if (XTYPE (c) == Lisp_Int | |
485 && XINT (c) >= 0200 | |
486 && !metized) | |
487 { | |
488 c = meta_prefix_char; | |
489 metized = 1; | |
490 } | |
491 else | |
492 { | |
493 if (XTYPE (c) == Lisp_Int) | |
494 XSETINT (c, XINT (c) & 0177); | |
495 | |
496 metized = 0; | |
497 idx++; | |
498 } | |
499 | |
500 if (idx == length) | |
501 return store_in_keymap (keymap, c, def); | |
502 | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
503 cmd = get_keyelt (access_keymap (keymap, c, 0)); |
250 | 504 |
485 | 505 if (NILP (cmd)) |
250 | 506 { |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
507 cmd = Fmake_sparse_keymap (Qnil); |
250 | 508 store_in_keymap (keymap, c, cmd); |
509 } | |
510 | |
511 tem = Fkeymapp (cmd); | |
485 | 512 if (NILP (tem)) |
250 | 513 error ("Key sequence %s uses invalid prefix characters", |
514 XSTRING (key)->data); | |
515 | |
516 keymap = get_keymap (cmd); | |
517 } | |
518 } | |
519 | |
520 /* Value is number if KEY is too long; NIL if valid but has no definition. */ | |
521 | |
522 DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 2, 0, | |
523 "In keymap KEYMAP, look up key sequence KEY. Return the definition.\n\ | |
524 nil means undefined. See doc of `define-key' for kinds of definitions.\n\ | |
525 A number as value means KEY is \"too long\";\n\ | |
526 that is, characters or symbols in it except for the last one\n\ | |
527 fail to be a valid sequence of prefix characters in KEYMAP.\n\ | |
528 The number is how many characters at the front of KEY\n\ | |
529 it takes to reach a non-prefix command.") | |
530 (keymap, key) | |
531 register Lisp_Object keymap; | |
532 Lisp_Object key; | |
533 { | |
534 register int idx; | |
535 register Lisp_Object tem; | |
536 register Lisp_Object cmd; | |
537 register Lisp_Object c; | |
538 int metized = 0; | |
539 int length; | |
540 | |
541 keymap = get_keymap (keymap); | |
542 | |
543 if (XTYPE (key) != Lisp_Vector | |
544 && XTYPE (key) != Lisp_String) | |
545 key = wrong_type_argument (Qarrayp, key); | |
546 | |
547 length = Flength (key); | |
548 if (length == 0) | |
549 return keymap; | |
550 | |
551 idx = 0; | |
552 while (1) | |
553 { | |
554 c = Faref (key, make_number (idx)); | |
555 | |
556 if (XTYPE (c) == Lisp_Int | |
557 && XINT (c) >= 0200 | |
558 && !metized) | |
559 { | |
560 c = meta_prefix_char; | |
561 metized = 1; | |
562 } | |
563 else | |
564 { | |
565 if (XTYPE (c) == Lisp_Int) | |
566 XSETINT (c, XINT (c) & 0177); | |
567 | |
568 metized = 0; | |
569 idx++; | |
570 } | |
571 | |
1388
02226bff1476
* keymap.c (initial_define_lispy_key): New function, for defining
Jim Blandy <jimb@redhat.com>
parents:
1315
diff
changeset
|
572 cmd = get_keyelt (access_keymap (keymap, c, 0)); |
250 | 573 if (idx == length) |
574 return cmd; | |
575 | |
576 tem = Fkeymapp (cmd); | |
485 | 577 if (NILP (tem)) |
250 | 578 return make_number (idx); |
579 | |
580 keymap = get_keymap (cmd); | |
581 QUIT; | |
582 } | |
583 } | |
584 | |
585 /* Append a key to the end of a key sequence. If key_sequence is a | |
586 string and key is a character, the result will be another string; | |
587 otherwise, it will be a vector. */ | |
588 Lisp_Object | |
589 append_key (key_sequence, key) | |
590 Lisp_Object key_sequence, key; | |
591 { | |
592 Lisp_Object args[2]; | |
593 | |
594 args[0] = key_sequence; | |
595 | |
596 if (XTYPE (key_sequence) == Lisp_String | |
597 && XTYPE (key) == Lisp_Int) | |
598 { | |
599 args[1] = Fchar_to_string (key); | |
600 return Fconcat (2, args); | |
601 } | |
602 else | |
603 { | |
604 args[1] = Fcons (key, Qnil); | |
605 return Fvconcat (2, args); | |
606 } | |
607 } | |
608 | |
609 | |
465 | 610 /* Global, local, and minor mode keymap stuff. */ |
611 | |
485 | 612 /* We can't put these variables inside current_minor_maps, since under |
517 | 613 some systems, static gets macro-defined to be the empty string. |
614 Ickypoo. */ | |
485 | 615 static Lisp_Object *cmm_modes, *cmm_maps; |
616 static int cmm_size; | |
617 | |
465 | 618 /* Store a pointer to an array of the keymaps of the currently active |
619 minor modes in *buf, and return the number of maps it contains. | |
620 | |
621 This function always returns a pointer to the same buffer, and may | |
622 free or reallocate it, so if you want to keep it for a long time or | |
623 hand it out to lisp code, copy it. This procedure will be called | |
624 for every key sequence read, so the nice lispy approach (return a | |
625 new assoclist, list, what have you) for each invocation would | |
626 result in a lot of consing over time. | |
627 | |
628 If we used xrealloc/xmalloc and ran out of memory, they would throw | |
629 back to the command loop, which would try to read a key sequence, | |
630 which would call this function again, resulting in an infinite | |
631 loop. Instead, we'll use realloc/malloc and silently truncate the | |
632 list, let the key sequence be read, and hope some other piece of | |
633 code signals the error. */ | |
634 int | |
635 current_minor_maps (modeptr, mapptr) | |
636 Lisp_Object **modeptr, **mapptr; | |
637 { | |
638 int i = 0; | |
517 | 639 Lisp_Object alist, assoc, var, val; |
465 | 640 |
641 for (alist = Vminor_mode_map_alist; | |
642 CONSP (alist); | |
643 alist = XCONS (alist)->cdr) | |
644 if (CONSP (assoc = XCONS (alist)->car) | |
645 && XTYPE (var = XCONS (assoc)->car) == Lisp_Symbol | |
517 | 646 && ! EQ ((val = find_symbol_value (var)), Qunbound) |
647 && ! NILP (val)) | |
465 | 648 { |
485 | 649 if (i >= cmm_size) |
465 | 650 { |
651 Lisp_Object *newmodes, *newmaps; | |
652 | |
485 | 653 if (cmm_maps) |
465 | 654 { |
485 | 655 newmodes = (Lisp_Object *) realloc (cmm_modes, cmm_size *= 2); |
656 newmaps = (Lisp_Object *) realloc (cmm_maps, cmm_size); | |
465 | 657 } |
658 else | |
659 { | |
485 | 660 newmodes = (Lisp_Object *) malloc (cmm_size = 30); |
661 newmaps = (Lisp_Object *) malloc (cmm_size); | |
465 | 662 } |
663 | |
664 if (newmaps && newmodes) | |
665 { | |
485 | 666 cmm_modes = newmodes; |
667 cmm_maps = newmaps; | |
465 | 668 } |
669 else | |
670 break; | |
671 } | |
485 | 672 cmm_modes[i] = var; |
673 cmm_maps [i] = XCONS (assoc)->cdr; | |
465 | 674 i++; |
675 } | |
676 | |
485 | 677 if (modeptr) *modeptr = cmm_modes; |
678 if (mapptr) *mapptr = cmm_maps; | |
465 | 679 return i; |
680 } | |
681 | |
250 | 682 DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 1, 0, |
683 "Return the binding for command KEY in current keymaps.\n\ | |
684 KEY is a string, a sequence of keystrokes.\n\ | |
685 The binding is probably a symbol with a function definition.") | |
686 (key) | |
687 Lisp_Object key; | |
688 { | |
465 | 689 Lisp_Object *maps, value; |
690 int nmaps, i; | |
691 | |
692 nmaps = current_minor_maps (0, &maps); | |
693 for (i = 0; i < nmaps; i++) | |
485 | 694 if (! NILP (maps[i])) |
465 | 695 { |
696 value = Flookup_key (maps[i], key); | |
485 | 697 if (! NILP (value) && XTYPE (value) != Lisp_Int) |
465 | 698 return value; |
699 } | |
700 | |
485 | 701 if (! NILP (current_buffer->keymap)) |
250 | 702 { |
465 | 703 value = Flookup_key (current_buffer->keymap, key); |
485 | 704 if (! NILP (value) && XTYPE (value) != Lisp_Int) |
250 | 705 return value; |
706 } | |
465 | 707 |
708 value = Flookup_key (current_global_map, key); | |
485 | 709 if (! NILP (value) && XTYPE (value) != Lisp_Int) |
465 | 710 return value; |
711 | |
712 return Qnil; | |
250 | 713 } |
714 | |
715 DEFUN ("local-key-binding", Flocal_key_binding, Slocal_key_binding, 1, 1, 0, | |
716 "Return the binding for command KEYS in current local keymap only.\n\ | |
717 KEYS is a string, a sequence of keystrokes.\n\ | |
718 The binding is probably a symbol with a function definition.") | |
719 (keys) | |
720 Lisp_Object keys; | |
721 { | |
722 register Lisp_Object map; | |
723 map = current_buffer->keymap; | |
485 | 724 if (NILP (map)) |
250 | 725 return Qnil; |
726 return Flookup_key (map, keys); | |
727 } | |
728 | |
729 DEFUN ("global-key-binding", Fglobal_key_binding, Sglobal_key_binding, 1, 1, 0, | |
730 "Return the binding for command KEYS in current global keymap only.\n\ | |
731 KEYS is a string, a sequence of keystrokes.\n\ | |
517 | 732 The binding is probably a symbol with a function definition.\n\ |
733 This function's return values are the same as those of lookup-key\n\ | |
734 (which see).") | |
250 | 735 (keys) |
736 Lisp_Object keys; | |
737 { | |
738 return Flookup_key (current_global_map, keys); | |
739 } | |
740 | |
465 | 741 DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_binding, 1, 1, 0, |
742 "Find the visible minor mode bindings of KEY.\n\ | |
743 Return an alist of pairs (MODENAME . BINDING), where MODENAME is the\n\ | |
744 the symbol which names the minor mode binding KEY, and BINDING is\n\ | |
745 KEY's definition in that mode. In particular, if KEY has no\n\ | |
746 minor-mode bindings, return nil. If the first binding is a\n\ | |
747 non-prefix, all subsequent bindings will be omitted, since they would\n\ | |
748 be ignored. Similarly, the list doesn't include non-prefix bindings\n\ | |
749 that come after prefix bindings.") | |
750 (key) | |
751 { | |
752 Lisp_Object *modes, *maps; | |
753 int nmaps; | |
754 Lisp_Object binding; | |
755 int i, j; | |
756 | |
757 nmaps = current_minor_maps (&modes, &maps); | |
758 | |
759 for (i = j = 0; i < nmaps; i++) | |
485 | 760 if (! NILP (maps[i]) |
761 && ! NILP (binding = Flookup_key (maps[i], key)) | |
465 | 762 && XTYPE (binding) != Lisp_Int) |
763 { | |
485 | 764 if (! NILP (get_keymap_1 (binding, 0))) |
465 | 765 maps[j++] = Fcons (modes[i], binding); |
766 else if (j == 0) | |
767 return Fcons (Fcons (modes[i], binding), Qnil); | |
768 } | |
769 | |
770 return Flist (j, maps); | |
771 } | |
772 | |
250 | 773 DEFUN ("global-set-key", Fglobal_set_key, Sglobal_set_key, 2, 2, |
774 "kSet key globally: \nCSet key %s to command: ", | |
775 "Give KEY a global binding as COMMAND.\n\ | |
776 COMMAND is a symbol naming an interactively-callable function.\n\ | |
777 KEY is a string representing a sequence of keystrokes.\n\ | |
778 Note that if KEY has a local binding in the current buffer\n\ | |
779 that local binding will continue to shadow any global binding.") | |
780 (keys, function) | |
781 Lisp_Object keys, function; | |
782 { | |
783 if (XTYPE (keys) != Lisp_Vector | |
784 && XTYPE (keys) != Lisp_String) | |
785 keys = wrong_type_argument (Qarrayp, keys); | |
786 | |
787 Fdefine_key (current_global_map, keys, function); | |
788 return Qnil; | |
789 } | |
790 | |
791 DEFUN ("local-set-key", Flocal_set_key, Slocal_set_key, 2, 2, | |
792 "kSet key locally: \nCSet key %s locally to command: ", | |
793 "Give KEY a local binding as COMMAND.\n\ | |
794 COMMAND is a symbol naming an interactively-callable function.\n\ | |
795 KEY is a string representing a sequence of keystrokes.\n\ | |
796 The binding goes in the current buffer's local map,\n\ | |
797 which is shared with other buffers in the same major mode.") | |
798 (keys, function) | |
799 Lisp_Object keys, function; | |
800 { | |
801 register Lisp_Object map; | |
802 map = current_buffer->keymap; | |
485 | 803 if (NILP (map)) |
250 | 804 { |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
805 map = Fmake_sparse_keymap (Qnil); |
250 | 806 current_buffer->keymap = map; |
807 } | |
808 | |
809 if (XTYPE (keys) != Lisp_Vector | |
810 && XTYPE (keys) != Lisp_String) | |
811 keys = wrong_type_argument (Qarrayp, keys); | |
812 | |
813 Fdefine_key (map, keys, function); | |
814 return Qnil; | |
815 } | |
816 | |
817 DEFUN ("global-unset-key", Fglobal_unset_key, Sglobal_unset_key, | |
818 1, 1, "kUnset key globally: ", | |
819 "Remove global binding of KEY.\n\ | |
820 KEY is a string representing a sequence of keystrokes.") | |
821 (keys) | |
822 Lisp_Object keys; | |
823 { | |
824 return Fglobal_set_key (keys, Qnil); | |
825 } | |
826 | |
827 DEFUN ("local-unset-key", Flocal_unset_key, Slocal_unset_key, 1, 1, | |
828 "kUnset key locally: ", | |
829 "Remove local binding of KEY.\n\ | |
830 KEY is a string representing a sequence of keystrokes.") | |
831 (keys) | |
832 Lisp_Object keys; | |
833 { | |
485 | 834 if (!NILP (current_buffer->keymap)) |
250 | 835 Flocal_set_key (keys, Qnil); |
836 return Qnil; | |
837 } | |
838 | |
839 DEFUN ("define-prefix-command", Fdefine_prefix_command, Sdefine_prefix_command, 1, 2, 0, | |
840 "Define COMMAND as a prefix command.\n\ | |
841 A new sparse keymap is stored as COMMAND's function definition and its value.\n\ | |
362 | 842 If a second optional argument MAPVAR is given, the map is stored as\n\ |
843 its value instead of as COMMAND's value; but COMMAND is still defined\n\ | |
844 as a function.") | |
250 | 845 (name, mapvar) |
846 Lisp_Object name, mapvar; | |
847 { | |
848 Lisp_Object map; | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
849 map = Fmake_sparse_keymap (Qnil); |
250 | 850 Ffset (name, map); |
485 | 851 if (!NILP (mapvar)) |
250 | 852 Fset (mapvar, map); |
853 else | |
854 Fset (name, map); | |
855 return name; | |
856 } | |
857 | |
858 DEFUN ("use-global-map", Fuse_global_map, Suse_global_map, 1, 1, 0, | |
859 "Select KEYMAP as the global keymap.") | |
860 (keymap) | |
861 Lisp_Object keymap; | |
862 { | |
863 keymap = get_keymap (keymap); | |
864 current_global_map = keymap; | |
865 return Qnil; | |
866 } | |
867 | |
868 DEFUN ("use-local-map", Fuse_local_map, Suse_local_map, 1, 1, 0, | |
869 "Select KEYMAP as the local keymap.\n\ | |
870 If KEYMAP is nil, that means no local keymap.") | |
871 (keymap) | |
872 Lisp_Object keymap; | |
873 { | |
485 | 874 if (!NILP (keymap)) |
250 | 875 keymap = get_keymap (keymap); |
876 | |
877 current_buffer->keymap = keymap; | |
878 | |
879 return Qnil; | |
880 } | |
881 | |
882 DEFUN ("current-local-map", Fcurrent_local_map, Scurrent_local_map, 0, 0, 0, | |
883 "Return current buffer's local keymap, or nil if it has none.") | |
884 () | |
885 { | |
886 return current_buffer->keymap; | |
887 } | |
888 | |
889 DEFUN ("current-global-map", Fcurrent_global_map, Scurrent_global_map, 0, 0, 0, | |
890 "Return the current global keymap.") | |
891 () | |
892 { | |
893 return current_global_map; | |
894 } | |
465 | 895 |
896 DEFUN ("current-minor-mode-maps", Fcurrent_minor_mode_maps, Scurrent_minor_mode_maps, 0, 0, 0, | |
897 "Return a list of keymaps for the minor modes of the current buffer.") | |
898 () | |
899 { | |
900 Lisp_Object *maps; | |
901 int nmaps = current_minor_maps (0, &maps); | |
902 | |
903 return Flist (nmaps, maps); | |
904 } | |
250 | 905 |
465 | 906 /* Help functions for describing and documenting keymaps. */ |
907 | |
250 | 908 DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps, |
909 1, 1, 0, | |
910 "Find all keymaps accessible via prefix characters from KEYMAP.\n\ | |
911 Returns a list of elements of the form (KEYS . MAP), where the sequence\n\ | |
912 KEYS starting from KEYMAP gets you to MAP. These elements are ordered\n\ | |
913 so that the KEYS increase in length. The first element is (\"\" . KEYMAP).") | |
914 (startmap) | |
915 Lisp_Object startmap; | |
916 { | |
917 Lisp_Object maps, tail; | |
918 | |
919 maps = Fcons (Fcons (build_string (""), get_keymap (startmap)), Qnil); | |
920 | |
921 /* For each map in the list maps, | |
922 look at any other maps it points to, | |
923 and stick them at the end if they are not already in the list. | |
924 | |
925 This is a breadth-first traversal, where tail is the queue of | |
926 nodes, and maps accumulates a list of all nodes visited. */ | |
927 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
928 for (tail = maps; CONSP (tail); tail = XCONS (tail)->cdr) |
250 | 929 { |
930 register Lisp_Object thisseq = Fcar (Fcar (tail)); | |
931 register Lisp_Object thismap = Fcdr (Fcar (tail)); | |
932 Lisp_Object last = make_number (XINT (Flength (thisseq)) - 1); | |
933 | |
934 /* Does the current sequence end in the meta-prefix-char? */ | |
935 int is_metized = (XINT (last) >= 0 | |
936 && EQ (Faref (thisseq, last), meta_prefix_char)); | |
937 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
938 for (; CONSP (thismap); thismap = XCONS (thismap)->cdr) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
939 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
940 Lisp_Object elt = XCONS (thismap)->car; |
250 | 941 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
942 QUIT; |
250 | 943 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
944 if (XTYPE (elt) == Lisp_Vector) |
250 | 945 { |
946 register int i; | |
947 | |
948 /* Vector keymap. Scan all the elements. */ | |
949 for (i = 0; i < DENSE_TABLE_SIZE; i++) | |
950 { | |
951 register Lisp_Object tem; | |
952 register Lisp_Object cmd; | |
953 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
954 cmd = get_keyelt (XVECTOR (elt)->contents[i]); |
485 | 955 if (NILP (cmd)) continue; |
250 | 956 tem = Fkeymapp (cmd); |
485 | 957 if (!NILP (tem)) |
250 | 958 { |
959 cmd = get_keymap (cmd); | |
960 /* Ignore keymaps that are already added to maps. */ | |
961 tem = Frassq (cmd, maps); | |
485 | 962 if (NILP (tem)) |
250 | 963 { |
964 /* If the last key in thisseq is meta-prefix-char, | |
965 turn it into a meta-ized keystroke. We know | |
966 that the event we're about to append is an | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
967 ascii keystroke since we're processing a |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
968 keymap table. */ |
250 | 969 if (is_metized) |
970 { | |
971 tem = Fcopy_sequence (thisseq); | |
972 Faset (tem, last, make_number (i | 0200)); | |
973 | |
974 /* This new sequence is the same length as | |
975 thisseq, so stick it in the list right | |
976 after this one. */ | |
977 XCONS (tail)->cdr = | |
978 Fcons (Fcons (tem, cmd), XCONS (tail)->cdr); | |
979 } | |
980 else | |
981 { | |
982 tem = append_key (thisseq, make_number (i)); | |
983 nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil)); | |
984 } | |
985 } | |
986 } | |
987 } | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
988 } |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
989 else if (CONSP (elt)) |
250 | 990 { |
991 register Lisp_Object cmd = get_keyelt (XCONS (elt)->cdr); | |
992 register Lisp_Object tem; | |
993 | |
994 /* Ignore definitions that aren't keymaps themselves. */ | |
995 tem = Fkeymapp (cmd); | |
485 | 996 if (!NILP (tem)) |
250 | 997 { |
998 /* Ignore keymaps that have been seen already. */ | |
999 cmd = get_keymap (cmd); | |
1000 tem = Frassq (cmd, maps); | |
485 | 1001 if (NILP (tem)) |
250 | 1002 { |
1003 /* let elt be the event defined by this map entry. */ | |
1004 elt = XCONS (elt)->car; | |
1005 | |
1006 /* If the last key in thisseq is meta-prefix-char, and | |
1007 this entry is a binding for an ascii keystroke, | |
1008 turn it into a meta-ized keystroke. */ | |
1009 if (is_metized && XTYPE (elt) == Lisp_Int) | |
1010 { | |
1011 tem = Fcopy_sequence (thisseq); | |
1012 Faset (tem, last, make_number (XINT (elt) | 0200)); | |
1013 | |
1014 /* This new sequence is the same length as | |
1015 thisseq, so stick it in the list right | |
1016 after this one. */ | |
1017 XCONS (tail)->cdr = | |
1018 Fcons (Fcons (tem, cmd), XCONS (tail)->cdr); | |
1019 } | |
1020 else | |
1021 nconc2 (tail, | |
1022 Fcons (Fcons (append_key (thisseq, elt), cmd), | |
1023 Qnil)); | |
1024 } | |
1025 } | |
1026 } | |
1027 } | |
1028 } | |
1029 | |
1030 return maps; | |
1031 } | |
1032 | |
1033 Lisp_Object Qsingle_key_description, Qkey_description; | |
1034 | |
1035 DEFUN ("key-description", Fkey_description, Skey_description, 1, 1, 0, | |
1036 "Return a pretty description of key-sequence KEYS.\n\ | |
1037 Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"\n\ | |
1038 spaces are put between sequence elements, etc.") | |
1039 (keys) | |
1040 Lisp_Object keys; | |
1041 { | |
1042 return Fmapconcat (Qsingle_key_description, keys, build_string (" ")); | |
1043 } | |
1044 | |
1045 char * | |
1046 push_key_description (c, p) | |
1047 register unsigned int c; | |
1048 register char *p; | |
1049 { | |
1050 if (c >= 0200) | |
1051 { | |
1052 *p++ = 'M'; | |
1053 *p++ = '-'; | |
1054 c -= 0200; | |
1055 } | |
1056 if (c < 040) | |
1057 { | |
1058 if (c == 033) | |
1059 { | |
1060 *p++ = 'E'; | |
1061 *p++ = 'S'; | |
1062 *p++ = 'C'; | |
1063 } | |
1064 else if (c == Ctl('I')) | |
1065 { | |
1066 *p++ = 'T'; | |
1067 *p++ = 'A'; | |
1068 *p++ = 'B'; | |
1069 } | |
1070 else if (c == Ctl('J')) | |
1071 { | |
1072 *p++ = 'L'; | |
1073 *p++ = 'F'; | |
1074 *p++ = 'D'; | |
1075 } | |
1076 else if (c == Ctl('M')) | |
1077 { | |
1078 *p++ = 'R'; | |
1079 *p++ = 'E'; | |
1080 *p++ = 'T'; | |
1081 } | |
1082 else | |
1083 { | |
1084 *p++ = 'C'; | |
1085 *p++ = '-'; | |
1086 if (c > 0 && c <= Ctl ('Z')) | |
1087 *p++ = c + 0140; | |
1088 else | |
1089 *p++ = c + 0100; | |
1090 } | |
1091 } | |
1092 else if (c == 0177) | |
1093 { | |
1094 *p++ = 'D'; | |
1095 *p++ = 'E'; | |
1096 *p++ = 'L'; | |
1097 } | |
1098 else if (c == ' ') | |
1099 { | |
1100 *p++ = 'S'; | |
1101 *p++ = 'P'; | |
1102 *p++ = 'C'; | |
1103 } | |
1104 else | |
1105 *p++ = c; | |
1106 | |
1107 return p; | |
1108 } | |
1109 | |
1110 DEFUN ("single-key-description", Fsingle_key_description, Ssingle_key_description, 1, 1, 0, | |
1111 "Return a pretty description of command character KEY.\n\ | |
1112 Control characters turn into C-whatever, etc.") | |
1113 (key) | |
1114 Lisp_Object key; | |
1115 { | |
1116 register unsigned char c; | |
1117 char tem[6]; | |
1118 | |
1315
884c3d7e7172
* keymap.c (access_keymap, store_in_keymap,
Jim Blandy <jimb@redhat.com>
parents:
1264
diff
changeset
|
1119 key = EVENT_HEAD (key); |
517 | 1120 |
250 | 1121 switch (XTYPE (key)) |
1122 { | |
1123 case Lisp_Int: /* Normal character */ | |
1124 c = XINT (key) & 0377; | |
1125 *push_key_description (c, tem) = 0; | |
1126 return build_string (tem); | |
1127 | |
1128 case Lisp_Symbol: /* Function key or event-symbol */ | |
1129 return Fsymbol_name (key); | |
1130 | |
1131 default: | |
1132 error ("KEY must be an integer, cons, or symbol."); | |
1133 } | |
1134 } | |
1135 | |
1136 char * | |
1137 push_text_char_description (c, p) | |
1138 register unsigned int c; | |
1139 register char *p; | |
1140 { | |
1141 if (c >= 0200) | |
1142 { | |
1143 *p++ = 'M'; | |
1144 *p++ = '-'; | |
1145 c -= 0200; | |
1146 } | |
1147 if (c < 040) | |
1148 { | |
1149 *p++ = '^'; | |
1150 *p++ = c + 64; /* 'A' - 1 */ | |
1151 } | |
1152 else if (c == 0177) | |
1153 { | |
1154 *p++ = '^'; | |
1155 *p++ = '?'; | |
1156 } | |
1157 else | |
1158 *p++ = c; | |
1159 return p; | |
1160 } | |
1161 | |
1162 DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0, | |
1163 "Return a pretty description of file-character CHAR.\n\ | |
1164 Control characters turn into \"^char\", etc.") | |
1165 (chr) | |
1166 Lisp_Object chr; | |
1167 { | |
1168 char tem[6]; | |
1169 | |
1170 CHECK_NUMBER (chr, 0); | |
1171 | |
1172 *push_text_char_description (XINT (chr) & 0377, tem) = 0; | |
1173 | |
1174 return build_string (tem); | |
1175 } | |
1176 | |
465 | 1177 /* where-is - finding a command in a set of keymaps. */ |
1178 | |
250 | 1179 DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0, |
1180 "Return list of keys that invoke DEFINITION in KEYMAP or KEYMAP1.\n\ | |
1181 If KEYMAP is nil, search only KEYMAP1.\n\ | |
1182 If KEYMAP1 is nil, use the current global map.\n\ | |
1183 \n\ | |
1184 If optional 4th arg FIRSTONLY is non-nil,\n\ | |
1185 return a string representing the first key sequence found,\n\ | |
1186 rather than a list of all possible key sequences.\n\ | |
1187 \n\ | |
1188 If optional 5th arg NOINDIRECT is non-nil, don't follow indirections\n\ | |
1189 to other keymaps or slots. This makes it possible to search for an\n\ | |
1190 indirect definition itself.") | |
1191 (definition, local_keymap, global_keymap, firstonly, noindirect) | |
1192 Lisp_Object definition, local_keymap, global_keymap; | |
1193 Lisp_Object firstonly, noindirect; | |
1194 { | |
1195 register Lisp_Object maps; | |
1196 Lisp_Object found; | |
1197 | |
485 | 1198 if (NILP (global_keymap)) |
250 | 1199 global_keymap = current_global_map; |
1200 | |
485 | 1201 if (!NILP (local_keymap)) |
250 | 1202 maps = nconc2 (Faccessible_keymaps (get_keymap (local_keymap)), |
1203 Faccessible_keymaps (get_keymap (global_keymap))); | |
1204 else | |
1205 maps = Faccessible_keymaps (get_keymap (global_keymap)); | |
1206 | |
1207 found = Qnil; | |
1208 | |
485 | 1209 for (; !NILP (maps); maps = Fcdr (maps)) |
250 | 1210 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1211 /* Key sequence to reach map */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1212 register Lisp_Object this = Fcar (Fcar (maps)); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1213 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1214 /* The map that it reaches */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1215 register Lisp_Object map = Fcdr (Fcar (maps)); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1216 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1217 /* If Fcar (map) is a VECTOR, the current element within that vector. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1218 int i = 0; |
250 | 1219 |
1220 /* In order to fold [META-PREFIX-CHAR CHAR] sequences into | |
1221 [M-CHAR] sequences, check if last character of the sequence | |
1222 is the meta-prefix char. */ | |
1223 Lisp_Object last = make_number (XINT (Flength (this)) - 1); | |
1224 int last_is_meta = (XINT (last) >= 0 | |
1225 && EQ (Faref (this, last), meta_prefix_char)); | |
1226 | |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1227 QUIT; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1228 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1229 while (CONSP (map)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1230 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1231 /* Because the code we want to run on each binding is rather |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1232 large, we don't want to have two separate loop bodies for |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1233 sparse keymap bindings and tables; we want to iterate one |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1234 loop body over both keymap and vector bindings. |
250 | 1235 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1236 For this reason, if Fcar (map) is a vector, we don't |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1237 advance map to the next element until i indicates that we |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1238 have finished off the vector. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1239 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1240 Lisp_Object elt = XCONS (map)->car; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1241 Lisp_Object key, binding, sequence; |
250 | 1242 |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1243 QUIT; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1244 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1245 /* Set key and binding to the current key and binding, and |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1246 advance map and i to the next binding. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1247 if (XTYPE (elt) == Lisp_Vector) |
250 | 1248 { |
1249 /* In a vector, look at each element. */ | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1250 binding = XVECTOR (elt)->contents[i]; |
250 | 1251 XFASTINT (key) = i; |
1252 i++; | |
1253 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1254 /* If we've just finished scanning a vector, advance map |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1255 to the next element, and reset i in anticipation of the |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1256 next vector we may find. */ |
250 | 1257 if (i >= DENSE_TABLE_SIZE) |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1258 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1259 map = XCONS (map)->cdr; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1260 i = 0; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1261 } |
250 | 1262 } |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1263 else if (CONSP (elt)) |
250 | 1264 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1265 key = Fcar (Fcar (map)); |
250 | 1266 binding = Fcdr (Fcar (map)); |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1267 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1268 map = XCONS (map)->cdr; |
250 | 1269 } |
1270 else | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1271 /* We want to ignore keymap elements that are neither |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1272 vectors nor conses. */ |
1236
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1273 { |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1274 map = XCONS (map)->cdr; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1275 continue; |
5e8c234e5f03
* keymap.c (access_keymap): Remove code to notice bindings for
Jim Blandy <jimb@redhat.com>
parents:
1209
diff
changeset
|
1276 } |
250 | 1277 |
1278 /* Search through indirections unless that's not wanted. */ | |
485 | 1279 if (NILP (noindirect)) |
250 | 1280 binding = get_keyelt (binding); |
1281 | |
1282 /* End this iteration if this element does not match | |
1283 the target. */ | |
1284 | |
1285 if (XTYPE (definition) == Lisp_Cons) | |
1286 { | |
1287 Lisp_Object tem; | |
1288 tem = Fequal (binding, definition); | |
485 | 1289 if (NILP (tem)) |
250 | 1290 continue; |
1291 } | |
1292 else | |
1293 if (!EQ (binding, definition)) | |
1294 continue; | |
1295 | |
1296 /* We have found a match. | |
1297 Construct the key sequence where we found it. */ | |
1298 if (XTYPE (key) == Lisp_Int && last_is_meta) | |
1299 { | |
1300 sequence = Fcopy_sequence (this); | |
1301 Faset (sequence, last, make_number (XINT (key) | 0200)); | |
1302 } | |
1303 else | |
1304 sequence = append_key (this, key); | |
1305 | |
1306 /* Verify that this key binding is not shadowed by another | |
1307 binding for the same key, before we say it exists. | |
1308 | |
1309 Mechanism: look for local definition of this key and if | |
1310 it is defined and does not match what we found then | |
1311 ignore this key. | |
1312 | |
1313 Either nil or number as value from Flookup_key | |
1314 means undefined. */ | |
485 | 1315 if (!NILP (local_keymap)) |
250 | 1316 { |
1317 binding = Flookup_key (local_keymap, sequence); | |
485 | 1318 if (!NILP (binding) && XTYPE (binding) != Lisp_Int) |
250 | 1319 { |
1320 if (XTYPE (definition) == Lisp_Cons) | |
1321 { | |
1322 Lisp_Object tem; | |
1323 tem = Fequal (binding, definition); | |
485 | 1324 if (NILP (tem)) |
250 | 1325 continue; |
1326 } | |
1327 else | |
1328 if (!EQ (binding, definition)) | |
1329 continue; | |
1330 } | |
1331 } | |
1332 | |
1333 /* It is a true unshadowed match. Record it. */ | |
1334 | |
485 | 1335 if (!NILP (firstonly)) |
250 | 1336 return sequence; |
1337 found = Fcons (sequence, found); | |
1338 } | |
1339 } | |
1340 return Fnreverse (found); | |
1341 } | |
1342 | |
1343 /* Return a string listing the keys and buttons that run DEFINITION. */ | |
1344 | |
1345 static Lisp_Object | |
1346 where_is_string (definition) | |
1347 Lisp_Object definition; | |
1348 { | |
1349 register Lisp_Object keys, keys1; | |
1350 | |
1351 keys = Fwhere_is_internal (definition, | |
1352 current_buffer->keymap, Qnil, Qnil, Qnil); | |
1353 keys1 = Fmapconcat (Qkey_description, keys, build_string (", ")); | |
1354 | |
1355 return keys1; | |
1356 } | |
1357 | |
1358 DEFUN ("where-is", Fwhere_is, Swhere_is, 1, 1, "CWhere is command: ", | |
1359 "Print message listing key sequences that invoke specified command.\n\ | |
1360 Argument is a command definition, usually a symbol with a function definition.") | |
1361 (definition) | |
1362 Lisp_Object definition; | |
1363 { | |
1364 register Lisp_Object string; | |
1365 | |
1366 CHECK_SYMBOL (definition, 0); | |
1367 string = where_is_string (definition); | |
1368 | |
1369 if (XSTRING (string)->size) | |
1370 message ("%s is on %s", XSYMBOL (definition)->name->data, | |
1371 XSTRING (string)->data); | |
1372 else | |
1373 message ("%s is not on any key", XSYMBOL (definition)->name->data); | |
1374 return Qnil; | |
1375 } | |
1376 | |
465 | 1377 /* describe-bindings - summarizing all the bindings in a set of keymaps. */ |
1378 | |
250 | 1379 DEFUN ("describe-bindings", Fdescribe_bindings, Sdescribe_bindings, 0, 0, "", |
1380 "Show a list of all defined keys, and their definitions.\n\ | |
1381 The list is put in a buffer, which is displayed.") | |
1382 () | |
1383 { | |
1384 register Lisp_Object thisbuf; | |
1385 XSET (thisbuf, Lisp_Buffer, current_buffer); | |
1386 internal_with_output_to_temp_buffer ("*Help*", | |
1387 describe_buffer_bindings, | |
1388 thisbuf); | |
1389 return Qnil; | |
1390 } | |
1391 | |
1392 static Lisp_Object | |
1393 describe_buffer_bindings (descbuf) | |
1394 Lisp_Object descbuf; | |
1395 { | |
1396 register Lisp_Object start1, start2; | |
1397 | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1398 char *key_heading |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1399 = "\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1400 key binding\n\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1401 --- -------\n"; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1402 char *alternate_heading |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1403 = "\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1404 Alternate Characters (use anywhere the nominal character is listed):\n\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1405 nominal alternate\n\ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1406 ------- ---------\n"; |
250 | 1407 |
1408 Fset_buffer (Vstandard_output); | |
1409 | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1410 /* Report on alternates for keys. */ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1411 if (XTYPE (Vkeyboard_translate_table) == Lisp_String) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1412 { |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1413 int c; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1414 unsigned char *translate = XSTRING (Vkeyboard_translate_table)->data; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1415 int translate_len = XSTRING (Vkeyboard_translate_table)->size; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1416 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1417 for (c = 0; c < translate_len; c++) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1418 if (translate[c] != c) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1419 { |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1420 char buf[20]; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1421 char *bufend; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1422 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1423 if (alternate_heading) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1424 { |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1425 insert_string (alternate_heading); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1426 alternate_heading = 0; |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1427 } |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1428 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1429 bufend = push_key_description (translate[c], buf); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1430 insert (buf, bufend - buf); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1431 Findent_to (make_number (16), make_number (1)); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1432 bufend = push_key_description (c, buf); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1433 insert (buf, bufend - buf); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1434 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1435 insert ("\n", 1); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1436 } |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1437 |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1438 insert ("\n", 1); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1439 } |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1440 |
465 | 1441 { |
1442 int i, nmaps; | |
1443 Lisp_Object *modes, *maps; | |
1444 | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1445 /* Temporarily switch to descbuf, so that we can get that buffer's |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1446 minor modes correctly. */ |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1447 Fset_buffer (descbuf); |
465 | 1448 nmaps = current_minor_maps (&modes, &maps); |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1449 Fset_buffer (Vstandard_output); |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1450 |
465 | 1451 for (i = 0; i < nmaps; i++) |
1452 { | |
1453 if (XTYPE (modes[i]) == Lisp_Symbol) | |
1454 { | |
1455 insert_char ('`'); | |
1456 insert_string (XSYMBOL (modes[i])->name->data); | |
1457 insert_char ('\''); | |
1458 } | |
1459 else | |
1460 insert_string ("Strangely Named"); | |
1461 insert_string (" Minor Mode Bindings:\n"); | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1462 insert_string (key_heading); |
465 | 1463 describe_map_tree (maps[i], 0, Qnil); |
1464 insert_char ('\n'); | |
1465 } | |
1466 } | |
1467 | |
250 | 1468 start1 = XBUFFER (descbuf)->keymap; |
485 | 1469 if (!NILP (start1)) |
250 | 1470 { |
1471 insert_string ("Local Bindings:\n"); | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1472 insert_string (key_heading); |
465 | 1473 describe_map_tree (start1, 0, Qnil); |
250 | 1474 insert_string ("\n"); |
1475 } | |
1476 | |
1477 insert_string ("Global Bindings:\n"); | |
1120
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1478 if (NILP (start1)) |
0a486e1a45bc
* keymap.c (describe_buffer_bindings): Adjust key_heading to match
Jim Blandy <jimb@redhat.com>
parents:
1095
diff
changeset
|
1479 insert_string (key_heading); |
250 | 1480 |
465 | 1481 describe_map_tree (current_global_map, 0, XBUFFER (descbuf)->keymap); |
250 | 1482 |
1483 Fset_buffer (descbuf); | |
1484 return Qnil; | |
1485 } | |
1486 | |
1487 /* Insert a desription of the key bindings in STARTMAP, | |
1488 followed by those of all maps reachable through STARTMAP. | |
1489 If PARTIAL is nonzero, omit certain "uninteresting" commands | |
1490 (such as `undefined'). | |
1491 If SHADOW is non-nil, it is another map; | |
1492 don't mention keys which would be shadowed by it. */ | |
1493 | |
1494 void | |
1495 describe_map_tree (startmap, partial, shadow) | |
1496 Lisp_Object startmap, shadow; | |
1497 int partial; | |
1498 { | |
1499 register Lisp_Object elt, sh; | |
1500 Lisp_Object maps; | |
1501 struct gcpro gcpro1; | |
1502 | |
1503 maps = Faccessible_keymaps (startmap); | |
1504 GCPRO1 (maps); | |
1505 | |
485 | 1506 for (; !NILP (maps); maps = Fcdr (maps)) |
250 | 1507 { |
1508 elt = Fcar (maps); | |
1509 sh = Fcar (elt); | |
1510 | |
1511 /* If there is no shadow keymap given, don't shadow. */ | |
485 | 1512 if (NILP (shadow)) |
250 | 1513 sh = Qnil; |
1514 | |
1515 /* If the sequence by which we reach this keymap is zero-length, | |
1516 then the shadow map for this keymap is just SHADOW. */ | |
1517 else if ((XTYPE (sh) == Lisp_String | |
1518 && XSTRING (sh)->size == 0) | |
1519 || (XTYPE (sh) == Lisp_Vector | |
1520 && XVECTOR (sh)->size == 0)) | |
1521 sh = shadow; | |
1522 | |
1523 /* If the sequence by which we reach this keymap actually has | |
1524 some elements, then the sequence's definition in SHADOW is | |
1525 what we should use. */ | |
1526 else | |
1527 { | |
1528 sh = Flookup_key (shadow, Fcar (elt)); | |
1529 if (XTYPE (sh) == Lisp_Int) | |
1530 sh = Qnil; | |
1531 } | |
1532 | |
1533 /* If sh is null (meaning that the current map is not shadowed), | |
1534 or a keymap (meaning that bindings from the current map might | |
1535 show through), describe the map. Otherwise, sh is a command | |
1536 that completely shadows the current map, and we shouldn't | |
1537 bother. */ | |
485 | 1538 if (NILP (sh) || !NILP (Fkeymapp (sh))) |
250 | 1539 describe_map (Fcdr (elt), Fcar (elt), partial, sh); |
1540 } | |
1541 | |
1542 UNGCPRO; | |
1543 } | |
1544 | |
1545 static void | |
1546 describe_command (definition) | |
1547 Lisp_Object definition; | |
1548 { | |
1549 register Lisp_Object tem1; | |
1550 | |
1551 Findent_to (make_number (16), make_number (1)); | |
1552 | |
1553 if (XTYPE (definition) == Lisp_Symbol) | |
1554 { | |
1555 XSET (tem1, Lisp_String, XSYMBOL (definition)->name); | |
1556 insert1 (tem1); | |
1557 insert_string ("\n"); | |
1558 } | |
1559 else | |
1560 { | |
1561 tem1 = Fkeymapp (definition); | |
485 | 1562 if (!NILP (tem1)) |
250 | 1563 insert_string ("Prefix Command\n"); |
1564 else | |
1565 insert_string ("??\n"); | |
1566 } | |
1567 } | |
1568 | |
1569 /* Describe the contents of map MAP, assuming that this map itself is | |
1570 reached by the sequence of prefix keys KEYS (a string or vector). | |
1571 PARTIAL, SHADOW is as in `describe_map_tree' above. */ | |
1572 | |
1573 static void | |
1574 describe_map (map, keys, partial, shadow) | |
1575 Lisp_Object map, keys; | |
1576 int partial; | |
1577 Lisp_Object shadow; | |
1578 { | |
1579 register Lisp_Object keysdesc; | |
1580 | |
485 | 1581 if (!NILP (keys) && Flength (keys) > 0) |
250 | 1582 keysdesc = concat2 (Fkey_description (keys), |
1583 build_string (" ")); | |
1584 else | |
1585 keysdesc = Qnil; | |
1586 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1587 describe_map_2 (map, keysdesc, describe_command, partial, shadow); |
250 | 1588 } |
1589 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1590 /* Insert a description of KEYMAP into the current buffer. */ |
250 | 1591 |
1592 static void | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1593 describe_map_2 (keymap, elt_prefix, elt_describer, partial, shadow) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1594 register Lisp_Object keymap; |
250 | 1595 Lisp_Object elt_prefix; |
1596 int (*elt_describer) (); | |
1597 int partial; | |
1598 Lisp_Object shadow; | |
1599 { | |
1600 Lisp_Object this; | |
1601 Lisp_Object tem1, tem2 = Qnil; | |
1602 Lisp_Object suppress; | |
1603 Lisp_Object kludge; | |
1604 int first = 1; | |
1605 struct gcpro gcpro1, gcpro2, gcpro3; | |
1606 | |
1607 if (partial) | |
1608 suppress = intern ("suppress-keymap"); | |
1609 | |
1610 /* This vector gets used to present single keys to Flookup_key. Since | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1611 that is done once per keymap element, we don't want to cons up a |
250 | 1612 fresh vector every time. */ |
1613 kludge = Fmake_vector (make_number (1), Qnil); | |
1614 | |
1615 GCPRO3 (elt_prefix, tem2, kludge); | |
1616 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1617 for (; CONSP (keymap); keymap = Fcdr (keymap)) |
250 | 1618 { |
1619 QUIT; | |
1620 | |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1621 if (XTYPE (XCONS (keymap)->car) == Lisp_Vector) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1622 describe_vector (XCONS (keymap)->car, |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1623 elt_prefix, elt_describer, partial, shadow); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1624 else |
250 | 1625 { |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1626 tem1 = Fcar_safe (Fcar (keymap)); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1627 tem2 = get_keyelt (Fcdr_safe (Fcar (keymap))); |
250 | 1628 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1629 /* Don't show undefined commands or suppressed commands. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1630 if (NILP (tem2)) continue; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1631 if (XTYPE (tem2) == Lisp_Symbol && partial) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1632 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1633 this = Fget (tem2, suppress); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1634 if (!NILP (this)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1635 continue; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1636 } |
250 | 1637 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1638 /* Don't show a command that isn't really visible |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1639 because a local definition of the same key shadows it. */ |
250 | 1640 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1641 if (!NILP (shadow)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1642 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1643 Lisp_Object tem; |
250 | 1644 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1645 XVECTOR (kludge)->contents[0] = tem1; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1646 tem = Flookup_key (shadow, kludge); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1647 if (!NILP (tem)) continue; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1648 } |
250 | 1649 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1650 if (first) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1651 { |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1652 insert ("\n", 1); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1653 first = 0; |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1654 } |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1655 |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1656 if (!NILP (elt_prefix)) |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1657 insert1 (elt_prefix); |
250 | 1658 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1659 /* THIS gets the string to describe the character TEM1. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1660 this = Fsingle_key_description (tem1); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1661 insert1 (this); |
250 | 1662 |
1209
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1663 /* Print a description of the definition of this character. |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1664 elt_describer will take care of spacing out far enough |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1665 for alignment purposes. */ |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1666 (*elt_describer) (tem2); |
1aa2cd425737
* keymap.c (DENSE_TABLE_SIZE): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1160
diff
changeset
|
1667 } |
250 | 1668 } |
1669 | |
1670 UNGCPRO; | |
1671 } | |
1672 | |
1673 static int | |
1674 describe_vector_princ (elt) | |
1675 Lisp_Object elt; | |
1676 { | |
1677 Fprinc (elt, Qnil); | |
1678 } | |
1679 | |
1680 DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 1, 0, | |
1681 "Print on `standard-output' a description of contents of VECTOR.\n\ | |
1682 This is text showing the elements of vector matched against indices.") | |
1683 (vector) | |
1684 Lisp_Object vector; | |
1685 { | |
1686 CHECK_VECTOR (vector, 0); | |
1687 describe_vector (vector, Qnil, describe_vector_princ, 0, Qnil, Qnil); | |
1688 } | |
1689 | |
1690 describe_vector (vector, elt_prefix, elt_describer, partial, shadow) | |
1691 register Lisp_Object vector; | |
1692 Lisp_Object elt_prefix; | |
1693 int (*elt_describer) (); | |
1694 int partial; | |
1695 Lisp_Object shadow; | |
1696 { | |
1697 Lisp_Object this; | |
1698 Lisp_Object dummy; | |
1699 Lisp_Object tem1, tem2; | |
1700 register int i; | |
1701 Lisp_Object suppress; | |
1702 Lisp_Object kludge; | |
1703 int first = 1; | |
1704 struct gcpro gcpro1, gcpro2, gcpro3; | |
1705 | |
1706 tem1 = Qnil; | |
1707 | |
1708 /* This vector gets used to present single keys to Flookup_key. Since | |
1709 that is done once per vector element, we don't want to cons up a | |
1710 fresh vector every time. */ | |
1711 kludge = Fmake_vector (make_number (1), Qnil); | |
1712 GCPRO3 (elt_prefix, tem1, kludge); | |
1713 | |
1714 if (partial) | |
1715 suppress = intern ("suppress-keymap"); | |
1716 | |
1717 for (i = 0; i < DENSE_TABLE_SIZE; i++) | |
1718 { | |
1719 QUIT; | |
1720 tem1 = get_keyelt (XVECTOR (vector)->contents[i]); | |
1721 | |
485 | 1722 if (NILP (tem1)) continue; |
250 | 1723 |
1724 /* Don't mention suppressed commands. */ | |
1725 if (XTYPE (tem1) == Lisp_Symbol && partial) | |
1726 { | |
1727 this = Fget (tem1, suppress); | |
485 | 1728 if (!NILP (this)) |
250 | 1729 continue; |
1730 } | |
1731 | |
1732 /* If this command in this map is shadowed by some other map, | |
1733 ignore it. */ | |
485 | 1734 if (!NILP (shadow)) |
250 | 1735 { |
1736 Lisp_Object tem; | |
1737 | |
1738 XVECTOR (kludge)->contents[0] = make_number (i); | |
1739 tem = Flookup_key (shadow, kludge); | |
1740 | |
485 | 1741 if (!NILP (tem)) continue; |
250 | 1742 } |
1743 | |
1744 if (first) | |
1745 { | |
1746 insert ("\n", 1); | |
1747 first = 0; | |
1748 } | |
1749 | |
1750 /* Output the prefix that applies to every entry in this map. */ | |
485 | 1751 if (!NILP (elt_prefix)) |
250 | 1752 insert1 (elt_prefix); |
1753 | |
1754 /* Get the string to describe the character I, and print it. */ | |
1755 XFASTINT (dummy) = i; | |
1756 | |
1757 /* THIS gets the string to describe the character DUMMY. */ | |
1758 this = Fsingle_key_description (dummy); | |
1759 insert1 (this); | |
1760 | |
1761 /* Find all consecutive characters that have the same definition. */ | |
1762 while (i + 1 < DENSE_TABLE_SIZE | |
1763 && (tem2 = get_keyelt (XVECTOR (vector)->contents[i+1]), | |
1764 EQ (tem2, tem1))) | |
1765 i++; | |
1766 | |
1767 /* If we have a range of more than one character, | |
1768 print where the range reaches to. */ | |
1769 | |
1770 if (i != XINT (dummy)) | |
1771 { | |
1772 insert (" .. ", 4); | |
485 | 1773 if (!NILP (elt_prefix)) |
250 | 1774 insert1 (elt_prefix); |
1775 | |
1776 XFASTINT (dummy) = i; | |
1777 insert1 (Fsingle_key_description (dummy)); | |
1778 } | |
1779 | |
1780 /* Print a description of the definition of this character. | |
1781 elt_describer will take care of spacing out far enough | |
1782 for alignment purposes. */ | |
1783 (*elt_describer) (tem1); | |
1784 } | |
1785 | |
1786 UNGCPRO; | |
1787 } | |
1788 | |
465 | 1789 /* Apropos - finding all symbols whose names match a regexp. */ |
250 | 1790 Lisp_Object apropos_predicate; |
1791 Lisp_Object apropos_accumulate; | |
1792 | |
1793 static void | |
1794 apropos_accum (symbol, string) | |
1795 Lisp_Object symbol, string; | |
1796 { | |
1797 register Lisp_Object tem; | |
1798 | |
1799 tem = Fstring_match (string, Fsymbol_name (symbol), Qnil); | |
485 | 1800 if (!NILP (tem) && !NILP (apropos_predicate)) |
250 | 1801 tem = call1 (apropos_predicate, symbol); |
485 | 1802 if (!NILP (tem)) |
250 | 1803 apropos_accumulate = Fcons (symbol, apropos_accumulate); |
1804 } | |
1805 | |
1806 DEFUN ("apropos-internal", Fapropos_internal, Sapropos_internal, 1, 2, 0, | |
1807 "Show all symbols whose names contain match for REGEXP.\n\ | |
1808 If optional 2nd arg PRED is non-nil, (funcall PRED SYM) is done\n\ | |
1809 for each symbol and a symbol is mentioned only if that returns non-nil.\n\ | |
1810 Return list of symbols found.") | |
1811 (string, pred) | |
1812 Lisp_Object string, pred; | |
1813 { | |
1814 struct gcpro gcpro1, gcpro2; | |
1815 CHECK_STRING (string, 0); | |
1816 apropos_predicate = pred; | |
1817 GCPRO2 (apropos_predicate, apropos_accumulate); | |
1818 apropos_accumulate = Qnil; | |
1819 map_obarray (Vobarray, apropos_accum, string); | |
1820 apropos_accumulate = Fsort (apropos_accumulate, Qstring_lessp); | |
1821 UNGCPRO; | |
1822 return apropos_accumulate; | |
1823 } | |
1824 | |
1825 syms_of_keymap () | |
1826 { | |
1827 Lisp_Object tem; | |
1828 | |
1829 Qkeymap = intern ("keymap"); | |
1830 staticpro (&Qkeymap); | |
1831 | |
1832 /* Initialize the keymaps standardly used. | |
1833 Each one is the value of a Lisp variable, and is also | |
1834 pointed to by a C variable */ | |
1835 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1836 global_map = Fmake_keymap (Qnil); |
250 | 1837 Fset (intern ("global-map"), global_map); |
1838 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1839 meta_map = Fmake_keymap (Qnil); |
250 | 1840 Fset (intern ("esc-map"), meta_map); |
1841 Ffset (intern ("ESC-prefix"), meta_map); | |
1842 | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1843 control_x_map = Fmake_keymap (Qnil); |
250 | 1844 Fset (intern ("ctl-x-map"), control_x_map); |
1845 Ffset (intern ("Control-X-prefix"), control_x_map); | |
1846 | |
1847 DEFVAR_LISP ("minibuffer-local-map", &Vminibuffer_local_map, | |
1848 "Default keymap to use when reading from the minibuffer."); | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1849 Vminibuffer_local_map = Fmake_sparse_keymap (Qnil); |
250 | 1850 |
1851 DEFVAR_LISP ("minibuffer-local-ns-map", &Vminibuffer_local_ns_map, | |
1852 "Local keymap for the minibuffer when spaces are not allowed."); | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1853 Vminibuffer_local_ns_map = Fmake_sparse_keymap (Qnil); |
250 | 1854 |
1855 DEFVAR_LISP ("minibuffer-local-completion-map", &Vminibuffer_local_completion_map, | |
1856 "Local keymap for minibuffer input with completion."); | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1857 Vminibuffer_local_completion_map = Fmake_sparse_keymap (Qnil); |
250 | 1858 |
1859 DEFVAR_LISP ("minibuffer-local-must-match-map", &Vminibuffer_local_must_match_map, | |
1860 "Local keymap for minibuffer input with completion, for exact match."); | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1861 Vminibuffer_local_must_match_map = Fmake_sparse_keymap (Qnil); |
250 | 1862 |
1863 current_global_map = global_map; | |
1864 | |
465 | 1865 DEFVAR_LISP ("minor-mode-map-alist", &Vminor_mode_map_alist, |
1866 "Alist of keymaps to use for minor modes.\n\ | |
1867 Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read\n\ | |
1868 key sequences and look up bindings iff VARIABLE's value is non-nil.\n\ | |
1869 If two active keymaps bind the same key, the keymap appearing earlier\n\ | |
1870 in the list takes precedence."); | |
1871 Vminor_mode_map_alist = Qnil; | |
1872 | |
517 | 1873 DEFVAR_LISP ("function-key-map", &Vfunction_key_map, |
1874 "Keymap mapping ASCII function key sequences onto their preferred forms.\n\ | |
1875 This allows Emacs to recognize function keys sent from ASCII\n\ | |
1876 terminals at any point in a key sequence.\n\ | |
1877 \n\ | |
1878 The read-key-sequence function replaces subsequences bound by\n\ | |
1879 function-key-map with their bindings. When the current local and global\n\ | |
1880 keymaps have no binding for the current key sequence but\n\ | |
1881 function-key-map binds a suffix of the sequence to a vector,\n\ | |
1882 read-key-sequence replaces the matching suffix with its binding, and\n\ | |
1883 continues with the new sequence.\n\ | |
1884 \n\ | |
1885 For example, suppose function-key-map binds `ESC O P' to [pf1].\n\ | |
1886 Typing `ESC O P' to read-key-sequence would return [pf1]. Typing\n\ | |
1887 `C-x ESC O P' would return [?\C-x pf1]. If [pf1] were a prefix\n\ | |
1888 key, typing `ESC O P x' would return [pf1 x]."); | |
1095
6578f07e9eb8
(Fmake_sparse_keymap, Fmake_keymap): New optional arg. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
647
diff
changeset
|
1889 Vfunction_key_map = Fmake_sparse_keymap (Qnil); |
517 | 1890 |
250 | 1891 Qsingle_key_description = intern ("single-key-description"); |
1892 staticpro (&Qsingle_key_description); | |
1893 | |
1894 Qkey_description = intern ("key-description"); | |
1895 staticpro (&Qkey_description); | |
1896 | |
1897 Qkeymapp = intern ("keymapp"); | |
1898 staticpro (&Qkeymapp); | |
1899 | |
1900 defsubr (&Skeymapp); | |
1901 defsubr (&Smake_keymap); | |
1902 defsubr (&Smake_sparse_keymap); | |
1903 defsubr (&Scopy_keymap); | |
1904 defsubr (&Skey_binding); | |
1905 defsubr (&Slocal_key_binding); | |
1906 defsubr (&Sglobal_key_binding); | |
465 | 1907 defsubr (&Sminor_mode_key_binding); |
250 | 1908 defsubr (&Sglobal_set_key); |
1909 defsubr (&Slocal_set_key); | |
1910 defsubr (&Sdefine_key); | |
1911 defsubr (&Slookup_key); | |
1912 defsubr (&Sglobal_unset_key); | |
1913 defsubr (&Slocal_unset_key); | |
1914 defsubr (&Sdefine_prefix_command); | |
1915 defsubr (&Suse_global_map); | |
1916 defsubr (&Suse_local_map); | |
1917 defsubr (&Scurrent_local_map); | |
1918 defsubr (&Scurrent_global_map); | |
465 | 1919 defsubr (&Scurrent_minor_mode_maps); |
250 | 1920 defsubr (&Saccessible_keymaps); |
1921 defsubr (&Skey_description); | |
1922 defsubr (&Sdescribe_vector); | |
1923 defsubr (&Ssingle_key_description); | |
1924 defsubr (&Stext_char_description); | |
1925 defsubr (&Swhere_is_internal); | |
1926 defsubr (&Swhere_is); | |
1927 defsubr (&Sdescribe_bindings); | |
1928 defsubr (&Sapropos_internal); | |
1929 } | |
1930 | |
1931 keys_of_keymap () | |
1932 { | |
1933 Lisp_Object tem; | |
1934 | |
1935 initial_define_key (global_map, 033, "ESC-prefix"); | |
1936 initial_define_key (global_map, Ctl('X'), "Control-X-prefix"); | |
1937 } |