0
|
1 /* Manipulation of keymaps
|
|
2 Copyright (C) 1985, 1991-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5 Totally redesigned by jwz in 1991.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not synched with FSF. Substantially different
|
|
25 from FSF. */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include "buffer.h"
|
|
31 #include "bytecode.h"
|
|
32 #include "commands.h"
|
|
33 #include "console.h"
|
|
34 #include "elhash.h"
|
|
35 #include "events.h"
|
|
36 #include "frame.h"
|
|
37 #include "insdel.h"
|
|
38 #include "keymap.h"
|
|
39 #include "window.h"
|
|
40
|
|
41
|
|
42 /* A keymap contains four slots:
|
|
43
|
|
44 parents Ordered list of keymaps to search after
|
|
45 this one if no match is found.
|
|
46 Keymaps can thus be arranged in a hierarchy.
|
|
47
|
|
48 table A hash table, hashing keysyms to their bindings.
|
|
49 As in the rest of emacs, a keysym is either a symbol or
|
|
50 an integer, which is an ASCII code (of one of the printing
|
|
51 ASCII characters: not 003 meaning C-c, for instance).
|
|
52 It can also be an integer representing a modifier
|
|
53 combination; this will be greater than or equal to
|
|
54 (1 << 16).
|
|
55
|
|
56 inverse_table A hash table, hashing bindings to the list of keysyms
|
|
57 in this keymap which are bound to them. This is to make
|
|
58 the Fwhere_is_internal() function be fast. It needs to be
|
|
59 fast because we want to be able to call it in realtime to
|
|
60 update the keyboard-equivalents on the pulldown menus.
|
|
61 Values of the table are either atoms (keysyms)
|
|
62 or a dotted list of keysyms.
|
|
63
|
|
64 sub_maps_cache An alist; for each entry in this keymap whose binding is
|
|
65 a keymap (that is, Fkeymapp()) this alist associates that
|
|
66 keysym with that binding. This is used to optimize both
|
|
67 Fwhere_is_internal() and Faccessible_keymaps(). This slot
|
|
68 gets set to the symbol `t' every time a change is made to
|
|
69 this keymap, causing it to be recomputed when next needed.
|
|
70
|
|
71 prompt See `set-keymap-prompt'.
|
|
72
|
|
73 default_binding See `set-keymap-default-binding'.
|
|
74
|
|
75 Sequences of keys are stored in the obvious way: if the sequence of keys
|
|
76 "abc" was bound to some command `foo', the hierarchy would look like
|
|
77
|
|
78 keymap-1: associates "a" with keymap-2
|
|
79 keymap-2: associates "b" with keymap-3
|
|
80 keymap-3: associates "c" with foo
|
|
81
|
|
82 However, bucky bits ("modifiers" to the X-minded) are represented in the
|
|
83 keymap hierarchy as well. (This lets us use EQable objects as hash keys.)
|
|
84 Each combination of modifiers (e.g. control-hyper) gets its own submap
|
|
85 off of the main map. The hash key for a modifier combination is
|
|
86 a large integer, computed by MAKE_MODIFIER_HASH_KEY().
|
|
87
|
|
88 If the key `C-a' was bound to some command, the hierarchy would look like
|
|
89
|
|
90 keymap-1: associates the integer (MOD_CONTROL << 16) with keymap-2
|
|
91 keymap-2: associates "a" with the command
|
|
92
|
|
93 Similarly, if the key `C-H-a' was bound to some command, the hierarchy
|
|
94 would look like
|
|
95
|
|
96 keymap-1: associates the integer ((MOD_CONTROL | MOD_HYPER) << 16)
|
|
97 with keymap-2
|
|
98 keymap-2: associates "a" with the command
|
|
99
|
|
100 Note that a special exception is made for the meta modifier, in order
|
|
101 to deal with ESC/meta lossage. Any key combination containing the
|
|
102 meta modifier is first indexed off of the main map into the meta
|
|
103 submap (with hash key (MOD_META << 16)) and then indexed off of the
|
|
104 meta submap with the meta modifier removed from the key combination.
|
|
105 For example, when associating a command with C-M-H-a, we'd have
|
|
106
|
|
107 keymap-1: associates the integer (MOD_META << 16) with keymap-2
|
|
108 keymap-2: associates the integer ((MOD_CONTROL | MOD_HYPER) << 16)
|
|
109 with keymap-3
|
|
110 keymap-3: associates "a" with the command
|
|
111
|
|
112 Note that keymap-2 might have normal bindings in it; these would be
|
|
113 for key combinations containing only the meta modifier, such as
|
|
114 M-y or meta-backspace.
|
|
115
|
|
116 If the command that "a" was bound to in keymap-3 was itself a keymap,
|
|
117 then that would make the key "C-M-H-a" be a prefix character.
|
|
118
|
|
119 Note that this new model of keymaps takes much of the magic away from
|
|
120 the Escape key: the value of the variable `esc-map' is no longer indexed
|
|
121 in the `global-map' under the ESC key. It's indexed under the integer
|
|
122 (MOD_META << 16). This is not user-visible, however; none of the "bucky"
|
|
123 maps are.
|
|
124
|
|
125 There is a hack in Flookup_key() that makes (lookup-key global-map "\^[")
|
|
126 and (define-key some-random-map "\^[" my-esc-map) work as before, for
|
|
127 compatibility.
|
|
128
|
|
129 Since keymaps are opaque, the only way to extract information from them
|
|
130 is with the functions lookup-key, key-binding, local-key-binding, and
|
|
131 global-key-binding, which work just as before, and the new function
|
|
132 map-keymap, which is roughly analagous to maphash.
|
|
133
|
|
134 Note that map-keymap perpetuates the illusion that the "bucky" submaps
|
|
135 don't exist: if you map over a keymap with bucky submaps, it will also
|
|
136 map over those submaps. It does not, however, map over other random
|
|
137 submaps of the keymap, just the bucky ones.
|
|
138
|
|
139 One implication of this is that when you map over `global-map', you will
|
|
140 also map over `esc-map'. It is merely for compatibility that the esc-map
|
|
141 is accessible at all; I think that's a bad thing, since it blurs the
|
|
142 distinction between ESC and "meta" even more. "M-x" is no more a two-
|
|
143 key sequence than "C-x" is.
|
|
144
|
|
145 */
|
|
146
|
|
147 struct keymap
|
|
148 {
|
|
149 struct lcrecord_header header;
|
|
150 Lisp_Object parents; /* Keymaps to be searched after this one
|
|
151 * An ordered list */
|
|
152 Lisp_Object prompt; /* Qnil or a string to print in the minibuffer
|
|
153 * when reading from this keymap */
|
|
154
|
|
155 Lisp_Object table; /* The contents of this keymap */
|
|
156 Lisp_Object inverse_table; /* The inverse mapping of the above */
|
|
157
|
|
158 Lisp_Object default_binding; /* Use this if no other binding is found
|
|
159 * (this overrides parent maps and the
|
|
160 * normal global-map lookup). */
|
|
161
|
|
162
|
|
163 Lisp_Object sub_maps_cache; /* Cache of directly inferior keymaps;
|
|
164 This holds an alist, of the key and the
|
|
165 maps, or the modifier bit and the map.
|
|
166 If this is the symbol t, then the cache
|
|
167 needs to be recomputed.
|
|
168 */
|
|
169 int fullness; /* How many entries there are in this table.
|
|
170 This should be the same as the fullness
|
|
171 of the `table', but hash.c is broken. */
|
|
172 Lisp_Object name; /* Just for debugging convenience */
|
|
173 };
|
|
174
|
|
175 #define XKEYMAP(x) XRECORD (x, keymap, struct keymap)
|
|
176 #define XSETKEYMAP(x, p) XSETRECORD (x, p, keymap)
|
|
177 #define KEYMAPP(x) RECORDP (x, keymap)
|
|
178 #define CHECK_KEYMAP(x) CHECK_RECORD (x, keymap)
|
|
179
|
|
180 /* Hash key is shifted so it can't conflict with eight-bit
|
|
181 string-char constituents */
|
|
182 #define MAKE_MODIFIER_HASH_KEY(modifier) (make_int ((modifier) << 16))
|
|
183 #define MODIFIER_HASH_KEY_BITS(x) ((INTP((x))) ? (XINT ((x)) >> 16) : 0)
|
|
184
|
|
185
|
|
186
|
|
187 /* Actually allocate storage for these variables */
|
|
188
|
|
189 static Lisp_Object Vcurrent_global_map; /* Always a keymap */
|
|
190
|
|
191 static Lisp_Object Vmouse_grabbed_buffer;
|
|
192
|
|
193 /* Alist of minor mode variables and keymaps. */
|
|
194 static Lisp_Object Qminor_mode_map_alist;
|
|
195
|
|
196 static Lisp_Object Voverriding_local_map;
|
|
197
|
|
198 static Lisp_Object Vkey_translation_map;
|
|
199
|
|
200 /* This is incremented whenever a change is made to a keymap. This is
|
|
201 so that things which care (such as the menubar code) can recompute
|
|
202 privately-cached data when the user has changed keybindings.
|
|
203 */
|
|
204 int keymap_tick;
|
|
205
|
|
206 /* Prefixing a key with this character is the same as sending a meta bit. */
|
|
207 Lisp_Object Vmeta_prefix_char;
|
|
208
|
|
209 Lisp_Object Qkeymapp;
|
|
210
|
|
211 Lisp_Object Vsingle_space_string;
|
|
212
|
|
213 Lisp_Object Qsuppress_keymap;
|
|
214
|
|
215 Lisp_Object Qmodeline_map;
|
|
216 Lisp_Object Qtoolbar_map;
|
|
217
|
|
218 static void describe_command (Lisp_Object definition);
|
|
219 static void describe_map (Lisp_Object keymap, Lisp_Object elt_prefix,
|
|
220 void (*elt_describer) (Lisp_Object),
|
|
221 int partial,
|
|
222 Lisp_Object shadow,
|
|
223 int mice_only_p);
|
|
224 Lisp_Object Qcontrol, Qctrl, Qmeta, Qsuper, Qhyper, Qalt, Qshift;
|
|
225 /* Lisp_Object Qsymbol; defined in general.c */
|
|
226 Lisp_Object Qbutton0, Qbutton1, Qbutton2, Qbutton3, Qbutton4, Qbutton5,
|
|
227 Qbutton6, Qbutton7;
|
|
228 Lisp_Object Qbutton0up, Qbutton1up, Qbutton2up, Qbutton3up, Qbutton4up,
|
|
229 Qbutton5up, Qbutton6up, Qbutton7up;
|
|
230 Lisp_Object Qmenu_selection;
|
|
231
|
|
232 /* Kludge kludge kludge */
|
|
233 Lisp_Object QLFD, QTAB, QRET, QESC, QDEL, QSPC, QBS;
|
|
234
|
|
235
|
|
236 /************************************************************************/
|
|
237 /* The keymap Lisp object */
|
|
238 /************************************************************************/
|
|
239
|
|
240 static Lisp_Object mark_keymap (Lisp_Object, void (*) (Lisp_Object));
|
|
241 static void print_keymap (Lisp_Object, Lisp_Object, int);
|
|
242 /* No need for keymap_equal #### Why not? */
|
|
243 DEFINE_LRECORD_IMPLEMENTATION ("keymap", keymap,
|
|
244 mark_keymap, print_keymap, 0, 0, 0,
|
|
245 struct keymap);
|
|
246 static Lisp_Object
|
|
247 mark_keymap (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
248 {
|
|
249 struct keymap *keymap = XKEYMAP (obj);
|
|
250 ((markobj) (keymap->parents));
|
|
251 ((markobj) (keymap->prompt));
|
|
252 ((markobj) (keymap->inverse_table));
|
|
253 ((markobj) (keymap->sub_maps_cache));
|
|
254 ((markobj) (keymap->default_binding));
|
|
255 ((markobj) (keymap->name));
|
|
256 return (keymap->table);
|
|
257 }
|
|
258
|
|
259 static void
|
|
260 print_keymap (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
261 {
|
|
262 /* This function can GC */
|
|
263 struct keymap *keymap = XKEYMAP (obj);
|
|
264 char buf[200];
|
|
265 int size = XINT (Fkeymap_fullness (obj));
|
|
266 if (print_readably)
|
|
267 error ("printing unreadable object #<keymap 0x%x>", keymap->header.uid);
|
|
268 write_c_string ("#<keymap ", printcharfun);
|
|
269 if (!NILP (keymap->name))
|
|
270 print_internal (keymap->name, printcharfun, 1);
|
|
271 sprintf (buf, "%s%d entr%s 0x%x>",
|
|
272 ((NILP (keymap->name)) ? "" : " "),
|
|
273 size,
|
|
274 ((size == 1) ? "y" : "ies"),
|
|
275 keymap->header.uid);
|
|
276 write_c_string (buf, printcharfun);
|
|
277 }
|
|
278
|
|
279
|
|
280 /************************************************************************/
|
|
281 /* Traversing keymaps and their parents */
|
|
282 /************************************************************************/
|
|
283
|
|
284 static Lisp_Object
|
|
285 traverse_keymaps (Lisp_Object start_keymap, Lisp_Object start_parents,
|
|
286 Lisp_Object (*mapper) (Lisp_Object keymap, void *mapper_arg),
|
|
287 void *mapper_arg)
|
|
288 {
|
|
289 /* This function can GC */
|
|
290 Lisp_Object keymap;
|
|
291 Lisp_Object tail = start_parents;
|
|
292 Lisp_Object malloc_sucks[10];
|
|
293 Lisp_Object malloc_bites = Qnil;
|
|
294 int stack_depth = 0;
|
|
295 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
296 GCPRO4 (*malloc_sucks, malloc_bites, start_keymap, tail);
|
|
297 gcpro1.nvars = 0;
|
|
298
|
|
299 start_keymap = get_keymap (start_keymap, 1, 1);
|
|
300 keymap = start_keymap;
|
|
301 /* Hack special-case parents at top-level */
|
|
302 tail = ((!NILP (tail)) ? tail : XKEYMAP (keymap)->parents);
|
|
303
|
|
304 for (;;)
|
|
305 {
|
|
306 Lisp_Object result;
|
|
307
|
|
308 QUIT;
|
|
309 result = ((mapper) (keymap, mapper_arg));
|
|
310 if (!NILP (result))
|
|
311 {
|
|
312 while (CONSP (malloc_bites))
|
|
313 {
|
|
314 struct Lisp_Cons *victim = XCONS (malloc_bites);
|
|
315 malloc_bites = victim->cdr;
|
|
316 free_cons (victim);
|
|
317 }
|
|
318 UNGCPRO;
|
|
319 return (result);
|
|
320 }
|
|
321 if (NILP (tail))
|
|
322 {
|
|
323 if (stack_depth == 0)
|
|
324 {
|
|
325 UNGCPRO;
|
|
326 return (Qnil); /* Nothing found */
|
|
327 }
|
|
328 stack_depth--;
|
|
329 if (CONSP (malloc_bites))
|
|
330 {
|
|
331 struct Lisp_Cons *victim = XCONS (malloc_bites);
|
|
332 tail = victim->car;
|
|
333 malloc_bites = victim->cdr;
|
|
334 free_cons (victim);
|
|
335 }
|
|
336 else
|
|
337 {
|
|
338 tail = malloc_sucks[stack_depth];
|
|
339 gcpro1.nvars = stack_depth;
|
|
340 }
|
|
341 keymap = XCAR (tail);
|
|
342 tail = XCDR (tail);
|
|
343 }
|
|
344 else
|
|
345 {
|
|
346 Lisp_Object parents;
|
|
347
|
|
348 keymap = XCAR (tail);
|
|
349 tail = XCDR (tail);
|
|
350 parents = XKEYMAP (keymap)->parents;
|
|
351 if (!CONSP (parents))
|
|
352 ;
|
|
353 else if (NILP (tail))
|
|
354 /* Tail-recurse */
|
|
355 tail = parents;
|
|
356 else
|
|
357 {
|
|
358 if (CONSP (malloc_bites))
|
|
359 malloc_bites = noseeum_cons (tail, malloc_bites);
|
|
360 else if (stack_depth < countof (malloc_sucks))
|
|
361 {
|
|
362 malloc_sucks[stack_depth++] = tail;
|
|
363 gcpro1.nvars = stack_depth;
|
|
364 }
|
|
365 else
|
|
366 {
|
|
367 /* *&@##[*&^$ C. @#[$*&@# Unix. Losers all. */
|
|
368 int i;
|
|
369 for (i = 0, malloc_bites = Qnil;
|
|
370 i < countof (malloc_sucks);
|
|
371 i++)
|
|
372 malloc_bites = noseeum_cons (malloc_sucks[i],
|
|
373 malloc_bites);
|
|
374 gcpro1.nvars = 0;
|
|
375 }
|
|
376 tail = parents;
|
|
377 }
|
|
378 }
|
|
379 keymap = get_keymap (keymap, 1, 1);
|
|
380 if (EQ (keymap, start_keymap))
|
|
381 {
|
|
382 signal_simple_error ("Cyclic keymap indirection",
|
|
383 start_keymap);
|
|
384 }
|
|
385 }
|
|
386 }
|
|
387
|
|
388
|
|
389 /************************************************************************/
|
|
390 /* Some low-level functions */
|
|
391 /************************************************************************/
|
|
392
|
|
393 static unsigned int
|
|
394 bucky_sym_to_bucky_bit (Lisp_Object sym)
|
|
395 {
|
|
396 if (EQ (sym, Qcontrol))
|
|
397 return MOD_CONTROL;
|
|
398 else if (EQ (sym, Qmeta))
|
|
399 return MOD_META;
|
|
400 else if (EQ (sym, Qsuper))
|
|
401 return MOD_SUPER;
|
|
402 else if (EQ (sym, Qhyper))
|
|
403 return MOD_HYPER;
|
|
404 else if (EQ (sym, Qalt) || EQ (sym, Qsymbol)) /* #### - reverse compat */
|
|
405 return MOD_ALT;
|
|
406 else if (EQ (sym, Qshift))
|
|
407 return MOD_SHIFT;
|
|
408 else
|
|
409 return 0;
|
|
410 }
|
|
411
|
|
412 static Lisp_Object
|
|
413 control_meta_superify (Lisp_Object frob, unsigned int modifiers)
|
|
414 {
|
|
415 if (modifiers == 0)
|
|
416 return frob;
|
|
417 frob = Fcons (frob, Qnil);
|
|
418 if (modifiers & MOD_SHIFT)
|
|
419 frob = Fcons (Qshift, frob);
|
|
420 if (modifiers & MOD_ALT)
|
|
421 frob = Fcons (Qalt, frob);
|
|
422 if (modifiers & MOD_HYPER)
|
|
423 frob = Fcons (Qhyper, frob);
|
|
424 if (modifiers & MOD_SUPER)
|
|
425 frob = Fcons (Qsuper, frob);
|
|
426 if (modifiers & MOD_CONTROL)
|
|
427 frob = Fcons (Qcontrol, frob);
|
|
428 if (modifiers & MOD_META)
|
|
429 frob = Fcons (Qmeta, frob);
|
|
430 return (frob);
|
|
431 }
|
|
432
|
|
433 static Lisp_Object
|
|
434 make_key_description (CONST struct key_data *key, int prettify)
|
|
435 {
|
|
436 Lisp_Object keysym = key->keysym;
|
|
437 unsigned int modifiers = key->modifiers;
|
|
438
|
|
439 if (prettify && INTP (keysym))
|
|
440 {
|
|
441 /* This is a little slow, but (control a) is prettier than (control 65).
|
|
442 It's now ok to do this for digit-chars too, since we've fixed the
|
|
443 bug where \9 read as the integer 9 instead of as the symbol with
|
|
444 "9" as its name.
|
|
445 */
|
|
446 /* !!#### I'm not sure how correct this is. */
|
|
447 Bufbyte str [1 + MAX_EMCHAR_LEN];
|
|
448 Bytecount count = set_charptr_emchar (str, XCHAR (keysym));
|
|
449 str[count] = 0;
|
|
450 keysym = intern ((char *) str);
|
|
451 }
|
|
452 return (control_meta_superify (keysym, modifiers));
|
|
453 }
|
|
454
|
|
455
|
|
456 /************************************************************************/
|
|
457 /* Low-level keymap-store functions */
|
|
458 /************************************************************************/
|
|
459
|
|
460 static Lisp_Object
|
|
461 raw_lookup_key (Lisp_Object keymap,
|
|
462 CONST struct key_data *raw_keys, int raw_keys_count,
|
|
463 int keys_so_far, int accept_default);
|
|
464
|
|
465 /* Relies on caller to gc-protect args */
|
|
466 static Lisp_Object
|
|
467 keymap_lookup_directly (Lisp_Object keymap,
|
|
468 Lisp_Object keysym, unsigned int modifiers)
|
|
469 {
|
|
470 struct keymap *k;
|
|
471
|
|
472 if ((modifiers & ~(MOD_CONTROL | MOD_META | MOD_SUPER | MOD_HYPER
|
|
473 | MOD_ALT | MOD_SHIFT)) != 0)
|
|
474 abort ();
|
|
475
|
|
476 k = XKEYMAP (keymap);
|
|
477
|
|
478 /* If the keysym is a one-character symbol, use the char code instead. */
|
|
479 if (SYMBOLP (keysym) && string_char_length (XSYMBOL (keysym)->name) == 1)
|
|
480 {
|
|
481 Lisp_Object i_fart_on_gcc =
|
|
482 make_char (string_char (XSYMBOL (keysym)->name, 0));
|
|
483 keysym = i_fart_on_gcc;
|
|
484 }
|
|
485
|
|
486 if (modifiers & MOD_META) /* Utterly hateful ESC lossage */
|
2
|
487 {
|
|
488 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META),
|
|
489 k->table, Qnil);
|
|
490 if (NILP (submap))
|
|
491 return (Qnil);
|
|
492 k = XKEYMAP (submap);
|
|
493 modifiers &= ~MOD_META;
|
|
494 }
|
0
|
495
|
|
496 if (modifiers != 0)
|
2
|
497 {
|
|
498 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (modifiers),
|
|
499 k->table, Qnil);
|
|
500 if (NILP (submap))
|
|
501 return (Qnil);
|
|
502 k = XKEYMAP (submap);
|
|
503 }
|
0
|
504 return (Fgethash (keysym, k->table, Qnil));
|
|
505 }
|
|
506
|
|
507 static void
|
|
508 keymap_store_inverse_internal (Lisp_Object inverse_table,
|
|
509 Lisp_Object keysym,
|
|
510 Lisp_Object value)
|
|
511 {
|
|
512 Lisp_Object keys = Fgethash (value, inverse_table, Qunbound);
|
|
513
|
|
514 if (UNBOUNDP (keys))
|
|
515 {
|
|
516 keys = keysym;
|
|
517 /* Don't cons this unless necessary */
|
|
518 /* keys = Fcons (keysym, Qnil); */
|
|
519 Fputhash (value, keys, inverse_table);
|
|
520 }
|
|
521 else if (!CONSP (keys))
|
|
522 {
|
|
523 /* Now it's necessary to cons */
|
|
524 keys = Fcons (keys, keysym);
|
|
525 Fputhash (value, keys, inverse_table);
|
|
526 }
|
|
527 else
|
|
528 {
|
|
529 while (CONSP (Fcdr (keys)))
|
|
530 keys = XCDR (keys);
|
|
531 XCDR (keys) = Fcons (XCDR (keys), keysym);
|
|
532 /* No need to call puthash because we've destructively
|
|
533 modified the list tail in place */
|
|
534 }
|
|
535 }
|
|
536
|
|
537
|
|
538 static void
|
|
539 keymap_delete_inverse_internal (Lisp_Object inverse_table,
|
|
540 Lisp_Object keysym,
|
|
541 Lisp_Object value)
|
|
542 {
|
|
543 Lisp_Object keys = Fgethash (value, inverse_table, Qunbound);
|
|
544 Lisp_Object new_keys = keys;
|
|
545 Lisp_Object tail;
|
|
546 Lisp_Object *prev;
|
|
547
|
|
548 if (UNBOUNDP (keys))
|
|
549 abort ();
|
|
550
|
|
551 for (prev = &new_keys, tail = new_keys;
|
|
552 ;
|
|
553 prev = &(XCDR (tail)), tail = XCDR (tail))
|
|
554 {
|
|
555 if (EQ (tail, keysym))
|
|
556 {
|
|
557 *prev = Qnil;
|
|
558 break;
|
|
559 }
|
|
560 else if (EQ (keysym, XCAR (tail)))
|
|
561 {
|
|
562 *prev = XCDR (tail);
|
|
563 break;
|
|
564 }
|
|
565 }
|
|
566
|
|
567 if (NILP (new_keys))
|
|
568 Fremhash (value, inverse_table);
|
|
569 else if (!EQ (keys, new_keys))
|
|
570 /* Removed the first elt */
|
|
571 Fputhash (value, new_keys, inverse_table);
|
|
572 /* else the list's tail has been modified, so we don't need to
|
|
573 touch the hash table again (the pointer in there is ok).
|
|
574 */
|
|
575 }
|
|
576
|
|
577
|
|
578 static void
|
|
579 keymap_store_internal (Lisp_Object keysym, struct keymap *keymap,
|
|
580 Lisp_Object value)
|
|
581 {
|
|
582 Lisp_Object prev_value = Fgethash (keysym, keymap->table, Qnil);
|
|
583
|
|
584 if (EQ (prev_value, value))
|
|
585 return;
|
|
586 if (!NILP (prev_value))
|
|
587 keymap_delete_inverse_internal (keymap->inverse_table,
|
|
588 keysym, prev_value);
|
|
589 if (NILP (value))
|
|
590 {
|
|
591 keymap->fullness--;
|
|
592 if (keymap->fullness < 0) abort ();
|
|
593 Fremhash (keysym, keymap->table);
|
|
594 }
|
|
595 else
|
|
596 {
|
|
597 if (NILP (prev_value))
|
|
598 keymap->fullness++;
|
|
599 Fputhash (keysym, value, keymap->table);
|
|
600 keymap_store_inverse_internal (keymap->inverse_table,
|
|
601 keysym, value);
|
|
602 }
|
|
603 keymap_tick++;
|
|
604 }
|
|
605
|
|
606
|
|
607 static Lisp_Object
|
|
608 create_bucky_submap (struct keymap *k, unsigned int modifiers,
|
|
609 Lisp_Object parent_for_debugging_info)
|
|
610 {
|
|
611 Lisp_Object submap = Fmake_sparse_keymap (Qnil);
|
|
612 /* User won't see this, but it is nice for debugging Emacs */
|
|
613 XKEYMAP (submap)->name
|
|
614 = control_meta_superify (parent_for_debugging_info, modifiers);
|
|
615 /* Invalidate cache */
|
|
616 k->sub_maps_cache = Qt;
|
|
617 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (modifiers), k, submap);
|
|
618 return (submap);
|
|
619 }
|
|
620
|
|
621
|
|
622 /* Relies on caller to gc-protect keymap, keysym, value */
|
|
623 static void
|
|
624 keymap_store (Lisp_Object keymap, CONST struct key_data *key,
|
|
625 Lisp_Object value)
|
|
626 {
|
|
627 Lisp_Object keysym = key->keysym;
|
|
628 unsigned int modifiers = key->modifiers;
|
|
629 struct keymap *k;
|
|
630
|
|
631 if ((modifiers & ~(MOD_CONTROL | MOD_META | MOD_SUPER | MOD_HYPER
|
|
632 | MOD_ALT | MOD_SHIFT)) != 0)
|
|
633 abort ();
|
|
634
|
|
635 k = XKEYMAP (keymap);
|
|
636
|
|
637 /* If the keysym is a one-character symbol, use the char code instead. */
|
|
638 if (SYMBOLP (keysym) && string_char_length (XSYMBOL (keysym)->name) == 1)
|
|
639 {
|
|
640 Lisp_Object run_the_gcc_developers_over_with_a_steamroller =
|
|
641 make_char (string_char (XSYMBOL (keysym)->name, 0));
|
|
642 keysym = run_the_gcc_developers_over_with_a_steamroller;
|
|
643 }
|
|
644
|
|
645 if (modifiers & MOD_META) /* Utterly hateful ESC lossage */
|
|
646 {
|
|
647 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META),
|
|
648 k->table, Qnil);
|
|
649 if (NILP (submap))
|
|
650 submap = create_bucky_submap (k, MOD_META, keymap);
|
|
651 k = XKEYMAP (submap);
|
|
652 modifiers &= ~MOD_META;
|
|
653 }
|
|
654
|
|
655 if (modifiers != 0)
|
|
656 {
|
|
657 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (modifiers),
|
|
658 k->table, Qnil);
|
|
659 if (NILP (submap))
|
|
660 submap = create_bucky_submap (k, modifiers, keymap);
|
|
661 k = XKEYMAP (submap);
|
|
662 }
|
|
663 k->sub_maps_cache = Qt; /* Invalidate cache */
|
|
664 keymap_store_internal (keysym, k, value);
|
|
665 }
|
|
666
|
|
667
|
|
668 /************************************************************************/
|
|
669 /* Listing the submaps of a keymap */
|
|
670 /************************************************************************/
|
|
671
|
|
672 struct keymap_submaps_closure
|
|
673 {
|
|
674 Lisp_Object *result_locative;
|
|
675 };
|
|
676
|
|
677 static void
|
|
678 keymap_submaps_mapper_0 (CONST void *hash_key, void *hash_contents,
|
|
679 void *keymap_submaps_closure)
|
|
680 {
|
|
681 /* This function can GC */
|
|
682 Lisp_Object contents;
|
|
683 VOID_TO_LISP (contents, hash_contents);
|
|
684 /* Perform any autoloads, etc */
|
|
685 (void) Fkeymapp (contents);
|
|
686 }
|
|
687
|
|
688 static void
|
|
689 keymap_submaps_mapper (CONST void *hash_key, void *hash_contents,
|
|
690 void *keymap_submaps_closure)
|
|
691 {
|
|
692 /* This function can GC */
|
|
693 Lisp_Object key, contents;
|
|
694 Lisp_Object *result_locative;
|
|
695 struct keymap_submaps_closure *cl = keymap_submaps_closure;
|
|
696 CVOID_TO_LISP (key, hash_key);
|
|
697 VOID_TO_LISP (contents, hash_contents);
|
|
698 result_locative = cl->result_locative;
|
|
699
|
|
700 if (!NILP (Fkeymapp (contents)))
|
|
701 *result_locative = Fcons (Fcons (key, contents), *result_locative);
|
|
702 }
|
|
703
|
|
704 static int map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
|
|
705 Lisp_Object pred);
|
|
706
|
|
707 static Lisp_Object
|
|
708 keymap_submaps (Lisp_Object keymap)
|
|
709 {
|
|
710 /* This function can GC */
|
|
711 struct keymap *k = XKEYMAP (keymap);
|
|
712
|
|
713 if (EQ (k->sub_maps_cache, Qt)) /* Unknown */
|
|
714 {
|
|
715 Lisp_Object result = Qnil;
|
|
716 struct gcpro gcpro1, gcpro2;
|
|
717 struct keymap_submaps_closure keymap_submaps_closure;
|
|
718
|
|
719 GCPRO2 (keymap, result);
|
|
720 keymap_submaps_closure.result_locative = &result;
|
|
721 /* Do this first pass to touch (and load) any autoloaded maps */
|
|
722 elisp_maphash (keymap_submaps_mapper_0, k->table,
|
|
723 &keymap_submaps_closure);
|
|
724 result = Qnil;
|
|
725 elisp_maphash (keymap_submaps_mapper, k->table,
|
|
726 &keymap_submaps_closure);
|
|
727 /* keep it sorted so that the result of accessible-keymaps is ordered */
|
|
728 k->sub_maps_cache = list_sort (result,
|
|
729 Qnil,
|
|
730 map_keymap_sort_predicate);
|
|
731 UNGCPRO;
|
|
732 }
|
|
733 return (k->sub_maps_cache);
|
|
734 }
|
|
735
|
|
736
|
|
737 /************************************************************************/
|
|
738 /* Basic operations on keymaps */
|
|
739 /************************************************************************/
|
|
740
|
|
741 static Lisp_Object
|
|
742 make_keymap (int size)
|
|
743 {
|
|
744 Lisp_Object result = Qnil;
|
|
745 struct keymap *keymap = alloc_lcrecord (sizeof (struct keymap),
|
|
746 lrecord_keymap);
|
|
747
|
|
748 XSETKEYMAP (result, keymap);
|
|
749
|
|
750 keymap->parents = Qnil;
|
|
751 keymap->table = Qnil;
|
|
752 keymap->prompt = Qnil;
|
|
753 keymap->default_binding = Qnil;
|
|
754 keymap->inverse_table = Qnil;
|
|
755 keymap->sub_maps_cache = Qnil; /* No possible submaps */
|
|
756 keymap->fullness = 0;
|
|
757 if (size != 0) /* hack for copy-keymap */
|
|
758 {
|
|
759 keymap->table = Fmake_hashtable (make_int (size), Qnil);
|
|
760 /* Inverse table is often less dense because of duplicate key-bindings.
|
|
761 If not, it will grow anyway. */
|
|
762 keymap->inverse_table = Fmake_hashtable (make_int (size * 3 / 4), Qnil);
|
|
763 }
|
|
764 keymap->name = Qnil;
|
|
765 return (result);
|
|
766 }
|
|
767
|
|
768 DEFUN ("make-keymap", Fmake_keymap, Smake_keymap, 0, 1, 0 /*
|
|
769 Construct and return a new keymap object.
|
|
770 All entries in it are nil, meaning \"command undefined\".
|
|
771
|
|
772 Optional argument NAME specifies a name to assign to the keymap,
|
|
773 as in `set-keymap-name'. This name is only a debugging convenience;
|
|
774 it is not used except when printing the keymap.
|
|
775 */ )
|
|
776 (name)
|
|
777 Lisp_Object name;
|
|
778 {
|
|
779 Lisp_Object keymap = make_keymap (60);
|
|
780 if (!NILP (name))
|
|
781 Fset_keymap_name (keymap, name);
|
|
782 return keymap;
|
|
783 }
|
|
784
|
|
785 DEFUN ("make-sparse-keymap", Fmake_sparse_keymap, Smake_sparse_keymap,
|
|
786 0, 1, 0 /*
|
|
787 Construct and return a new keymap object.
|
|
788 All entries in it are nil, meaning \"command undefined\". The only
|
|
789 difference between this function and make-keymap is that this function
|
|
790 returns a \"smaller\" keymap (one that is expected to contain fewer
|
|
791 entries). As keymaps dynamically resize, the distinction is not great.
|
|
792
|
|
793 Optional argument NAME specifies a name to assign to the keymap,
|
|
794 as in `set-keymap-name'. This name is only a debugging convenience;
|
|
795 it is not used except when printing the keymap.
|
|
796 */ )
|
|
797 (name)
|
|
798 Lisp_Object name;
|
|
799 {
|
|
800 Lisp_Object keymap = make_keymap (8);
|
|
801 if (!NILP (name))
|
|
802 Fset_keymap_name (keymap, name);
|
|
803 return keymap;
|
|
804 }
|
|
805
|
|
806 DEFUN ("keymap-parents", Fkeymap_parents, Skeymap_parents, 1, 1, 0 /*
|
|
807 Return the `parent' keymaps of the given keymap, or nil.
|
|
808 The parents of a keymap are searched for keybindings when a key sequence
|
|
809 isn't bound in this one. `(current-global-map)' is the default parent
|
|
810 of all keymaps.
|
|
811 */ )
|
|
812 (keymap)
|
|
813 Lisp_Object keymap;
|
|
814 {
|
|
815 keymap = get_keymap (keymap, 1, 1);
|
|
816 return (Fcopy_sequence (XKEYMAP (keymap)->parents));
|
|
817 }
|
|
818
|
|
819
|
|
820
|
|
821 static Lisp_Object
|
|
822 traverse_keymaps_noop (Lisp_Object keymap, void *arg)
|
|
823 {
|
|
824 return (Qnil);
|
|
825 }
|
|
826
|
|
827 DEFUN ("set-keymap-parents", Fset_keymap_parents, Sset_keymap_parents, 2, 2, 0 /*
|
|
828 Sets the `parent' keymaps of the given keymap.
|
|
829 The parents of a keymap are searched for keybindings when a key sequence
|
|
830 isn't bound in this one. `(current-global-map)' is the default parent
|
|
831 of all keymaps.
|
|
832 */ )
|
|
833 (keymap, parents)
|
|
834 Lisp_Object keymap, parents;
|
|
835 {
|
|
836 /* This function can GC */
|
|
837 Lisp_Object k;
|
|
838 struct gcpro gcpro1, gcpro2;
|
|
839
|
|
840 GCPRO2 (keymap, parents);
|
|
841 keymap = get_keymap (keymap, 1, 1);
|
|
842
|
|
843 if (KEYMAPP (parents)) /* backwards-compatibility */
|
|
844 parents = list1 (parents);
|
|
845 if (!NILP (parents))
|
|
846 {
|
|
847 Lisp_Object tail = parents;
|
|
848 while (!NILP (tail))
|
|
849 {
|
|
850 QUIT;
|
|
851 CHECK_CONS (tail);
|
|
852 k = XCAR (tail);
|
|
853 /* Require that it be an actual keymap object, rather than a symbol
|
|
854 with a (crockish) symbol-function which is a keymap */
|
|
855 CHECK_KEYMAP (k); /* get_keymap (k, 1, 1); */
|
|
856 tail = XCDR (tail);
|
|
857 }
|
|
858 }
|
|
859
|
|
860 /* Check for circularities */
|
|
861 traverse_keymaps (keymap, parents, traverse_keymaps_noop, 0);
|
|
862 keymap_tick++;
|
|
863 XKEYMAP (keymap)->parents = Fcopy_sequence (parents);
|
|
864 UNGCPRO;
|
|
865 return (parents);
|
|
866 }
|
|
867
|
|
868 DEFUN ("set-keymap-name", Fset_keymap_name, Sset_keymap_name, 2, 2, 0 /*
|
|
869 Set the `name' of the KEYMAP to NEW-NAME.
|
|
870 The name is only a debugging convenience; it is not used except
|
|
871 when printing the keymap.
|
|
872 */ )
|
|
873 (keymap, new_name)
|
|
874 Lisp_Object keymap, new_name;
|
|
875 {
|
|
876 keymap = get_keymap (keymap, 1, 1);
|
|
877
|
|
878 XKEYMAP (keymap)->name = new_name;
|
|
879 return (new_name);
|
|
880 }
|
|
881
|
|
882 DEFUN ("keymap-name", Fkeymap_name, Skeymap_name, 1, 1, 0 /*
|
|
883 Return the `name' of KEYMAP.
|
|
884 The name is only a debugging convenience; it is not used except
|
|
885 when printing the keymap.
|
|
886 */ )
|
|
887 (keymap)
|
|
888 Lisp_Object keymap;
|
|
889 {
|
|
890 keymap = get_keymap (keymap, 1, 1);
|
|
891
|
|
892 return (XKEYMAP (keymap)->name);
|
|
893 }
|
|
894
|
|
895 DEFUN ("set-keymap-prompt", Fset_keymap_prompt, Sset_keymap_prompt, 2, 2, 0 /*
|
|
896 Sets the `prompt' of KEYMAP to string NEW-PROMPT, or `nil'
|
|
897 if no prompt is desired. The prompt is shown in the echo-area
|
|
898 when reading a key-sequence to be looked-up in this keymap.
|
|
899 */ )
|
|
900 (keymap, new_prompt)
|
|
901 Lisp_Object keymap, new_prompt;
|
|
902 {
|
|
903 keymap = get_keymap (keymap, 1, 1);
|
|
904
|
|
905 if (!NILP (new_prompt))
|
|
906 CHECK_STRING (new_prompt);
|
|
907
|
|
908 XKEYMAP (keymap)->prompt = new_prompt;
|
|
909 return (new_prompt);
|
|
910 }
|
|
911
|
|
912 static Lisp_Object
|
|
913 keymap_prompt_mapper (Lisp_Object keymap, void *arg)
|
|
914 {
|
|
915 return (XKEYMAP (keymap)->prompt);
|
|
916 }
|
|
917
|
|
918
|
|
919 DEFUN ("keymap-prompt", Fkeymap_prompt, Skeymap_prompt, 1, 2, 0 /*
|
|
920 Return the `prompt' of the given keymap.
|
|
921 If non-nil, the prompt is shown in the echo-area
|
|
922 when reading a key-sequence to be looked-up in this keymap.
|
|
923 */ )
|
|
924 (keymap, use_inherited)
|
|
925 Lisp_Object keymap, use_inherited;
|
|
926 {
|
|
927 /* This function can GC */
|
|
928 Lisp_Object prompt;
|
|
929
|
|
930 keymap = get_keymap (keymap, 1, 1);
|
|
931 prompt = XKEYMAP (keymap)->prompt;
|
|
932 if (!NILP (prompt) || NILP (use_inherited))
|
|
933 return (prompt);
|
|
934 else
|
|
935 return (traverse_keymaps (keymap, Qnil,
|
|
936 keymap_prompt_mapper, 0));
|
|
937 }
|
|
938
|
|
939 DEFUN ("set-keymap-default-binding",
|
|
940 Fset_keymap_default_binding, Sset_keymap_default_binding, 2, 2, 0 /*
|
|
941 Sets the default binding of KEYMAP to COMMAND, or `nil'
|
|
942 if no default is desired. The default-binding is returned when
|
|
943 no other binding for a key-sequence is found in the keymap.
|
|
944 If a keymap has a non-nil default-binding, neither the keymap's
|
|
945 parents nor the current global map are searched for key bindings.
|
|
946 */ )
|
|
947 (keymap, command)
|
|
948 Lisp_Object keymap, command;
|
|
949 {
|
|
950 /* This function can GC */
|
|
951 keymap = get_keymap (keymap, 1, 1);
|
|
952
|
|
953 XKEYMAP (keymap)->default_binding = command;
|
|
954 return (command);
|
|
955 }
|
|
956
|
|
957 DEFUN ("keymap-default-binding",
|
|
958 Fkeymap_default_binding, Skeymap_default_binding, 1, 1, 0 /*
|
|
959 Return the default binding of KEYMAP, or `nil' if it has none.
|
|
960 The default-binding is returned when no other binding for a key-sequence
|
|
961 is found in the keymap.
|
|
962 If a keymap has a non-nil default-binding, neither the keymap's
|
|
963 parents nor the current global map are searched for key bindings.
|
|
964 */ )
|
|
965 (keymap)
|
|
966 Lisp_Object keymap;
|
|
967 {
|
|
968 /* This function can GC */
|
|
969 keymap = get_keymap (keymap, 1, 1);
|
|
970 return (XKEYMAP (keymap)->default_binding);
|
|
971 }
|
|
972
|
|
973 DEFUN ("keymapp", Fkeymapp, Skeymapp, 1, 1, 0 /*
|
|
974 Return t if ARG is a keymap object.
|
|
975 The keymap may be autoloaded first if necessary.
|
|
976 */ )
|
|
977 (object)
|
|
978 Lisp_Object object;
|
|
979 {
|
|
980 /* This function can GC */
|
|
981 Lisp_Object tem = get_keymap (object, 0, 1);
|
|
982 return ((KEYMAPP (tem)) ? Qt : Qnil);
|
|
983 }
|
|
984
|
|
985 /* Check that OBJECT is a keymap (after dereferencing through any
|
|
986 symbols). If it is, return it.
|
|
987
|
|
988 If AUTOLOAD is non-zero and OBJECT is a symbol whose function value
|
|
989 is an autoload form, do the autoload and try again.
|
|
990
|
|
991 ERRORP controls how we respond if OBJECT isn't a keymap.
|
|
992 If ERRORP is non-zero, signal an error; otherwise, just return Qnil.
|
|
993 */
|
|
994 Lisp_Object
|
|
995 get_keymap (Lisp_Object object, int errorp, int autoload)
|
|
996 {
|
|
997 /* This function can GC */
|
|
998 while (1)
|
|
999 {
|
|
1000 Lisp_Object tem = indirect_function (object, 0);
|
|
1001
|
|
1002 if (KEYMAPP (tem))
|
|
1003 return tem;
|
|
1004 /* Should we do an autoload? */
|
|
1005 else if (autoload
|
|
1006 /* (autoload "filename" doc nil keymap) */
|
|
1007 && SYMBOLP (object)
|
|
1008 && CONSP (tem)
|
|
1009 && EQ (XCAR (tem), Qautoload)
|
|
1010 && EQ (Fcar (Fcdr (Fcdr (Fcdr (Fcdr (tem))))), Qkeymap))
|
|
1011 {
|
|
1012 struct gcpro gcpro1, gcpro2;
|
|
1013 GCPRO2 (tem, object);
|
|
1014 do_autoload (tem, object);
|
|
1015 UNGCPRO;
|
|
1016 }
|
|
1017 else if (errorp)
|
|
1018 object = wrong_type_argument (Qkeymapp, object);
|
|
1019 else
|
|
1020 return Qnil;
|
|
1021 }
|
|
1022 }
|
|
1023
|
|
1024 /* Given OBJECT which was found in a slot in a keymap,
|
|
1025 trace indirect definitions to get the actual definition of that slot.
|
|
1026 An indirect definition is a list of the form
|
|
1027 (KEYMAP . INDEX), where KEYMAP is a keymap or a symbol defined as one
|
|
1028 and INDEX is an ASCII code, or a cons of (KEYSYM . MODIFIERS).
|
|
1029 */
|
|
1030 static Lisp_Object
|
|
1031 get_keyelt (Lisp_Object object, int accept_default)
|
|
1032 {
|
|
1033 /* This function can GC */
|
|
1034 Lisp_Object map;
|
|
1035
|
|
1036 tail_recurse:
|
|
1037 if (!CONSP (object))
|
|
1038 return (object);
|
|
1039
|
|
1040 {
|
|
1041 struct gcpro gcpro1;
|
|
1042 GCPRO1 (object);
|
|
1043 map = XCAR (object);
|
|
1044 map = get_keymap (map, 0, 1);
|
|
1045 UNGCPRO;
|
|
1046 }
|
|
1047 /* If the contents are (KEYMAP . ELEMENT), go indirect. */
|
|
1048 if (!NILP (map))
|
|
1049 {
|
|
1050 Lisp_Object idx = Fcdr (object);
|
|
1051 struct key_data indirection;
|
|
1052 if (CHARP (idx))
|
|
1053 {
|
|
1054 struct Lisp_Event event;
|
|
1055 event.event_type = empty_event;
|
|
1056 character_to_event (XCHAR (idx), &event,
|
|
1057 XCONSOLE (Vselected_console), 0);
|
|
1058 indirection = event.event.key;
|
|
1059 }
|
|
1060 else if (CONSP (idx))
|
|
1061 {
|
|
1062 if (!INTP (XCDR (idx)))
|
|
1063 return (Qnil);
|
|
1064 indirection.keysym = XCAR (idx);
|
|
1065 indirection.modifiers = XINT (XCDR (idx));
|
|
1066 }
|
|
1067 else if (SYMBOLP (idx))
|
|
1068 {
|
|
1069 indirection.keysym = idx;
|
|
1070 indirection.modifiers = 0;
|
|
1071 }
|
|
1072 else
|
|
1073 {
|
|
1074 /* Random junk */
|
|
1075 return (Qnil);
|
|
1076 }
|
|
1077 return (raw_lookup_key (map, &indirection, 1, 0,
|
|
1078 accept_default));
|
|
1079 }
|
|
1080 else if (STRINGP (XCAR (object)))
|
|
1081 {
|
|
1082 /* If the keymap contents looks like (STRING . DEFN),
|
|
1083 use DEFN.
|
|
1084 Keymap alist elements like (CHAR MENUSTRING . DEFN)
|
|
1085 will be used by HierarKey menus. */
|
|
1086 object = XCDR (object);
|
|
1087 goto tail_recurse;
|
|
1088 }
|
|
1089 else
|
|
1090 {
|
|
1091 /* Anything else is really the value. */
|
|
1092 return (object);
|
|
1093 }
|
|
1094 }
|
|
1095
|
|
1096 static Lisp_Object
|
|
1097 keymap_lookup_1 (Lisp_Object keymap, CONST struct key_data *key,
|
|
1098 int accept_default)
|
|
1099 {
|
|
1100 /* This function can GC */
|
|
1101 return (get_keyelt (keymap_lookup_directly (keymap,
|
|
1102 key->keysym, key->modifiers),
|
|
1103 accept_default));
|
|
1104 }
|
|
1105
|
|
1106
|
|
1107 /************************************************************************/
|
|
1108 /* Copying keymaps */
|
|
1109 /************************************************************************/
|
|
1110
|
|
1111 struct copy_keymap_inverse_closure
|
|
1112 {
|
|
1113 Lisp_Object inverse_table;
|
|
1114 };
|
|
1115
|
|
1116 static void
|
|
1117 copy_keymap_inverse_mapper (CONST void *hash_key, void *hash_contents,
|
|
1118 void *copy_keymap_inverse_closure)
|
|
1119 {
|
|
1120 Lisp_Object key, inverse_table, inverse_contents;
|
|
1121 struct copy_keymap_inverse_closure *closure = copy_keymap_inverse_closure;
|
|
1122
|
|
1123 VOID_TO_LISP (inverse_table, closure);
|
|
1124 VOID_TO_LISP (inverse_contents, hash_contents);
|
|
1125 CVOID_TO_LISP (key, hash_key);
|
|
1126 /* copy-sequence deals with dotted lists. */
|
|
1127 if (CONSP (inverse_contents))
|
|
1128 inverse_contents = Fcopy_sequence (inverse_contents);
|
|
1129 Fputhash (key, inverse_contents, closure->inverse_table);
|
|
1130 }
|
|
1131
|
|
1132
|
|
1133 static Lisp_Object
|
|
1134 copy_keymap_internal (struct keymap *keymap)
|
|
1135 {
|
|
1136 Lisp_Object nkm = make_keymap (0);
|
|
1137 struct keymap *new_keymap = XKEYMAP (nkm);
|
|
1138 struct copy_keymap_inverse_closure copy_keymap_inverse_closure;
|
|
1139 copy_keymap_inverse_closure.inverse_table = keymap->inverse_table;
|
|
1140
|
|
1141 new_keymap->parents = Fcopy_sequence (keymap->parents);
|
|
1142 new_keymap->fullness = keymap->fullness;
|
|
1143 new_keymap->sub_maps_cache = Qnil; /* No submaps */
|
|
1144 new_keymap->table = Fcopy_hashtable (keymap->table);
|
|
1145 new_keymap->inverse_table = Fcopy_hashtable (keymap->inverse_table);
|
|
1146 /* After copying the inverse map, we need to copy the conses which
|
|
1147 are its values, lest they be shared by the copy, and mangled.
|
|
1148 */
|
|
1149 elisp_maphash (copy_keymap_inverse_mapper, keymap->inverse_table,
|
|
1150 ©_keymap_inverse_closure);
|
|
1151 return nkm;
|
|
1152 }
|
|
1153
|
|
1154
|
|
1155 static Lisp_Object copy_keymap (Lisp_Object keymap);
|
|
1156
|
|
1157 struct copy_keymap_closure
|
|
1158 {
|
|
1159 struct keymap *self;
|
|
1160 };
|
|
1161
|
|
1162 static void
|
|
1163 copy_keymap_mapper (CONST void *hash_key, void *hash_contents,
|
|
1164 void *copy_keymap_closure)
|
|
1165 {
|
|
1166 /* This function can GC */
|
|
1167 Lisp_Object key, contents;
|
|
1168 struct copy_keymap_closure *closure = copy_keymap_closure;
|
|
1169
|
|
1170 CVOID_TO_LISP (key, hash_key);
|
|
1171 VOID_TO_LISP (contents, hash_contents);
|
|
1172 /* When we encounter a keymap which is indirected through a
|
|
1173 symbol, we need to copy the sub-map. In v18, the form
|
|
1174 (lookup-key (copy-keymap global-map) "\C-x")
|
|
1175 returned a new keymap, not the symbol 'Control-X-prefix.
|
|
1176 */
|
|
1177 contents = get_keymap (contents,
|
|
1178 0, 1); /* #### autoload GC-safe here? */
|
|
1179 if (KEYMAPP (contents))
|
|
1180 keymap_store_internal (key, closure->self,
|
|
1181 copy_keymap (contents));
|
|
1182 }
|
|
1183
|
|
1184 static Lisp_Object
|
|
1185 copy_keymap (Lisp_Object keymap)
|
|
1186 {
|
|
1187 /* This function can GC */
|
|
1188 struct copy_keymap_closure copy_keymap_closure;
|
|
1189
|
|
1190 keymap = copy_keymap_internal (XKEYMAP (keymap));
|
|
1191 copy_keymap_closure.self = XKEYMAP (keymap);
|
|
1192 elisp_maphash (copy_keymap_mapper,
|
|
1193 XKEYMAP (keymap)->table,
|
|
1194 ©_keymap_closure);
|
|
1195 return keymap;
|
|
1196 }
|
|
1197
|
|
1198 DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0 /*
|
|
1199 Return a copy of the keymap KEYMAP.
|
|
1200 The copy starts out with the same definitions of KEYMAP,
|
|
1201 but changing either the copy or KEYMAP does not affect the other.
|
|
1202 Any key definitions that are subkeymaps are recursively copied.
|
|
1203 */ )
|
|
1204 (keymap)
|
|
1205 Lisp_Object keymap;
|
|
1206 {
|
|
1207 /* This function can GC */
|
|
1208 keymap = get_keymap (keymap, 1, 1);
|
|
1209 return copy_keymap (keymap);
|
|
1210 }
|
|
1211
|
|
1212
|
|
1213 static int
|
|
1214 keymap_fullness (Lisp_Object keymap)
|
|
1215 {
|
|
1216 /* This function can GC */
|
|
1217 int fullness;
|
|
1218 Lisp_Object sub_maps;
|
|
1219 struct gcpro gcpro1, gcpro2;
|
|
1220
|
|
1221 keymap = get_keymap (keymap, 1, 1);
|
|
1222 fullness = XKEYMAP (keymap)->fullness;
|
|
1223 sub_maps = keymap_submaps (keymap);
|
|
1224 GCPRO2 (keymap, sub_maps);
|
|
1225 for (; !NILP (sub_maps); sub_maps = XCDR (sub_maps))
|
|
1226 {
|
|
1227 if (MODIFIER_HASH_KEY_BITS (XCAR (XCAR (sub_maps))) != 0)
|
|
1228 {
|
|
1229 Lisp_Object sub_map = XCDR (XCAR (sub_maps));
|
|
1230 fullness--; /* don't count bucky maps */
|
|
1231 fullness += keymap_fullness (sub_map);
|
|
1232 }
|
|
1233 }
|
|
1234 UNGCPRO;
|
|
1235 return (fullness);
|
|
1236 }
|
|
1237
|
|
1238 DEFUN ("keymap-fullness", Fkeymap_fullness, Skeymap_fullness, 1, 1, 0 /*
|
|
1239 Return the number of bindings in the keymap.
|
|
1240 */ )
|
|
1241 (keymap)
|
|
1242 Lisp_Object keymap;
|
|
1243 {
|
|
1244 /* This function can GC */
|
|
1245 return (make_int (keymap_fullness
|
|
1246 (get_keymap (keymap, 1, 1))));
|
|
1247 }
|
|
1248
|
|
1249
|
|
1250 /************************************************************************/
|
|
1251 /* Defining keys in keymaps */
|
|
1252 /************************************************************************/
|
|
1253
|
|
1254 static void
|
|
1255 define_key_check_keysym (Lisp_Object spec,
|
|
1256 Lisp_Object keysym, unsigned int modifiers)
|
|
1257 {
|
|
1258 /* Now, check and massage the trailing keysym specifier. */
|
|
1259 if (SYMBOLP (keysym))
|
|
1260 {
|
|
1261 if (string_length (XSYMBOL (keysym)->name) == 1)
|
|
1262 {
|
|
1263 keysym = make_int (string_char (XSYMBOL (keysym)->name, 0));
|
|
1264 goto fixnum_keysym;
|
|
1265 }
|
|
1266 }
|
|
1267 else if (INTP (keysym))
|
|
1268 {
|
|
1269 fixnum_keysym:
|
|
1270 if (XINT (keysym) < ' ' || XINT (keysym) > 255)
|
|
1271 signal_simple_error ("keysym must be in the range 32 - 255",
|
|
1272 keysym);
|
|
1273 /* #### This bites! I want to be able to write (control shift a) */
|
|
1274 if (modifiers & MOD_SHIFT)
|
|
1275 signal_simple_error ("the `shift' modifier may not be applied to ASCII keysyms",
|
|
1276 spec);
|
|
1277 }
|
|
1278 else
|
|
1279 {
|
|
1280 signal_simple_error ("unknown keysym specifier",
|
|
1281 keysym);
|
|
1282 }
|
|
1283 }
|
|
1284
|
|
1285
|
|
1286 /* Given any kind of key-specifier, return a keysym and modifier mask.
|
|
1287 */
|
|
1288 static void
|
|
1289 define_key_parser (Lisp_Object spec, struct key_data *returned_value)
|
|
1290 {
|
|
1291 if (INTP (spec))
|
|
1292 {
|
|
1293 struct Lisp_Event event;
|
|
1294 event.event_type = empty_event;
|
|
1295 character_to_event (XINT (spec), &event,
|
|
1296 XCONSOLE (Vselected_console), 0);
|
|
1297 returned_value->keysym = event.event.key.keysym;
|
|
1298 returned_value->modifiers = event.event.key.modifiers;
|
|
1299 }
|
|
1300 else if (EVENTP (spec))
|
|
1301 {
|
|
1302 switch (XEVENT (spec)->event_type)
|
|
1303 {
|
|
1304 case key_press_event:
|
|
1305 {
|
|
1306 returned_value->keysym = XEVENT (spec)->event.key.keysym;
|
|
1307 returned_value->modifiers = XEVENT (spec)->event.key.modifiers;
|
|
1308 break;
|
|
1309 }
|
|
1310 case button_press_event:
|
|
1311 case button_release_event:
|
|
1312 {
|
|
1313 int down = (XEVENT (spec)->event_type == button_press_event);
|
|
1314 switch (XEVENT (spec)->event.button.button)
|
|
1315 {
|
|
1316 case 1:
|
|
1317 returned_value->keysym = (down ? Qbutton1 : Qbutton1up); break;
|
|
1318 case 2:
|
|
1319 returned_value->keysym = (down ? Qbutton2 : Qbutton2up); break;
|
|
1320 case 3:
|
|
1321 returned_value->keysym = (down ? Qbutton3 : Qbutton3up); break;
|
|
1322 case 4:
|
|
1323 returned_value->keysym = (down ? Qbutton4 : Qbutton4up); break;
|
|
1324 case 5:
|
|
1325 returned_value->keysym = (down ? Qbutton5 : Qbutton5up); break;
|
|
1326 case 6:
|
|
1327 returned_value->keysym = (down ? Qbutton6 : Qbutton6up); break;
|
|
1328 case 7:
|
|
1329 returned_value->keysym = (down ? Qbutton7 : Qbutton7up); break;
|
|
1330 default:
|
|
1331 returned_value->keysym =(down ? Qbutton0 : Qbutton0up); break;
|
|
1332 }
|
|
1333 returned_value->modifiers = XEVENT (spec)->event.button.modifiers;
|
|
1334 break;
|
|
1335 }
|
|
1336 default:
|
|
1337 signal_error (Qwrong_type_argument,
|
|
1338 list2 (build_translated_string
|
|
1339 ("unable to bind this type of event"),
|
|
1340 spec));
|
|
1341 }
|
|
1342 }
|
|
1343 else if (SYMBOLP (spec))
|
|
1344 {
|
|
1345 /* Be nice, allow = to mean (=) */
|
|
1346 if (bucky_sym_to_bucky_bit (spec) != 0)
|
|
1347 signal_simple_error ("Key is a modifier name", spec);
|
|
1348 define_key_check_keysym (spec, spec, 0);
|
|
1349 returned_value->keysym = spec;
|
|
1350 returned_value->modifiers = 0;
|
|
1351 }
|
|
1352 else if (CONSP (spec))
|
|
1353 {
|
|
1354 unsigned int modifiers = 0;
|
|
1355 Lisp_Object keysym = Qnil;
|
|
1356 Lisp_Object rest = spec;
|
|
1357
|
|
1358 /* First, parse out the leading modifier symbols. */
|
|
1359 while (CONSP (rest))
|
|
1360 {
|
|
1361 unsigned int modifier;
|
|
1362
|
|
1363 keysym = XCAR (rest);
|
|
1364 modifier = bucky_sym_to_bucky_bit (keysym);
|
|
1365 modifiers |= modifier;
|
|
1366 if (!NILP (XCDR (rest)))
|
|
1367 {
|
|
1368 if (! modifier)
|
|
1369 signal_simple_error ("unknown modifier", keysym);
|
|
1370 }
|
|
1371 else
|
|
1372 {
|
|
1373 if (modifier)
|
|
1374 signal_simple_error ("nothing but modifiers here",
|
|
1375 spec);
|
|
1376 }
|
|
1377 rest = XCDR (rest);
|
|
1378 QUIT;
|
|
1379 }
|
|
1380 if (!NILP (rest))
|
|
1381 signal_simple_error ("dotted list", spec);
|
|
1382
|
|
1383 define_key_check_keysym (spec, keysym, modifiers);
|
|
1384 returned_value->keysym = keysym;
|
|
1385 returned_value->modifiers = modifiers;
|
|
1386 }
|
|
1387 else
|
|
1388 {
|
|
1389 signal_simple_error ("unknown key-sequence specifier",
|
|
1390 spec);
|
|
1391 }
|
|
1392
|
|
1393 /* Convert single-character symbols into ints, since that's the
|
|
1394 way the events arrive from the keyboard... */
|
|
1395 if (SYMBOLP (returned_value->keysym) &&
|
|
1396 string_length (XSYMBOL (returned_value->keysym)->name) == 1)
|
|
1397 {
|
|
1398 returned_value->keysym =
|
|
1399 make_int (string_char (XSYMBOL (returned_value->keysym)->name, 0));
|
|
1400
|
|
1401 /* Detect bogus (user-provided) keysyms like '\?C-a;
|
|
1402 We can't do that for '\?M-a because that interferes with
|
|
1403 legitimate 8-bit input. */
|
|
1404 if (XINT (returned_value->keysym) < ' ' ||
|
|
1405 XINT (returned_value->keysym) > 255)
|
|
1406 signal_simple_error ("keysym must be in the range 32 - 255",
|
|
1407 returned_value->keysym);
|
|
1408 }
|
|
1409
|
|
1410 if (SYMBOLP (returned_value->keysym))
|
|
1411 {
|
|
1412 char *name = (char *) string_data (XSYMBOL (returned_value->keysym)->name);
|
|
1413
|
|
1414 /* FSFmacs uses symbols with the printed representation of keysyms in
|
|
1415 their names, like 'M-x, and we use the syntax '(meta x). So, to avoid
|
|
1416 confusion, notice the M-x syntax and signal an error - because
|
|
1417 otherwise it would be interpreted as a regular keysym, and would even
|
|
1418 show up in the list-buffers output, causing confusion to the naive.
|
|
1419
|
|
1420 We can get away with this because none of the X keysym names contain
|
|
1421 a hyphen (some contain underscore, however).
|
|
1422
|
|
1423 It might be useful to reject keysyms which are not x-valid-keysym-
|
|
1424 name-p, but that would interfere with various tricks we do to
|
|
1425 sanitize the Sun keyboards, and would make it trickier to
|
|
1426 conditionalize a .emacs file for multiple X servers.
|
|
1427 */
|
|
1428 if (((unsigned int) strlen (name) >= 2 && name[1] == '-')
|
|
1429 #if 1
|
|
1430 ||
|
|
1431 /* Ok, this is a bit more dubious - prevent people from doing things
|
|
1432 like (global-set-key 'RET 'something) because that will have the
|
|
1433 same problem as above. (Gag!) Maybe we should just silently
|
|
1434 accept these as aliases for the "real" names?
|
|
1435 */
|
|
1436 (string_length (XSYMBOL (returned_value->keysym)->name) < 4 &&
|
|
1437 (!strcmp (name, "LFD") ||
|
|
1438 !strcmp (name, "TAB") ||
|
|
1439 !strcmp (name, "RET") ||
|
|
1440 !strcmp (name, "ESC") ||
|
|
1441 !strcmp (name, "DEL") ||
|
|
1442 !strcmp (name, "SPC") ||
|
|
1443 !strcmp (name, "BS")))
|
|
1444 #endif /* unused */
|
|
1445 )
|
|
1446 signal_simple_error ("invalid keysym (see doc of define-key)",
|
|
1447 returned_value->keysym);
|
|
1448
|
|
1449 /* #### Ok, this is a bit more dubious - make people not lose if they
|
|
1450 do things like (global-set-key 'RET 'something) because that would
|
|
1451 otherwise have the same problem as above. (Gag!) We silently
|
|
1452 accept these as aliases for the "real" names.
|
|
1453 */
|
|
1454 else if (EQ (returned_value->keysym, QLFD))
|
|
1455 returned_value->keysym = QKlinefeed;
|
|
1456 else if (EQ (returned_value->keysym, QTAB))
|
|
1457 returned_value->keysym = QKtab;
|
|
1458 else if (EQ (returned_value->keysym, QRET))
|
|
1459 returned_value->keysym = QKreturn;
|
|
1460 else if (EQ (returned_value->keysym, QESC))
|
|
1461 returned_value->keysym = QKescape;
|
|
1462 else if (EQ (returned_value->keysym, QDEL))
|
|
1463 returned_value->keysym = QKdelete;
|
|
1464 else if (EQ (returned_value->keysym, QBS))
|
|
1465 returned_value->keysym = QKbackspace;
|
|
1466 }
|
|
1467 }
|
|
1468
|
|
1469 /* Used by character-to-event */
|
|
1470 void
|
|
1471 key_desc_list_to_event (Lisp_Object list, Lisp_Object event,
|
|
1472 int allow_menu_events)
|
|
1473 {
|
|
1474 struct key_data raw_key;
|
|
1475
|
|
1476 if (allow_menu_events &&
|
|
1477 CONSP (list) &&
|
|
1478 /* #### where the hell does this come from? */
|
|
1479 EQ (XCAR (list), Qmenu_selection))
|
|
1480 {
|
|
1481 Lisp_Object fn, arg;
|
|
1482 if (! NILP (Fcdr (Fcdr (list))))
|
|
1483 signal_simple_error ("invalid menu event desc", list);
|
|
1484 arg = Fcar (Fcdr (list));
|
|
1485 if (SYMBOLP (arg))
|
|
1486 fn = Qcall_interactively;
|
|
1487 else
|
|
1488 fn = Qeval;
|
|
1489 XSETFRAME (XEVENT (event)->channel, selected_frame ());
|
|
1490 XEVENT (event)->event_type = misc_user_event;
|
|
1491 XEVENT (event)->event.eval.function = fn;
|
|
1492 XEVENT (event)->event.eval.object = arg;
|
|
1493 return;
|
|
1494 }
|
|
1495
|
|
1496 define_key_parser (list, &raw_key);
|
|
1497
|
|
1498 if (EQ (raw_key.keysym, Qbutton0) || EQ (raw_key.keysym, Qbutton0up) ||
|
|
1499 EQ (raw_key.keysym, Qbutton1) || EQ (raw_key.keysym, Qbutton1up) ||
|
|
1500 EQ (raw_key.keysym, Qbutton2) || EQ (raw_key.keysym, Qbutton2up) ||
|
|
1501 EQ (raw_key.keysym, Qbutton3) || EQ (raw_key.keysym, Qbutton3up) ||
|
|
1502 EQ (raw_key.keysym, Qbutton4) || EQ (raw_key.keysym, Qbutton4up) ||
|
|
1503 EQ (raw_key.keysym, Qbutton5) || EQ (raw_key.keysym, Qbutton5up) ||
|
|
1504 EQ (raw_key.keysym, Qbutton6) || EQ (raw_key.keysym, Qbutton6up) ||
|
|
1505 EQ (raw_key.keysym, Qbutton7) || EQ (raw_key.keysym, Qbutton7up))
|
|
1506 error ("Mouse-clicks can't appear in saved keyboard macros.");
|
|
1507
|
|
1508 XEVENT (event)->channel = Vselected_console;
|
|
1509 XEVENT (event)->event_type = key_press_event;
|
|
1510 XEVENT (event)->event.key.keysym = raw_key.keysym;
|
|
1511 XEVENT (event)->event.key.modifiers = raw_key.modifiers;
|
|
1512 }
|
|
1513
|
|
1514
|
|
1515 int
|
|
1516 event_matches_key_specifier_p (struct Lisp_Event *event,
|
|
1517 Lisp_Object key_specifier)
|
|
1518 {
|
|
1519 Lisp_Object event2;
|
|
1520 int retval;
|
|
1521 struct gcpro gcpro1;
|
|
1522
|
|
1523 if (event->event_type != key_press_event || NILP (key_specifier) ||
|
|
1524 (INTP (key_specifier) && XINT (key_specifier) < 0))
|
|
1525 return 0;
|
|
1526
|
|
1527 /* if the specifier is an integer such as 27, then it should match
|
|
1528 both of the events 'escape' and 'control ['. Calling
|
|
1529 Fcharacter_to_event() will only match 'escape'. */
|
|
1530 if (INTP (key_specifier))
|
|
1531 return XINT (key_specifier) == event_to_character (event, 0, 0, 0);
|
|
1532
|
|
1533 /* Otherwise, we cannot call event_to_character() because we may
|
|
1534 be dealing with non-ASCII keystrokes. In any case, if I ask
|
|
1535 for 'control [' then I should get exactly that, and not
|
|
1536 'escape'.
|
|
1537
|
|
1538 However, we have to behave differently on TTY's, where 'control ['
|
|
1539 is silently converted into 'escape' by the keyboard driver.
|
|
1540 In this case, ASCII is the only thing we know about, so we have
|
|
1541 to compare the ASCII values. */
|
|
1542
|
|
1543 GCPRO1 (event2);
|
|
1544 event2 = Fmake_event ();
|
|
1545 Fcharacter_to_event (key_specifier, event2, Qnil, Qnil);
|
|
1546 if (XEVENT (event2)->event_type != key_press_event)
|
|
1547 retval = 0;
|
|
1548 else if (CONSOLE_TTY_P (XCONSOLE (EVENT_CHANNEL (event))))
|
|
1549 {
|
|
1550 int ch1, ch2;
|
|
1551
|
|
1552 ch1 = event_to_character (event, 0, 0, 0);
|
|
1553 ch2 = event_to_character (XEVENT (event2), 0, 0, 0);
|
|
1554 retval = (ch1 >= 0 && ch2 >= 0 && ch1 == ch2);
|
|
1555 }
|
|
1556 else if (EQ (event->event.key.keysym, XEVENT (event2)->event.key.keysym) &&
|
|
1557 event->event.key.modifiers == XEVENT (event2)->event.key.modifiers)
|
|
1558 retval = 1;
|
|
1559 else
|
|
1560 retval = 0;
|
|
1561 Fdeallocate_event (event2);
|
|
1562 UNGCPRO;
|
|
1563 return retval;
|
|
1564 }
|
|
1565
|
|
1566 static int
|
|
1567 meta_prefix_char_p (CONST struct key_data *key)
|
|
1568 {
|
|
1569 struct Lisp_Event event;
|
|
1570
|
|
1571 event.event_type = key_press_event;
|
|
1572 event.channel = Vselected_console;
|
|
1573 event.event.key.keysym = key->keysym;
|
|
1574 event.event.key.modifiers = key->modifiers;
|
|
1575 return event_matches_key_specifier_p (&event, Vmeta_prefix_char);
|
|
1576 }
|
|
1577
|
|
1578 DEFUN ("event-matches-key-specifier-p",
|
|
1579 Fevent_matches_key_specifier_p,
|
|
1580 Sevent_matches_key_specifier_p,
|
|
1581 2, 2, 0 /*
|
|
1582 Return non-nil if EVENT matches KEY-SPECIFIER.
|
|
1583 This can be useful, e.g., to determine if the user pressed `help-char' or
|
|
1584 `quit-char'.
|
|
1585 */ )
|
|
1586 (event, key_specifier)
|
|
1587 Lisp_Object event, key_specifier;
|
|
1588 {
|
|
1589 CHECK_LIVE_EVENT (event);
|
|
1590 return (event_matches_key_specifier_p (XEVENT (event), key_specifier)
|
|
1591 ? Qt : Qnil);
|
|
1592 }
|
|
1593
|
|
1594 /* ASCII grunge.
|
|
1595 Given a keysym, return another keysym/modifier pair which could be
|
|
1596 considered the same key in an ASCII world. Backspace returns ^H, for
|
|
1597 example.
|
|
1598 */
|
|
1599 static void
|
|
1600 define_key_alternate_name (struct key_data *key,
|
|
1601 struct key_data *returned_value)
|
|
1602 {
|
|
1603 Lisp_Object keysym = key->keysym;
|
|
1604 unsigned int modifiers = key->modifiers;
|
|
1605 unsigned int modifiers_sans_control = (modifiers & (~MOD_CONTROL));
|
|
1606 unsigned int modifiers_sans_meta = (modifiers & (~MOD_META));
|
|
1607 returned_value->keysym = Qnil; /* By default, no "alternate" key */
|
|
1608 returned_value->modifiers = 0;
|
|
1609 #define MACROLET(k,m) do { returned_value->keysym = (k); \
|
|
1610 returned_value->modifiers = (m); \
|
|
1611 RETURN__; } while (0)
|
|
1612 if (modifiers_sans_meta == MOD_CONTROL)
|
|
1613 {
|
|
1614 if EQ (keysym, QKspace)
|
|
1615 MACROLET (make_char ('@'), modifiers);
|
|
1616 else if (!CHARP (keysym))
|
|
1617 return;
|
|
1618 else switch (XCHAR (keysym))
|
|
1619 {
|
|
1620 case '@': /* c-@ => c-space */
|
|
1621 MACROLET (QKspace, modifiers);
|
|
1622 case 'h': /* c-h => backspace */
|
|
1623 MACROLET (QKbackspace, modifiers_sans_control);
|
|
1624 case 'i': /* c-i => tab */
|
|
1625 MACROLET (QKtab, modifiers_sans_control);
|
|
1626 case 'j': /* c-j => linefeed */
|
|
1627 MACROLET (QKlinefeed, modifiers_sans_control);
|
|
1628 case 'm': /* c-m => return */
|
|
1629 MACROLET (QKreturn, modifiers_sans_control);
|
|
1630 case '[': /* c-[ => escape */
|
|
1631 MACROLET (QKescape, modifiers_sans_control);
|
|
1632 default:
|
|
1633 return;
|
|
1634 }
|
|
1635 }
|
|
1636 else if (modifiers_sans_meta != 0)
|
|
1637 return;
|
|
1638 else if (EQ (keysym, QKbackspace)) /* backspace => c-h */
|
|
1639 MACROLET (make_char ('h'), (modifiers | MOD_CONTROL));
|
|
1640 else if (EQ (keysym, QKtab)) /* tab => c-i */
|
|
1641 MACROLET (make_char ('i'), (modifiers | MOD_CONTROL));
|
|
1642 else if (EQ (keysym, QKlinefeed)) /* linefeed => c-j */
|
|
1643 MACROLET (make_char ('j'), (modifiers | MOD_CONTROL));
|
|
1644 else if (EQ (keysym, QKreturn)) /* return => c-m */
|
|
1645 MACROLET (make_char ('m'), (modifiers | MOD_CONTROL));
|
|
1646 else if (EQ (keysym, QKescape)) /* escape => c-[ */
|
|
1647 MACROLET (make_char ('['), (modifiers | MOD_CONTROL));
|
|
1648 else
|
|
1649 return;
|
|
1650 #undef MACROLET
|
|
1651 }
|
|
1652
|
|
1653
|
|
1654 static void
|
|
1655 ensure_meta_prefix_char_keymapp (Lisp_Object keys, int indx,
|
|
1656 Lisp_Object keymap)
|
|
1657 {
|
|
1658 /* This function can GC */
|
|
1659 char buf [255];
|
|
1660 Lisp_Object new_keys;
|
|
1661 int i;
|
|
1662 Lisp_Object mpc_binding;
|
|
1663 struct key_data meta_key;
|
|
1664
|
|
1665 if (NILP (Vmeta_prefix_char) ||
|
|
1666 (INTP (Vmeta_prefix_char) && XINT (Vmeta_prefix_char) < 0))
|
|
1667 return;
|
|
1668
|
|
1669 define_key_parser (Vmeta_prefix_char, &meta_key);
|
|
1670 mpc_binding = keymap_lookup_1 (keymap, &meta_key, 0);
|
|
1671 if (NILP (mpc_binding) || !NILP (Fkeymapp (mpc_binding)))
|
|
1672 return;
|
|
1673
|
|
1674 if (indx == 0)
|
|
1675 new_keys = keys;
|
|
1676 else if (STRINGP (keys))
|
|
1677 new_keys = Fsubstring (keys, Qzero, make_int (indx));
|
|
1678 else if (VECTORP (keys))
|
|
1679 {
|
|
1680 new_keys = make_vector (indx, Qnil);
|
|
1681 for (i = 0; i < indx; i++)
|
|
1682 vector_data (XVECTOR (new_keys)) [i] =
|
|
1683 vector_data (XVECTOR (keys)) [i];
|
|
1684 }
|
|
1685 else
|
|
1686 abort ();
|
|
1687 if (EQ (keys, new_keys))
|
|
1688 sprintf (buf, GETTEXT ("can't bind %s: %s has a non-keymap binding"),
|
|
1689 (char *) string_data (XSTRING (Fkey_description (keys))),
|
|
1690 (char *) string_data (XSTRING
|
|
1691 (Fsingle_key_description
|
|
1692 (Vmeta_prefix_char))));
|
|
1693 else
|
|
1694 sprintf (buf, GETTEXT ("can't bind %s: %s %s has a non-keymap binding"),
|
|
1695 (char *) string_data (XSTRING (Fkey_description (keys))),
|
|
1696 (char *) string_data (XSTRING (Fkey_description (new_keys))),
|
|
1697 (char *) string_data (XSTRING
|
|
1698 (Fsingle_key_description
|
|
1699 (Vmeta_prefix_char))));
|
|
1700 signal_simple_error (buf, mpc_binding);
|
|
1701 }
|
|
1702
|
|
1703 DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0 /*
|
|
1704 Define key sequence KEYS, in KEYMAP, as DEF.
|
|
1705 KEYMAP is a keymap object.
|
|
1706 KEYS is the sequence of keystrokes to bind, described below.
|
|
1707 DEF is anything that can be a key's definition:
|
|
1708 nil (means key is undefined in this keymap);
|
|
1709 a command (a Lisp function suitable for interactive calling);
|
|
1710 a string or key sequence vector (treated as a keyboard macro);
|
|
1711 a keymap (to define a prefix key);
|
|
1712 a symbol; when the key is looked up, the symbol will stand for its
|
|
1713 function definition, that should at that time be one of the above,
|
|
1714 or another symbol whose function definition is used, and so on.
|
|
1715 a cons (STRING . DEFN), meaning that DEFN is the definition
|
|
1716 (DEFN should be a valid definition in its own right);
|
|
1717 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP.
|
|
1718
|
|
1719 Contrary to popular belief, the world is not ASCII. When running under a
|
|
1720 window manager, XEmacs can tell the difference between, for example, the
|
|
1721 keystrokes control-h, control-shift-h, and backspace. You can, in fact,
|
|
1722 bind different commands to each of these.
|
|
1723
|
|
1724 A `key sequence' is a set of keystrokes. A `keystroke' is a keysym and some
|
|
1725 set of modifiers (such as control and meta). A `keysym' is what is printed
|
|
1726 on the keys on your keyboard.
|
|
1727
|
|
1728 A keysym may be represented by a symbol, or (if and only if it is equivalent
|
|
1729 to an ASCII character in the range 32 - 255) by a character or its equivalent
|
|
1730 ASCII code. The `A' key may be represented by the symbol `A', the character
|
|
1731 `?A', or by the number 65. The `break' key may be represented only by the
|
|
1732 symbol `break'.
|
|
1733
|
|
1734 A keystroke may be represented by a list: the last element of the list
|
|
1735 is the key (a symbol, character, or number, as above) and the
|
|
1736 preceding elements are the symbolic names of modifier keys (control,
|
|
1737 meta, super, hyper, alt, and shift). Thus, the sequence control-b is
|
|
1738 represented by the forms `(control b)', `(control ?b)', and `(control
|
|
1739 98)'. A keystroke may also be represented by an event object, as
|
|
1740 returned by the `next-command-event' and `read-key-sequence'
|
|
1741 functions.
|
|
1742
|
|
1743 Note that in this context, the keystroke `control-b' is *not* represented
|
|
1744 by the number 2 (the ASCII code for ^B) or the character `?\^B'. See below.
|
|
1745
|
|
1746 The `shift' modifier is somewhat of a special case. You should not (and
|
|
1747 cannot) use `(meta shift a)' to mean `(meta A)', since for characters that
|
|
1748 have ASCII equivalents, the state of the shift key is implicit in the
|
|
1749 keysym (a vs. A). You also cannot say `(shift =)' to mean `+', as that
|
|
1750 sort of thing varies from keyboard to keyboard. The shift modifier is for
|
|
1751 use only with characters that do not have a second keysym on the same key,
|
|
1752 such as `backspace' and `tab'.
|
|
1753
|
|
1754 A key sequence is a vector of keystrokes. As a degenerate case, elements
|
|
1755 of this vector may also be keysyms if they have no modifiers. That is,
|
|
1756 the `A' keystroke is represented by all of these forms:
|
|
1757 A ?A 65 (A) (?A) (65)
|
|
1758 [A] [?A] [65] [(A)] [(?A)] [(65)]
|
|
1759
|
|
1760 the `control-a' keystroke is represented by these forms:
|
|
1761 (control A) (control ?A) (control 65)
|
|
1762 [(control A)] [(control ?A)] [(control 65)]
|
|
1763 the key sequence `control-c control-a' is represented by these forms:
|
|
1764 [(control c) (control a)] [(control ?c) (control ?a)]
|
|
1765 [(control 99) (control 65)] etc.
|
|
1766
|
|
1767 Mouse button clicks work just like keypresses: (control button1) means
|
|
1768 pressing the left mouse button while holding down the control key.
|
|
1769 \[(control c) (shift button3)] means control-c, hold shift, click right.
|
|
1770
|
|
1771 Commands may be bound to the mouse-button up-stroke rather than the down-
|
|
1772 stroke as well. `button1' means the down-stroke, and `button1up' means the
|
|
1773 up-stroke. Different commands may be bound to the up and down strokes,
|
|
1774 though that is probably not what you want, so be careful.
|
|
1775
|
|
1776 For backward compatibility, a key sequence may also be represented by a
|
|
1777 string. In this case, it represents the key sequence(s) that would
|
|
1778 produce that sequence of ASCII characters in a purely ASCII world. For
|
|
1779 example, a string containing the ASCII backspace character, \"\\^H\", would
|
|
1780 represent two key sequences: `(control h)' and `backspace'. Binding a
|
|
1781 command to this will actually bind both of those key sequences. Likewise
|
|
1782 for the following pairs:
|
|
1783
|
|
1784 control h backspace
|
|
1785 control i tab
|
|
1786 control m return
|
|
1787 control j linefeed
|
|
1788 control [ escape
|
|
1789 control @ control space
|
|
1790
|
|
1791 After binding a command to two key sequences with a form like
|
|
1792
|
|
1793 (define-key global-map \"\\^X\\^I\" \'command-1)
|
|
1794
|
|
1795 it is possible to redefine only one of those sequences like so:
|
|
1796
|
|
1797 (define-key global-map [(control x) (control i)] \'command-2)
|
|
1798 (define-key global-map [(control x) tab] \'command-3)
|
|
1799
|
|
1800 Of course, all of this applies only when running under a window system. If
|
|
1801 you're talking to XEmacs through a TTY connection, you don't get any of
|
|
1802 these features.
|
|
1803 */ )
|
|
1804 (keymap, keys, def)
|
|
1805 Lisp_Object keymap;
|
|
1806 Lisp_Object keys;
|
|
1807 Lisp_Object def;
|
|
1808 {
|
|
1809 /* This function can GC */
|
|
1810 int idx;
|
|
1811 int metized = 0;
|
|
1812 int size;
|
|
1813 int ascii_hack;
|
|
1814 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1815
|
|
1816 if (VECTORP (keys))
|
|
1817 size = vector_length (XVECTOR (keys));
|
|
1818 else if (STRINGP (keys))
|
|
1819 size = string_length (XSTRING (keys));
|
|
1820 else if (INTP (keys) || SYMBOLP (keys) || CONSP (keys))
|
|
1821 {
|
|
1822 if (!CONSP (keys)) keys = list1 (keys);
|
|
1823 size = 1;
|
|
1824 keys = make_vector (1, keys); /* this is kinda sleazy. */
|
|
1825 }
|
|
1826 else
|
|
1827 {
|
|
1828 keys = wrong_type_argument (Qsequencep, keys);
|
|
1829 size = XINT (Flength (keys));
|
|
1830 }
|
|
1831 if (size == 0)
|
|
1832 return (Qnil);
|
|
1833
|
|
1834 GCPRO3 (keymap, keys, def);
|
|
1835
|
|
1836 /* ASCII grunge.
|
|
1837 When the user defines a key which, in a strictly ASCII world, would be
|
|
1838 produced by two different keys (^J and linefeed, or ^H and backspace,
|
|
1839 for example) then the binding will be made for both keysyms.
|
|
1840
|
|
1841 This is done if the user binds a command to a string, as in
|
|
1842 (define-key map "\^H" 'something), but not when using one of the new
|
|
1843 syntaxes, like (define-key map '(control h) 'something).
|
|
1844 */
|
|
1845 ascii_hack = (STRINGP (keys));
|
|
1846
|
|
1847 keymap = get_keymap (keymap, 1, 1);
|
|
1848
|
|
1849 idx = 0;
|
|
1850 while (1)
|
|
1851 {
|
|
1852 Lisp_Object c;
|
|
1853 struct key_data raw_key1;
|
|
1854 struct key_data raw_key2;
|
|
1855
|
|
1856 if (STRINGP (keys))
|
|
1857 c = make_char (string_char (XSTRING (keys), idx));
|
|
1858 else
|
|
1859 {
|
|
1860 c = vector_data (XVECTOR (keys)) [idx];
|
|
1861 if (INTP (c) &&
|
|
1862 (XINT (c) < ' ' || XINT (c) > 127))
|
|
1863 args_out_of_range_3 (c, make_int (32), make_int (127));
|
|
1864 }
|
|
1865
|
|
1866 define_key_parser (c, &raw_key1);
|
|
1867
|
|
1868 if (!metized && ascii_hack && meta_prefix_char_p (&raw_key1))
|
|
1869 {
|
|
1870 if (idx == (size - 1))
|
|
1871 {
|
|
1872 /* This is a hack to prevent a binding for the meta-prefix-char
|
|
1873 from being made in a map which already has a non-empty "meta"
|
|
1874 submap. That is, we can't let both "escape" and "meta" have
|
|
1875 a binding in the same keymap. This implies that the idiom
|
|
1876 (define-key my-map "\e" my-escape-map)
|
|
1877 (define-key my-escape-map "a" 'my-command)
|
|
1878 no longer works. That's ok. Instead the luser should do
|
|
1879 (define-key my-map "\ea" 'my-command)
|
|
1880 or, more correctly
|
|
1881 (define-key my-map "\M-a" 'my-command)
|
|
1882 and then perhaps
|
|
1883 (defvar my-escape-map (lookup-key my-map "\e"))
|
|
1884 if the luser really wants the map in a variable.
|
|
1885 */
|
|
1886 Lisp_Object mmap;
|
|
1887 struct gcpro ngcpro1;
|
|
1888
|
|
1889 NGCPRO1 (c);
|
|
1890 mmap = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META),
|
|
1891 XKEYMAP (keymap)->table, Qnil);
|
|
1892 if (!NILP (mmap)
|
|
1893 && keymap_fullness (mmap) != 0)
|
|
1894 {
|
|
1895 Lisp_Object desc
|
|
1896 = Fsingle_key_description (Vmeta_prefix_char);
|
|
1897 signal_simple_error_2
|
|
1898 ("Map contains meta-bindings, can't bind", desc, keymap);
|
|
1899 }
|
|
1900 NUNGCPRO;
|
|
1901 }
|
|
1902 else
|
|
1903 {
|
|
1904 metized = 1;
|
|
1905 idx++;
|
|
1906 continue;
|
|
1907 }
|
|
1908 }
|
|
1909
|
|
1910 if (ascii_hack)
|
|
1911 define_key_alternate_name (&raw_key1, &raw_key2);
|
|
1912 else
|
|
1913 {
|
|
1914 raw_key2.keysym = Qnil;
|
|
1915 raw_key2.modifiers = 0;
|
|
1916 }
|
|
1917
|
|
1918 if (metized)
|
|
1919 {
|
|
1920 raw_key1.modifiers |= MOD_META;
|
|
1921 raw_key2.modifiers |= MOD_META;
|
|
1922 metized = 0;
|
|
1923 }
|
|
1924
|
|
1925 /* This crap is to make sure that someone doesn't bind something like
|
|
1926 "C-x M-a" while "C-x ESC" has a non-keymap binding. */
|
|
1927 if (raw_key1.modifiers & MOD_META)
|
|
1928 ensure_meta_prefix_char_keymapp (keys, idx, keymap);
|
|
1929
|
|
1930 if (++idx == size)
|
|
1931 {
|
|
1932 keymap_store (keymap, &raw_key1, def);
|
|
1933 if (ascii_hack && !NILP (raw_key2.keysym))
|
|
1934 keymap_store (keymap, &raw_key2, def);
|
|
1935 UNGCPRO;
|
|
1936 return def;
|
|
1937 }
|
|
1938
|
|
1939 {
|
|
1940 Lisp_Object cmd;
|
|
1941 struct gcpro ngcpro1;
|
|
1942 NGCPRO1 (c);
|
|
1943
|
|
1944 cmd = keymap_lookup_1 (keymap, &raw_key1, 0);
|
|
1945 if (NILP (cmd))
|
|
1946 {
|
|
1947 cmd = Fmake_sparse_keymap (Qnil);
|
|
1948 XKEYMAP (cmd)->name /* for debugging */
|
|
1949 = list2 (make_key_description (&raw_key1, 1), keymap);
|
|
1950 keymap_store (keymap, &raw_key1, cmd);
|
|
1951 }
|
|
1952 if (NILP (Fkeymapp (cmd)))
|
|
1953 signal_simple_error_2 ("invalid prefix keys in sequence",
|
|
1954 c, keys);
|
|
1955
|
|
1956 if (ascii_hack && !NILP (raw_key2.keysym) &&
|
|
1957 NILP (keymap_lookup_1 (keymap, &raw_key2, 0)))
|
|
1958 keymap_store (keymap, &raw_key2, cmd);
|
|
1959
|
|
1960 keymap = get_keymap (cmd, 1, 1);
|
|
1961 NUNGCPRO;
|
|
1962 }
|
|
1963 }
|
|
1964 }
|
|
1965
|
|
1966
|
|
1967 /************************************************************************/
|
|
1968 /* Looking up keys in keymaps */
|
|
1969 /************************************************************************/
|
|
1970
|
|
1971 /* We need a very fast (i.e., non-consing) version of lookup-key in order
|
2
|
1972 to make where-is-internal really fly. */
|
0
|
1973
|
|
1974 struct raw_lookup_key_mapper_closure
|
2
|
1975 {
|
|
1976 int remaining;
|
|
1977 CONST struct key_data *raw_keys;
|
|
1978 int raw_keys_count;
|
|
1979 int keys_so_far;
|
|
1980 int accept_default;
|
|
1981 };
|
0
|
1982
|
|
1983 static Lisp_Object raw_lookup_key_mapper (Lisp_Object k, void *);
|
|
1984
|
|
1985 /* Caller should gc-protect args (keymaps may autoload) */
|
|
1986 static Lisp_Object
|
|
1987 raw_lookup_key (Lisp_Object keymap,
|
|
1988 CONST struct key_data *raw_keys, int raw_keys_count,
|
|
1989 int keys_so_far, int accept_default)
|
|
1990 {
|
|
1991 /* This function can GC */
|
|
1992 struct raw_lookup_key_mapper_closure c;
|
|
1993 c.remaining = raw_keys_count - 1;
|
|
1994 c.raw_keys = raw_keys;
|
|
1995 c.raw_keys_count = raw_keys_count;
|
|
1996 c.keys_so_far = keys_so_far;
|
|
1997 c.accept_default = accept_default;
|
|
1998
|
|
1999 return (traverse_keymaps (keymap, Qnil, raw_lookup_key_mapper,
|
|
2000 &c));
|
|
2001 }
|
|
2002
|
|
2003 static Lisp_Object
|
|
2004 raw_lookup_key_mapper (Lisp_Object k, void *arg)
|
|
2005 {
|
|
2006 /* This function can GC */
|
|
2007 struct raw_lookup_key_mapper_closure *c = arg;
|
|
2008 int accept_default = c->accept_default;
|
|
2009 int remaining = c->remaining;
|
|
2010 int keys_so_far = c->keys_so_far;
|
|
2011 CONST struct key_data *raw_keys = c->raw_keys;
|
|
2012 Lisp_Object cmd;
|
|
2013
|
|
2014 if (! meta_prefix_char_p (&(raw_keys[0])))
|
|
2015 {
|
|
2016 /* Normal case: every case except the meta-hack (see below). */
|
|
2017 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
|
|
2018
|
|
2019 if (remaining == 0)
|
|
2020 /* Return whatever we found if we're out of keys */
|
|
2021 ;
|
|
2022 else if (NILP (cmd))
|
|
2023 /* Found nothing (though perhaps parent map may have binding) */
|
|
2024 ;
|
|
2025 else if (NILP (Fkeymapp (cmd)))
|
|
2026 /* Didn't find a keymap, and we have more keys.
|
|
2027 * Return a fixnum to indicate that keys were too long.
|
|
2028 */
|
|
2029 cmd = make_int (keys_so_far + 1);
|
|
2030 else
|
|
2031 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining,
|
|
2032 keys_so_far + 1, accept_default);
|
|
2033 }
|
|
2034 else
|
|
2035 {
|
|
2036 /* This is a hack so that looking up a key-sequence whose last
|
|
2037 * element is the meta-prefix-char will return the keymap that
|
|
2038 * the "meta" keys are stored in, if there is no binding for
|
|
2039 * the meta-prefix-char (and if this map has a "meta" submap).
|
|
2040 * If this map doesnt have a "meta" submap, then the
|
|
2041 * meta-prefix-char is looked up just like any other key.
|
|
2042 */
|
|
2043 if (remaining == 0)
|
|
2044 {
|
|
2045 /* First look for the prefix-char directly */
|
|
2046 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
|
|
2047 if (NILP (cmd))
|
|
2048 {
|
|
2049 /* Do kludgy return of the meta-map */
|
|
2050 cmd = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META),
|
|
2051 XKEYMAP (k)->table, Qnil);
|
|
2052 }
|
|
2053 }
|
|
2054 else
|
|
2055 {
|
|
2056 /* Search for the prefix-char-prefixed sequence directly */
|
|
2057 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
|
|
2058 cmd = get_keymap (cmd, 0, 1);
|
|
2059 if (!NILP (cmd))
|
|
2060 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining,
|
|
2061 keys_so_far + 1, accept_default);
|
|
2062 else if ((raw_keys[1].modifiers & MOD_META) == 0)
|
|
2063 {
|
|
2064 struct key_data metified;
|
|
2065 metified.keysym = raw_keys[1].keysym;
|
|
2066 metified.modifiers = raw_keys[1].modifiers | MOD_META;
|
|
2067
|
|
2068 /* Search for meta-next-char sequence directly */
|
|
2069 cmd = keymap_lookup_1 (k, &metified, accept_default);
|
|
2070 if (remaining == 1)
|
|
2071 ;
|
|
2072 else
|
|
2073 {
|
|
2074 cmd = get_keymap (cmd, 0, 1);
|
|
2075 if (!NILP (cmd))
|
|
2076 cmd = raw_lookup_key (cmd, raw_keys + 2, remaining - 1,
|
|
2077 keys_so_far + 2,
|
|
2078 accept_default);
|
|
2079 }
|
|
2080 }
|
|
2081 }
|
|
2082 }
|
|
2083 if (accept_default && NILP (cmd))
|
|
2084 cmd = XKEYMAP (k)->default_binding;
|
|
2085 return (cmd);
|
|
2086 }
|
|
2087
|
|
2088 /* Value is number if `keys' is too long; NIL if valid but has no definition.*/
|
|
2089 /* Caller should gc-protect arguments */
|
|
2090 static Lisp_Object
|
|
2091 lookup_keys (Lisp_Object keymap, int nkeys, Lisp_Object *keys,
|
|
2092 int accept_default)
|
|
2093 {
|
|
2094 /* This function can GC */
|
|
2095 struct key_data kkk[20];
|
|
2096 struct key_data *raw_keys;
|
|
2097 int i;
|
|
2098
|
|
2099 if (nkeys == 0)
|
|
2100 return Qnil;
|
|
2101
|
|
2102 if (nkeys > (countof (kkk)))
|
|
2103 raw_keys = kkk;
|
|
2104 else
|
|
2105 raw_keys = (struct key_data *) alloca (sizeof (struct key_data) * nkeys);
|
|
2106
|
|
2107 for (i = 0; i < nkeys; i++)
|
|
2108 {
|
|
2109 define_key_parser (keys[i], &(raw_keys[i]));
|
|
2110 }
|
|
2111 return (raw_lookup_key (keymap, raw_keys, nkeys, 0,
|
|
2112 accept_default));
|
|
2113 }
|
|
2114
|
|
2115 static Lisp_Object
|
|
2116 lookup_events (Lisp_Object event_head, int nmaps, Lisp_Object keymaps[],
|
|
2117 int accept_default)
|
|
2118 {
|
|
2119 /* This function can GC */
|
|
2120 struct key_data kkk[20];
|
|
2121 Lisp_Object event;
|
|
2122
|
|
2123 int nkeys;
|
|
2124 struct key_data *raw_keys;
|
|
2125 Lisp_Object tem = Qnil;
|
|
2126 struct gcpro gcpro1, gcpro2;
|
|
2127 int iii;
|
|
2128
|
|
2129 CHECK_LIVE_EVENT (event_head);
|
|
2130
|
|
2131 nkeys = event_chain_count (event_head);
|
|
2132
|
|
2133 if (nkeys < (countof (kkk)))
|
|
2134 raw_keys = kkk;
|
|
2135 else
|
|
2136 raw_keys = (struct key_data *) alloca (sizeof (struct key_data) * nkeys);
|
|
2137
|
|
2138 nkeys = 0;
|
|
2139 EVENT_CHAIN_LOOP (event, event_head)
|
|
2140 define_key_parser (event, &(raw_keys[nkeys++]));
|
|
2141 GCPRO2 (keymaps[0], event_head);
|
|
2142 gcpro1.nvars = nmaps;
|
|
2143 /* ####raw_keys[].keysym slots aren't gc-protected. We rely (but shouldn't)
|
|
2144 * on somebody else somewhere (obarray) having a pointer to all keysyms. */
|
|
2145 for (iii = 0; iii < nmaps; iii++)
|
|
2146 {
|
|
2147 tem = raw_lookup_key (keymaps[iii], raw_keys, nkeys, 0,
|
|
2148 accept_default);
|
|
2149 if (INTP (tem))
|
|
2150 {
|
|
2151 /* Too long in some local map means don't look at global map */
|
|
2152 tem = Qnil;
|
|
2153 break;
|
|
2154 }
|
|
2155 else if (!NILP (tem))
|
|
2156 break;
|
|
2157 }
|
|
2158 UNGCPRO;
|
|
2159 return (tem);
|
|
2160 }
|
|
2161
|
|
2162 DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0 /*
|
|
2163 In keymap KEYMAP, look up key-sequence KEYS. Return the definition.
|
|
2164 Nil is returned if KEYS is unbound. See documentation of `define-key'
|
|
2165 for valid key definitions and key-sequence specifications.
|
|
2166 A number is returned if KEYS is \"too long\"; that is, the leading
|
|
2167 characters fail to be a valid sequence of prefix characters in KEYMAP.
|
|
2168 The number is how many characters at the front of KEYS
|
|
2169 it takes to reach a non-prefix command.
|
|
2170 */ )
|
|
2171 (keymap, keys, accept_default)
|
|
2172 Lisp_Object keymap, keys, accept_default;
|
|
2173 {
|
|
2174 /* This function can GC */
|
|
2175 if (VECTORP (keys))
|
|
2176 {
|
|
2177 return lookup_keys (keymap,
|
|
2178 vector_length (XVECTOR (keys)),
|
|
2179 vector_data (XVECTOR (keys)),
|
|
2180 !NILP (accept_default));
|
|
2181 }
|
|
2182 else if (SYMBOLP (keys) || INTP (keys) || CONSP (keys))
|
|
2183 {
|
|
2184 return lookup_keys (keymap, 1, &keys,
|
|
2185 !NILP (accept_default));
|
|
2186 }
|
|
2187 else if (!STRINGP (keys))
|
|
2188 {
|
|
2189 keys = wrong_type_argument (Qsequencep, keys);
|
|
2190 return Flookup_key (keymap, keys, accept_default);
|
|
2191 }
|
2
|
2192 else /* STRINGP (keys) */
|
0
|
2193 {
|
|
2194 int length = string_char_length (XSTRING (keys));
|
|
2195 int i;
|
|
2196 struct key_data *raw_keys
|
|
2197 = (struct key_data *) alloca (sizeof (struct key_data) * length);
|
|
2198 if (length == 0)
|
|
2199 return Qnil;
|
|
2200
|
|
2201 for (i = 0; i < length; i++)
|
|
2202 {
|
|
2203 Emchar n = string_char (XSTRING (keys), i);
|
|
2204 define_key_parser (make_char (n), &(raw_keys[i]));
|
|
2205 }
|
|
2206 return (raw_lookup_key (keymap, raw_keys, length, 0,
|
|
2207 !NILP (accept_default)));
|
|
2208 }
|
|
2209 }
|
|
2210
|
|
2211 /* Given a key sequence, returns a list of keymaps to search for bindings.
|
|
2212 Does all manner of semi-hairy heuristics, like looking in the current
|
|
2213 buffer's map before looking in the global map and looking in the local
|
|
2214 map of the buffer in which the mouse was clicked in event0 is a click.
|
|
2215
|
|
2216 It would be kind of nice if this were in Lisp so that this semi-hairy
|
|
2217 semi-heuristic command-lookup behaviour could be readily understood and
|
|
2218 customised. However, this needs to be pretty fast, or performance of
|
|
2219 keyboard macros goes to shit; putting this in lisp slows macros down
|
|
2220 2-3x. And they're already slower than v18 by 5-6x.
|
|
2221 */
|
|
2222
|
|
2223 struct relevant_maps
|
|
2224 {
|
|
2225 int nmaps;
|
|
2226 unsigned int max_maps;
|
|
2227 Lisp_Object *maps;
|
|
2228 struct gcpro *gcpro;
|
|
2229 };
|
|
2230
|
|
2231 static void get_relevant_extent_keymaps (Lisp_Object pos,
|
|
2232 Lisp_Object buffer_or_string,
|
|
2233 Lisp_Object glyph,
|
|
2234 struct relevant_maps *closure);
|
|
2235 static void get_relevant_minor_maps (Lisp_Object buffer,
|
|
2236 struct relevant_maps *closure);
|
|
2237
|
|
2238 static void
|
|
2239 relevant_map_push (Lisp_Object map, struct relevant_maps *closure)
|
|
2240 {
|
|
2241 unsigned int nmaps = closure->nmaps;
|
|
2242
|
|
2243 if (!KEYMAPP (map))
|
|
2244 return;
|
|
2245 closure->nmaps = nmaps + 1;
|
|
2246 if (nmaps < closure->max_maps)
|
|
2247 {
|
|
2248 closure->maps[nmaps] = map;
|
|
2249 closure->gcpro->nvars = nmaps;
|
|
2250 }
|
|
2251 }
|
|
2252
|
|
2253 static int
|
|
2254 get_relevant_keymaps (Lisp_Object keys,
|
|
2255 int max_maps, Lisp_Object maps[])
|
|
2256 {
|
|
2257 /* This function can GC */
|
|
2258 Lisp_Object terminal = Qnil;
|
|
2259 struct gcpro gcpro1;
|
|
2260 struct relevant_maps closure;
|
|
2261 struct console *con;
|
|
2262
|
|
2263 GCPRO1 (*maps);
|
|
2264 gcpro1.nvars = 0;
|
|
2265 closure.nmaps = 0;
|
|
2266 closure.max_maps = max_maps;
|
|
2267 closure.maps = maps;
|
|
2268 closure.gcpro = &gcpro1;
|
|
2269
|
|
2270 if (EVENTP (keys))
|
|
2271 terminal = event_chain_tail (keys);
|
|
2272 else if (VECTORP (keys))
|
|
2273 {
|
|
2274 int len = vector_length (XVECTOR (keys));
|
|
2275 if (len > 0)
|
|
2276 terminal = vector_data (XVECTOR (keys))[len - 1];
|
|
2277 }
|
|
2278
|
|
2279 if (EVENTP (terminal))
|
|
2280 {
|
|
2281 CHECK_LIVE_EVENT (terminal);
|
|
2282 con = event_console_or_selected (terminal);
|
|
2283 }
|
|
2284 else
|
|
2285 con = XCONSOLE (Vselected_console);
|
|
2286
|
|
2287 if (KEYMAPP (con->overriding_terminal_local_map)
|
|
2288 || KEYMAPP (Voverriding_local_map))
|
|
2289 {
|
|
2290 if (KEYMAPP (con->overriding_terminal_local_map))
|
|
2291 relevant_map_push (con->overriding_terminal_local_map, &closure);
|
|
2292 if (KEYMAPP (Voverriding_local_map))
|
|
2293 relevant_map_push (Voverriding_local_map, &closure);
|
|
2294 }
|
|
2295 else if (!EVENTP (terminal)
|
|
2296 || (XEVENT (terminal)->event_type != button_press_event
|
|
2297 && XEVENT (terminal)->event_type != button_release_event))
|
|
2298 {
|
|
2299 Lisp_Object tem;
|
|
2300 XSETBUFFER (tem, current_buffer);
|
|
2301 /* It's not a mouse event; order of keymaps searched is:
|
|
2302 o keymap of any/all extents under the mouse
|
|
2303 o minor-mode maps
|
|
2304 o local-map of current-buffer
|
|
2305 o global-map
|
|
2306 */
|
|
2307 /* The terminal element of the lookup may be nil or a keysym.
|
|
2308 In those cases we don't want to check for an extent
|
|
2309 keymap. */
|
|
2310 if (EVENTP (terminal))
|
|
2311 {
|
|
2312 get_relevant_extent_keymaps (make_int (BUF_PT (current_buffer)),
|
|
2313 tem, Qnil, &closure);
|
|
2314 }
|
|
2315 get_relevant_minor_maps (tem, &closure);
|
|
2316
|
|
2317 tem = current_buffer->keymap;
|
|
2318 if (!NILP (tem))
|
|
2319 relevant_map_push (tem, &closure);
|
|
2320 }
|
|
2321 #ifdef HAVE_WINDOW_SYSTEM
|
|
2322 else
|
|
2323 {
|
|
2324 /* It's a mouse event; order of keymaps searched is:
|
|
2325 o local-map of mouse-grabbed-buffer
|
|
2326 o keymap of any/all extents under the mouse
|
|
2327 if the mouse is over a modeline:
|
|
2328 o modeline-map of buffer corresponding to that modeline
|
|
2329 o else, local-map of buffer under the mouse
|
|
2330 o minor-mode maps
|
|
2331 o local-map of current-buffer
|
|
2332 o global-map
|
|
2333 */
|
|
2334 Lisp_Object window = Fevent_window (terminal);
|
|
2335
|
|
2336 if (BUFFERP (Vmouse_grabbed_buffer))
|
|
2337 {
|
|
2338 Lisp_Object map = XBUFFER (Vmouse_grabbed_buffer)->keymap;
|
|
2339
|
|
2340 get_relevant_minor_maps (Vmouse_grabbed_buffer, &closure);
|
|
2341 if (!NILP (map))
|
|
2342 relevant_map_push (map, &closure);
|
|
2343 }
|
|
2344
|
|
2345 if (!NILP (window))
|
|
2346 {
|
|
2347 Lisp_Object buffer = Fwindow_buffer (window);
|
|
2348
|
|
2349 if (!NILP (buffer))
|
|
2350 {
|
|
2351 if (!NILP (Fevent_over_modeline_p (terminal)))
|
|
2352 {
|
|
2353 Lisp_Object map = symbol_value_in_buffer (Qmodeline_map,
|
|
2354 buffer);
|
|
2355
|
|
2356 get_relevant_extent_keymaps
|
|
2357 (Fevent_modeline_position (terminal),
|
|
2358 XBUFFER (buffer)->generated_modeline_string,
|
|
2359 /* #### third arg should maybe be a glyph. */
|
|
2360 Qnil, &closure);
|
|
2361
|
|
2362 if (!UNBOUNDP (map) && !NILP (map))
|
|
2363 relevant_map_push (get_keymap (map, 1, 1), &closure);
|
|
2364 }
|
|
2365 else
|
|
2366 {
|
|
2367 get_relevant_extent_keymaps (Fevent_point (terminal), buffer,
|
|
2368 Fevent_glyph_extent (terminal),
|
|
2369 &closure);
|
|
2370 }
|
|
2371
|
|
2372 if (!EQ (buffer, Vmouse_grabbed_buffer)) /* already pushed */
|
|
2373 {
|
|
2374 get_relevant_minor_maps (buffer, &closure);
|
|
2375 relevant_map_push (XBUFFER (buffer)->keymap, &closure);
|
|
2376 }
|
|
2377 }
|
|
2378 }
|
|
2379 else if (!NILP (Fevent_over_toolbar_p (terminal)))
|
|
2380 {
|
|
2381 Lisp_Object map = Fsymbol_value (Qtoolbar_map);
|
|
2382
|
|
2383 if (!UNBOUNDP (map) && !NILP (map))
|
|
2384 relevant_map_push (map, &closure);
|
|
2385 }
|
|
2386 }
|
|
2387 #endif /* HAVE_WINDOW_SYSTEM */
|
|
2388
|
|
2389 {
|
|
2390 int nmaps = closure.nmaps;
|
|
2391 /* Silently truncate at 100 keymaps to prevent infinite losssage */
|
|
2392 if (nmaps >= max_maps && max_maps > 0)
|
|
2393 maps[max_maps - 1] = Vcurrent_global_map;
|
|
2394 else
|
|
2395 maps[nmaps] = Vcurrent_global_map;
|
|
2396 UNGCPRO;
|
|
2397 return (nmaps + 1);
|
|
2398 }
|
|
2399 }
|
|
2400
|
|
2401 /* Returns a set of keymaps extracted from the extents at POS in
|
|
2402 BUFFER_OR_STRING. The GLYPH arg, if specified, is one more extent
|
|
2403 to look for a keymap in, and if it has one, its keymap will be the
|
|
2404 first element in the list returned. This is so we can correctly
|
|
2405 search the keymaps associated with glyphs which may be physically
|
|
2406 disjoint from their extents: for example, if a glyph is out in the
|
|
2407 margin, we should still consult the kemyap of that glyph's extent,
|
|
2408 which may not itself be under the mouse.
|
|
2409 */
|
|
2410 static void
|
|
2411 get_relevant_extent_keymaps (Lisp_Object pos, Lisp_Object buffer_or_string,
|
|
2412 Lisp_Object glyph,
|
|
2413 struct relevant_maps *closure)
|
|
2414 {
|
|
2415 /* This function can GC */
|
|
2416 /* the glyph keymap, if any, comes first.
|
|
2417 (Processing it twice is no big deal: noop.) */
|
|
2418 if (!NILP (glyph))
|
|
2419 {
|
|
2420 Lisp_Object keymap = Fextent_property (glyph, Qkeymap, Qnil);
|
|
2421 if (!NILP (keymap))
|
|
2422 relevant_map_push (get_keymap (keymap, 1, 1), closure);
|
|
2423 }
|
|
2424
|
|
2425 /* Next check the extents at the text position, if any */
|
|
2426 if (!NILP (pos))
|
|
2427 {
|
|
2428 Lisp_Object extent;
|
|
2429 for (extent = Fextent_at (pos, buffer_or_string, Qkeymap, Qnil, Qnil);
|
|
2430 !NILP (extent);
|
|
2431 extent = Fextent_at (pos, buffer_or_string, Qkeymap, extent, Qnil))
|
|
2432 {
|
|
2433 Lisp_Object keymap = Fextent_property (extent, Qkeymap, Qnil);
|
|
2434 if (!NILP (keymap))
|
|
2435 relevant_map_push (get_keymap (keymap, 1, 1), closure);
|
|
2436 QUIT;
|
|
2437 }
|
|
2438 }
|
|
2439 }
|
|
2440
|
|
2441 static Lisp_Object
|
|
2442 minor_mode_keymap_predicate (Lisp_Object assoc, Lisp_Object buffer)
|
|
2443 {
|
|
2444 /* This function can GC */
|
|
2445 if (CONSP (assoc))
|
|
2446 {
|
|
2447 Lisp_Object sym = XCAR (assoc);
|
|
2448 if (SYMBOLP (sym))
|
|
2449 {
|
|
2450 Lisp_Object val = symbol_value_in_buffer (sym, buffer);
|
|
2451 if (!NILP (val) && !UNBOUNDP (val))
|
|
2452 {
|
|
2453 Lisp_Object map = get_keymap (XCDR (assoc), 0, 1);
|
|
2454 return (map);
|
|
2455 }
|
|
2456 }
|
|
2457 }
|
|
2458 return (Qnil);
|
|
2459 }
|
|
2460
|
|
2461 static void
|
|
2462 get_relevant_minor_maps (Lisp_Object buffer, struct relevant_maps *closure)
|
|
2463 {
|
|
2464 /* This function can GC */
|
|
2465 Lisp_Object alist;
|
|
2466
|
|
2467 /* Will you ever lose badly if you make this circular! */
|
|
2468 for (alist = symbol_value_in_buffer (Qminor_mode_map_alist, buffer);
|
|
2469 CONSP (alist);
|
|
2470 alist = XCDR (alist))
|
|
2471 {
|
|
2472 Lisp_Object m = minor_mode_keymap_predicate (XCAR (alist),
|
|
2473 buffer);
|
|
2474 if (!NILP (m)) relevant_map_push (m, closure);
|
|
2475 QUIT;
|
|
2476 }
|
|
2477 }
|
|
2478
|
|
2479 /* #### Would map-current-keymaps be a better thing?? */
|
|
2480 DEFUN ("current-keymaps", Fcurrent_keymaps, Scurrent_keymaps, 0, 1, 0 /*
|
|
2481 Return a list of the current keymaps that will be searched for bindings.
|
|
2482 This lists keymaps such as the current local map and the minor-mode maps,
|
|
2483 but does not list the parents of those keymaps.
|
|
2484 EVENT-OR-KEYS controls which keymaps will be listed.
|
|
2485 If EVENT-OR-KEYS is a mouse event (or a vector whose last element is a
|
|
2486 mouse event), the keymaps for that mouse event will be listed (see
|
|
2487 `key-binding'). Otherwise, the keymaps for key presses will be listed.
|
|
2488 */ )
|
|
2489 (event_or_keys)
|
|
2490 Lisp_Object event_or_keys;
|
|
2491 {
|
|
2492 /* This function can GC */
|
|
2493 struct gcpro gcpro1;
|
|
2494 Lisp_Object maps[100];
|
|
2495 Lisp_Object *gubbish = maps;
|
|
2496 int nmaps;
|
|
2497
|
|
2498 GCPRO1 (event_or_keys);
|
|
2499 nmaps = get_relevant_keymaps (event_or_keys, countof (maps),
|
|
2500 gubbish);
|
|
2501 if (nmaps > countof (maps))
|
|
2502 {
|
|
2503 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
2504 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
|
|
2505 }
|
|
2506 UNGCPRO;
|
|
2507 return (Flist (nmaps, gubbish));
|
|
2508 }
|
|
2509
|
|
2510 DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 2, 0 /*
|
|
2511 Return the binding for command KEYS in current keymaps.
|
|
2512 KEYS is a string, a vector of events, or a vector of key-description lists
|
|
2513 as described in the documentation for the `define-key' function.
|
|
2514 The binding is probably a symbol with a function definition; see
|
|
2515 the documentation for `lookup-key' for more information.
|
|
2516
|
|
2517 For key-presses, the order of keymaps searched is:
|
|
2518 - the `keymap' property of any extent(s) at point;
|
|
2519 - any applicable minor-mode maps;
|
|
2520 - the current-local-map of the current-buffer;
|
|
2521 - the current global map.
|
|
2522
|
|
2523 For mouse-clicks, the order of keymaps searched is:
|
|
2524 - the current-local-map of the `mouse-grabbed-buffer' if any;
|
|
2525 - the `keymap' property of any extent(s) at the position of the click
|
|
2526 (this includes modeline extents);
|
|
2527 - the modeline-map of the buffer corresponding to the modeline under
|
|
2528 the mouse (if the click happened over a modeline);
|
|
2529 - the value of toolbar-map in the current-buffer (if the click
|
|
2530 happened over a toolbar);
|
|
2531 - the current-local-map of the buffer under the mouse (does not
|
|
2532 apply to toolbar clicks);
|
|
2533 - any applicable minor-mode maps;
|
|
2534 - the current global map.
|
|
2535
|
|
2536 Note that if `overriding-local-map' or `overriding-terminal-local-map'
|
|
2537 is non-nil, *only* those two maps and the current global map are searched.
|
|
2538 */ )
|
|
2539 (keys, accept_default)
|
|
2540 Lisp_Object keys, accept_default;
|
|
2541 {
|
|
2542 /* This function can GC */
|
|
2543 int i;
|
|
2544 Lisp_Object maps[100];
|
|
2545 int nmaps;
|
|
2546 struct gcpro gcpro1, gcpro2;
|
|
2547 GCPRO2 (keys, accept_default); /* get_relevant_keymaps may autoload */
|
|
2548
|
|
2549 nmaps = get_relevant_keymaps (keys, countof (maps), maps);
|
|
2550
|
|
2551 UNGCPRO;
|
|
2552
|
|
2553 if (EVENTP (keys)) /* unadvertised "feature" for the future */
|
|
2554 return (lookup_events (keys, nmaps, maps,
|
|
2555 !NILP (accept_default)));
|
|
2556
|
|
2557 for (i = 0; i < nmaps; i++)
|
|
2558 {
|
|
2559 Lisp_Object tem = Flookup_key (maps[i], keys,
|
|
2560 accept_default);
|
|
2561 if (INTP (tem))
|
|
2562 {
|
|
2563 /* Too long in some local map means don't look at global map */
|
|
2564 return (Qnil);
|
|
2565 }
|
|
2566 else if (!NILP (tem))
|
|
2567 return (tem);
|
|
2568 }
|
|
2569 return (Qnil);
|
|
2570 }
|
|
2571
|
|
2572 static Lisp_Object
|
|
2573 process_event_binding_result (Lisp_Object result)
|
|
2574 {
|
|
2575 if (EQ (result, Qundefined))
|
|
2576 /* The suppress-keymap function binds keys to 'undefined - special-case
|
|
2577 that here, so that being bound to that has the same error-behavior as
|
|
2578 not being defined at all.
|
|
2579 */
|
|
2580 result = Qnil;
|
|
2581 if (!NILP (result))
|
|
2582 {
|
|
2583 Lisp_Object map;
|
|
2584 /* Snap out possible keymap indirections */
|
|
2585 map = get_keymap (result, 0, 1);
|
|
2586 if (!NILP (map))
|
|
2587 result = map;
|
|
2588 }
|
|
2589
|
|
2590 return result;
|
|
2591 }
|
|
2592
|
|
2593 /* Attempts to find a command corresponding to the event-sequence
|
|
2594 whose head is event0 (sequence is threaded though event_next).
|
|
2595
|
|
2596 The return value will be
|
|
2597
|
|
2598 -- nil (there is no binding; this will also be returned
|
|
2599 whenever the event chain is "too long", i.e. there
|
|
2600 is a non-nil, non-keymap binding for a prefix of
|
|
2601 the event chain)
|
|
2602 -- a keymap (part of a command has been specified)
|
|
2603 -- a command (anything that satisfies `commandp'; this includes
|
|
2604 some symbols, lists, subrs, strings, vectors, and
|
|
2605 compiled-function objects) */
|
|
2606 Lisp_Object
|
|
2607 event_binding (Lisp_Object event0, int accept_default)
|
|
2608 {
|
|
2609 /* This function can GC */
|
|
2610 Lisp_Object maps[100];
|
|
2611 int nmaps;
|
|
2612
|
|
2613 assert (EVENTP (event0));
|
|
2614
|
|
2615 nmaps = get_relevant_keymaps (event0, countof (maps), maps);
|
|
2616 return (process_event_binding_result
|
|
2617 (lookup_events (event0, nmaps, maps, accept_default)));
|
|
2618 }
|
|
2619
|
|
2620 /* Attempts to find a function key mapping corresponding to the
|
|
2621 event-sequence whose head is event0 (sequence is threaded through
|
|
2622 event_next). The return value will be the same as for event_binding(). */
|
|
2623 Lisp_Object
|
|
2624 munging_key_map_event_binding (Lisp_Object event0,
|
|
2625 enum munge_me_out_the_door munge)
|
|
2626 {
|
|
2627 Lisp_Object the_map;
|
|
2628 Lisp_Object maps[1];
|
|
2629
|
|
2630 if (munge == MUNGE_ME_FUNCTION_KEY)
|
|
2631 {
|
|
2632 struct console *c = event_console_or_selected (event0);
|
|
2633
|
|
2634 the_map = CONSOLE_FUNCTION_KEY_MAP (c);
|
|
2635 }
|
|
2636 else
|
|
2637 the_map = Vkey_translation_map;
|
|
2638
|
|
2639 if (NILP (the_map))
|
|
2640 return Qnil;
|
|
2641
|
|
2642 maps[0] = the_map;
|
|
2643 return process_event_binding_result (lookup_events (event0, 1, maps, 1));
|
|
2644 }
|
|
2645
|
|
2646
|
|
2647 /************************************************************************/
|
|
2648 /* Setting/querying the global and local maps */
|
|
2649 /************************************************************************/
|
|
2650
|
|
2651 DEFUN ("use-global-map", Fuse_global_map, Suse_global_map, 1, 1, 0 /*
|
|
2652 Select KEYMAP as the global keymap.
|
|
2653 */ )
|
|
2654 (keymap)
|
|
2655 Lisp_Object keymap;
|
|
2656 {
|
|
2657 /* This function can GC */
|
|
2658 keymap = get_keymap (keymap, 1, 1);
|
|
2659 Vcurrent_global_map = keymap;
|
|
2660 return Qnil;
|
|
2661 }
|
|
2662
|
|
2663 DEFUN ("use-local-map", Fuse_local_map, Suse_local_map, 1, 2, 0 /*
|
|
2664 Select KEYMAP as the local keymap in BUFFER.
|
|
2665 If KEYMAP is nil, that means no local keymap.
|
|
2666 If BUFFER is nil, the current buffer is assumed.
|
|
2667 */ )
|
|
2668 (keymap, buffer)
|
|
2669 Lisp_Object keymap, buffer;
|
|
2670 {
|
|
2671 /* This function can GC */
|
|
2672 struct buffer *b = decode_buffer (buffer, 0);
|
|
2673 if (!NILP (keymap))
|
|
2674 keymap = get_keymap (keymap, 1, 1);
|
|
2675
|
|
2676 b->keymap = keymap;
|
|
2677
|
|
2678 return Qnil;
|
|
2679 }
|
|
2680
|
|
2681 DEFUN ("current-local-map", Fcurrent_local_map, Scurrent_local_map, 0, 1, 0 /*
|
|
2682 Return BUFFER's local keymap, or nil if it has none.
|
|
2683 If BUFFER is nil, the current buffer is assumed.
|
|
2684 */ )
|
|
2685 (buffer)
|
|
2686 Lisp_Object buffer;
|
|
2687 {
|
|
2688 struct buffer *b = decode_buffer (buffer, 0);
|
|
2689 return b->keymap;
|
|
2690 }
|
|
2691
|
|
2692 DEFUN ("current-global-map", Fcurrent_global_map, Scurrent_global_map, 0, 0, 0 /*
|
|
2693 Return the current global keymap.
|
|
2694 */ )
|
|
2695 ()
|
|
2696 {
|
|
2697 return (Vcurrent_global_map);
|
|
2698 }
|
|
2699
|
|
2700
|
|
2701 /************************************************************************/
|
|
2702 /* Mapping over keymap elements */
|
|
2703 /************************************************************************/
|
|
2704
|
|
2705 /* Since keymaps are arranged in a hierarchy, one keymap per bucky bit or
|
|
2706 prefix key, it's not entirely objvious what map-keymap should do, but
|
|
2707 what it does is: map over all keys in this map; then recursively map
|
|
2708 over all submaps of this map that are "bucky" submaps. This means that,
|
|
2709 when mapping over a keymap, it appears that "x" and "C-x" are in the
|
|
2710 same map, although "C-x" is really in the "control" submap of this one.
|
|
2711 However, since we don't recursively descend the submaps that are bound
|
|
2712 to prefix keys (like C-x, C-h, etc) the caller will have to recurse on
|
|
2713 those explicitly, if that's what they want.
|
|
2714
|
|
2715 So the end result of this is that the bucky keymaps (the ones indexed
|
|
2716 under the large integers returned from MAKE_MODIFIER_HASH_KEY()) are
|
|
2717 invisible from elisp. They're just an implementation detail that code
|
|
2718 outside of this file doesn't need to know about.
|
|
2719 */
|
|
2720
|
|
2721 struct map_keymap_unsorted_closure
|
|
2722 {
|
|
2723 void (*fn) (CONST struct key_data *, Lisp_Object binding, void *arg);
|
|
2724 void *arg;
|
|
2725 unsigned int modifiers;
|
|
2726 };
|
|
2727
|
|
2728 /* used by map_keymap() */
|
|
2729 static void
|
|
2730 map_keymap_unsorted_mapper (CONST void *hash_key, void *hash_contents,
|
|
2731 void *map_keymap_unsorted_closure)
|
|
2732 {
|
|
2733 /* This function can GC */
|
|
2734 Lisp_Object keysym;
|
|
2735 Lisp_Object contents;
|
|
2736 struct map_keymap_unsorted_closure *closure = map_keymap_unsorted_closure;
|
|
2737 unsigned int modifiers = closure->modifiers;
|
|
2738 unsigned int mod_bit;
|
|
2739 CVOID_TO_LISP (keysym, hash_key);
|
|
2740 VOID_TO_LISP (contents, hash_contents);
|
|
2741 mod_bit = MODIFIER_HASH_KEY_BITS (keysym);
|
|
2742 if (mod_bit != 0)
|
|
2743 {
|
|
2744 int omod = modifiers;
|
|
2745 closure->modifiers = (modifiers | mod_bit);
|
|
2746 contents = get_keymap (contents, 1, 1);
|
|
2747 elisp_maphash (map_keymap_unsorted_mapper,
|
|
2748 XKEYMAP (contents)->table,
|
|
2749 map_keymap_unsorted_closure);
|
|
2750 closure->modifiers = omod;
|
|
2751 }
|
|
2752 else
|
|
2753 {
|
|
2754 struct key_data key;
|
|
2755 key.keysym = keysym;
|
|
2756 key.modifiers = modifiers;
|
|
2757 ((*closure->fn) (&key, contents, closure->arg));
|
|
2758 }
|
|
2759 }
|
|
2760
|
|
2761
|
|
2762 struct map_keymap_sorted_closure
|
|
2763 {
|
|
2764 Lisp_Object *result_locative;
|
|
2765 };
|
|
2766
|
|
2767 /* used by map_keymap_sorted() */
|
|
2768 static void
|
|
2769 map_keymap_sorted_mapper (CONST void *hash_key, void *hash_contents,
|
|
2770 void *map_keymap_sorted_closure)
|
|
2771 {
|
|
2772 struct map_keymap_sorted_closure *cl = map_keymap_sorted_closure;
|
|
2773 Lisp_Object key, contents;
|
|
2774 Lisp_Object *list = cl->result_locative;
|
|
2775 CVOID_TO_LISP (key, hash_key);
|
|
2776 VOID_TO_LISP (contents, hash_contents);
|
|
2777 *list = Fcons (Fcons (key, contents), *list);
|
|
2778 }
|
|
2779
|
|
2780
|
|
2781 /* used by map_keymap_sorted(), describe_map_sort_predicate(),
|
|
2782 and keymap_submaps().
|
|
2783 */
|
|
2784 static int
|
|
2785 map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
|
|
2786 Lisp_Object pred)
|
|
2787 {
|
|
2788 /* obj1 and obj2 are conses with keysyms in their cars. Cdrs are ignored.
|
|
2789 */
|
|
2790 unsigned int bit1, bit2;
|
|
2791 int sym1_p = 0;
|
|
2792 int sym2_p = 0;
|
|
2793 obj1 = XCAR (obj1);
|
|
2794 obj2 = XCAR (obj2);
|
|
2795
|
|
2796 if (EQ (obj1, obj2))
|
|
2797 return -1;
|
|
2798 bit1 = MODIFIER_HASH_KEY_BITS (obj1);
|
|
2799 bit2 = MODIFIER_HASH_KEY_BITS (obj2);
|
|
2800
|
|
2801 /* If either is a symbol with a character-set-property, then sort it by
|
|
2802 that code instead of alphabetically.
|
|
2803 */
|
|
2804 if (! bit1 && SYMBOLP (obj1))
|
|
2805 {
|
|
2806 Lisp_Object code = Fget (obj1, Vcharacter_set_property, Qnil);
|
|
2807 if (INTP (code))
|
|
2808 obj1 = code, sym1_p = 1;
|
|
2809 }
|
|
2810 if (! bit2 && SYMBOLP (obj2))
|
|
2811 {
|
|
2812 Lisp_Object code = Fget (obj2, Vcharacter_set_property, Qnil);
|
|
2813 if (INTP (code))
|
|
2814 obj2 = code, sym2_p = 1;
|
|
2815 }
|
|
2816
|
|
2817 /* all symbols (non-ASCIIs) come after characters (ASCIIs) */
|
|
2818 if (XTYPE (obj1) != XTYPE (obj2))
|
|
2819 return (SYMBOLP (obj2) ? 1 : -1);
|
|
2820
|
|
2821 if (! bit1 && CHARP (obj1)) /* they're both ASCII */
|
|
2822 {
|
|
2823 int o1 = XCHAR (obj1);
|
|
2824 int o2 = XCHAR (obj2);
|
|
2825 if (o1 == o2 && /* If one started out as a symbol and the */
|
|
2826 sym1_p != sym2_p) /* other didn't, the symbol comes last. */
|
|
2827 return (sym2_p ? 1 : -1);
|
|
2828
|
|
2829 return ((o1 < o2) ? 1 : -1); /* else just compare them */
|
|
2830 }
|
|
2831
|
|
2832 /* else they're both symbols. If they're both buckys, then order them. */
|
|
2833 if (bit1 && bit2)
|
|
2834 return ((bit1 < bit2) ? 1 : -1);
|
|
2835
|
|
2836 /* if only one is a bucky, then it comes later */
|
|
2837 if (bit1 || bit2)
|
|
2838 return (bit2 ? 1 : -1);
|
|
2839
|
|
2840 /* otherwise, string-sort them. */
|
|
2841 {
|
|
2842 char *s1 = (char *) string_data (XSYMBOL (obj1)->name);
|
|
2843 char *s2 = (char *) string_data (XSYMBOL (obj2)->name);
|
|
2844 return (
|
|
2845 #ifdef I18N2
|
|
2846 (0 > strcoll (s1, s2))
|
|
2847 #else
|
|
2848 (0 > strcmp (s1, s2))
|
|
2849 #endif
|
|
2850 ? 1 : -1);
|
|
2851 }
|
|
2852 }
|
|
2853
|
|
2854
|
|
2855 /* used by map_keymap() */
|
|
2856 static void
|
|
2857 map_keymap_sorted (Lisp_Object keymap_table,
|
|
2858 unsigned int modifiers,
|
|
2859 void (*function) (CONST struct key_data *key,
|
|
2860 Lisp_Object binding,
|
|
2861 void *map_keymap_sorted_closure),
|
|
2862 void *map_keymap_sorted_closure)
|
|
2863 {
|
|
2864 /* This function can GC */
|
|
2865 struct gcpro gcpro1;
|
|
2866 Lisp_Object contents = Qnil;
|
|
2867
|
|
2868 if (XINT (Fhashtable_fullness (keymap_table)) == 0)
|
|
2869 return;
|
|
2870
|
|
2871 GCPRO1 (contents);
|
|
2872
|
|
2873 {
|
|
2874 struct map_keymap_sorted_closure c1;
|
|
2875 c1.result_locative = &contents;
|
|
2876 elisp_maphash (map_keymap_sorted_mapper, keymap_table, &c1);
|
|
2877 }
|
|
2878 contents = list_sort (contents, Qnil, map_keymap_sort_predicate);
|
|
2879 for (; !NILP (contents); contents = XCDR (contents))
|
|
2880 {
|
|
2881 Lisp_Object keysym = XCAR (XCAR (contents));
|
|
2882 Lisp_Object binding = XCDR (XCAR (contents));
|
|
2883 unsigned int sub_bits = MODIFIER_HASH_KEY_BITS (keysym);
|
|
2884 if (sub_bits != 0)
|
|
2885 map_keymap_sorted (XKEYMAP (get_keymap (binding,
|
|
2886 1, 1))->table,
|
|
2887 (modifiers | sub_bits),
|
|
2888 function,
|
|
2889 map_keymap_sorted_closure);
|
|
2890 else
|
|
2891 {
|
|
2892 struct key_data k;
|
|
2893 k.keysym = keysym;
|
|
2894 k.modifiers = modifiers;
|
|
2895 ((*function) (&k, binding, map_keymap_sorted_closure));
|
|
2896 }
|
|
2897 }
|
|
2898 UNGCPRO;
|
|
2899 }
|
|
2900
|
|
2901
|
|
2902 /* used by Fmap_keymap() */
|
|
2903 static void
|
|
2904 map_keymap_mapper (CONST struct key_data *key,
|
|
2905 Lisp_Object binding,
|
|
2906 void *function)
|
|
2907 {
|
|
2908 /* This function can GC */
|
|
2909 Lisp_Object fn;
|
|
2910 VOID_TO_LISP (fn, function);
|
|
2911 call2 (fn, make_key_description (key, 1), binding);
|
|
2912 }
|
|
2913
|
|
2914
|
|
2915 static void
|
|
2916 map_keymap (Lisp_Object keymap_table, int sort_first,
|
|
2917 void (*function) (CONST struct key_data *key,
|
|
2918 Lisp_Object binding,
|
|
2919 void *fn_arg),
|
|
2920 void *fn_arg)
|
|
2921 {
|
|
2922 /* This function can GC */
|
|
2923 if (sort_first)
|
|
2924 map_keymap_sorted (keymap_table, 0, function, fn_arg);
|
|
2925 else
|
|
2926 {
|
|
2927 struct map_keymap_unsorted_closure map_keymap_unsorted_closure;
|
|
2928 map_keymap_unsorted_closure.fn = function;
|
|
2929 map_keymap_unsorted_closure.arg = fn_arg;
|
|
2930 map_keymap_unsorted_closure.modifiers = 0;
|
|
2931 elisp_maphash (map_keymap_unsorted_mapper, keymap_table,
|
|
2932 &map_keymap_unsorted_closure);
|
|
2933 }
|
|
2934 }
|
|
2935
|
|
2936 DEFUN ("map-keymap", Fmap_keymap, Smap_keymap, 2, 3, 0 /*
|
|
2937 Apply FUNCTION to each element of KEYMAP.
|
|
2938 FUNCTION will be called with two arguments: a key-description list, and
|
|
2939 the binding. The order in which the elements of the keymap are passed to
|
|
2940 the function is unspecified. If the function inserts new elements into
|
|
2941 the keymap, it may or may not be called with them later. No element of
|
|
2942 the keymap will ever be passed to the function more than once.
|
|
2943
|
|
2944 The function will not be called on elements of this keymap's parents
|
|
2945 (see the function `keymap-parents') or upon keymaps which are contained
|
|
2946 within this keymap (multi-character definitions).
|
|
2947 It will be called on \"meta\" characters since they are not really
|
|
2948 two-character sequences.
|
|
2949
|
|
2950 If the optional third argument SORT-FIRST is non-nil, then the elements of
|
|
2951 the keymap will be passed to the mapper function in a canonical order.
|
|
2952 Otherwise, they will be passed in hash (that is, random) order, which is
|
|
2953 faster.
|
|
2954 */ )
|
|
2955 (function, keymap, sort_first)
|
|
2956 Lisp_Object function, keymap, sort_first;
|
|
2957 {
|
|
2958 /* This function can GC */
|
|
2959 struct gcpro gcpro1, gcpro2;
|
|
2960
|
|
2961 /* tolerate obviously transposed args */
|
|
2962 if (!NILP (Fkeymapp (function)))
|
|
2963 {
|
|
2964 Lisp_Object tmp = function;
|
|
2965 function = keymap;
|
|
2966 keymap = tmp;
|
|
2967 }
|
|
2968 GCPRO2 (function, keymap);
|
|
2969 keymap = get_keymap (keymap, 1, 1);
|
|
2970 map_keymap (XKEYMAP (keymap)->table, !NILP (sort_first),
|
|
2971 map_keymap_mapper, LISP_TO_VOID (function));
|
|
2972 UNGCPRO;
|
|
2973 return Qnil;
|
|
2974 }
|
|
2975
|
|
2976
|
|
2977
|
|
2978 /************************************************************************/
|
|
2979 /* Accessible keymaps */
|
|
2980 /************************************************************************/
|
|
2981
|
|
2982 struct accessible_keymaps_closure
|
|
2983 {
|
|
2984 Lisp_Object tail;
|
|
2985 };
|
|
2986
|
|
2987
|
|
2988 static void
|
|
2989 accessible_keymaps_mapper_1 (Lisp_Object keysym, Lisp_Object contents,
|
|
2990 unsigned int modifiers,
|
|
2991 struct accessible_keymaps_closure *closure)
|
|
2992 {
|
|
2993 /* This function can GC */
|
|
2994 unsigned int subbits = MODIFIER_HASH_KEY_BITS (keysym);
|
|
2995
|
|
2996 if (subbits != 0)
|
|
2997 {
|
|
2998 Lisp_Object submaps;
|
|
2999
|
|
3000 contents = get_keymap (contents, 1, 1);
|
|
3001 submaps = keymap_submaps (contents);
|
|
3002 for (; !NILP (submaps); submaps = XCDR (submaps))
|
|
3003 {
|
|
3004 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)),
|
|
3005 XCDR (XCAR (submaps)),
|
|
3006 (subbits | modifiers),
|
|
3007 closure);
|
|
3008 }
|
|
3009 }
|
|
3010 else
|
|
3011 {
|
|
3012 Lisp_Object thisseq = Fcar (Fcar (closure->tail));
|
|
3013 Lisp_Object cmd = get_keyelt (contents, 1);
|
|
3014 Lisp_Object vec;
|
|
3015 int j;
|
|
3016 struct key_data key;
|
|
3017 key.keysym = keysym;
|
|
3018 key.modifiers = modifiers;
|
|
3019
|
|
3020 if (NILP (cmd))
|
|
3021 abort ();
|
|
3022 cmd = get_keymap (cmd, 0, 1);
|
|
3023 if (!KEYMAPP (cmd))
|
|
3024 abort ();
|
|
3025
|
|
3026 vec = make_vector (vector_length (XVECTOR (thisseq)) + 1, Qnil);
|
|
3027 for (j = 0; j < vector_length (XVECTOR (thisseq)); j++)
|
|
3028 vector_data (XVECTOR (vec)) [j] = vector_data (XVECTOR (thisseq)) [j];
|
|
3029 vector_data (XVECTOR (vec)) [j] = make_key_description (&key, 1);
|
|
3030
|
|
3031 nconc2 (closure->tail, list1 (Fcons (vec, cmd)));
|
|
3032 }
|
|
3033 }
|
|
3034
|
|
3035
|
|
3036 static Lisp_Object
|
|
3037 accessible_keymaps_keymap_mapper (Lisp_Object thismap, void *arg)
|
|
3038 {
|
|
3039 /* This function can GC */
|
|
3040 struct accessible_keymaps_closure *closure = arg;
|
|
3041 Lisp_Object submaps = keymap_submaps (thismap);
|
|
3042
|
|
3043 for (; !NILP (submaps); submaps = XCDR (submaps))
|
|
3044 {
|
|
3045 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)),
|
|
3046 XCDR (XCAR (submaps)),
|
|
3047 0,
|
|
3048 closure);
|
|
3049 }
|
|
3050 return (Qnil);
|
|
3051 }
|
|
3052
|
|
3053
|
|
3054 DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps,
|
|
3055 1, 2, 0 /*
|
|
3056 Find all keymaps accessible via prefix characters from STARTMAP.
|
|
3057 Returns a list of elements of the form (KEYS . MAP), where the sequence
|
|
3058 KEYS starting from STARTMAP gets you to MAP. These elements are ordered
|
|
3059 so that the KEYS increase in length. The first element is ([] . STARTMAP).
|
|
3060 An optional argument PREFIX, if non-nil, should be a key sequence;
|
|
3061 then the value includes only maps for prefixes that start with PREFIX.
|
|
3062 */ )
|
|
3063 (startmap, prefix)
|
|
3064 Lisp_Object startmap, prefix;
|
|
3065 {
|
|
3066 /* This function can GC */
|
|
3067 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
3068 Lisp_Object accessible_keymaps = Qnil;
|
|
3069 struct accessible_keymaps_closure c;
|
|
3070 c.tail = Qnil;
|
|
3071 GCPRO4 (accessible_keymaps, c.tail, prefix, startmap);
|
|
3072
|
|
3073 retry:
|
|
3074 startmap = get_keymap (startmap, 1, 1);
|
|
3075 if (NILP (prefix))
|
|
3076 prefix = make_vector (0, Qnil);
|
|
3077 else if (!VECTORP (prefix) || STRINGP (prefix))
|
|
3078 {
|
|
3079 prefix = wrong_type_argument (Qarrayp, prefix);
|
|
3080 goto retry;
|
|
3081 }
|
|
3082 else
|
|
3083 {
|
|
3084 int len = XINT (Flength (prefix));
|
|
3085 Lisp_Object def = Flookup_key (startmap, prefix, Qnil);
|
|
3086 Lisp_Object p;
|
|
3087 int iii;
|
|
3088 struct gcpro ngcpro1;
|
|
3089
|
|
3090 def = get_keymap (def, 0, 1);
|
|
3091 if (!KEYMAPP (def))
|
|
3092 goto RETURN;
|
|
3093
|
|
3094 startmap = def;
|
|
3095 p = make_vector (len, Qnil);
|
|
3096 NGCPRO1 (p);
|
|
3097 for (iii = 0; iii < len; iii++)
|
|
3098 {
|
|
3099 struct key_data key;
|
|
3100 define_key_parser (Faref (prefix, make_int (iii)), &key);
|
|
3101 vector_data (XVECTOR (p))[iii] = make_key_description (&key, 1);
|
|
3102 }
|
|
3103 NUNGCPRO;
|
|
3104 prefix = p;
|
|
3105 }
|
|
3106
|
|
3107 accessible_keymaps = list1 (Fcons (prefix, startmap));
|
|
3108
|
|
3109 /* For each map in the list maps,
|
|
3110 look at any other maps it points to
|
|
3111 and stick them at the end if they are not already in the list */
|
|
3112
|
|
3113 for (c.tail = accessible_keymaps;
|
|
3114 !NILP (c.tail);
|
|
3115 c.tail = XCDR (c.tail))
|
|
3116 {
|
|
3117 Lisp_Object thismap = Fcdr (Fcar (c.tail));
|
|
3118 CHECK_KEYMAP (thismap);
|
|
3119 traverse_keymaps (thismap, Qnil,
|
|
3120 accessible_keymaps_keymap_mapper, &c);
|
|
3121 }
|
|
3122 RETURN:
|
|
3123 UNGCPRO;
|
|
3124 return (accessible_keymaps);
|
|
3125 }
|
|
3126
|
|
3127
|
|
3128
|
|
3129 /************************************************************************/
|
|
3130 /* Pretty descriptions of key sequences */
|
|
3131 /************************************************************************/
|
|
3132
|
|
3133 DEFUN ("key-description", Fkey_description, Skey_description, 1, 1, 0 /*
|
|
3134 Return a pretty description of key-sequence KEYS.
|
|
3135 Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"
|
|
3136 spaces are put between sequence elements, etc.
|
|
3137 */ )
|
|
3138 (keys)
|
|
3139 Lisp_Object keys;
|
|
3140 {
|
|
3141 if (INTP (keys) || CONSP (keys) || SYMBOLP (keys) || EVENTP (keys))
|
|
3142 {
|
|
3143 return Fsingle_key_description (keys);
|
|
3144 }
|
|
3145 else if (VECTORP (keys) ||
|
|
3146 STRINGP (keys))
|
|
3147 {
|
|
3148 Lisp_Object string = Qnil;
|
|
3149 /* Lisp_Object sep = Qnil; */
|
|
3150 int size = XINT (Flength (keys));
|
|
3151 int i;
|
|
3152
|
|
3153 for (i = 0; i < size; i++)
|
|
3154 {
|
|
3155 Lisp_Object s2 = Fsingle_key_description
|
|
3156 (((STRINGP (keys))
|
|
3157 ? make_char (string_char (XSTRING (keys), i))
|
|
3158 : vector_data (XVECTOR (keys))[i]));
|
|
3159
|
|
3160 if (i == 0)
|
|
3161 string = s2;
|
|
3162 else
|
|
3163 {
|
|
3164 /* if (NILP (sep)) Lisp_Object sep = build_string (" ") */;
|
|
3165 string = concat2 (string, concat2 (Vsingle_space_string, s2));
|
|
3166 }
|
|
3167 }
|
|
3168 return (string);
|
|
3169 }
|
|
3170 return Fkey_description (wrong_type_argument (Qsequencep, keys));
|
|
3171 }
|
|
3172
|
|
3173 DEFUN ("single-key-description", Fsingle_key_description,
|
|
3174 Ssingle_key_description, 1, 1, 0 /*
|
|
3175 Return a pretty description of command character KEY.
|
|
3176 Control characters turn into C-whatever, etc.
|
|
3177 This differs from `text-char-description' in that it returns a description
|
|
3178 of a key read from the user rather than a character from a buffer.
|
|
3179 */ )
|
|
3180 (key)
|
|
3181 Lisp_Object key;
|
|
3182 {
|
|
3183 if (SYMBOLP (key))
|
|
3184 key = Fcons (key, Qnil); /* sleaze sleaze */
|
|
3185
|
|
3186 if (EVENTP (key) || CHARP (key))
|
|
3187 {
|
|
3188 char buf [255];
|
|
3189 if (!EVENTP (key))
|
|
3190 {
|
|
3191 struct Lisp_Event event;
|
|
3192 event.event_type = empty_event;
|
|
3193 CHECK_CHAR_COERCE_INT (key);
|
|
3194 character_to_event (XCHAR (key), &event,
|
|
3195 XCONSOLE (Vselected_console), 0);
|
|
3196 format_event_object (buf, &event, 1);
|
|
3197 }
|
|
3198 else
|
|
3199 format_event_object (buf, XEVENT (key), 1);
|
|
3200 return (build_string (buf));
|
|
3201 }
|
|
3202
|
|
3203 if (CONSP (key))
|
|
3204 {
|
|
3205 char buf[255];
|
|
3206 char *bufp = buf;
|
|
3207 Lisp_Object rest;
|
|
3208 buf[0] = 0;
|
|
3209 LIST_LOOP (rest, key)
|
|
3210 {
|
|
3211 Lisp_Object keysym = XCAR (rest);
|
|
3212 if (EQ (keysym, Qcontrol)) strcpy (bufp, "C-"), bufp += 2;
|
|
3213 else if (EQ (keysym, Qctrl)) strcpy (bufp, "C-"), bufp += 2;
|
|
3214 else if (EQ (keysym, Qmeta)) strcpy (bufp, "M-"), bufp += 2;
|
|
3215 else if (EQ (keysym, Qsuper)) strcpy (bufp, "S-"), bufp += 2;
|
|
3216 else if (EQ (keysym, Qhyper)) strcpy (bufp, "H-"), bufp += 2;
|
|
3217 else if (EQ (keysym, Qalt)) strcpy (bufp, "A-"), bufp += 2;
|
|
3218 else if (EQ (keysym, Qshift)) strcpy (bufp, "Sh-"), bufp += 3;
|
|
3219 else if (INTP (keysym))
|
|
3220 *bufp = XINT (keysym), bufp++, *bufp = 0;
|
|
3221 else
|
|
3222 {
|
|
3223 CHECK_SYMBOL (keysym);
|
|
3224 #if 0 /* This is bogus */
|
|
3225 if (EQ (keysym, QKlinefeed)) strcpy (bufp, "LFD");
|
|
3226 else if (EQ (keysym, QKtab)) strcpy (bufp, "TAB");
|
|
3227 else if (EQ (keysym, QKreturn)) strcpy (bufp, "RET");
|
|
3228 else if (EQ (keysym, QKescape)) strcpy (bufp, "ESC");
|
|
3229 else if (EQ (keysym, QKdelete)) strcpy (bufp, "DEL");
|
|
3230 else if (EQ (keysym, QKspace)) strcpy (bufp, "SPC");
|
|
3231 else if (EQ (keysym, QKbackspace)) strcpy (bufp, "BS");
|
|
3232 else
|
|
3233 #endif
|
|
3234 strcpy (bufp, (char *) string_data (XSYMBOL (keysym)->name));
|
|
3235 if (!NILP (XCDR (rest)))
|
|
3236 signal_simple_error ("invalid key description",
|
|
3237 key);
|
|
3238 }
|
|
3239 }
|
|
3240 return build_string (buf);
|
|
3241 }
|
|
3242 return Fsingle_key_description
|
|
3243 (wrong_type_argument (intern ("char-or-event-p"), key));
|
|
3244 }
|
|
3245
|
|
3246 DEFUN ("text-char-description", Ftext_char_description, Stext_char_description,
|
|
3247 1, 1, 0 /*
|
|
3248 Return a pretty description of file-character CHR.
|
|
3249 Unprintable characters turn into \"^char\" or \\NNN, depending on the value
|
|
3250 of the `ctl-arrow' variable.
|
|
3251 This differs from `single-key-description' in that it returns a description
|
|
3252 of a character from a buffer rather than a key read from the user.
|
|
3253 */ )
|
|
3254 (chr)
|
|
3255 Lisp_Object chr;
|
|
3256 {
|
|
3257 Bufbyte buf[200];
|
|
3258 Bufbyte *p;
|
|
3259 unsigned int c;
|
|
3260 Lisp_Object ctl_arrow = current_buffer->ctl_arrow;
|
|
3261 int ctl_p = !NILP (ctl_arrow);
|
|
3262 int printable_min = (INTP (ctl_arrow)
|
|
3263 ? XINT (ctl_arrow)
|
|
3264 : ((EQ (ctl_arrow, Qt) || EQ (ctl_arrow, Qnil))
|
|
3265 ? 256 : 160));
|
|
3266
|
|
3267 if (EVENTP (chr))
|
|
3268 {
|
|
3269 Lisp_Object ch = Fevent_to_character (chr, Qnil, Qnil, Qt);
|
|
3270 if (NILP (ch))
|
|
3271 return
|
|
3272 signal_simple_continuable_error
|
|
3273 ("character has no ASCII equivalent", Fcopy_event (chr, Qnil));
|
|
3274 chr = ch;
|
|
3275 }
|
|
3276
|
|
3277 CHECK_CHAR_COERCE_INT (chr);
|
|
3278
|
|
3279 c = XCHAR (chr);
|
|
3280 p = buf;
|
|
3281
|
|
3282 if (c >= printable_min)
|
|
3283 {
|
|
3284 p += set_charptr_emchar (p, c);
|
|
3285 }
|
|
3286 else if (c < 040 && ctl_p)
|
|
3287 {
|
|
3288 *p++ = '^';
|
|
3289 *p++ = c + 64; /* 'A' - 1 */
|
|
3290 }
|
|
3291 else if (c == 0177)
|
|
3292 {
|
|
3293 *p++ = '^';
|
|
3294 *p++ = '?';
|
|
3295 }
|
|
3296 else if (c >= 0200 || c < 040)
|
|
3297 {
|
|
3298 *p++ = '\\';
|
|
3299 *p++ = '0' + ((c & 0700) >> 6);
|
|
3300 *p++ = '0' + ((c & 0070) >> 3);
|
|
3301 *p++ = '0' + ((c & 0007));
|
|
3302 }
|
|
3303 else
|
|
3304 {
|
|
3305 p += set_charptr_emchar (p, c);
|
|
3306 }
|
|
3307
|
|
3308 *p = 0;
|
|
3309 return build_string ((char *) buf);
|
|
3310 }
|
|
3311
|
|
3312
|
|
3313 /************************************************************************/
|
|
3314 /* where-is (mapping bindings to keys) */
|
|
3315 /************************************************************************/
|
|
3316
|
|
3317 static Lisp_Object
|
|
3318 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
|
|
3319 Lisp_Object firstonly, char *target_buffer);
|
|
3320
|
|
3321 DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0 /*
|
|
3322 Return list of keys that invoke DEFINITION in KEYMAPS.
|
|
3323 KEYMAPS can be either a keymap (meaning search in that keymap and the
|
|
3324 current global keymap) or a list of keymaps (meaning search in exactly
|
|
3325 those keymaps and no others). If KEYMAPS is nil, search in the currently
|
|
3326 applicable maps for EVENT-OR-KEYS (this is equivalent to specifying
|
|
3327 `(current-keymaps EVENT-OR-KEYS)' as the argument to KEYMAPS).
|
|
3328
|
|
3329 If optional 3rd arg FIRSTONLY is non-nil, return a vector representing
|
|
3330 the first key sequence found, rather than a list of all possible key
|
|
3331 sequences.
|
|
3332
|
|
3333 If optional 4th arg NOINDIRECT is non-nil, don't follow indirections
|
|
3334 to other keymaps or slots. This makes it possible to search for an
|
|
3335 indirect definition itself.
|
|
3336 */ )
|
|
3337 (definition, keymaps, firstonly, noindirect, event_or_keys)
|
|
3338 Lisp_Object definition, keymaps, firstonly, noindirect, event_or_keys;
|
|
3339 {
|
|
3340 /* This function can GC */
|
|
3341 Lisp_Object maps[100];
|
|
3342 Lisp_Object *gubbish = maps;
|
|
3343 int nmaps;
|
|
3344
|
|
3345 /* Get keymaps as an array */
|
|
3346 if (NILP (keymaps))
|
|
3347 {
|
|
3348 nmaps = get_relevant_keymaps (event_or_keys, countof (maps),
|
|
3349 gubbish);
|
|
3350 if (nmaps > countof (maps))
|
|
3351 {
|
|
3352 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
3353 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
|
|
3354 }
|
|
3355 }
|
|
3356 else if (CONSP (keymaps))
|
|
3357 {
|
|
3358 Lisp_Object rest;
|
|
3359 int i;
|
|
3360
|
|
3361 nmaps = XINT (Flength (keymaps));
|
|
3362 if (nmaps > countof (maps))
|
|
3363 {
|
|
3364 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
3365 }
|
|
3366 for (rest = keymaps, i = 0; !NILP (rest);
|
|
3367 rest = XCDR (keymaps), i++)
|
|
3368 {
|
|
3369 gubbish[i] = get_keymap (XCAR (keymaps), 1, 1);
|
|
3370 }
|
|
3371 }
|
|
3372 else
|
|
3373 {
|
|
3374 nmaps = 1;
|
|
3375 gubbish[0] = get_keymap (keymaps, 1, 1);
|
|
3376 if (!EQ (gubbish[0], Vcurrent_global_map))
|
|
3377 {
|
|
3378 gubbish[1] = Vcurrent_global_map;
|
|
3379 nmaps++;
|
|
3380 }
|
|
3381 }
|
|
3382
|
|
3383 return where_is_internal (definition, gubbish, nmaps, firstonly, 0);
|
|
3384 }
|
|
3385
|
|
3386 /* This function is like
|
|
3387 (key-description (where-is-internal definition nil t))
|
|
3388 except that it writes its output into a (char *) buffer that you
|
|
3389 provide; it doesn't cons (or allocate memory) at all, so it's
|
|
3390 very fast. This is used by menubar.c.
|
|
3391 */
|
|
3392 void
|
|
3393 where_is_to_char (Lisp_Object definition, char *buffer)
|
|
3394 {
|
|
3395 /* This function can GC */
|
|
3396 Lisp_Object maps[100];
|
|
3397 Lisp_Object *gubbish = maps;
|
|
3398 int nmaps;
|
|
3399
|
|
3400 /* Get keymaps as an array */
|
|
3401 nmaps = get_relevant_keymaps (Qnil, countof (maps), gubbish);
|
|
3402 if (nmaps > countof (maps))
|
|
3403 {
|
|
3404 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
3405 nmaps = get_relevant_keymaps (Qnil, nmaps, gubbish);
|
|
3406 }
|
|
3407
|
|
3408 buffer[0] = 0;
|
|
3409 where_is_internal (definition, maps, nmaps, Qt, buffer);
|
|
3410 }
|
|
3411
|
|
3412
|
|
3413 static Lisp_Object
|
|
3414 raw_keys_to_keys (struct key_data *keys, int count)
|
|
3415 {
|
|
3416 Lisp_Object result = make_vector (count, Qnil);
|
|
3417 while (count--)
|
|
3418 vector_data (XVECTOR (result)) [count] =
|
|
3419 make_key_description (&(keys[count]), 1);
|
|
3420 return (result);
|
|
3421 }
|
|
3422
|
|
3423
|
|
3424 static void
|
|
3425 format_raw_keys (struct key_data *keys, int count, char *buf)
|
|
3426 {
|
|
3427 int i;
|
|
3428 struct Lisp_Event event;
|
|
3429 event.event_type = key_press_event;
|
|
3430 event.channel = Vselected_console;
|
|
3431 for (i = 0; i < count; i++)
|
|
3432 {
|
|
3433 event.event.key.keysym = keys[i].keysym;
|
|
3434 event.event.key.modifiers = keys[i].modifiers;
|
|
3435 format_event_object (buf, &event, 1);
|
|
3436 buf += strlen (buf);
|
|
3437 if (i < count-1)
|
|
3438 buf[0] = ' ', buf++;
|
|
3439 }
|
|
3440 }
|
|
3441
|
|
3442
|
|
3443 /* definition is the thing to look for.
|
|
3444 map is a keymap.
|
|
3445 shadow is an array of shadow_count keymaps; if there is a different
|
|
3446 binding in any of the keymaps of a key that we are considering
|
|
3447 returning, then we reconsider.
|
|
3448 firstonly means give up after finding the first match;
|
|
3449 keys_so_far and modifiers_so_far describe which map we're looking in;
|
|
3450 If we're in the "meta" submap of the map that "C-x 4" is bound to,
|
|
3451 then keys_so_far will be {(control x), \4}, and modifiers_so_far
|
|
3452 will be MOD_META. That is, keys_so_far is the chain of keys that we
|
|
3453 have followed, and modifiers_so_far_so_far is the bits (partial keys)
|
|
3454 beyond that.
|
|
3455
|
|
3456 (keys_so_far is a global buffer and the keys_count arg says how much
|
|
3457 of it we're currently interested in.)
|
|
3458
|
|
3459 If target_buffer is provided, then we write a key-description into it,
|
|
3460 to avoid consing a string. This only works with firstonly on.
|
|
3461 */
|
|
3462
|
|
3463 struct where_is_closure
|
|
3464 {
|
|
3465 Lisp_Object definition;
|
|
3466 Lisp_Object *shadow;
|
|
3467 int shadow_count;
|
|
3468 int firstonly;
|
|
3469 int keys_count;
|
|
3470 unsigned int modifiers_so_far;
|
|
3471 char *target_buffer;
|
|
3472 struct key_data *keys_so_far;
|
|
3473 int keys_so_far_total_size;
|
|
3474 int keys_so_far_malloced;
|
|
3475 };
|
|
3476
|
|
3477 static Lisp_Object where_is_recursive_mapper (Lisp_Object map, void *arg);
|
|
3478
|
|
3479 static Lisp_Object
|
|
3480 where_is_recursive_mapper (Lisp_Object map, void *arg)
|
|
3481 {
|
|
3482 /* This function can GC */
|
|
3483 struct where_is_closure *c = arg;
|
|
3484 Lisp_Object definition = c->definition;
|
|
3485 CONST int firstonly = c->firstonly;
|
|
3486 CONST unsigned int keys_count = c->keys_count;
|
|
3487 CONST unsigned int modifiers_so_far = c->modifiers_so_far;
|
|
3488 char *target_buffer = c->target_buffer;
|
|
3489 Lisp_Object keys = Fgethash (definition,
|
|
3490 XKEYMAP (map)->inverse_table,
|
|
3491 Qnil);
|
|
3492 Lisp_Object submaps;
|
|
3493 Lisp_Object result = Qnil;
|
|
3494
|
|
3495 if (!NILP (keys))
|
|
3496 {
|
|
3497 /* One or more keys in this map match the definition we're looking
|
|
3498 for. Verify that these bindings aren't shadowed by other bindings
|
|
3499 in the shadow maps. Either nil or number as value from
|
|
3500 raw_lookup_key() means undefined.
|
|
3501 */
|
|
3502 struct key_data *so_far = c->keys_so_far;
|
|
3503
|
|
3504 for (;;) /* loop over all keys that match */
|
|
3505 {
|
|
3506 Lisp_Object k = ((CONSP (keys)) ? XCAR (keys) : keys);
|
|
3507 int i;
|
|
3508
|
|
3509 so_far [keys_count].keysym = k;
|
|
3510 so_far [keys_count].modifiers = modifiers_so_far;
|
|
3511
|
|
3512 /* now loop over all shadow maps */
|
|
3513 for (i = 0; i < c->shadow_count; i++)
|
|
3514 {
|
|
3515 Lisp_Object shadowed = raw_lookup_key (c->shadow[i],
|
|
3516 so_far,
|
|
3517 keys_count + 1,
|
|
3518 0, 1);
|
|
3519
|
|
3520 if (NILP (shadowed) || CHARP (shadowed) ||
|
|
3521 EQ (shadowed, definition))
|
|
3522 continue; /* we passed this test; it's not shadowed here. */
|
|
3523 else
|
|
3524 /* ignore this key binding, since it actually has a
|
|
3525 different binding in a shadowing map */
|
|
3526 goto c_doesnt_have_proper_loop_exit_statements;
|
|
3527 }
|
|
3528
|
|
3529 /* OK, the key is for real */
|
|
3530 if (target_buffer)
|
|
3531 {
|
|
3532 if (!firstonly) abort ();
|
|
3533 format_raw_keys (so_far, keys_count + 1, target_buffer);
|
|
3534 return (make_int (1));
|
|
3535 }
|
|
3536 else if (firstonly)
|
|
3537 return raw_keys_to_keys (so_far, keys_count + 1);
|
|
3538 else
|
|
3539 result = Fcons (raw_keys_to_keys (so_far, keys_count + 1),
|
|
3540 result);
|
|
3541
|
|
3542 c_doesnt_have_proper_loop_exit_statements:
|
|
3543 /* now on to the next matching key ... */
|
|
3544 if (!CONSP (keys)) break;
|
|
3545 keys = XCDR (keys);
|
|
3546 }
|
|
3547 }
|
|
3548
|
|
3549 /* Now search the sub-keymaps of this map.
|
|
3550 If we're in "firstonly" mode and have already found one, this
|
|
3551 point is not reached. If we get one from lower down, either
|
|
3552 return it immediately (in firstonly mode) or tack it onto the
|
|
3553 end of the ones we've gotten so far.
|
|
3554 */
|
|
3555 for (submaps = keymap_submaps (map);
|
|
3556 !NILP (submaps);
|
|
3557 submaps = XCDR (submaps))
|
|
3558 {
|
|
3559 Lisp_Object key = XCAR (XCAR (submaps));
|
|
3560 Lisp_Object submap = XCDR (XCAR (submaps));
|
|
3561 unsigned int lower_modifiers;
|
|
3562 int lower_keys_count = keys_count;
|
|
3563 unsigned int bucky;
|
|
3564
|
|
3565 submap = get_keymap (submap, 0, 1);
|
|
3566
|
|
3567 if (EQ (submap, map))
|
|
3568 /* Arrgh! Some loser has introduced a loop... */
|
|
3569 continue;
|
|
3570
|
|
3571 /* If this is not a keymap, then that's probably because someone
|
|
3572 did an `fset' of a symbol that used to point to a map such that
|
|
3573 it no longer does. Sigh. Ignore this, and invalidate the cache
|
|
3574 so that it doesn't happen to us next time too.
|
|
3575 */
|
|
3576 if (NILP (submap))
|
|
3577 {
|
|
3578 XKEYMAP (map)->sub_maps_cache = Qt;
|
|
3579 continue;
|
|
3580 }
|
|
3581
|
|
3582 /* If the map is a "bucky" map, then add a bit to the
|
|
3583 modifiers_so_far list.
|
|
3584 Otherwise, add a new raw_key onto the end of keys_so_far.
|
|
3585 */
|
|
3586 bucky = MODIFIER_HASH_KEY_BITS (key);
|
|
3587 if (bucky != 0)
|
|
3588 lower_modifiers = (modifiers_so_far | bucky);
|
|
3589 else
|
|
3590 {
|
|
3591 struct key_data *so_far = c->keys_so_far;
|
|
3592 lower_modifiers = 0;
|
|
3593 so_far [lower_keys_count].keysym = key;
|
|
3594 so_far [lower_keys_count].modifiers = modifiers_so_far;
|
|
3595 lower_keys_count++;
|
|
3596 }
|
|
3597
|
|
3598 if (lower_keys_count >= c->keys_so_far_total_size)
|
|
3599 {
|
|
3600 int size = lower_keys_count + 50;
|
|
3601 if (! c->keys_so_far_malloced)
|
|
3602 {
|
|
3603 struct key_data *new = xmalloc (size * sizeof (struct key_data));
|
|
3604 memcpy ((void *)new, (const void *)c->keys_so_far,
|
|
3605 c->keys_so_far_total_size * sizeof (struct key_data));
|
|
3606 }
|
|
3607 else
|
|
3608 c->keys_so_far = xrealloc (c->keys_so_far,
|
|
3609 size * sizeof (struct key_data));
|
|
3610
|
|
3611 c->keys_so_far_total_size = size;
|
|
3612 c->keys_so_far_malloced = 1;
|
|
3613 }
|
|
3614
|
|
3615 {
|
|
3616 Lisp_Object lower;
|
|
3617
|
|
3618 c->keys_count = lower_keys_count;
|
|
3619 c->modifiers_so_far = lower_modifiers;
|
|
3620
|
|
3621 lower = traverse_keymaps (submap, Qnil, where_is_recursive_mapper,
|
|
3622 c);
|
|
3623 c->keys_count = keys_count;
|
|
3624 c->modifiers_so_far = modifiers_so_far;
|
|
3625
|
|
3626 if (!firstonly)
|
|
3627 result = nconc2 (lower, result);
|
|
3628 else if (!NILP (lower))
|
|
3629 return (lower);
|
|
3630 }
|
|
3631 }
|
|
3632 return (result);
|
|
3633 }
|
|
3634
|
|
3635
|
|
3636 static Lisp_Object
|
|
3637 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
|
|
3638 Lisp_Object firstonly, char *target_buffer)
|
|
3639 {
|
|
3640 /* This function can GC */
|
|
3641 Lisp_Object result = Qnil;
|
|
3642 int i;
|
|
3643 struct key_data raw[20];
|
|
3644 struct where_is_closure c;
|
|
3645
|
|
3646 c.definition = definition;
|
|
3647 c.shadow = maps;
|
|
3648 c.firstonly = !NILP (firstonly);
|
|
3649 c.target_buffer = target_buffer;
|
|
3650 c.keys_so_far = raw;
|
|
3651 c.keys_so_far_total_size = countof (raw);
|
|
3652 c.keys_so_far_malloced = 0;
|
|
3653
|
|
3654 /* Loop over each of the maps, accumulating the keys found.
|
|
3655 For each map searched, all previous maps shadow this one
|
|
3656 so that bogus keys aren't listed. */
|
|
3657 for (i = 0; i < nmaps; i++)
|
|
3658 {
|
|
3659 Lisp_Object this_result;
|
|
3660 c.shadow_count = i;
|
|
3661 /* Reset the things set in each iteration */
|
|
3662 c.keys_count = 0;
|
|
3663 c.modifiers_so_far = 0;
|
|
3664
|
|
3665 this_result = traverse_keymaps (maps[i], Qnil, where_is_recursive_mapper,
|
|
3666 &c);
|
|
3667 if (!NILP (firstonly))
|
|
3668 {
|
|
3669 result = this_result;
|
|
3670 if (!NILP (result))
|
|
3671 break;
|
|
3672 }
|
|
3673 else
|
|
3674 result = nconc2 (this_result, result);
|
|
3675 }
|
|
3676
|
|
3677 if (NILP (firstonly))
|
|
3678 result = Fnreverse (result);
|
|
3679
|
|
3680 if (c.keys_so_far_malloced)
|
|
3681 xfree (c.keys_so_far);
|
|
3682 return (result);
|
|
3683 }
|
|
3684
|
|
3685
|
|
3686 /************************************************************************/
|
|
3687 /* Describing keymaps */
|
|
3688 /************************************************************************/
|
|
3689
|
|
3690 DEFUN ("describe-bindings-internal",
|
|
3691 Fdescribe_bindings_internal, Sdescribe_bindings_internal, 1, 5, 0 /*
|
|
3692 Insert a list of all defined keys and their definitions in MAP.
|
|
3693 Optional second argument ALL says whether to include even \"uninteresting\"
|
|
3694 definitions (ie symbols with a non-nil `suppress-keymap' property.
|
|
3695 Third argument SHADOW is a list of keymaps whose bindings shadow those
|
|
3696 of map; if a binding is present in any shadowing map, it is not printed.
|
|
3697 Fourth argument PREFIX, if non-nil, should be a key sequence;
|
|
3698 only bindings which start with that key sequence will be printed.
|
|
3699 Fifth argument MOUSE-ONLY-P says to only print bindings for mouse clicks.
|
|
3700 */ )
|
|
3701 (map, all, shadow, prefix, mouse_only_p)
|
|
3702 Lisp_Object map, all, shadow, prefix, mouse_only_p;
|
|
3703 {
|
|
3704 /* This function can GC */
|
|
3705 describe_map_tree (map, NILP (all), shadow, prefix,
|
|
3706 !NILP (mouse_only_p));
|
|
3707 return (Qnil);
|
|
3708 }
|
|
3709
|
|
3710
|
|
3711 /* Insert a desription of the key bindings in STARTMAP,
|
|
3712 followed by those of all maps reachable through STARTMAP.
|
|
3713 If PARTIAL is nonzero, omit certain "uninteresting" commands
|
|
3714 (such as `undefined').
|
|
3715 If SHADOW is non-nil, it is a list of other maps;
|
|
3716 don't mention keys which would be shadowed by any of them
|
|
3717 If PREFIX is non-nil, only list bindings which start with those keys
|
|
3718 */
|
|
3719
|
|
3720 void
|
|
3721 describe_map_tree (Lisp_Object startmap, int partial, Lisp_Object shadow,
|
|
3722 Lisp_Object prefix, int mice_only_p)
|
|
3723 {
|
|
3724 /* This function can GC */
|
|
3725 Lisp_Object maps = Qnil;
|
|
3726 struct gcpro gcpro1, gcpro2; /* get_keymap may autoload */
|
|
3727 GCPRO2 (maps, shadow);
|
|
3728
|
|
3729 maps = Faccessible_keymaps (startmap, prefix);
|
|
3730
|
|
3731 for (; !NILP (maps); maps = Fcdr (maps))
|
|
3732 {
|
|
3733 Lisp_Object sub_shadow = Qnil;
|
|
3734 Lisp_Object elt = Fcar (maps);
|
|
3735 Lisp_Object tail = shadow;
|
|
3736 int no_prefix = (VECTORP (Fcar (elt))
|
|
3737 && XINT (Flength (Fcar (elt))) == 0);
|
|
3738 struct gcpro ngcpro1, ngcpro2, ngcpro3;
|
|
3739 NGCPRO3 (sub_shadow, elt, tail);
|
|
3740
|
|
3741 for (; CONSP (tail); tail = XCDR (tail))
|
|
3742 {
|
|
3743 Lisp_Object sh = XCAR (tail);
|
|
3744
|
|
3745 /* If the sequence by which we reach this keymap is zero-length,
|
|
3746 then the shadow maps for this keymap are just SHADOW. */
|
|
3747 if (no_prefix)
|
|
3748 ;
|
|
3749 /* If the sequence by which we reach this keymap actually has
|
|
3750 some elements, then the sequence's definition in SHADOW is
|
|
3751 what we should use. */
|
|
3752 else
|
|
3753 {
|
|
3754 sh = Flookup_key (sh, Fcar (elt), Qt);
|
|
3755 if (CHARP (sh))
|
|
3756 sh = Qnil;
|
|
3757 }
|
|
3758
|
|
3759 if (!NILP (sh))
|
|
3760 {
|
|
3761 Lisp_Object shm = get_keymap (sh, 0, 1);
|
|
3762 if (!KEYMAPP (shm))
|
|
3763 /* If sh is not nil and not a keymap, it completely shadows
|
|
3764 this map, so don't describe this map at all. */
|
|
3765 goto SKIP;
|
|
3766 sub_shadow = Fcons (shm, sub_shadow);
|
|
3767 }
|
|
3768 }
|
|
3769
|
|
3770 {
|
|
3771 /* Describe the contents of map MAP, assuming that this map
|
|
3772 itself is reached by the sequence of prefix keys KEYS (a vector).
|
|
3773 PARTIAL and SHADOW are as in `describe_map_tree'. */
|
|
3774 Lisp_Object keysdesc
|
|
3775 = ((!no_prefix)
|
|
3776 ? concat2 (Fkey_description (Fcar (elt)), Vsingle_space_string)
|
|
3777 : Qnil);
|
|
3778 describe_map (Fcdr (elt), keysdesc,
|
|
3779 describe_command,
|
|
3780 partial,
|
|
3781 sub_shadow,
|
|
3782 mice_only_p);
|
|
3783 }
|
|
3784 SKIP:
|
|
3785 NUNGCPRO;
|
|
3786 }
|
|
3787 UNGCPRO;
|
|
3788 }
|
|
3789
|
|
3790
|
|
3791 static void
|
|
3792 describe_command (Lisp_Object definition)
|
|
3793 {
|
|
3794 /* This function can GC */
|
|
3795 Lisp_Object buffer;
|
|
3796 int keymapp = !NILP (Fkeymapp (definition));
|
|
3797 struct gcpro gcpro1, gcpro2;
|
|
3798 GCPRO2 (definition, buffer);
|
|
3799
|
|
3800 XSETBUFFER (buffer, current_buffer);
|
|
3801 Findent_to (make_int (16), make_int (3), buffer);
|
|
3802 if (keymapp)
|
|
3803 buffer_insert_c_string (XBUFFER (buffer), "<< ");
|
|
3804
|
|
3805 if (SYMBOLP (definition))
|
|
3806 {
|
|
3807 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (definition));
|
|
3808 }
|
|
3809 else if (STRINGP (definition) || VECTORP (definition))
|
|
3810 {
|
|
3811 buffer_insert_c_string (XBUFFER (buffer), "Kbd Macro: ");
|
|
3812 buffer_insert1 (XBUFFER (buffer), Fkey_description (definition));
|
|
3813 }
|
|
3814 else if (COMPILED_FUNCTIONP (definition))
|
|
3815 buffer_insert_c_string (XBUFFER (buffer), "Anonymous Compiled Function");
|
|
3816 else if (CONSP (definition) && EQ (XCAR (definition), Qlambda))
|
|
3817 buffer_insert_c_string (XBUFFER (buffer), "Anonymous Lambda");
|
|
3818 else if (KEYMAPP (definition))
|
|
3819 {
|
|
3820 Lisp_Object name = XKEYMAP (definition)->name;
|
|
3821 if (STRINGP (name) || (SYMBOLP (name) && !NILP (name)))
|
|
3822 {
|
|
3823 buffer_insert_c_string (XBUFFER (buffer), "Prefix command ");
|
|
3824 if (SYMBOLP (name)
|
|
3825 && EQ (find_symbol_value (name), definition))
|
|
3826 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (name));
|
|
3827 else
|
|
3828 {
|
|
3829 buffer_insert1 (XBUFFER (buffer), Fprin1_to_string (name, Qnil));
|
|
3830 }
|
|
3831 }
|
|
3832 else
|
|
3833 buffer_insert_c_string (XBUFFER (buffer), "Prefix Command");
|
|
3834 }
|
|
3835 else
|
|
3836 buffer_insert_c_string (XBUFFER (buffer), "??");
|
|
3837
|
|
3838 if (keymapp)
|
|
3839 buffer_insert_c_string (XBUFFER (buffer), " >>");
|
|
3840 buffer_insert_c_string (XBUFFER (buffer), "\n");
|
|
3841 UNGCPRO;
|
|
3842 }
|
|
3843
|
|
3844 struct describe_map_closure
|
|
3845 {
|
|
3846 Lisp_Object *list; /* pointer to the list to update */
|
|
3847 Lisp_Object partial; /* whether to ignore suppressed commands */
|
|
3848 Lisp_Object shadow; /* list of maps shadowing this one */
|
|
3849 Lisp_Object self; /* this map */
|
|
3850 Lisp_Object self_root; /* this map, or some map that has this map as
|
|
3851 a parent. this is the base of the tree */
|
|
3852 int mice_only_p; /* whether we are to display only button bindings */
|
|
3853 };
|
|
3854
|
|
3855 struct describe_map_shadow_closure
|
|
3856 {
|
|
3857 CONST struct key_data *raw_key;
|
|
3858 Lisp_Object self;
|
|
3859 };
|
|
3860
|
|
3861 static Lisp_Object
|
|
3862 describe_map_mapper_shadow_search (Lisp_Object map, void *arg)
|
|
3863 {
|
|
3864 struct describe_map_shadow_closure *c = arg;
|
|
3865
|
|
3866 if (EQ (map, c->self))
|
|
3867 return (Qzero); /* Not shadowed; terminate search */
|
|
3868 else if (!NILP (keymap_lookup_directly (map,
|
|
3869 c->raw_key->keysym,
|
|
3870 c->raw_key->modifiers)))
|
|
3871 return (Qt);
|
|
3872 else
|
|
3873 return (Qnil);
|
|
3874 }
|
|
3875
|
|
3876
|
|
3877 static Lisp_Object
|
|
3878 keymap_lookup_inherited_mapper (Lisp_Object km, void *arg)
|
|
3879 {
|
|
3880 struct key_data *k = arg;
|
|
3881 return (keymap_lookup_directly (km, k->keysym, k->modifiers));
|
|
3882 }
|
|
3883
|
|
3884
|
|
3885 static void
|
|
3886 describe_map_mapper (CONST struct key_data *key,
|
|
3887 Lisp_Object binding,
|
|
3888 void *describe_map_closure)
|
|
3889 {
|
|
3890 /* This function can GC */
|
|
3891 struct describe_map_closure *closure = describe_map_closure;
|
|
3892 Lisp_Object keysym = key->keysym;
|
|
3893 unsigned int modifiers = key->modifiers;
|
|
3894
|
|
3895 /* Dont mention suppressed commands. */
|
|
3896 if (SYMBOLP (binding)
|
|
3897 && !NILP (closure->partial)
|
|
3898 && !NILP (Fget (binding, closure->partial, Qnil)))
|
|
3899 return;
|
|
3900
|
|
3901 /* If we're only supposed to display mouse bindings and this isn't one,
|
|
3902 then bug out. */
|
|
3903 if (closure->mice_only_p &&
|
|
3904 (! (EQ (keysym, Qbutton0) || EQ (keysym, Qbutton1)
|
|
3905 || EQ (keysym, Qbutton2) || EQ (keysym, Qbutton3)
|
|
3906 || EQ (keysym, Qbutton4) || EQ (keysym, Qbutton5)
|
|
3907 || EQ (keysym, Qbutton6) || EQ (keysym, Qbutton7))))
|
|
3908 return;
|
|
3909
|
|
3910 /* If this command in this map is shadowed by some other map, ignore it. */
|
|
3911 {
|
|
3912 Lisp_Object tail;
|
|
3913
|
|
3914 for (tail = closure->shadow; CONSP (tail); tail = XCDR (tail))
|
|
3915 {
|
|
3916 QUIT;
|
|
3917 if (!NILP (traverse_keymaps (XCAR (tail), Qnil,
|
|
3918 keymap_lookup_inherited_mapper,
|
|
3919 /* Cast to discard `const' */
|
|
3920 (void *)key)))
|
|
3921 return;
|
|
3922 }
|
|
3923 }
|
|
3924
|
|
3925 /* If this key is in some map of which this map is a parent, then ignore
|
|
3926 it (in that case, it has been shadowed).
|
|
3927 */
|
|
3928 {
|
|
3929 Lisp_Object sh;
|
|
3930 struct describe_map_shadow_closure c;
|
|
3931 c.raw_key = key;
|
|
3932 c.self = closure->self;
|
|
3933
|
|
3934 sh = traverse_keymaps (closure->self_root, Qnil,
|
|
3935 describe_map_mapper_shadow_search, &c);
|
|
3936 if (!NILP (sh) && !ZEROP (sh))
|
|
3937 return;
|
|
3938 }
|
|
3939
|
|
3940 /* Otherwise add it to the list to be sorted. */
|
|
3941 *(closure->list) = Fcons (Fcons (Fcons (keysym, make_int (modifiers)),
|
|
3942 binding),
|
|
3943 *(closure->list));
|
|
3944 }
|
|
3945
|
|
3946
|
|
3947 static int
|
|
3948 describe_map_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
|
|
3949 Lisp_Object pred)
|
|
3950 {
|
|
3951 /* obj1 and obj2 are conses of the form
|
|
3952 ( ( <keysym> . <modifiers> ) . <binding> )
|
|
3953 keysym and modifiers are used, binding is ignored.
|
|
3954 */
|
|
3955 unsigned int bit1, bit2;
|
|
3956 obj1 = XCAR (obj1);
|
|
3957 obj2 = XCAR (obj2);
|
|
3958 bit1 = XINT (XCDR (obj1));
|
|
3959 bit2 = XINT (XCDR (obj2));
|
|
3960 if (bit1 != bit2)
|
|
3961 return ((bit1 < bit2) ? 1 : -1);
|
|
3962 else
|
|
3963 return map_keymap_sort_predicate (obj1, obj2, pred);
|
|
3964 }
|
|
3965
|
|
3966 /* Elide 2 or more consecutive numeric keysyms bound to the same thing,
|
|
3967 or 2 or more symbolic keysyms that are bound to the same thing and
|
|
3968 have consecutive character-set-properties.
|
|
3969 */
|
|
3970 static int
|
|
3971 elide_next_two_p (Lisp_Object list)
|
|
3972 {
|
|
3973 Lisp_Object s1, s2;
|
|
3974
|
|
3975 if (NILP (XCDR (list)))
|
|
3976 return 0;
|
|
3977
|
|
3978 /* next two bindings differ */
|
|
3979 if (!EQ (XCDR (XCAR (list)),
|
|
3980 XCDR (XCAR (XCDR (list)))))
|
|
3981 return 0;
|
|
3982
|
|
3983 /* next two modifier-sets differ */
|
|
3984 if (!EQ (XCDR (XCAR (XCAR (list))),
|
|
3985 XCDR (XCAR (XCAR (XCDR (list))))))
|
|
3986 return 0;
|
|
3987
|
|
3988 s1 = XCAR (XCAR (XCAR (list)));
|
|
3989 s2 = XCAR (XCAR (XCAR (XCDR (list))));
|
|
3990
|
|
3991 if (SYMBOLP (s1))
|
|
3992 {
|
|
3993 Lisp_Object code = Fget (s1, Vcharacter_set_property, Qnil);
|
|
3994 if (INTP (code)) s1 = code;
|
|
3995 else return 0;
|
|
3996 }
|
|
3997 if (SYMBOLP (s2))
|
|
3998 {
|
|
3999 Lisp_Object code = Fget (s2, Vcharacter_set_property, Qnil);
|
|
4000 if (INTP (code)) s2 = code;
|
|
4001 else return 0;
|
|
4002 }
|
|
4003
|
|
4004 if (XCHAR (s1) == XCHAR (s2) ||
|
|
4005 XCHAR (s1) + 1 == XCHAR (s2))
|
|
4006 return 1;
|
|
4007 return 0;
|
|
4008 }
|
|
4009
|
|
4010
|
|
4011 static Lisp_Object
|
|
4012 describe_map_parent_mapper (Lisp_Object keymap, void *arg)
|
|
4013 {
|
|
4014 /* This function can GC */
|
|
4015 struct describe_map_closure *describe_map_closure = arg;
|
|
4016 describe_map_closure->self = keymap;
|
|
4017 map_keymap (XKEYMAP (keymap)->table,
|
|
4018 0, /* don't sort: we'll do it later */
|
|
4019 describe_map_mapper, describe_map_closure);
|
|
4020 return (Qnil);
|
|
4021 }
|
|
4022
|
|
4023
|
|
4024 static void
|
|
4025 describe_map (Lisp_Object keymap, Lisp_Object elt_prefix,
|
|
4026 void (*elt_describer) (Lisp_Object),
|
|
4027 int partial,
|
|
4028 Lisp_Object shadow,
|
|
4029 int mice_only_p)
|
|
4030 {
|
|
4031 /* This function can GC */
|
|
4032 struct describe_map_closure describe_map_closure;
|
|
4033 Lisp_Object list = Qnil;
|
|
4034 struct buffer *buf = current_buffer;
|
|
4035 Emchar printable_min = (CHAR_OR_CHAR_INTP (buf->ctl_arrow)
|
|
4036 ? XCHAR_OR_CHAR_INT (buf->ctl_arrow)
|
|
4037 : ((EQ (buf->ctl_arrow, Qt)
|
|
4038 || EQ (buf->ctl_arrow, Qnil))
|
|
4039 ? 256 : 160));
|
|
4040 int elided = 0;
|
|
4041 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
4042
|
|
4043 keymap = get_keymap (keymap, 1, 1);
|
|
4044 describe_map_closure.partial = (partial ? Qsuppress_keymap : Qnil);
|
|
4045 describe_map_closure.shadow = shadow;
|
|
4046 describe_map_closure.list = &list;
|
|
4047 describe_map_closure.self_root = keymap;
|
|
4048 describe_map_closure.mice_only_p = mice_only_p;
|
|
4049
|
|
4050 GCPRO4 (keymap, elt_prefix, shadow, list);
|
|
4051
|
|
4052 traverse_keymaps (keymap, Qnil,
|
|
4053 describe_map_parent_mapper, &describe_map_closure);
|
|
4054
|
|
4055 if (!NILP (list))
|
|
4056 {
|
|
4057 list = list_sort (list, Qnil, describe_map_sort_predicate);
|
|
4058 buffer_insert_c_string (buf, "\n");
|
|
4059 while (!NILP (list))
|
|
4060 {
|
|
4061 Lisp_Object elt = XCAR (XCAR (list));
|
|
4062 Lisp_Object keysym = XCAR (elt);
|
|
4063 unsigned int modifiers = XINT (XCDR (elt));
|
|
4064
|
|
4065 if (!NILP (elt_prefix))
|
|
4066 buffer_insert_lisp_string (buf, elt_prefix);
|
|
4067
|
|
4068 if (modifiers & MOD_META) buffer_insert_c_string (buf, "M-");
|
|
4069 if (modifiers & MOD_CONTROL) buffer_insert_c_string (buf, "C-");
|
|
4070 if (modifiers & MOD_SUPER) buffer_insert_c_string (buf, "S-");
|
|
4071 if (modifiers & MOD_HYPER) buffer_insert_c_string (buf, "H-");
|
|
4072 if (modifiers & MOD_ALT) buffer_insert_c_string (buf, "Alt-");
|
|
4073 if (modifiers & MOD_SHIFT) buffer_insert_c_string (buf, "Sh-");
|
|
4074 if (SYMBOLP (keysym))
|
|
4075 {
|
|
4076 Lisp_Object code = Fget (keysym, Vcharacter_set_property, Qnil);
|
|
4077 Emchar c = (CHAR_OR_CHAR_INTP (code)
|
|
4078 ? XCHAR_OR_CHAR_INT (code) : -1);
|
|
4079 /* Calling Fsingle_key_description() would cons more */
|
|
4080 #if 0 /* This is bogus */
|
|
4081 if (EQ (keysym, QKlinefeed))
|
|
4082 buffer_insert_c_string (buf, "LFD");
|
|
4083 else if (EQ (keysym, QKtab))
|
|
4084 buffer_insert_c_string (buf, "TAB");
|
|
4085 else if (EQ (keysym, QKreturn))
|
|
4086 buffer_insert_c_string (buf, "RET");
|
|
4087 else if (EQ (keysym, QKescape))
|
|
4088 buffer_insert_c_string (buf, "ESC");
|
|
4089 else if (EQ (keysym, QKdelete))
|
|
4090 buffer_insert_c_string (buf, "DEL");
|
|
4091 else if (EQ (keysym, QKspace))
|
|
4092 buffer_insert_c_string (buf, "SPC");
|
|
4093 else if (EQ (keysym, QKbackspace))
|
|
4094 buffer_insert_c_string (buf, "BS");
|
|
4095 else
|
|
4096 #endif
|
|
4097 if (c >= printable_min)
|
|
4098 buffer_insert_emacs_char (buf, c);
|
|
4099 else buffer_insert1 (buf, Fsymbol_name (keysym));
|
|
4100 }
|
|
4101 else if (CHARP (keysym))
|
|
4102 buffer_insert_emacs_char (buf, XCHAR (keysym));
|
|
4103 else
|
|
4104 buffer_insert_c_string (buf, "---bad keysym---");
|
|
4105
|
|
4106 if (elided)
|
|
4107 elided = 0;
|
|
4108 else
|
|
4109 {
|
|
4110 int k = 0;
|
|
4111
|
|
4112 while (elide_next_two_p (list))
|
|
4113 {
|
|
4114 k++;
|
|
4115 list = XCDR (list);
|
|
4116 }
|
|
4117 if (k != 0)
|
|
4118 {
|
|
4119 if (k == 1)
|
|
4120 buffer_insert_c_string (buf, ", ");
|
|
4121 else
|
|
4122 buffer_insert_c_string (buf, " .. ");
|
|
4123 elided = 1;
|
|
4124 continue;
|
|
4125 }
|
|
4126 }
|
|
4127
|
|
4128 /* Print a description of the definition of this character. */
|
|
4129 (*elt_describer) (XCDR (XCAR (list)));
|
|
4130 list = XCDR (list);
|
|
4131 }
|
|
4132 }
|
|
4133 UNGCPRO;
|
|
4134 }
|
|
4135
|
|
4136
|
|
4137 void
|
|
4138 syms_of_keymap (void)
|
|
4139 {
|
|
4140 defsymbol (&Qminor_mode_map_alist, "minor-mode-map-alist");
|
|
4141
|
|
4142 defsymbol (&Qkeymapp, "keymapp");
|
|
4143
|
|
4144 defsymbol (&Qsuppress_keymap, "suppress-keymap");
|
|
4145
|
|
4146 defsymbol (&Qmodeline_map, "modeline-map");
|
|
4147 defsymbol (&Qtoolbar_map, "toolbar-map");
|
|
4148
|
|
4149 defsubr (&Skeymap_parents);
|
|
4150 defsubr (&Sset_keymap_parents);
|
|
4151 defsubr (&Skeymap_name);
|
|
4152 defsubr (&Sset_keymap_name);
|
|
4153 defsubr (&Skeymap_prompt);
|
|
4154 defsubr (&Sset_keymap_prompt);
|
|
4155 defsubr (&Skeymap_default_binding);
|
|
4156 defsubr (&Sset_keymap_default_binding);
|
|
4157
|
|
4158 defsubr (&Skeymapp);
|
|
4159 defsubr (&Smake_keymap);
|
|
4160 defsubr (&Smake_sparse_keymap);
|
|
4161
|
|
4162 defsubr (&Scopy_keymap);
|
|
4163 defsubr (&Skeymap_fullness);
|
|
4164 defsubr (&Smap_keymap);
|
|
4165 defsubr (&Sevent_matches_key_specifier_p);
|
|
4166 defsubr (&Sdefine_key);
|
|
4167 defsubr (&Slookup_key);
|
|
4168 defsubr (&Skey_binding);
|
|
4169 defsubr (&Suse_global_map);
|
|
4170 defsubr (&Suse_local_map);
|
|
4171 defsubr (&Scurrent_local_map);
|
|
4172 defsubr (&Scurrent_global_map);
|
|
4173 defsubr (&Scurrent_keymaps);
|
|
4174 defsubr (&Saccessible_keymaps);
|
|
4175 defsubr (&Skey_description);
|
|
4176 defsubr (&Ssingle_key_description);
|
|
4177 defsubr (&Swhere_is_internal);
|
|
4178 defsubr (&Sdescribe_bindings_internal);
|
|
4179
|
|
4180 defsubr (&Stext_char_description);
|
|
4181
|
|
4182 defsymbol (&Qcontrol, "control");
|
|
4183 defsymbol (&Qctrl, "ctrl");
|
|
4184 defsymbol (&Qmeta, "meta");
|
|
4185 defsymbol (&Qsuper, "super");
|
|
4186 defsymbol (&Qhyper, "hyper");
|
|
4187 defsymbol (&Qalt, "alt");
|
|
4188 defsymbol (&Qshift, "shift");
|
|
4189 defsymbol (&Qbutton0, "button0");
|
|
4190 defsymbol (&Qbutton1, "button1");
|
|
4191 defsymbol (&Qbutton2, "button2");
|
|
4192 defsymbol (&Qbutton3, "button3");
|
|
4193 defsymbol (&Qbutton4, "button4");
|
|
4194 defsymbol (&Qbutton5, "button5");
|
|
4195 defsymbol (&Qbutton6, "button6");
|
|
4196 defsymbol (&Qbutton7, "button7");
|
|
4197 defsymbol (&Qbutton0up, "button0up");
|
|
4198 defsymbol (&Qbutton1up, "button1up");
|
|
4199 defsymbol (&Qbutton2up, "button2up");
|
|
4200 defsymbol (&Qbutton3up, "button3up");
|
|
4201 defsymbol (&Qbutton4up, "button4up");
|
|
4202 defsymbol (&Qbutton5up, "button5up");
|
|
4203 defsymbol (&Qbutton6up, "button6up");
|
|
4204 defsymbol (&Qbutton7up, "button7up");
|
|
4205 defsymbol (&Qmenu_selection, "menu-selection");
|
|
4206 defsymbol (&QLFD, "LFD");
|
|
4207 defsymbol (&QTAB, "TAB");
|
|
4208 defsymbol (&QRET, "RET");
|
|
4209 defsymbol (&QESC, "ESC");
|
|
4210 defsymbol (&QDEL, "DEL");
|
|
4211 defsymbol (&QBS, "BS");
|
|
4212 }
|
|
4213
|
|
4214 void
|
|
4215 vars_of_keymap (void)
|
|
4216 {
|
|
4217 DEFVAR_LISP ("meta-prefix-char", &Vmeta_prefix_char /*
|
|
4218 Meta-prefix character.
|
|
4219 This character followed by some character `foo' turns into `Meta-foo'.
|
|
4220 This can be any form recognized as a single key specifier.
|
|
4221 To disable the meta-prefix-char, set it to a negative number.
|
|
4222 */ );
|
|
4223 Vmeta_prefix_char = make_char (033);
|
|
4224
|
|
4225 DEFVAR_LISP ("mouse-grabbed-buffer", &Vmouse_grabbed_buffer /*
|
|
4226 A buffer which should be consulted first for all mouse activity.
|
|
4227 When a mouse-click is processed, it will first be looked up in the
|
|
4228 local-map of this buffer, and then through the normal mechanism if there
|
|
4229 is no binding for that click. This buffer's value of `mode-motion-hook'
|
|
4230 will be consulted instead of the `mode-motion-hook' of the buffer of the
|
|
4231 window under the mouse. You should *bind* this, not set it.
|
|
4232 */ );
|
|
4233 Vmouse_grabbed_buffer = Qnil;
|
|
4234
|
|
4235 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map /*
|
|
4236 Keymap that overrides all other local keymaps.
|
|
4237 If this variable is non-nil, it is used as a keymap instead of the
|
|
4238 buffer's local map, and the minor mode keymaps and extent-local keymaps.
|
|
4239 You should *bind* this, not set it.
|
|
4240 */ );
|
|
4241 Voverriding_local_map = Qnil;
|
|
4242
|
|
4243 Fset (Qminor_mode_map_alist, Qnil);
|
|
4244
|
|
4245 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map /*
|
|
4246 Keymap of key translations that can override keymaps.
|
|
4247 This keymap works like `function-key-map', but comes after that,
|
|
4248 and applies even for keys that have ordinary bindings.
|
|
4249 */ );
|
|
4250
|
|
4251 DEFVAR_INT ("keymap-tick", &keymap_tick /*
|
|
4252 Incremented for each change to any keymap.
|
|
4253 */ );
|
|
4254 keymap_tick = 0;
|
|
4255
|
|
4256 staticpro (&Vcurrent_global_map);
|
|
4257
|
|
4258 Vsingle_space_string = make_pure_string ((CONST Bufbyte *) " ", 1, Qnil, 1);
|
|
4259 staticpro (&Vsingle_space_string);
|
|
4260 }
|
|
4261
|
|
4262 void
|
|
4263 complex_vars_of_keymap (void)
|
|
4264 {
|
|
4265 /* This function can GC */
|
|
4266 Lisp_Object ESC_prefix = intern ("ESC-prefix");
|
|
4267 Lisp_Object meta_disgustitute;
|
|
4268
|
|
4269 Vcurrent_global_map = Fmake_keymap (Qnil);
|
|
4270
|
|
4271 meta_disgustitute = Fmake_keymap (Qnil);
|
|
4272 Ffset (ESC_prefix, meta_disgustitute);
|
|
4273 /* no need to protect meta_disgustitute, though */
|
|
4274 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (MOD_META),
|
|
4275 XKEYMAP (Vcurrent_global_map),
|
|
4276 meta_disgustitute);
|
|
4277 XKEYMAP (Vcurrent_global_map)->sub_maps_cache = Qt;
|
|
4278
|
|
4279 Vkey_translation_map = Fmake_sparse_keymap (intern ("key-translation-map"));
|
|
4280 }
|