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