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,
|
8
|
1256 Lisp_Object *keysym, unsigned int modifiers)
|
0
|
1257 {
|
|
1258 /* Now, check and massage the trailing keysym specifier. */
|
8
|
1259 if (SYMBOLP (*keysym))
|
0
|
1260 {
|
8
|
1261 if (string_length (XSYMBOL (*keysym)->name) == 1)
|
0
|
1262 {
|
8
|
1263 *keysym = make_int (string_char (XSYMBOL (*keysym)->name, 0));
|
0
|
1264 goto fixnum_keysym;
|
|
1265 }
|
|
1266 }
|
8
|
1267 else if (INTP (*keysym))
|
0
|
1268 {
|
|
1269 fixnum_keysym:
|
8
|
1270 if (XINT (*keysym) < ' ' || XINT (*keysym) > 255)
|
0
|
1271 signal_simple_error ("keysym must be in the range 32 - 255",
|
8
|
1272 *keysym);
|
0
|
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",
|
8
|
1281 *keysym);
|
|
1282 }
|
|
1283
|
|
1284 /* Code semi-snarfed from v20. */
|
|
1285 if (SYMBOLP (*keysym))
|
|
1286 {
|
|
1287 char *name = (char *)
|
|
1288 string_data (XSYMBOL (*keysym)->name);
|
|
1289
|
|
1290 if (!strncmp(name, "kp_", 3)) {
|
|
1291 /* Likewise, the obsolete keysym binding of kp_.* should not lose. */
|
|
1292 char temp[50];
|
|
1293
|
|
1294 strncpy(temp, name, sizeof (temp));
|
|
1295 temp[sizeof (temp) - 1] = '\0';
|
|
1296 temp[2] = '-';
|
|
1297 *keysym = Fintern_soft(make_string(temp, strlen(temp)), Qnil);
|
|
1298 }
|
0
|
1299 }
|
|
1300 }
|
|
1301
|
|
1302 /* Given any kind of key-specifier, return a keysym and modifier mask.
|
|
1303 */
|
|
1304 static void
|
|
1305 define_key_parser (Lisp_Object spec, struct key_data *returned_value)
|
|
1306 {
|
|
1307 if (INTP (spec))
|
|
1308 {
|
|
1309 struct Lisp_Event event;
|
|
1310 event.event_type = empty_event;
|
|
1311 character_to_event (XINT (spec), &event,
|
|
1312 XCONSOLE (Vselected_console), 0);
|
|
1313 returned_value->keysym = event.event.key.keysym;
|
|
1314 returned_value->modifiers = event.event.key.modifiers;
|
|
1315 }
|
|
1316 else if (EVENTP (spec))
|
|
1317 {
|
|
1318 switch (XEVENT (spec)->event_type)
|
|
1319 {
|
|
1320 case key_press_event:
|
|
1321 {
|
|
1322 returned_value->keysym = XEVENT (spec)->event.key.keysym;
|
|
1323 returned_value->modifiers = XEVENT (spec)->event.key.modifiers;
|
|
1324 break;
|
|
1325 }
|
|
1326 case button_press_event:
|
|
1327 case button_release_event:
|
|
1328 {
|
|
1329 int down = (XEVENT (spec)->event_type == button_press_event);
|
|
1330 switch (XEVENT (spec)->event.button.button)
|
|
1331 {
|
|
1332 case 1:
|
|
1333 returned_value->keysym = (down ? Qbutton1 : Qbutton1up); break;
|
|
1334 case 2:
|
|
1335 returned_value->keysym = (down ? Qbutton2 : Qbutton2up); break;
|
|
1336 case 3:
|
|
1337 returned_value->keysym = (down ? Qbutton3 : Qbutton3up); break;
|
|
1338 case 4:
|
|
1339 returned_value->keysym = (down ? Qbutton4 : Qbutton4up); break;
|
|
1340 case 5:
|
|
1341 returned_value->keysym = (down ? Qbutton5 : Qbutton5up); break;
|
|
1342 case 6:
|
|
1343 returned_value->keysym = (down ? Qbutton6 : Qbutton6up); break;
|
|
1344 case 7:
|
|
1345 returned_value->keysym = (down ? Qbutton7 : Qbutton7up); break;
|
|
1346 default:
|
|
1347 returned_value->keysym =(down ? Qbutton0 : Qbutton0up); break;
|
|
1348 }
|
|
1349 returned_value->modifiers = XEVENT (spec)->event.button.modifiers;
|
|
1350 break;
|
|
1351 }
|
|
1352 default:
|
|
1353 signal_error (Qwrong_type_argument,
|
|
1354 list2 (build_translated_string
|
|
1355 ("unable to bind this type of event"),
|
|
1356 spec));
|
|
1357 }
|
|
1358 }
|
|
1359 else if (SYMBOLP (spec))
|
|
1360 {
|
|
1361 /* Be nice, allow = to mean (=) */
|
|
1362 if (bucky_sym_to_bucky_bit (spec) != 0)
|
|
1363 signal_simple_error ("Key is a modifier name", spec);
|
8
|
1364 define_key_check_keysym (spec, &spec, 0);
|
0
|
1365 returned_value->keysym = spec;
|
|
1366 returned_value->modifiers = 0;
|
|
1367 }
|
|
1368 else if (CONSP (spec))
|
|
1369 {
|
|
1370 unsigned int modifiers = 0;
|
|
1371 Lisp_Object keysym = Qnil;
|
|
1372 Lisp_Object rest = spec;
|
|
1373
|
|
1374 /* First, parse out the leading modifier symbols. */
|
|
1375 while (CONSP (rest))
|
|
1376 {
|
|
1377 unsigned int modifier;
|
|
1378
|
|
1379 keysym = XCAR (rest);
|
|
1380 modifier = bucky_sym_to_bucky_bit (keysym);
|
|
1381 modifiers |= modifier;
|
|
1382 if (!NILP (XCDR (rest)))
|
|
1383 {
|
|
1384 if (! modifier)
|
|
1385 signal_simple_error ("unknown modifier", keysym);
|
|
1386 }
|
|
1387 else
|
|
1388 {
|
|
1389 if (modifier)
|
|
1390 signal_simple_error ("nothing but modifiers here",
|
|
1391 spec);
|
|
1392 }
|
|
1393 rest = XCDR (rest);
|
|
1394 QUIT;
|
|
1395 }
|
|
1396 if (!NILP (rest))
|
|
1397 signal_simple_error ("dotted list", spec);
|
|
1398
|
8
|
1399 define_key_check_keysym (spec, &keysym, modifiers);
|
0
|
1400 returned_value->keysym = keysym;
|
|
1401 returned_value->modifiers = modifiers;
|
|
1402 }
|
|
1403 else
|
|
1404 {
|
|
1405 signal_simple_error ("unknown key-sequence specifier",
|
|
1406 spec);
|
|
1407 }
|
|
1408
|
|
1409 /* Convert single-character symbols into ints, since that's the
|
|
1410 way the events arrive from the keyboard... */
|
|
1411 if (SYMBOLP (returned_value->keysym) &&
|
|
1412 string_length (XSYMBOL (returned_value->keysym)->name) == 1)
|
|
1413 {
|
|
1414 returned_value->keysym =
|
|
1415 make_int (string_char (XSYMBOL (returned_value->keysym)->name, 0));
|
|
1416
|
|
1417 /* Detect bogus (user-provided) keysyms like '\?C-a;
|
|
1418 We can't do that for '\?M-a because that interferes with
|
|
1419 legitimate 8-bit input. */
|
|
1420 if (XINT (returned_value->keysym) < ' ' ||
|
|
1421 XINT (returned_value->keysym) > 255)
|
|
1422 signal_simple_error ("keysym must be in the range 32 - 255",
|
|
1423 returned_value->keysym);
|
|
1424 }
|
|
1425
|
|
1426 if (SYMBOLP (returned_value->keysym))
|
|
1427 {
|
|
1428 char *name = (char *) string_data (XSYMBOL (returned_value->keysym)->name);
|
|
1429
|
|
1430 /* FSFmacs uses symbols with the printed representation of keysyms in
|
|
1431 their names, like 'M-x, and we use the syntax '(meta x). So, to avoid
|
|
1432 confusion, notice the M-x syntax and signal an error - because
|
|
1433 otherwise it would be interpreted as a regular keysym, and would even
|
|
1434 show up in the list-buffers output, causing confusion to the naive.
|
|
1435
|
|
1436 We can get away with this because none of the X keysym names contain
|
|
1437 a hyphen (some contain underscore, however).
|
|
1438
|
|
1439 It might be useful to reject keysyms which are not x-valid-keysym-
|
|
1440 name-p, but that would interfere with various tricks we do to
|
|
1441 sanitize the Sun keyboards, and would make it trickier to
|
|
1442 conditionalize a .emacs file for multiple X servers.
|
|
1443 */
|
|
1444 if (((unsigned int) strlen (name) >= 2 && name[1] == '-')
|
|
1445 #if 1
|
|
1446 ||
|
|
1447 /* Ok, this is a bit more dubious - prevent people from doing things
|
|
1448 like (global-set-key 'RET 'something) because that will have the
|
|
1449 same problem as above. (Gag!) Maybe we should just silently
|
|
1450 accept these as aliases for the "real" names?
|
|
1451 */
|
|
1452 (string_length (XSYMBOL (returned_value->keysym)->name) < 4 &&
|
|
1453 (!strcmp (name, "LFD") ||
|
|
1454 !strcmp (name, "TAB") ||
|
|
1455 !strcmp (name, "RET") ||
|
|
1456 !strcmp (name, "ESC") ||
|
|
1457 !strcmp (name, "DEL") ||
|
|
1458 !strcmp (name, "SPC") ||
|
|
1459 !strcmp (name, "BS")))
|
|
1460 #endif /* unused */
|
|
1461 )
|
|
1462 signal_simple_error ("invalid keysym (see doc of define-key)",
|
|
1463 returned_value->keysym);
|
|
1464
|
|
1465 /* #### Ok, this is a bit more dubious - make people not lose if they
|
|
1466 do things like (global-set-key 'RET 'something) because that would
|
|
1467 otherwise have the same problem as above. (Gag!) We silently
|
|
1468 accept these as aliases for the "real" names.
|
|
1469 */
|
|
1470 else if (EQ (returned_value->keysym, QLFD))
|
|
1471 returned_value->keysym = QKlinefeed;
|
|
1472 else if (EQ (returned_value->keysym, QTAB))
|
|
1473 returned_value->keysym = QKtab;
|
|
1474 else if (EQ (returned_value->keysym, QRET))
|
|
1475 returned_value->keysym = QKreturn;
|
|
1476 else if (EQ (returned_value->keysym, QESC))
|
|
1477 returned_value->keysym = QKescape;
|
|
1478 else if (EQ (returned_value->keysym, QDEL))
|
|
1479 returned_value->keysym = QKdelete;
|
|
1480 else if (EQ (returned_value->keysym, QBS))
|
|
1481 returned_value->keysym = QKbackspace;
|
|
1482 }
|
|
1483 }
|
|
1484
|
|
1485 /* Used by character-to-event */
|
|
1486 void
|
|
1487 key_desc_list_to_event (Lisp_Object list, Lisp_Object event,
|
|
1488 int allow_menu_events)
|
|
1489 {
|
|
1490 struct key_data raw_key;
|
|
1491
|
|
1492 if (allow_menu_events &&
|
|
1493 CONSP (list) &&
|
|
1494 /* #### where the hell does this come from? */
|
|
1495 EQ (XCAR (list), Qmenu_selection))
|
|
1496 {
|
|
1497 Lisp_Object fn, arg;
|
|
1498 if (! NILP (Fcdr (Fcdr (list))))
|
|
1499 signal_simple_error ("invalid menu event desc", list);
|
|
1500 arg = Fcar (Fcdr (list));
|
|
1501 if (SYMBOLP (arg))
|
|
1502 fn = Qcall_interactively;
|
|
1503 else
|
|
1504 fn = Qeval;
|
|
1505 XSETFRAME (XEVENT (event)->channel, selected_frame ());
|
|
1506 XEVENT (event)->event_type = misc_user_event;
|
|
1507 XEVENT (event)->event.eval.function = fn;
|
|
1508 XEVENT (event)->event.eval.object = arg;
|
|
1509 return;
|
|
1510 }
|
|
1511
|
|
1512 define_key_parser (list, &raw_key);
|
|
1513
|
|
1514 if (EQ (raw_key.keysym, Qbutton0) || EQ (raw_key.keysym, Qbutton0up) ||
|
|
1515 EQ (raw_key.keysym, Qbutton1) || EQ (raw_key.keysym, Qbutton1up) ||
|
|
1516 EQ (raw_key.keysym, Qbutton2) || EQ (raw_key.keysym, Qbutton2up) ||
|
|
1517 EQ (raw_key.keysym, Qbutton3) || EQ (raw_key.keysym, Qbutton3up) ||
|
|
1518 EQ (raw_key.keysym, Qbutton4) || EQ (raw_key.keysym, Qbutton4up) ||
|
|
1519 EQ (raw_key.keysym, Qbutton5) || EQ (raw_key.keysym, Qbutton5up) ||
|
|
1520 EQ (raw_key.keysym, Qbutton6) || EQ (raw_key.keysym, Qbutton6up) ||
|
|
1521 EQ (raw_key.keysym, Qbutton7) || EQ (raw_key.keysym, Qbutton7up))
|
|
1522 error ("Mouse-clicks can't appear in saved keyboard macros.");
|
|
1523
|
|
1524 XEVENT (event)->channel = Vselected_console;
|
|
1525 XEVENT (event)->event_type = key_press_event;
|
|
1526 XEVENT (event)->event.key.keysym = raw_key.keysym;
|
|
1527 XEVENT (event)->event.key.modifiers = raw_key.modifiers;
|
|
1528 }
|
|
1529
|
|
1530
|
|
1531 int
|
|
1532 event_matches_key_specifier_p (struct Lisp_Event *event,
|
|
1533 Lisp_Object key_specifier)
|
|
1534 {
|
|
1535 Lisp_Object event2;
|
|
1536 int retval;
|
|
1537 struct gcpro gcpro1;
|
|
1538
|
|
1539 if (event->event_type != key_press_event || NILP (key_specifier) ||
|
|
1540 (INTP (key_specifier) && XINT (key_specifier) < 0))
|
|
1541 return 0;
|
|
1542
|
|
1543 /* if the specifier is an integer such as 27, then it should match
|
|
1544 both of the events 'escape' and 'control ['. Calling
|
|
1545 Fcharacter_to_event() will only match 'escape'. */
|
|
1546 if (INTP (key_specifier))
|
|
1547 return XINT (key_specifier) == event_to_character (event, 0, 0, 0);
|
|
1548
|
|
1549 /* Otherwise, we cannot call event_to_character() because we may
|
|
1550 be dealing with non-ASCII keystrokes. In any case, if I ask
|
|
1551 for 'control [' then I should get exactly that, and not
|
|
1552 'escape'.
|
|
1553
|
|
1554 However, we have to behave differently on TTY's, where 'control ['
|
|
1555 is silently converted into 'escape' by the keyboard driver.
|
|
1556 In this case, ASCII is the only thing we know about, so we have
|
|
1557 to compare the ASCII values. */
|
|
1558
|
|
1559 GCPRO1 (event2);
|
|
1560 event2 = Fmake_event ();
|
|
1561 Fcharacter_to_event (key_specifier, event2, Qnil, Qnil);
|
|
1562 if (XEVENT (event2)->event_type != key_press_event)
|
|
1563 retval = 0;
|
|
1564 else if (CONSOLE_TTY_P (XCONSOLE (EVENT_CHANNEL (event))))
|
|
1565 {
|
|
1566 int ch1, ch2;
|
|
1567
|
|
1568 ch1 = event_to_character (event, 0, 0, 0);
|
|
1569 ch2 = event_to_character (XEVENT (event2), 0, 0, 0);
|
|
1570 retval = (ch1 >= 0 && ch2 >= 0 && ch1 == ch2);
|
|
1571 }
|
|
1572 else if (EQ (event->event.key.keysym, XEVENT (event2)->event.key.keysym) &&
|
|
1573 event->event.key.modifiers == XEVENT (event2)->event.key.modifiers)
|
|
1574 retval = 1;
|
|
1575 else
|
|
1576 retval = 0;
|
|
1577 Fdeallocate_event (event2);
|
|
1578 UNGCPRO;
|
|
1579 return retval;
|
|
1580 }
|
|
1581
|
|
1582 static int
|
|
1583 meta_prefix_char_p (CONST struct key_data *key)
|
|
1584 {
|
|
1585 struct Lisp_Event event;
|
|
1586
|
|
1587 event.event_type = key_press_event;
|
|
1588 event.channel = Vselected_console;
|
|
1589 event.event.key.keysym = key->keysym;
|
|
1590 event.event.key.modifiers = key->modifiers;
|
|
1591 return event_matches_key_specifier_p (&event, Vmeta_prefix_char);
|
|
1592 }
|
|
1593
|
|
1594 DEFUN ("event-matches-key-specifier-p",
|
|
1595 Fevent_matches_key_specifier_p,
|
|
1596 Sevent_matches_key_specifier_p,
|
|
1597 2, 2, 0 /*
|
|
1598 Return non-nil if EVENT matches KEY-SPECIFIER.
|
|
1599 This can be useful, e.g., to determine if the user pressed `help-char' or
|
|
1600 `quit-char'.
|
|
1601 */ )
|
|
1602 (event, key_specifier)
|
|
1603 Lisp_Object event, key_specifier;
|
|
1604 {
|
|
1605 CHECK_LIVE_EVENT (event);
|
|
1606 return (event_matches_key_specifier_p (XEVENT (event), key_specifier)
|
|
1607 ? Qt : Qnil);
|
|
1608 }
|
|
1609
|
|
1610 /* ASCII grunge.
|
|
1611 Given a keysym, return another keysym/modifier pair which could be
|
|
1612 considered the same key in an ASCII world. Backspace returns ^H, for
|
|
1613 example.
|
|
1614 */
|
|
1615 static void
|
|
1616 define_key_alternate_name (struct key_data *key,
|
|
1617 struct key_data *returned_value)
|
|
1618 {
|
|
1619 Lisp_Object keysym = key->keysym;
|
|
1620 unsigned int modifiers = key->modifiers;
|
|
1621 unsigned int modifiers_sans_control = (modifiers & (~MOD_CONTROL));
|
|
1622 unsigned int modifiers_sans_meta = (modifiers & (~MOD_META));
|
|
1623 returned_value->keysym = Qnil; /* By default, no "alternate" key */
|
|
1624 returned_value->modifiers = 0;
|
|
1625 #define MACROLET(k,m) do { returned_value->keysym = (k); \
|
|
1626 returned_value->modifiers = (m); \
|
|
1627 RETURN__; } while (0)
|
|
1628 if (modifiers_sans_meta == MOD_CONTROL)
|
|
1629 {
|
|
1630 if EQ (keysym, QKspace)
|
|
1631 MACROLET (make_char ('@'), modifiers);
|
|
1632 else if (!CHARP (keysym))
|
|
1633 return;
|
|
1634 else switch (XCHAR (keysym))
|
|
1635 {
|
|
1636 case '@': /* c-@ => c-space */
|
|
1637 MACROLET (QKspace, modifiers);
|
|
1638 case 'h': /* c-h => backspace */
|
|
1639 MACROLET (QKbackspace, modifiers_sans_control);
|
|
1640 case 'i': /* c-i => tab */
|
|
1641 MACROLET (QKtab, modifiers_sans_control);
|
|
1642 case 'j': /* c-j => linefeed */
|
|
1643 MACROLET (QKlinefeed, modifiers_sans_control);
|
|
1644 case 'm': /* c-m => return */
|
|
1645 MACROLET (QKreturn, modifiers_sans_control);
|
|
1646 case '[': /* c-[ => escape */
|
|
1647 MACROLET (QKescape, modifiers_sans_control);
|
|
1648 default:
|
|
1649 return;
|
|
1650 }
|
|
1651 }
|
|
1652 else if (modifiers_sans_meta != 0)
|
|
1653 return;
|
|
1654 else if (EQ (keysym, QKbackspace)) /* backspace => c-h */
|
|
1655 MACROLET (make_char ('h'), (modifiers | MOD_CONTROL));
|
|
1656 else if (EQ (keysym, QKtab)) /* tab => c-i */
|
|
1657 MACROLET (make_char ('i'), (modifiers | MOD_CONTROL));
|
|
1658 else if (EQ (keysym, QKlinefeed)) /* linefeed => c-j */
|
|
1659 MACROLET (make_char ('j'), (modifiers | MOD_CONTROL));
|
|
1660 else if (EQ (keysym, QKreturn)) /* return => c-m */
|
|
1661 MACROLET (make_char ('m'), (modifiers | MOD_CONTROL));
|
|
1662 else if (EQ (keysym, QKescape)) /* escape => c-[ */
|
|
1663 MACROLET (make_char ('['), (modifiers | MOD_CONTROL));
|
|
1664 else
|
|
1665 return;
|
|
1666 #undef MACROLET
|
|
1667 }
|
|
1668
|
|
1669
|
|
1670 static void
|
|
1671 ensure_meta_prefix_char_keymapp (Lisp_Object keys, int indx,
|
|
1672 Lisp_Object keymap)
|
|
1673 {
|
|
1674 /* This function can GC */
|
|
1675 char buf [255];
|
|
1676 Lisp_Object new_keys;
|
|
1677 int i;
|
|
1678 Lisp_Object mpc_binding;
|
|
1679 struct key_data meta_key;
|
|
1680
|
|
1681 if (NILP (Vmeta_prefix_char) ||
|
|
1682 (INTP (Vmeta_prefix_char) && XINT (Vmeta_prefix_char) < 0))
|
|
1683 return;
|
|
1684
|
|
1685 define_key_parser (Vmeta_prefix_char, &meta_key);
|
|
1686 mpc_binding = keymap_lookup_1 (keymap, &meta_key, 0);
|
|
1687 if (NILP (mpc_binding) || !NILP (Fkeymapp (mpc_binding)))
|
|
1688 return;
|
|
1689
|
|
1690 if (indx == 0)
|
|
1691 new_keys = keys;
|
|
1692 else if (STRINGP (keys))
|
|
1693 new_keys = Fsubstring (keys, Qzero, make_int (indx));
|
|
1694 else if (VECTORP (keys))
|
|
1695 {
|
|
1696 new_keys = make_vector (indx, Qnil);
|
|
1697 for (i = 0; i < indx; i++)
|
|
1698 vector_data (XVECTOR (new_keys)) [i] =
|
|
1699 vector_data (XVECTOR (keys)) [i];
|
|
1700 }
|
|
1701 else
|
|
1702 abort ();
|
|
1703 if (EQ (keys, new_keys))
|
|
1704 sprintf (buf, GETTEXT ("can't bind %s: %s has a non-keymap binding"),
|
|
1705 (char *) string_data (XSTRING (Fkey_description (keys))),
|
|
1706 (char *) string_data (XSTRING
|
|
1707 (Fsingle_key_description
|
|
1708 (Vmeta_prefix_char))));
|
|
1709 else
|
|
1710 sprintf (buf, GETTEXT ("can't bind %s: %s %s has a non-keymap binding"),
|
|
1711 (char *) string_data (XSTRING (Fkey_description (keys))),
|
|
1712 (char *) string_data (XSTRING (Fkey_description (new_keys))),
|
|
1713 (char *) string_data (XSTRING
|
|
1714 (Fsingle_key_description
|
|
1715 (Vmeta_prefix_char))));
|
|
1716 signal_simple_error (buf, mpc_binding);
|
|
1717 }
|
|
1718
|
|
1719 DEFUN ("define-key", Fdefine_key, Sdefine_key, 3, 3, 0 /*
|
|
1720 Define key sequence KEYS, in KEYMAP, as DEF.
|
|
1721 KEYMAP is a keymap object.
|
|
1722 KEYS is the sequence of keystrokes to bind, described below.
|
|
1723 DEF is anything that can be a key's definition:
|
|
1724 nil (means key is undefined in this keymap);
|
|
1725 a command (a Lisp function suitable for interactive calling);
|
|
1726 a string or key sequence vector (treated as a keyboard macro);
|
|
1727 a keymap (to define a prefix key);
|
|
1728 a symbol; when the key is looked up, the symbol will stand for its
|
|
1729 function definition, that should at that time be one of the above,
|
|
1730 or another symbol whose function definition is used, and so on.
|
|
1731 a cons (STRING . DEFN), meaning that DEFN is the definition
|
|
1732 (DEFN should be a valid definition in its own right);
|
|
1733 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP.
|
|
1734
|
|
1735 Contrary to popular belief, the world is not ASCII. When running under a
|
|
1736 window manager, XEmacs can tell the difference between, for example, the
|
|
1737 keystrokes control-h, control-shift-h, and backspace. You can, in fact,
|
|
1738 bind different commands to each of these.
|
|
1739
|
|
1740 A `key sequence' is a set of keystrokes. A `keystroke' is a keysym and some
|
|
1741 set of modifiers (such as control and meta). A `keysym' is what is printed
|
|
1742 on the keys on your keyboard.
|
|
1743
|
|
1744 A keysym may be represented by a symbol, or (if and only if it is equivalent
|
|
1745 to an ASCII character in the range 32 - 255) by a character or its equivalent
|
|
1746 ASCII code. The `A' key may be represented by the symbol `A', the character
|
|
1747 `?A', or by the number 65. The `break' key may be represented only by the
|
|
1748 symbol `break'.
|
|
1749
|
|
1750 A keystroke may be represented by a list: the last element of the list
|
|
1751 is the key (a symbol, character, or number, as above) and the
|
|
1752 preceding elements are the symbolic names of modifier keys (control,
|
|
1753 meta, super, hyper, alt, and shift). Thus, the sequence control-b is
|
|
1754 represented by the forms `(control b)', `(control ?b)', and `(control
|
|
1755 98)'. A keystroke may also be represented by an event object, as
|
|
1756 returned by the `next-command-event' and `read-key-sequence'
|
|
1757 functions.
|
|
1758
|
|
1759 Note that in this context, the keystroke `control-b' is *not* represented
|
|
1760 by the number 2 (the ASCII code for ^B) or the character `?\^B'. See below.
|
|
1761
|
|
1762 The `shift' modifier is somewhat of a special case. You should not (and
|
|
1763 cannot) use `(meta shift a)' to mean `(meta A)', since for characters that
|
|
1764 have ASCII equivalents, the state of the shift key is implicit in the
|
|
1765 keysym (a vs. A). You also cannot say `(shift =)' to mean `+', as that
|
|
1766 sort of thing varies from keyboard to keyboard. The shift modifier is for
|
|
1767 use only with characters that do not have a second keysym on the same key,
|
|
1768 such as `backspace' and `tab'.
|
|
1769
|
|
1770 A key sequence is a vector of keystrokes. As a degenerate case, elements
|
|
1771 of this vector may also be keysyms if they have no modifiers. That is,
|
|
1772 the `A' keystroke is represented by all of these forms:
|
|
1773 A ?A 65 (A) (?A) (65)
|
|
1774 [A] [?A] [65] [(A)] [(?A)] [(65)]
|
|
1775
|
|
1776 the `control-a' keystroke is represented by these forms:
|
|
1777 (control A) (control ?A) (control 65)
|
|
1778 [(control A)] [(control ?A)] [(control 65)]
|
|
1779 the key sequence `control-c control-a' is represented by these forms:
|
|
1780 [(control c) (control a)] [(control ?c) (control ?a)]
|
|
1781 [(control 99) (control 65)] etc.
|
|
1782
|
|
1783 Mouse button clicks work just like keypresses: (control button1) means
|
|
1784 pressing the left mouse button while holding down the control key.
|
|
1785 \[(control c) (shift button3)] means control-c, hold shift, click right.
|
|
1786
|
|
1787 Commands may be bound to the mouse-button up-stroke rather than the down-
|
|
1788 stroke as well. `button1' means the down-stroke, and `button1up' means the
|
|
1789 up-stroke. Different commands may be bound to the up and down strokes,
|
|
1790 though that is probably not what you want, so be careful.
|
|
1791
|
|
1792 For backward compatibility, a key sequence may also be represented by a
|
|
1793 string. In this case, it represents the key sequence(s) that would
|
|
1794 produce that sequence of ASCII characters in a purely ASCII world. For
|
|
1795 example, a string containing the ASCII backspace character, \"\\^H\", would
|
|
1796 represent two key sequences: `(control h)' and `backspace'. Binding a
|
|
1797 command to this will actually bind both of those key sequences. Likewise
|
|
1798 for the following pairs:
|
|
1799
|
|
1800 control h backspace
|
|
1801 control i tab
|
|
1802 control m return
|
|
1803 control j linefeed
|
|
1804 control [ escape
|
|
1805 control @ control space
|
|
1806
|
|
1807 After binding a command to two key sequences with a form like
|
|
1808
|
|
1809 (define-key global-map \"\\^X\\^I\" \'command-1)
|
|
1810
|
|
1811 it is possible to redefine only one of those sequences like so:
|
|
1812
|
|
1813 (define-key global-map [(control x) (control i)] \'command-2)
|
|
1814 (define-key global-map [(control x) tab] \'command-3)
|
|
1815
|
|
1816 Of course, all of this applies only when running under a window system. If
|
|
1817 you're talking to XEmacs through a TTY connection, you don't get any of
|
|
1818 these features.
|
|
1819 */ )
|
|
1820 (keymap, keys, def)
|
|
1821 Lisp_Object keymap;
|
|
1822 Lisp_Object keys;
|
|
1823 Lisp_Object def;
|
|
1824 {
|
|
1825 /* This function can GC */
|
|
1826 int idx;
|
|
1827 int metized = 0;
|
|
1828 int size;
|
|
1829 int ascii_hack;
|
|
1830 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1831
|
|
1832 if (VECTORP (keys))
|
|
1833 size = vector_length (XVECTOR (keys));
|
|
1834 else if (STRINGP (keys))
|
|
1835 size = string_length (XSTRING (keys));
|
|
1836 else if (INTP (keys) || SYMBOLP (keys) || CONSP (keys))
|
|
1837 {
|
|
1838 if (!CONSP (keys)) keys = list1 (keys);
|
|
1839 size = 1;
|
|
1840 keys = make_vector (1, keys); /* this is kinda sleazy. */
|
|
1841 }
|
|
1842 else
|
|
1843 {
|
|
1844 keys = wrong_type_argument (Qsequencep, keys);
|
|
1845 size = XINT (Flength (keys));
|
|
1846 }
|
|
1847 if (size == 0)
|
|
1848 return (Qnil);
|
|
1849
|
|
1850 GCPRO3 (keymap, keys, def);
|
|
1851
|
|
1852 /* ASCII grunge.
|
|
1853 When the user defines a key which, in a strictly ASCII world, would be
|
|
1854 produced by two different keys (^J and linefeed, or ^H and backspace,
|
|
1855 for example) then the binding will be made for both keysyms.
|
|
1856
|
|
1857 This is done if the user binds a command to a string, as in
|
|
1858 (define-key map "\^H" 'something), but not when using one of the new
|
|
1859 syntaxes, like (define-key map '(control h) 'something).
|
|
1860 */
|
|
1861 ascii_hack = (STRINGP (keys));
|
|
1862
|
|
1863 keymap = get_keymap (keymap, 1, 1);
|
|
1864
|
|
1865 idx = 0;
|
|
1866 while (1)
|
|
1867 {
|
|
1868 Lisp_Object c;
|
|
1869 struct key_data raw_key1;
|
|
1870 struct key_data raw_key2;
|
|
1871
|
|
1872 if (STRINGP (keys))
|
|
1873 c = make_char (string_char (XSTRING (keys), idx));
|
|
1874 else
|
|
1875 {
|
|
1876 c = vector_data (XVECTOR (keys)) [idx];
|
|
1877 if (INTP (c) &&
|
|
1878 (XINT (c) < ' ' || XINT (c) > 127))
|
|
1879 args_out_of_range_3 (c, make_int (32), make_int (127));
|
|
1880 }
|
|
1881
|
|
1882 define_key_parser (c, &raw_key1);
|
|
1883
|
|
1884 if (!metized && ascii_hack && meta_prefix_char_p (&raw_key1))
|
|
1885 {
|
|
1886 if (idx == (size - 1))
|
|
1887 {
|
|
1888 /* This is a hack to prevent a binding for the meta-prefix-char
|
|
1889 from being made in a map which already has a non-empty "meta"
|
|
1890 submap. That is, we can't let both "escape" and "meta" have
|
|
1891 a binding in the same keymap. This implies that the idiom
|
|
1892 (define-key my-map "\e" my-escape-map)
|
|
1893 (define-key my-escape-map "a" 'my-command)
|
|
1894 no longer works. That's ok. Instead the luser should do
|
|
1895 (define-key my-map "\ea" 'my-command)
|
|
1896 or, more correctly
|
|
1897 (define-key my-map "\M-a" 'my-command)
|
|
1898 and then perhaps
|
|
1899 (defvar my-escape-map (lookup-key my-map "\e"))
|
|
1900 if the luser really wants the map in a variable.
|
|
1901 */
|
|
1902 Lisp_Object mmap;
|
|
1903 struct gcpro ngcpro1;
|
|
1904
|
|
1905 NGCPRO1 (c);
|
|
1906 mmap = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META),
|
|
1907 XKEYMAP (keymap)->table, Qnil);
|
|
1908 if (!NILP (mmap)
|
|
1909 && keymap_fullness (mmap) != 0)
|
|
1910 {
|
|
1911 Lisp_Object desc
|
|
1912 = Fsingle_key_description (Vmeta_prefix_char);
|
|
1913 signal_simple_error_2
|
|
1914 ("Map contains meta-bindings, can't bind", desc, keymap);
|
|
1915 }
|
|
1916 NUNGCPRO;
|
|
1917 }
|
|
1918 else
|
|
1919 {
|
|
1920 metized = 1;
|
|
1921 idx++;
|
|
1922 continue;
|
|
1923 }
|
|
1924 }
|
|
1925
|
|
1926 if (ascii_hack)
|
|
1927 define_key_alternate_name (&raw_key1, &raw_key2);
|
|
1928 else
|
|
1929 {
|
|
1930 raw_key2.keysym = Qnil;
|
|
1931 raw_key2.modifiers = 0;
|
|
1932 }
|
|
1933
|
|
1934 if (metized)
|
|
1935 {
|
|
1936 raw_key1.modifiers |= MOD_META;
|
|
1937 raw_key2.modifiers |= MOD_META;
|
|
1938 metized = 0;
|
|
1939 }
|
|
1940
|
|
1941 /* This crap is to make sure that someone doesn't bind something like
|
|
1942 "C-x M-a" while "C-x ESC" has a non-keymap binding. */
|
|
1943 if (raw_key1.modifiers & MOD_META)
|
|
1944 ensure_meta_prefix_char_keymapp (keys, idx, keymap);
|
|
1945
|
|
1946 if (++idx == size)
|
|
1947 {
|
|
1948 keymap_store (keymap, &raw_key1, def);
|
|
1949 if (ascii_hack && !NILP (raw_key2.keysym))
|
|
1950 keymap_store (keymap, &raw_key2, def);
|
|
1951 UNGCPRO;
|
|
1952 return def;
|
|
1953 }
|
|
1954
|
|
1955 {
|
|
1956 Lisp_Object cmd;
|
|
1957 struct gcpro ngcpro1;
|
|
1958 NGCPRO1 (c);
|
|
1959
|
|
1960 cmd = keymap_lookup_1 (keymap, &raw_key1, 0);
|
|
1961 if (NILP (cmd))
|
|
1962 {
|
|
1963 cmd = Fmake_sparse_keymap (Qnil);
|
|
1964 XKEYMAP (cmd)->name /* for debugging */
|
|
1965 = list2 (make_key_description (&raw_key1, 1), keymap);
|
|
1966 keymap_store (keymap, &raw_key1, cmd);
|
|
1967 }
|
|
1968 if (NILP (Fkeymapp (cmd)))
|
|
1969 signal_simple_error_2 ("invalid prefix keys in sequence",
|
|
1970 c, keys);
|
|
1971
|
|
1972 if (ascii_hack && !NILP (raw_key2.keysym) &&
|
|
1973 NILP (keymap_lookup_1 (keymap, &raw_key2, 0)))
|
|
1974 keymap_store (keymap, &raw_key2, cmd);
|
|
1975
|
|
1976 keymap = get_keymap (cmd, 1, 1);
|
|
1977 NUNGCPRO;
|
|
1978 }
|
|
1979 }
|
|
1980 }
|
|
1981
|
|
1982
|
|
1983 /************************************************************************/
|
|
1984 /* Looking up keys in keymaps */
|
|
1985 /************************************************************************/
|
|
1986
|
|
1987 /* We need a very fast (i.e., non-consing) version of lookup-key in order
|
2
|
1988 to make where-is-internal really fly. */
|
0
|
1989
|
|
1990 struct raw_lookup_key_mapper_closure
|
2
|
1991 {
|
|
1992 int remaining;
|
|
1993 CONST struct key_data *raw_keys;
|
|
1994 int raw_keys_count;
|
|
1995 int keys_so_far;
|
|
1996 int accept_default;
|
|
1997 };
|
0
|
1998
|
|
1999 static Lisp_Object raw_lookup_key_mapper (Lisp_Object k, void *);
|
|
2000
|
|
2001 /* Caller should gc-protect args (keymaps may autoload) */
|
|
2002 static Lisp_Object
|
|
2003 raw_lookup_key (Lisp_Object keymap,
|
|
2004 CONST struct key_data *raw_keys, int raw_keys_count,
|
|
2005 int keys_so_far, int accept_default)
|
|
2006 {
|
|
2007 /* This function can GC */
|
|
2008 struct raw_lookup_key_mapper_closure c;
|
|
2009 c.remaining = raw_keys_count - 1;
|
|
2010 c.raw_keys = raw_keys;
|
|
2011 c.raw_keys_count = raw_keys_count;
|
|
2012 c.keys_so_far = keys_so_far;
|
|
2013 c.accept_default = accept_default;
|
|
2014
|
|
2015 return (traverse_keymaps (keymap, Qnil, raw_lookup_key_mapper,
|
|
2016 &c));
|
|
2017 }
|
|
2018
|
|
2019 static Lisp_Object
|
|
2020 raw_lookup_key_mapper (Lisp_Object k, void *arg)
|
|
2021 {
|
|
2022 /* This function can GC */
|
|
2023 struct raw_lookup_key_mapper_closure *c = arg;
|
|
2024 int accept_default = c->accept_default;
|
|
2025 int remaining = c->remaining;
|
|
2026 int keys_so_far = c->keys_so_far;
|
|
2027 CONST struct key_data *raw_keys = c->raw_keys;
|
|
2028 Lisp_Object cmd;
|
|
2029
|
|
2030 if (! meta_prefix_char_p (&(raw_keys[0])))
|
|
2031 {
|
|
2032 /* Normal case: every case except the meta-hack (see below). */
|
|
2033 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
|
|
2034
|
|
2035 if (remaining == 0)
|
|
2036 /* Return whatever we found if we're out of keys */
|
|
2037 ;
|
|
2038 else if (NILP (cmd))
|
|
2039 /* Found nothing (though perhaps parent map may have binding) */
|
|
2040 ;
|
|
2041 else if (NILP (Fkeymapp (cmd)))
|
|
2042 /* Didn't find a keymap, and we have more keys.
|
|
2043 * Return a fixnum to indicate that keys were too long.
|
|
2044 */
|
|
2045 cmd = make_int (keys_so_far + 1);
|
|
2046 else
|
|
2047 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining,
|
|
2048 keys_so_far + 1, accept_default);
|
|
2049 }
|
|
2050 else
|
|
2051 {
|
|
2052 /* This is a hack so that looking up a key-sequence whose last
|
|
2053 * element is the meta-prefix-char will return the keymap that
|
|
2054 * the "meta" keys are stored in, if there is no binding for
|
|
2055 * the meta-prefix-char (and if this map has a "meta" submap).
|
|
2056 * If this map doesnt have a "meta" submap, then the
|
|
2057 * meta-prefix-char is looked up just like any other key.
|
|
2058 */
|
|
2059 if (remaining == 0)
|
|
2060 {
|
|
2061 /* First look for the prefix-char directly */
|
|
2062 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
|
|
2063 if (NILP (cmd))
|
|
2064 {
|
|
2065 /* Do kludgy return of the meta-map */
|
|
2066 cmd = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META),
|
|
2067 XKEYMAP (k)->table, Qnil);
|
|
2068 }
|
|
2069 }
|
|
2070 else
|
|
2071 {
|
|
2072 /* Search for the prefix-char-prefixed sequence directly */
|
|
2073 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
|
|
2074 cmd = get_keymap (cmd, 0, 1);
|
|
2075 if (!NILP (cmd))
|
|
2076 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining,
|
|
2077 keys_so_far + 1, accept_default);
|
|
2078 else if ((raw_keys[1].modifiers & MOD_META) == 0)
|
|
2079 {
|
|
2080 struct key_data metified;
|
|
2081 metified.keysym = raw_keys[1].keysym;
|
|
2082 metified.modifiers = raw_keys[1].modifiers | MOD_META;
|
|
2083
|
|
2084 /* Search for meta-next-char sequence directly */
|
|
2085 cmd = keymap_lookup_1 (k, &metified, accept_default);
|
|
2086 if (remaining == 1)
|
|
2087 ;
|
|
2088 else
|
|
2089 {
|
|
2090 cmd = get_keymap (cmd, 0, 1);
|
|
2091 if (!NILP (cmd))
|
|
2092 cmd = raw_lookup_key (cmd, raw_keys + 2, remaining - 1,
|
|
2093 keys_so_far + 2,
|
|
2094 accept_default);
|
|
2095 }
|
|
2096 }
|
|
2097 }
|
|
2098 }
|
|
2099 if (accept_default && NILP (cmd))
|
|
2100 cmd = XKEYMAP (k)->default_binding;
|
|
2101 return (cmd);
|
|
2102 }
|
|
2103
|
|
2104 /* Value is number if `keys' is too long; NIL if valid but has no definition.*/
|
|
2105 /* Caller should gc-protect arguments */
|
|
2106 static Lisp_Object
|
|
2107 lookup_keys (Lisp_Object keymap, int nkeys, Lisp_Object *keys,
|
|
2108 int accept_default)
|
|
2109 {
|
|
2110 /* This function can GC */
|
|
2111 struct key_data kkk[20];
|
|
2112 struct key_data *raw_keys;
|
|
2113 int i;
|
|
2114
|
|
2115 if (nkeys == 0)
|
|
2116 return Qnil;
|
|
2117
|
|
2118 if (nkeys > (countof (kkk)))
|
|
2119 raw_keys = kkk;
|
|
2120 else
|
|
2121 raw_keys = (struct key_data *) alloca (sizeof (struct key_data) * nkeys);
|
|
2122
|
|
2123 for (i = 0; i < nkeys; i++)
|
|
2124 {
|
|
2125 define_key_parser (keys[i], &(raw_keys[i]));
|
|
2126 }
|
|
2127 return (raw_lookup_key (keymap, raw_keys, nkeys, 0,
|
|
2128 accept_default));
|
|
2129 }
|
|
2130
|
|
2131 static Lisp_Object
|
|
2132 lookup_events (Lisp_Object event_head, int nmaps, Lisp_Object keymaps[],
|
|
2133 int accept_default)
|
|
2134 {
|
|
2135 /* This function can GC */
|
|
2136 struct key_data kkk[20];
|
|
2137 Lisp_Object event;
|
|
2138
|
|
2139 int nkeys;
|
|
2140 struct key_data *raw_keys;
|
|
2141 Lisp_Object tem = Qnil;
|
|
2142 struct gcpro gcpro1, gcpro2;
|
|
2143 int iii;
|
|
2144
|
|
2145 CHECK_LIVE_EVENT (event_head);
|
|
2146
|
|
2147 nkeys = event_chain_count (event_head);
|
|
2148
|
|
2149 if (nkeys < (countof (kkk)))
|
|
2150 raw_keys = kkk;
|
|
2151 else
|
|
2152 raw_keys = (struct key_data *) alloca (sizeof (struct key_data) * nkeys);
|
|
2153
|
|
2154 nkeys = 0;
|
|
2155 EVENT_CHAIN_LOOP (event, event_head)
|
|
2156 define_key_parser (event, &(raw_keys[nkeys++]));
|
|
2157 GCPRO2 (keymaps[0], event_head);
|
|
2158 gcpro1.nvars = nmaps;
|
|
2159 /* ####raw_keys[].keysym slots aren't gc-protected. We rely (but shouldn't)
|
|
2160 * on somebody else somewhere (obarray) having a pointer to all keysyms. */
|
|
2161 for (iii = 0; iii < nmaps; iii++)
|
|
2162 {
|
|
2163 tem = raw_lookup_key (keymaps[iii], raw_keys, nkeys, 0,
|
|
2164 accept_default);
|
|
2165 if (INTP (tem))
|
|
2166 {
|
|
2167 /* Too long in some local map means don't look at global map */
|
|
2168 tem = Qnil;
|
|
2169 break;
|
|
2170 }
|
|
2171 else if (!NILP (tem))
|
|
2172 break;
|
|
2173 }
|
|
2174 UNGCPRO;
|
|
2175 return (tem);
|
|
2176 }
|
|
2177
|
|
2178 DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0 /*
|
|
2179 In keymap KEYMAP, look up key-sequence KEYS. Return the definition.
|
|
2180 Nil is returned if KEYS is unbound. See documentation of `define-key'
|
|
2181 for valid key definitions and key-sequence specifications.
|
|
2182 A number is returned if KEYS is \"too long\"; that is, the leading
|
|
2183 characters fail to be a valid sequence of prefix characters in KEYMAP.
|
|
2184 The number is how many characters at the front of KEYS
|
|
2185 it takes to reach a non-prefix command.
|
|
2186 */ )
|
|
2187 (keymap, keys, accept_default)
|
|
2188 Lisp_Object keymap, keys, accept_default;
|
|
2189 {
|
|
2190 /* This function can GC */
|
|
2191 if (VECTORP (keys))
|
|
2192 {
|
|
2193 return lookup_keys (keymap,
|
|
2194 vector_length (XVECTOR (keys)),
|
|
2195 vector_data (XVECTOR (keys)),
|
|
2196 !NILP (accept_default));
|
|
2197 }
|
|
2198 else if (SYMBOLP (keys) || INTP (keys) || CONSP (keys))
|
|
2199 {
|
|
2200 return lookup_keys (keymap, 1, &keys,
|
|
2201 !NILP (accept_default));
|
|
2202 }
|
|
2203 else if (!STRINGP (keys))
|
|
2204 {
|
|
2205 keys = wrong_type_argument (Qsequencep, keys);
|
|
2206 return Flookup_key (keymap, keys, accept_default);
|
|
2207 }
|
2
|
2208 else /* STRINGP (keys) */
|
0
|
2209 {
|
|
2210 int length = string_char_length (XSTRING (keys));
|
|
2211 int i;
|
|
2212 struct key_data *raw_keys
|
|
2213 = (struct key_data *) alloca (sizeof (struct key_data) * length);
|
|
2214 if (length == 0)
|
|
2215 return Qnil;
|
|
2216
|
|
2217 for (i = 0; i < length; i++)
|
|
2218 {
|
|
2219 Emchar n = string_char (XSTRING (keys), i);
|
|
2220 define_key_parser (make_char (n), &(raw_keys[i]));
|
|
2221 }
|
|
2222 return (raw_lookup_key (keymap, raw_keys, length, 0,
|
|
2223 !NILP (accept_default)));
|
|
2224 }
|
|
2225 }
|
|
2226
|
|
2227 /* Given a key sequence, returns a list of keymaps to search for bindings.
|
|
2228 Does all manner of semi-hairy heuristics, like looking in the current
|
|
2229 buffer's map before looking in the global map and looking in the local
|
|
2230 map of the buffer in which the mouse was clicked in event0 is a click.
|
|
2231
|
|
2232 It would be kind of nice if this were in Lisp so that this semi-hairy
|
|
2233 semi-heuristic command-lookup behaviour could be readily understood and
|
|
2234 customised. However, this needs to be pretty fast, or performance of
|
|
2235 keyboard macros goes to shit; putting this in lisp slows macros down
|
|
2236 2-3x. And they're already slower than v18 by 5-6x.
|
|
2237 */
|
|
2238
|
|
2239 struct relevant_maps
|
|
2240 {
|
|
2241 int nmaps;
|
|
2242 unsigned int max_maps;
|
|
2243 Lisp_Object *maps;
|
|
2244 struct gcpro *gcpro;
|
|
2245 };
|
|
2246
|
|
2247 static void get_relevant_extent_keymaps (Lisp_Object pos,
|
|
2248 Lisp_Object buffer_or_string,
|
|
2249 Lisp_Object glyph,
|
|
2250 struct relevant_maps *closure);
|
|
2251 static void get_relevant_minor_maps (Lisp_Object buffer,
|
|
2252 struct relevant_maps *closure);
|
|
2253
|
|
2254 static void
|
|
2255 relevant_map_push (Lisp_Object map, struct relevant_maps *closure)
|
|
2256 {
|
|
2257 unsigned int nmaps = closure->nmaps;
|
|
2258
|
|
2259 if (!KEYMAPP (map))
|
|
2260 return;
|
|
2261 closure->nmaps = nmaps + 1;
|
|
2262 if (nmaps < closure->max_maps)
|
|
2263 {
|
|
2264 closure->maps[nmaps] = map;
|
|
2265 closure->gcpro->nvars = nmaps;
|
|
2266 }
|
|
2267 }
|
|
2268
|
|
2269 static int
|
|
2270 get_relevant_keymaps (Lisp_Object keys,
|
|
2271 int max_maps, Lisp_Object maps[])
|
|
2272 {
|
|
2273 /* This function can GC */
|
|
2274 Lisp_Object terminal = Qnil;
|
|
2275 struct gcpro gcpro1;
|
|
2276 struct relevant_maps closure;
|
|
2277 struct console *con;
|
|
2278
|
|
2279 GCPRO1 (*maps);
|
|
2280 gcpro1.nvars = 0;
|
|
2281 closure.nmaps = 0;
|
|
2282 closure.max_maps = max_maps;
|
|
2283 closure.maps = maps;
|
|
2284 closure.gcpro = &gcpro1;
|
|
2285
|
|
2286 if (EVENTP (keys))
|
|
2287 terminal = event_chain_tail (keys);
|
|
2288 else if (VECTORP (keys))
|
|
2289 {
|
|
2290 int len = vector_length (XVECTOR (keys));
|
|
2291 if (len > 0)
|
|
2292 terminal = vector_data (XVECTOR (keys))[len - 1];
|
|
2293 }
|
|
2294
|
|
2295 if (EVENTP (terminal))
|
|
2296 {
|
|
2297 CHECK_LIVE_EVENT (terminal);
|
|
2298 con = event_console_or_selected (terminal);
|
|
2299 }
|
|
2300 else
|
|
2301 con = XCONSOLE (Vselected_console);
|
|
2302
|
|
2303 if (KEYMAPP (con->overriding_terminal_local_map)
|
|
2304 || KEYMAPP (Voverriding_local_map))
|
|
2305 {
|
|
2306 if (KEYMAPP (con->overriding_terminal_local_map))
|
|
2307 relevant_map_push (con->overriding_terminal_local_map, &closure);
|
|
2308 if (KEYMAPP (Voverriding_local_map))
|
|
2309 relevant_map_push (Voverriding_local_map, &closure);
|
|
2310 }
|
|
2311 else if (!EVENTP (terminal)
|
|
2312 || (XEVENT (terminal)->event_type != button_press_event
|
|
2313 && XEVENT (terminal)->event_type != button_release_event))
|
|
2314 {
|
|
2315 Lisp_Object tem;
|
|
2316 XSETBUFFER (tem, current_buffer);
|
|
2317 /* It's not a mouse event; order of keymaps searched is:
|
|
2318 o keymap of any/all extents under the mouse
|
|
2319 o minor-mode maps
|
|
2320 o local-map of current-buffer
|
|
2321 o global-map
|
|
2322 */
|
|
2323 /* The terminal element of the lookup may be nil or a keysym.
|
|
2324 In those cases we don't want to check for an extent
|
|
2325 keymap. */
|
|
2326 if (EVENTP (terminal))
|
|
2327 {
|
|
2328 get_relevant_extent_keymaps (make_int (BUF_PT (current_buffer)),
|
|
2329 tem, Qnil, &closure);
|
|
2330 }
|
|
2331 get_relevant_minor_maps (tem, &closure);
|
|
2332
|
|
2333 tem = current_buffer->keymap;
|
|
2334 if (!NILP (tem))
|
|
2335 relevant_map_push (tem, &closure);
|
|
2336 }
|
|
2337 #ifdef HAVE_WINDOW_SYSTEM
|
|
2338 else
|
|
2339 {
|
|
2340 /* It's a mouse event; order of keymaps searched is:
|
|
2341 o local-map of mouse-grabbed-buffer
|
|
2342 o keymap of any/all extents under the mouse
|
|
2343 if the mouse is over a modeline:
|
|
2344 o modeline-map of buffer corresponding to that modeline
|
|
2345 o else, local-map of buffer under the mouse
|
|
2346 o minor-mode maps
|
|
2347 o local-map of current-buffer
|
|
2348 o global-map
|
|
2349 */
|
|
2350 Lisp_Object window = Fevent_window (terminal);
|
|
2351
|
|
2352 if (BUFFERP (Vmouse_grabbed_buffer))
|
|
2353 {
|
|
2354 Lisp_Object map = XBUFFER (Vmouse_grabbed_buffer)->keymap;
|
|
2355
|
|
2356 get_relevant_minor_maps (Vmouse_grabbed_buffer, &closure);
|
|
2357 if (!NILP (map))
|
|
2358 relevant_map_push (map, &closure);
|
|
2359 }
|
|
2360
|
|
2361 if (!NILP (window))
|
|
2362 {
|
|
2363 Lisp_Object buffer = Fwindow_buffer (window);
|
|
2364
|
|
2365 if (!NILP (buffer))
|
|
2366 {
|
|
2367 if (!NILP (Fevent_over_modeline_p (terminal)))
|
|
2368 {
|
|
2369 Lisp_Object map = symbol_value_in_buffer (Qmodeline_map,
|
|
2370 buffer);
|
|
2371
|
|
2372 get_relevant_extent_keymaps
|
|
2373 (Fevent_modeline_position (terminal),
|
|
2374 XBUFFER (buffer)->generated_modeline_string,
|
|
2375 /* #### third arg should maybe be a glyph. */
|
|
2376 Qnil, &closure);
|
|
2377
|
|
2378 if (!UNBOUNDP (map) && !NILP (map))
|
|
2379 relevant_map_push (get_keymap (map, 1, 1), &closure);
|
|
2380 }
|
|
2381 else
|
|
2382 {
|
|
2383 get_relevant_extent_keymaps (Fevent_point (terminal), buffer,
|
|
2384 Fevent_glyph_extent (terminal),
|
|
2385 &closure);
|
|
2386 }
|
|
2387
|
|
2388 if (!EQ (buffer, Vmouse_grabbed_buffer)) /* already pushed */
|
|
2389 {
|
|
2390 get_relevant_minor_maps (buffer, &closure);
|
|
2391 relevant_map_push (XBUFFER (buffer)->keymap, &closure);
|
|
2392 }
|
|
2393 }
|
|
2394 }
|
|
2395 else if (!NILP (Fevent_over_toolbar_p (terminal)))
|
|
2396 {
|
|
2397 Lisp_Object map = Fsymbol_value (Qtoolbar_map);
|
|
2398
|
|
2399 if (!UNBOUNDP (map) && !NILP (map))
|
|
2400 relevant_map_push (map, &closure);
|
|
2401 }
|
|
2402 }
|
|
2403 #endif /* HAVE_WINDOW_SYSTEM */
|
|
2404
|
|
2405 {
|
|
2406 int nmaps = closure.nmaps;
|
|
2407 /* Silently truncate at 100 keymaps to prevent infinite losssage */
|
|
2408 if (nmaps >= max_maps && max_maps > 0)
|
|
2409 maps[max_maps - 1] = Vcurrent_global_map;
|
|
2410 else
|
|
2411 maps[nmaps] = Vcurrent_global_map;
|
|
2412 UNGCPRO;
|
|
2413 return (nmaps + 1);
|
|
2414 }
|
|
2415 }
|
|
2416
|
|
2417 /* Returns a set of keymaps extracted from the extents at POS in
|
|
2418 BUFFER_OR_STRING. The GLYPH arg, if specified, is one more extent
|
|
2419 to look for a keymap in, and if it has one, its keymap will be the
|
|
2420 first element in the list returned. This is so we can correctly
|
|
2421 search the keymaps associated with glyphs which may be physically
|
|
2422 disjoint from their extents: for example, if a glyph is out in the
|
|
2423 margin, we should still consult the kemyap of that glyph's extent,
|
|
2424 which may not itself be under the mouse.
|
|
2425 */
|
|
2426 static void
|
|
2427 get_relevant_extent_keymaps (Lisp_Object pos, Lisp_Object buffer_or_string,
|
|
2428 Lisp_Object glyph,
|
|
2429 struct relevant_maps *closure)
|
|
2430 {
|
|
2431 /* This function can GC */
|
|
2432 /* the glyph keymap, if any, comes first.
|
|
2433 (Processing it twice is no big deal: noop.) */
|
|
2434 if (!NILP (glyph))
|
|
2435 {
|
|
2436 Lisp_Object keymap = Fextent_property (glyph, Qkeymap, Qnil);
|
|
2437 if (!NILP (keymap))
|
|
2438 relevant_map_push (get_keymap (keymap, 1, 1), closure);
|
|
2439 }
|
|
2440
|
|
2441 /* Next check the extents at the text position, if any */
|
|
2442 if (!NILP (pos))
|
|
2443 {
|
|
2444 Lisp_Object extent;
|
|
2445 for (extent = Fextent_at (pos, buffer_or_string, Qkeymap, Qnil, Qnil);
|
|
2446 !NILP (extent);
|
|
2447 extent = Fextent_at (pos, buffer_or_string, Qkeymap, extent, Qnil))
|
|
2448 {
|
|
2449 Lisp_Object keymap = Fextent_property (extent, Qkeymap, Qnil);
|
|
2450 if (!NILP (keymap))
|
|
2451 relevant_map_push (get_keymap (keymap, 1, 1), closure);
|
|
2452 QUIT;
|
|
2453 }
|
|
2454 }
|
|
2455 }
|
|
2456
|
|
2457 static Lisp_Object
|
|
2458 minor_mode_keymap_predicate (Lisp_Object assoc, Lisp_Object buffer)
|
|
2459 {
|
|
2460 /* This function can GC */
|
|
2461 if (CONSP (assoc))
|
|
2462 {
|
|
2463 Lisp_Object sym = XCAR (assoc);
|
|
2464 if (SYMBOLP (sym))
|
|
2465 {
|
|
2466 Lisp_Object val = symbol_value_in_buffer (sym, buffer);
|
|
2467 if (!NILP (val) && !UNBOUNDP (val))
|
|
2468 {
|
|
2469 Lisp_Object map = get_keymap (XCDR (assoc), 0, 1);
|
|
2470 return (map);
|
|
2471 }
|
|
2472 }
|
|
2473 }
|
|
2474 return (Qnil);
|
|
2475 }
|
|
2476
|
|
2477 static void
|
|
2478 get_relevant_minor_maps (Lisp_Object buffer, struct relevant_maps *closure)
|
|
2479 {
|
|
2480 /* This function can GC */
|
|
2481 Lisp_Object alist;
|
|
2482
|
|
2483 /* Will you ever lose badly if you make this circular! */
|
|
2484 for (alist = symbol_value_in_buffer (Qminor_mode_map_alist, buffer);
|
|
2485 CONSP (alist);
|
|
2486 alist = XCDR (alist))
|
|
2487 {
|
|
2488 Lisp_Object m = minor_mode_keymap_predicate (XCAR (alist),
|
|
2489 buffer);
|
|
2490 if (!NILP (m)) relevant_map_push (m, closure);
|
|
2491 QUIT;
|
|
2492 }
|
|
2493 }
|
|
2494
|
|
2495 /* #### Would map-current-keymaps be a better thing?? */
|
|
2496 DEFUN ("current-keymaps", Fcurrent_keymaps, Scurrent_keymaps, 0, 1, 0 /*
|
|
2497 Return a list of the current keymaps that will be searched for bindings.
|
|
2498 This lists keymaps such as the current local map and the minor-mode maps,
|
|
2499 but does not list the parents of those keymaps.
|
|
2500 EVENT-OR-KEYS controls which keymaps will be listed.
|
|
2501 If EVENT-OR-KEYS is a mouse event (or a vector whose last element is a
|
|
2502 mouse event), the keymaps for that mouse event will be listed (see
|
|
2503 `key-binding'). Otherwise, the keymaps for key presses will be listed.
|
|
2504 */ )
|
|
2505 (event_or_keys)
|
|
2506 Lisp_Object event_or_keys;
|
|
2507 {
|
|
2508 /* This function can GC */
|
|
2509 struct gcpro gcpro1;
|
|
2510 Lisp_Object maps[100];
|
|
2511 Lisp_Object *gubbish = maps;
|
|
2512 int nmaps;
|
|
2513
|
|
2514 GCPRO1 (event_or_keys);
|
|
2515 nmaps = get_relevant_keymaps (event_or_keys, countof (maps),
|
|
2516 gubbish);
|
|
2517 if (nmaps > countof (maps))
|
|
2518 {
|
|
2519 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
2520 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
|
|
2521 }
|
|
2522 UNGCPRO;
|
|
2523 return (Flist (nmaps, gubbish));
|
|
2524 }
|
|
2525
|
|
2526 DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 2, 0 /*
|
|
2527 Return the binding for command KEYS in current keymaps.
|
|
2528 KEYS is a string, a vector of events, or a vector of key-description lists
|
|
2529 as described in the documentation for the `define-key' function.
|
|
2530 The binding is probably a symbol with a function definition; see
|
|
2531 the documentation for `lookup-key' for more information.
|
|
2532
|
|
2533 For key-presses, the order of keymaps searched is:
|
|
2534 - the `keymap' property of any extent(s) at point;
|
|
2535 - any applicable minor-mode maps;
|
|
2536 - the current-local-map of the current-buffer;
|
|
2537 - the current global map.
|
|
2538
|
|
2539 For mouse-clicks, the order of keymaps searched is:
|
|
2540 - the current-local-map of the `mouse-grabbed-buffer' if any;
|
|
2541 - the `keymap' property of any extent(s) at the position of the click
|
|
2542 (this includes modeline extents);
|
|
2543 - the modeline-map of the buffer corresponding to the modeline under
|
|
2544 the mouse (if the click happened over a modeline);
|
|
2545 - the value of toolbar-map in the current-buffer (if the click
|
|
2546 happened over a toolbar);
|
|
2547 - the current-local-map of the buffer under the mouse (does not
|
|
2548 apply to toolbar clicks);
|
|
2549 - any applicable minor-mode maps;
|
|
2550 - the current global map.
|
|
2551
|
|
2552 Note that if `overriding-local-map' or `overriding-terminal-local-map'
|
|
2553 is non-nil, *only* those two maps and the current global map are searched.
|
|
2554 */ )
|
|
2555 (keys, accept_default)
|
|
2556 Lisp_Object keys, accept_default;
|
|
2557 {
|
|
2558 /* This function can GC */
|
|
2559 int i;
|
|
2560 Lisp_Object maps[100];
|
|
2561 int nmaps;
|
|
2562 struct gcpro gcpro1, gcpro2;
|
|
2563 GCPRO2 (keys, accept_default); /* get_relevant_keymaps may autoload */
|
|
2564
|
|
2565 nmaps = get_relevant_keymaps (keys, countof (maps), maps);
|
|
2566
|
|
2567 UNGCPRO;
|
|
2568
|
|
2569 if (EVENTP (keys)) /* unadvertised "feature" for the future */
|
|
2570 return (lookup_events (keys, nmaps, maps,
|
|
2571 !NILP (accept_default)));
|
|
2572
|
|
2573 for (i = 0; i < nmaps; i++)
|
|
2574 {
|
|
2575 Lisp_Object tem = Flookup_key (maps[i], keys,
|
|
2576 accept_default);
|
|
2577 if (INTP (tem))
|
|
2578 {
|
|
2579 /* Too long in some local map means don't look at global map */
|
|
2580 return (Qnil);
|
|
2581 }
|
|
2582 else if (!NILP (tem))
|
|
2583 return (tem);
|
|
2584 }
|
|
2585 return (Qnil);
|
|
2586 }
|
|
2587
|
|
2588 static Lisp_Object
|
|
2589 process_event_binding_result (Lisp_Object result)
|
|
2590 {
|
|
2591 if (EQ (result, Qundefined))
|
|
2592 /* The suppress-keymap function binds keys to 'undefined - special-case
|
|
2593 that here, so that being bound to that has the same error-behavior as
|
|
2594 not being defined at all.
|
|
2595 */
|
|
2596 result = Qnil;
|
|
2597 if (!NILP (result))
|
|
2598 {
|
|
2599 Lisp_Object map;
|
|
2600 /* Snap out possible keymap indirections */
|
|
2601 map = get_keymap (result, 0, 1);
|
|
2602 if (!NILP (map))
|
|
2603 result = map;
|
|
2604 }
|
|
2605
|
|
2606 return result;
|
|
2607 }
|
|
2608
|
|
2609 /* Attempts to find a command corresponding to the event-sequence
|
|
2610 whose head is event0 (sequence is threaded though event_next).
|
|
2611
|
|
2612 The return value will be
|
|
2613
|
|
2614 -- nil (there is no binding; this will also be returned
|
|
2615 whenever the event chain is "too long", i.e. there
|
|
2616 is a non-nil, non-keymap binding for a prefix of
|
|
2617 the event chain)
|
|
2618 -- a keymap (part of a command has been specified)
|
|
2619 -- a command (anything that satisfies `commandp'; this includes
|
|
2620 some symbols, lists, subrs, strings, vectors, and
|
|
2621 compiled-function objects) */
|
|
2622 Lisp_Object
|
|
2623 event_binding (Lisp_Object event0, int accept_default)
|
|
2624 {
|
|
2625 /* This function can GC */
|
|
2626 Lisp_Object maps[100];
|
|
2627 int nmaps;
|
|
2628
|
|
2629 assert (EVENTP (event0));
|
|
2630
|
|
2631 nmaps = get_relevant_keymaps (event0, countof (maps), maps);
|
|
2632 return (process_event_binding_result
|
|
2633 (lookup_events (event0, nmaps, maps, accept_default)));
|
|
2634 }
|
|
2635
|
|
2636 /* Attempts to find a function key mapping corresponding to the
|
|
2637 event-sequence whose head is event0 (sequence is threaded through
|
|
2638 event_next). The return value will be the same as for event_binding(). */
|
|
2639 Lisp_Object
|
|
2640 munging_key_map_event_binding (Lisp_Object event0,
|
|
2641 enum munge_me_out_the_door munge)
|
|
2642 {
|
|
2643 Lisp_Object the_map;
|
|
2644 Lisp_Object maps[1];
|
|
2645
|
|
2646 if (munge == MUNGE_ME_FUNCTION_KEY)
|
|
2647 {
|
|
2648 struct console *c = event_console_or_selected (event0);
|
|
2649
|
|
2650 the_map = CONSOLE_FUNCTION_KEY_MAP (c);
|
|
2651 }
|
|
2652 else
|
|
2653 the_map = Vkey_translation_map;
|
|
2654
|
|
2655 if (NILP (the_map))
|
|
2656 return Qnil;
|
|
2657
|
|
2658 maps[0] = the_map;
|
|
2659 return process_event_binding_result (lookup_events (event0, 1, maps, 1));
|
|
2660 }
|
|
2661
|
|
2662
|
|
2663 /************************************************************************/
|
|
2664 /* Setting/querying the global and local maps */
|
|
2665 /************************************************************************/
|
|
2666
|
|
2667 DEFUN ("use-global-map", Fuse_global_map, Suse_global_map, 1, 1, 0 /*
|
|
2668 Select KEYMAP as the global keymap.
|
|
2669 */ )
|
|
2670 (keymap)
|
|
2671 Lisp_Object keymap;
|
|
2672 {
|
|
2673 /* This function can GC */
|
|
2674 keymap = get_keymap (keymap, 1, 1);
|
|
2675 Vcurrent_global_map = keymap;
|
|
2676 return Qnil;
|
|
2677 }
|
|
2678
|
|
2679 DEFUN ("use-local-map", Fuse_local_map, Suse_local_map, 1, 2, 0 /*
|
|
2680 Select KEYMAP as the local keymap in BUFFER.
|
|
2681 If KEYMAP is nil, that means no local keymap.
|
|
2682 If BUFFER is nil, the current buffer is assumed.
|
|
2683 */ )
|
|
2684 (keymap, buffer)
|
|
2685 Lisp_Object keymap, buffer;
|
|
2686 {
|
|
2687 /* This function can GC */
|
|
2688 struct buffer *b = decode_buffer (buffer, 0);
|
|
2689 if (!NILP (keymap))
|
|
2690 keymap = get_keymap (keymap, 1, 1);
|
|
2691
|
|
2692 b->keymap = keymap;
|
|
2693
|
|
2694 return Qnil;
|
|
2695 }
|
|
2696
|
|
2697 DEFUN ("current-local-map", Fcurrent_local_map, Scurrent_local_map, 0, 1, 0 /*
|
|
2698 Return BUFFER's local keymap, or nil if it has none.
|
|
2699 If BUFFER is nil, the current buffer is assumed.
|
|
2700 */ )
|
|
2701 (buffer)
|
|
2702 Lisp_Object buffer;
|
|
2703 {
|
|
2704 struct buffer *b = decode_buffer (buffer, 0);
|
|
2705 return b->keymap;
|
|
2706 }
|
|
2707
|
|
2708 DEFUN ("current-global-map", Fcurrent_global_map, Scurrent_global_map, 0, 0, 0 /*
|
|
2709 Return the current global keymap.
|
|
2710 */ )
|
|
2711 ()
|
|
2712 {
|
|
2713 return (Vcurrent_global_map);
|
|
2714 }
|
|
2715
|
|
2716
|
|
2717 /************************************************************************/
|
|
2718 /* Mapping over keymap elements */
|
|
2719 /************************************************************************/
|
|
2720
|
|
2721 /* Since keymaps are arranged in a hierarchy, one keymap per bucky bit or
|
|
2722 prefix key, it's not entirely objvious what map-keymap should do, but
|
|
2723 what it does is: map over all keys in this map; then recursively map
|
|
2724 over all submaps of this map that are "bucky" submaps. This means that,
|
|
2725 when mapping over a keymap, it appears that "x" and "C-x" are in the
|
|
2726 same map, although "C-x" is really in the "control" submap of this one.
|
|
2727 However, since we don't recursively descend the submaps that are bound
|
|
2728 to prefix keys (like C-x, C-h, etc) the caller will have to recurse on
|
|
2729 those explicitly, if that's what they want.
|
|
2730
|
|
2731 So the end result of this is that the bucky keymaps (the ones indexed
|
|
2732 under the large integers returned from MAKE_MODIFIER_HASH_KEY()) are
|
|
2733 invisible from elisp. They're just an implementation detail that code
|
|
2734 outside of this file doesn't need to know about.
|
|
2735 */
|
|
2736
|
|
2737 struct map_keymap_unsorted_closure
|
|
2738 {
|
|
2739 void (*fn) (CONST struct key_data *, Lisp_Object binding, void *arg);
|
|
2740 void *arg;
|
|
2741 unsigned int modifiers;
|
|
2742 };
|
|
2743
|
|
2744 /* used by map_keymap() */
|
|
2745 static void
|
|
2746 map_keymap_unsorted_mapper (CONST void *hash_key, void *hash_contents,
|
|
2747 void *map_keymap_unsorted_closure)
|
|
2748 {
|
|
2749 /* This function can GC */
|
|
2750 Lisp_Object keysym;
|
|
2751 Lisp_Object contents;
|
|
2752 struct map_keymap_unsorted_closure *closure = map_keymap_unsorted_closure;
|
|
2753 unsigned int modifiers = closure->modifiers;
|
|
2754 unsigned int mod_bit;
|
|
2755 CVOID_TO_LISP (keysym, hash_key);
|
|
2756 VOID_TO_LISP (contents, hash_contents);
|
|
2757 mod_bit = MODIFIER_HASH_KEY_BITS (keysym);
|
|
2758 if (mod_bit != 0)
|
|
2759 {
|
|
2760 int omod = modifiers;
|
|
2761 closure->modifiers = (modifiers | mod_bit);
|
|
2762 contents = get_keymap (contents, 1, 1);
|
|
2763 elisp_maphash (map_keymap_unsorted_mapper,
|
|
2764 XKEYMAP (contents)->table,
|
|
2765 map_keymap_unsorted_closure);
|
|
2766 closure->modifiers = omod;
|
|
2767 }
|
|
2768 else
|
|
2769 {
|
|
2770 struct key_data key;
|
|
2771 key.keysym = keysym;
|
|
2772 key.modifiers = modifiers;
|
|
2773 ((*closure->fn) (&key, contents, closure->arg));
|
|
2774 }
|
|
2775 }
|
|
2776
|
|
2777
|
|
2778 struct map_keymap_sorted_closure
|
|
2779 {
|
|
2780 Lisp_Object *result_locative;
|
|
2781 };
|
|
2782
|
|
2783 /* used by map_keymap_sorted() */
|
|
2784 static void
|
|
2785 map_keymap_sorted_mapper (CONST void *hash_key, void *hash_contents,
|
|
2786 void *map_keymap_sorted_closure)
|
|
2787 {
|
|
2788 struct map_keymap_sorted_closure *cl = map_keymap_sorted_closure;
|
|
2789 Lisp_Object key, contents;
|
|
2790 Lisp_Object *list = cl->result_locative;
|
|
2791 CVOID_TO_LISP (key, hash_key);
|
|
2792 VOID_TO_LISP (contents, hash_contents);
|
|
2793 *list = Fcons (Fcons (key, contents), *list);
|
|
2794 }
|
|
2795
|
|
2796
|
|
2797 /* used by map_keymap_sorted(), describe_map_sort_predicate(),
|
|
2798 and keymap_submaps().
|
|
2799 */
|
|
2800 static int
|
|
2801 map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
|
|
2802 Lisp_Object pred)
|
|
2803 {
|
|
2804 /* obj1 and obj2 are conses with keysyms in their cars. Cdrs are ignored.
|
|
2805 */
|
|
2806 unsigned int bit1, bit2;
|
|
2807 int sym1_p = 0;
|
|
2808 int sym2_p = 0;
|
|
2809 obj1 = XCAR (obj1);
|
|
2810 obj2 = XCAR (obj2);
|
|
2811
|
|
2812 if (EQ (obj1, obj2))
|
|
2813 return -1;
|
|
2814 bit1 = MODIFIER_HASH_KEY_BITS (obj1);
|
|
2815 bit2 = MODIFIER_HASH_KEY_BITS (obj2);
|
|
2816
|
|
2817 /* If either is a symbol with a character-set-property, then sort it by
|
|
2818 that code instead of alphabetically.
|
|
2819 */
|
|
2820 if (! bit1 && SYMBOLP (obj1))
|
|
2821 {
|
|
2822 Lisp_Object code = Fget (obj1, Vcharacter_set_property, Qnil);
|
|
2823 if (INTP (code))
|
|
2824 obj1 = code, sym1_p = 1;
|
|
2825 }
|
|
2826 if (! bit2 && SYMBOLP (obj2))
|
|
2827 {
|
|
2828 Lisp_Object code = Fget (obj2, Vcharacter_set_property, Qnil);
|
|
2829 if (INTP (code))
|
|
2830 obj2 = code, sym2_p = 1;
|
|
2831 }
|
|
2832
|
|
2833 /* all symbols (non-ASCIIs) come after characters (ASCIIs) */
|
|
2834 if (XTYPE (obj1) != XTYPE (obj2))
|
|
2835 return (SYMBOLP (obj2) ? 1 : -1);
|
|
2836
|
|
2837 if (! bit1 && CHARP (obj1)) /* they're both ASCII */
|
|
2838 {
|
|
2839 int o1 = XCHAR (obj1);
|
|
2840 int o2 = XCHAR (obj2);
|
|
2841 if (o1 == o2 && /* If one started out as a symbol and the */
|
|
2842 sym1_p != sym2_p) /* other didn't, the symbol comes last. */
|
|
2843 return (sym2_p ? 1 : -1);
|
|
2844
|
|
2845 return ((o1 < o2) ? 1 : -1); /* else just compare them */
|
|
2846 }
|
|
2847
|
|
2848 /* else they're both symbols. If they're both buckys, then order them. */
|
|
2849 if (bit1 && bit2)
|
|
2850 return ((bit1 < bit2) ? 1 : -1);
|
|
2851
|
|
2852 /* if only one is a bucky, then it comes later */
|
|
2853 if (bit1 || bit2)
|
|
2854 return (bit2 ? 1 : -1);
|
|
2855
|
|
2856 /* otherwise, string-sort them. */
|
|
2857 {
|
|
2858 char *s1 = (char *) string_data (XSYMBOL (obj1)->name);
|
|
2859 char *s2 = (char *) string_data (XSYMBOL (obj2)->name);
|
|
2860 return (
|
|
2861 #ifdef I18N2
|
|
2862 (0 > strcoll (s1, s2))
|
|
2863 #else
|
|
2864 (0 > strcmp (s1, s2))
|
|
2865 #endif
|
|
2866 ? 1 : -1);
|
|
2867 }
|
|
2868 }
|
|
2869
|
|
2870
|
|
2871 /* used by map_keymap() */
|
|
2872 static void
|
|
2873 map_keymap_sorted (Lisp_Object keymap_table,
|
|
2874 unsigned int modifiers,
|
|
2875 void (*function) (CONST struct key_data *key,
|
|
2876 Lisp_Object binding,
|
|
2877 void *map_keymap_sorted_closure),
|
|
2878 void *map_keymap_sorted_closure)
|
|
2879 {
|
|
2880 /* This function can GC */
|
|
2881 struct gcpro gcpro1;
|
|
2882 Lisp_Object contents = Qnil;
|
|
2883
|
|
2884 if (XINT (Fhashtable_fullness (keymap_table)) == 0)
|
|
2885 return;
|
|
2886
|
|
2887 GCPRO1 (contents);
|
|
2888
|
|
2889 {
|
|
2890 struct map_keymap_sorted_closure c1;
|
|
2891 c1.result_locative = &contents;
|
|
2892 elisp_maphash (map_keymap_sorted_mapper, keymap_table, &c1);
|
|
2893 }
|
|
2894 contents = list_sort (contents, Qnil, map_keymap_sort_predicate);
|
|
2895 for (; !NILP (contents); contents = XCDR (contents))
|
|
2896 {
|
|
2897 Lisp_Object keysym = XCAR (XCAR (contents));
|
|
2898 Lisp_Object binding = XCDR (XCAR (contents));
|
|
2899 unsigned int sub_bits = MODIFIER_HASH_KEY_BITS (keysym);
|
|
2900 if (sub_bits != 0)
|
|
2901 map_keymap_sorted (XKEYMAP (get_keymap (binding,
|
|
2902 1, 1))->table,
|
|
2903 (modifiers | sub_bits),
|
|
2904 function,
|
|
2905 map_keymap_sorted_closure);
|
|
2906 else
|
|
2907 {
|
|
2908 struct key_data k;
|
|
2909 k.keysym = keysym;
|
|
2910 k.modifiers = modifiers;
|
|
2911 ((*function) (&k, binding, map_keymap_sorted_closure));
|
|
2912 }
|
|
2913 }
|
|
2914 UNGCPRO;
|
|
2915 }
|
|
2916
|
|
2917
|
|
2918 /* used by Fmap_keymap() */
|
|
2919 static void
|
|
2920 map_keymap_mapper (CONST struct key_data *key,
|
|
2921 Lisp_Object binding,
|
|
2922 void *function)
|
|
2923 {
|
|
2924 /* This function can GC */
|
|
2925 Lisp_Object fn;
|
|
2926 VOID_TO_LISP (fn, function);
|
|
2927 call2 (fn, make_key_description (key, 1), binding);
|
|
2928 }
|
|
2929
|
|
2930
|
|
2931 static void
|
|
2932 map_keymap (Lisp_Object keymap_table, int sort_first,
|
|
2933 void (*function) (CONST struct key_data *key,
|
|
2934 Lisp_Object binding,
|
|
2935 void *fn_arg),
|
|
2936 void *fn_arg)
|
|
2937 {
|
|
2938 /* This function can GC */
|
|
2939 if (sort_first)
|
|
2940 map_keymap_sorted (keymap_table, 0, function, fn_arg);
|
|
2941 else
|
|
2942 {
|
|
2943 struct map_keymap_unsorted_closure map_keymap_unsorted_closure;
|
|
2944 map_keymap_unsorted_closure.fn = function;
|
|
2945 map_keymap_unsorted_closure.arg = fn_arg;
|
|
2946 map_keymap_unsorted_closure.modifiers = 0;
|
|
2947 elisp_maphash (map_keymap_unsorted_mapper, keymap_table,
|
|
2948 &map_keymap_unsorted_closure);
|
|
2949 }
|
|
2950 }
|
|
2951
|
|
2952 DEFUN ("map-keymap", Fmap_keymap, Smap_keymap, 2, 3, 0 /*
|
|
2953 Apply FUNCTION to each element of KEYMAP.
|
|
2954 FUNCTION will be called with two arguments: a key-description list, and
|
|
2955 the binding. The order in which the elements of the keymap are passed to
|
|
2956 the function is unspecified. If the function inserts new elements into
|
|
2957 the keymap, it may or may not be called with them later. No element of
|
|
2958 the keymap will ever be passed to the function more than once.
|
|
2959
|
|
2960 The function will not be called on elements of this keymap's parents
|
|
2961 (see the function `keymap-parents') or upon keymaps which are contained
|
|
2962 within this keymap (multi-character definitions).
|
|
2963 It will be called on \"meta\" characters since they are not really
|
|
2964 two-character sequences.
|
|
2965
|
|
2966 If the optional third argument SORT-FIRST is non-nil, then the elements of
|
|
2967 the keymap will be passed to the mapper function in a canonical order.
|
|
2968 Otherwise, they will be passed in hash (that is, random) order, which is
|
|
2969 faster.
|
|
2970 */ )
|
|
2971 (function, keymap, sort_first)
|
|
2972 Lisp_Object function, keymap, sort_first;
|
|
2973 {
|
|
2974 /* This function can GC */
|
|
2975 struct gcpro gcpro1, gcpro2;
|
|
2976
|
|
2977 /* tolerate obviously transposed args */
|
|
2978 if (!NILP (Fkeymapp (function)))
|
|
2979 {
|
|
2980 Lisp_Object tmp = function;
|
|
2981 function = keymap;
|
|
2982 keymap = tmp;
|
|
2983 }
|
|
2984 GCPRO2 (function, keymap);
|
|
2985 keymap = get_keymap (keymap, 1, 1);
|
|
2986 map_keymap (XKEYMAP (keymap)->table, !NILP (sort_first),
|
|
2987 map_keymap_mapper, LISP_TO_VOID (function));
|
|
2988 UNGCPRO;
|
|
2989 return Qnil;
|
|
2990 }
|
|
2991
|
|
2992
|
|
2993
|
|
2994 /************************************************************************/
|
|
2995 /* Accessible keymaps */
|
|
2996 /************************************************************************/
|
|
2997
|
|
2998 struct accessible_keymaps_closure
|
|
2999 {
|
|
3000 Lisp_Object tail;
|
|
3001 };
|
|
3002
|
|
3003
|
|
3004 static void
|
|
3005 accessible_keymaps_mapper_1 (Lisp_Object keysym, Lisp_Object contents,
|
|
3006 unsigned int modifiers,
|
|
3007 struct accessible_keymaps_closure *closure)
|
|
3008 {
|
|
3009 /* This function can GC */
|
|
3010 unsigned int subbits = MODIFIER_HASH_KEY_BITS (keysym);
|
|
3011
|
|
3012 if (subbits != 0)
|
|
3013 {
|
|
3014 Lisp_Object submaps;
|
|
3015
|
|
3016 contents = get_keymap (contents, 1, 1);
|
|
3017 submaps = keymap_submaps (contents);
|
|
3018 for (; !NILP (submaps); submaps = XCDR (submaps))
|
|
3019 {
|
|
3020 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)),
|
|
3021 XCDR (XCAR (submaps)),
|
|
3022 (subbits | modifiers),
|
|
3023 closure);
|
|
3024 }
|
|
3025 }
|
|
3026 else
|
|
3027 {
|
|
3028 Lisp_Object thisseq = Fcar (Fcar (closure->tail));
|
|
3029 Lisp_Object cmd = get_keyelt (contents, 1);
|
|
3030 Lisp_Object vec;
|
|
3031 int j;
|
|
3032 struct key_data key;
|
|
3033 key.keysym = keysym;
|
|
3034 key.modifiers = modifiers;
|
|
3035
|
|
3036 if (NILP (cmd))
|
|
3037 abort ();
|
|
3038 cmd = get_keymap (cmd, 0, 1);
|
|
3039 if (!KEYMAPP (cmd))
|
|
3040 abort ();
|
|
3041
|
|
3042 vec = make_vector (vector_length (XVECTOR (thisseq)) + 1, Qnil);
|
|
3043 for (j = 0; j < vector_length (XVECTOR (thisseq)); j++)
|
|
3044 vector_data (XVECTOR (vec)) [j] = vector_data (XVECTOR (thisseq)) [j];
|
|
3045 vector_data (XVECTOR (vec)) [j] = make_key_description (&key, 1);
|
|
3046
|
|
3047 nconc2 (closure->tail, list1 (Fcons (vec, cmd)));
|
|
3048 }
|
|
3049 }
|
|
3050
|
|
3051
|
|
3052 static Lisp_Object
|
|
3053 accessible_keymaps_keymap_mapper (Lisp_Object thismap, void *arg)
|
|
3054 {
|
|
3055 /* This function can GC */
|
|
3056 struct accessible_keymaps_closure *closure = arg;
|
|
3057 Lisp_Object submaps = keymap_submaps (thismap);
|
|
3058
|
|
3059 for (; !NILP (submaps); submaps = XCDR (submaps))
|
|
3060 {
|
|
3061 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)),
|
|
3062 XCDR (XCAR (submaps)),
|
|
3063 0,
|
|
3064 closure);
|
|
3065 }
|
|
3066 return (Qnil);
|
|
3067 }
|
|
3068
|
|
3069
|
|
3070 DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps,
|
|
3071 1, 2, 0 /*
|
|
3072 Find all keymaps accessible via prefix characters from STARTMAP.
|
|
3073 Returns a list of elements of the form (KEYS . MAP), where the sequence
|
|
3074 KEYS starting from STARTMAP gets you to MAP. These elements are ordered
|
|
3075 so that the KEYS increase in length. The first element is ([] . STARTMAP).
|
|
3076 An optional argument PREFIX, if non-nil, should be a key sequence;
|
|
3077 then the value includes only maps for prefixes that start with PREFIX.
|
|
3078 */ )
|
|
3079 (startmap, prefix)
|
|
3080 Lisp_Object startmap, prefix;
|
|
3081 {
|
|
3082 /* This function can GC */
|
|
3083 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
3084 Lisp_Object accessible_keymaps = Qnil;
|
|
3085 struct accessible_keymaps_closure c;
|
|
3086 c.tail = Qnil;
|
|
3087 GCPRO4 (accessible_keymaps, c.tail, prefix, startmap);
|
|
3088
|
|
3089 retry:
|
|
3090 startmap = get_keymap (startmap, 1, 1);
|
|
3091 if (NILP (prefix))
|
|
3092 prefix = make_vector (0, Qnil);
|
|
3093 else if (!VECTORP (prefix) || STRINGP (prefix))
|
|
3094 {
|
|
3095 prefix = wrong_type_argument (Qarrayp, prefix);
|
|
3096 goto retry;
|
|
3097 }
|
|
3098 else
|
|
3099 {
|
|
3100 int len = XINT (Flength (prefix));
|
|
3101 Lisp_Object def = Flookup_key (startmap, prefix, Qnil);
|
|
3102 Lisp_Object p;
|
|
3103 int iii;
|
|
3104 struct gcpro ngcpro1;
|
|
3105
|
|
3106 def = get_keymap (def, 0, 1);
|
|
3107 if (!KEYMAPP (def))
|
|
3108 goto RETURN;
|
|
3109
|
|
3110 startmap = def;
|
|
3111 p = make_vector (len, Qnil);
|
|
3112 NGCPRO1 (p);
|
|
3113 for (iii = 0; iii < len; iii++)
|
|
3114 {
|
|
3115 struct key_data key;
|
|
3116 define_key_parser (Faref (prefix, make_int (iii)), &key);
|
|
3117 vector_data (XVECTOR (p))[iii] = make_key_description (&key, 1);
|
|
3118 }
|
|
3119 NUNGCPRO;
|
|
3120 prefix = p;
|
|
3121 }
|
|
3122
|
|
3123 accessible_keymaps = list1 (Fcons (prefix, startmap));
|
|
3124
|
|
3125 /* For each map in the list maps,
|
|
3126 look at any other maps it points to
|
|
3127 and stick them at the end if they are not already in the list */
|
|
3128
|
|
3129 for (c.tail = accessible_keymaps;
|
|
3130 !NILP (c.tail);
|
|
3131 c.tail = XCDR (c.tail))
|
|
3132 {
|
|
3133 Lisp_Object thismap = Fcdr (Fcar (c.tail));
|
|
3134 CHECK_KEYMAP (thismap);
|
|
3135 traverse_keymaps (thismap, Qnil,
|
|
3136 accessible_keymaps_keymap_mapper, &c);
|
|
3137 }
|
|
3138 RETURN:
|
|
3139 UNGCPRO;
|
|
3140 return (accessible_keymaps);
|
|
3141 }
|
|
3142
|
|
3143
|
|
3144
|
|
3145 /************************************************************************/
|
|
3146 /* Pretty descriptions of key sequences */
|
|
3147 /************************************************************************/
|
|
3148
|
|
3149 DEFUN ("key-description", Fkey_description, Skey_description, 1, 1, 0 /*
|
|
3150 Return a pretty description of key-sequence KEYS.
|
|
3151 Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"
|
|
3152 spaces are put between sequence elements, etc.
|
|
3153 */ )
|
|
3154 (keys)
|
|
3155 Lisp_Object keys;
|
|
3156 {
|
|
3157 if (INTP (keys) || CONSP (keys) || SYMBOLP (keys) || EVENTP (keys))
|
|
3158 {
|
|
3159 return Fsingle_key_description (keys);
|
|
3160 }
|
|
3161 else if (VECTORP (keys) ||
|
|
3162 STRINGP (keys))
|
|
3163 {
|
|
3164 Lisp_Object string = Qnil;
|
|
3165 /* Lisp_Object sep = Qnil; */
|
|
3166 int size = XINT (Flength (keys));
|
|
3167 int i;
|
|
3168
|
|
3169 for (i = 0; i < size; i++)
|
|
3170 {
|
|
3171 Lisp_Object s2 = Fsingle_key_description
|
|
3172 (((STRINGP (keys))
|
|
3173 ? make_char (string_char (XSTRING (keys), i))
|
|
3174 : vector_data (XVECTOR (keys))[i]));
|
|
3175
|
|
3176 if (i == 0)
|
|
3177 string = s2;
|
|
3178 else
|
|
3179 {
|
|
3180 /* if (NILP (sep)) Lisp_Object sep = build_string (" ") */;
|
|
3181 string = concat2 (string, concat2 (Vsingle_space_string, s2));
|
|
3182 }
|
|
3183 }
|
|
3184 return (string);
|
|
3185 }
|
|
3186 return Fkey_description (wrong_type_argument (Qsequencep, keys));
|
|
3187 }
|
|
3188
|
|
3189 DEFUN ("single-key-description", Fsingle_key_description,
|
|
3190 Ssingle_key_description, 1, 1, 0 /*
|
|
3191 Return a pretty description of command character KEY.
|
|
3192 Control characters turn into C-whatever, etc.
|
|
3193 This differs from `text-char-description' in that it returns a description
|
|
3194 of a key read from the user rather than a character from a buffer.
|
|
3195 */ )
|
|
3196 (key)
|
|
3197 Lisp_Object key;
|
|
3198 {
|
|
3199 if (SYMBOLP (key))
|
|
3200 key = Fcons (key, Qnil); /* sleaze sleaze */
|
|
3201
|
|
3202 if (EVENTP (key) || CHARP (key))
|
|
3203 {
|
|
3204 char buf [255];
|
|
3205 if (!EVENTP (key))
|
|
3206 {
|
|
3207 struct Lisp_Event event;
|
|
3208 event.event_type = empty_event;
|
|
3209 CHECK_CHAR_COERCE_INT (key);
|
|
3210 character_to_event (XCHAR (key), &event,
|
|
3211 XCONSOLE (Vselected_console), 0);
|
|
3212 format_event_object (buf, &event, 1);
|
|
3213 }
|
|
3214 else
|
|
3215 format_event_object (buf, XEVENT (key), 1);
|
|
3216 return (build_string (buf));
|
|
3217 }
|
|
3218
|
|
3219 if (CONSP (key))
|
|
3220 {
|
|
3221 char buf[255];
|
|
3222 char *bufp = buf;
|
|
3223 Lisp_Object rest;
|
|
3224 buf[0] = 0;
|
|
3225 LIST_LOOP (rest, key)
|
|
3226 {
|
|
3227 Lisp_Object keysym = XCAR (rest);
|
|
3228 if (EQ (keysym, Qcontrol)) strcpy (bufp, "C-"), bufp += 2;
|
|
3229 else if (EQ (keysym, Qctrl)) strcpy (bufp, "C-"), bufp += 2;
|
|
3230 else if (EQ (keysym, Qmeta)) strcpy (bufp, "M-"), bufp += 2;
|
|
3231 else if (EQ (keysym, Qsuper)) strcpy (bufp, "S-"), bufp += 2;
|
|
3232 else if (EQ (keysym, Qhyper)) strcpy (bufp, "H-"), bufp += 2;
|
|
3233 else if (EQ (keysym, Qalt)) strcpy (bufp, "A-"), bufp += 2;
|
|
3234 else if (EQ (keysym, Qshift)) strcpy (bufp, "Sh-"), bufp += 3;
|
|
3235 else if (INTP (keysym))
|
|
3236 *bufp = XINT (keysym), bufp++, *bufp = 0;
|
|
3237 else
|
|
3238 {
|
|
3239 CHECK_SYMBOL (keysym);
|
|
3240 #if 0 /* This is bogus */
|
|
3241 if (EQ (keysym, QKlinefeed)) strcpy (bufp, "LFD");
|
|
3242 else if (EQ (keysym, QKtab)) strcpy (bufp, "TAB");
|
|
3243 else if (EQ (keysym, QKreturn)) strcpy (bufp, "RET");
|
|
3244 else if (EQ (keysym, QKescape)) strcpy (bufp, "ESC");
|
|
3245 else if (EQ (keysym, QKdelete)) strcpy (bufp, "DEL");
|
|
3246 else if (EQ (keysym, QKspace)) strcpy (bufp, "SPC");
|
|
3247 else if (EQ (keysym, QKbackspace)) strcpy (bufp, "BS");
|
|
3248 else
|
|
3249 #endif
|
|
3250 strcpy (bufp, (char *) string_data (XSYMBOL (keysym)->name));
|
|
3251 if (!NILP (XCDR (rest)))
|
|
3252 signal_simple_error ("invalid key description",
|
|
3253 key);
|
|
3254 }
|
|
3255 }
|
|
3256 return build_string (buf);
|
|
3257 }
|
|
3258 return Fsingle_key_description
|
|
3259 (wrong_type_argument (intern ("char-or-event-p"), key));
|
|
3260 }
|
|
3261
|
|
3262 DEFUN ("text-char-description", Ftext_char_description, Stext_char_description,
|
|
3263 1, 1, 0 /*
|
|
3264 Return a pretty description of file-character CHR.
|
|
3265 Unprintable characters turn into \"^char\" or \\NNN, depending on the value
|
|
3266 of the `ctl-arrow' variable.
|
|
3267 This differs from `single-key-description' in that it returns a description
|
|
3268 of a character from a buffer rather than a key read from the user.
|
|
3269 */ )
|
|
3270 (chr)
|
|
3271 Lisp_Object chr;
|
|
3272 {
|
|
3273 Bufbyte buf[200];
|
|
3274 Bufbyte *p;
|
|
3275 unsigned int c;
|
|
3276 Lisp_Object ctl_arrow = current_buffer->ctl_arrow;
|
|
3277 int ctl_p = !NILP (ctl_arrow);
|
|
3278 int printable_min = (INTP (ctl_arrow)
|
|
3279 ? XINT (ctl_arrow)
|
|
3280 : ((EQ (ctl_arrow, Qt) || EQ (ctl_arrow, Qnil))
|
|
3281 ? 256 : 160));
|
|
3282
|
|
3283 if (EVENTP (chr))
|
|
3284 {
|
|
3285 Lisp_Object ch = Fevent_to_character (chr, Qnil, Qnil, Qt);
|
|
3286 if (NILP (ch))
|
|
3287 return
|
|
3288 signal_simple_continuable_error
|
|
3289 ("character has no ASCII equivalent", Fcopy_event (chr, Qnil));
|
|
3290 chr = ch;
|
|
3291 }
|
|
3292
|
|
3293 CHECK_CHAR_COERCE_INT (chr);
|
|
3294
|
|
3295 c = XCHAR (chr);
|
|
3296 p = buf;
|
|
3297
|
|
3298 if (c >= printable_min)
|
|
3299 {
|
|
3300 p += set_charptr_emchar (p, c);
|
|
3301 }
|
|
3302 else if (c < 040 && ctl_p)
|
|
3303 {
|
|
3304 *p++ = '^';
|
|
3305 *p++ = c + 64; /* 'A' - 1 */
|
|
3306 }
|
|
3307 else if (c == 0177)
|
|
3308 {
|
|
3309 *p++ = '^';
|
|
3310 *p++ = '?';
|
|
3311 }
|
|
3312 else if (c >= 0200 || c < 040)
|
|
3313 {
|
|
3314 *p++ = '\\';
|
|
3315 *p++ = '0' + ((c & 0700) >> 6);
|
|
3316 *p++ = '0' + ((c & 0070) >> 3);
|
|
3317 *p++ = '0' + ((c & 0007));
|
|
3318 }
|
|
3319 else
|
|
3320 {
|
|
3321 p += set_charptr_emchar (p, c);
|
|
3322 }
|
|
3323
|
|
3324 *p = 0;
|
|
3325 return build_string ((char *) buf);
|
|
3326 }
|
|
3327
|
|
3328
|
|
3329 /************************************************************************/
|
|
3330 /* where-is (mapping bindings to keys) */
|
|
3331 /************************************************************************/
|
|
3332
|
|
3333 static Lisp_Object
|
|
3334 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
|
|
3335 Lisp_Object firstonly, char *target_buffer);
|
|
3336
|
|
3337 DEFUN ("where-is-internal", Fwhere_is_internal, Swhere_is_internal, 1, 5, 0 /*
|
|
3338 Return list of keys that invoke DEFINITION in KEYMAPS.
|
|
3339 KEYMAPS can be either a keymap (meaning search in that keymap and the
|
|
3340 current global keymap) or a list of keymaps (meaning search in exactly
|
|
3341 those keymaps and no others). If KEYMAPS is nil, search in the currently
|
|
3342 applicable maps for EVENT-OR-KEYS (this is equivalent to specifying
|
|
3343 `(current-keymaps EVENT-OR-KEYS)' as the argument to KEYMAPS).
|
|
3344
|
|
3345 If optional 3rd arg FIRSTONLY is non-nil, return a vector representing
|
|
3346 the first key sequence found, rather than a list of all possible key
|
|
3347 sequences.
|
|
3348
|
|
3349 If optional 4th arg NOINDIRECT is non-nil, don't follow indirections
|
|
3350 to other keymaps or slots. This makes it possible to search for an
|
|
3351 indirect definition itself.
|
|
3352 */ )
|
|
3353 (definition, keymaps, firstonly, noindirect, event_or_keys)
|
|
3354 Lisp_Object definition, keymaps, firstonly, noindirect, event_or_keys;
|
|
3355 {
|
|
3356 /* This function can GC */
|
|
3357 Lisp_Object maps[100];
|
|
3358 Lisp_Object *gubbish = maps;
|
|
3359 int nmaps;
|
|
3360
|
|
3361 /* Get keymaps as an array */
|
|
3362 if (NILP (keymaps))
|
|
3363 {
|
|
3364 nmaps = get_relevant_keymaps (event_or_keys, countof (maps),
|
|
3365 gubbish);
|
|
3366 if (nmaps > countof (maps))
|
|
3367 {
|
|
3368 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
3369 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
|
|
3370 }
|
|
3371 }
|
|
3372 else if (CONSP (keymaps))
|
|
3373 {
|
|
3374 Lisp_Object rest;
|
|
3375 int i;
|
|
3376
|
|
3377 nmaps = XINT (Flength (keymaps));
|
|
3378 if (nmaps > countof (maps))
|
|
3379 {
|
|
3380 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
3381 }
|
|
3382 for (rest = keymaps, i = 0; !NILP (rest);
|
|
3383 rest = XCDR (keymaps), i++)
|
|
3384 {
|
|
3385 gubbish[i] = get_keymap (XCAR (keymaps), 1, 1);
|
|
3386 }
|
|
3387 }
|
|
3388 else
|
|
3389 {
|
|
3390 nmaps = 1;
|
|
3391 gubbish[0] = get_keymap (keymaps, 1, 1);
|
|
3392 if (!EQ (gubbish[0], Vcurrent_global_map))
|
|
3393 {
|
|
3394 gubbish[1] = Vcurrent_global_map;
|
|
3395 nmaps++;
|
|
3396 }
|
|
3397 }
|
|
3398
|
|
3399 return where_is_internal (definition, gubbish, nmaps, firstonly, 0);
|
|
3400 }
|
|
3401
|
|
3402 /* This function is like
|
|
3403 (key-description (where-is-internal definition nil t))
|
|
3404 except that it writes its output into a (char *) buffer that you
|
|
3405 provide; it doesn't cons (or allocate memory) at all, so it's
|
|
3406 very fast. This is used by menubar.c.
|
|
3407 */
|
|
3408 void
|
|
3409 where_is_to_char (Lisp_Object definition, char *buffer)
|
|
3410 {
|
|
3411 /* This function can GC */
|
|
3412 Lisp_Object maps[100];
|
|
3413 Lisp_Object *gubbish = maps;
|
|
3414 int nmaps;
|
|
3415
|
|
3416 /* Get keymaps as an array */
|
|
3417 nmaps = get_relevant_keymaps (Qnil, countof (maps), gubbish);
|
|
3418 if (nmaps > countof (maps))
|
|
3419 {
|
|
3420 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
3421 nmaps = get_relevant_keymaps (Qnil, nmaps, gubbish);
|
|
3422 }
|
|
3423
|
|
3424 buffer[0] = 0;
|
|
3425 where_is_internal (definition, maps, nmaps, Qt, buffer);
|
|
3426 }
|
|
3427
|
|
3428
|
|
3429 static Lisp_Object
|
|
3430 raw_keys_to_keys (struct key_data *keys, int count)
|
|
3431 {
|
|
3432 Lisp_Object result = make_vector (count, Qnil);
|
|
3433 while (count--)
|
|
3434 vector_data (XVECTOR (result)) [count] =
|
|
3435 make_key_description (&(keys[count]), 1);
|
|
3436 return (result);
|
|
3437 }
|
|
3438
|
|
3439
|
|
3440 static void
|
|
3441 format_raw_keys (struct key_data *keys, int count, char *buf)
|
|
3442 {
|
|
3443 int i;
|
|
3444 struct Lisp_Event event;
|
|
3445 event.event_type = key_press_event;
|
|
3446 event.channel = Vselected_console;
|
|
3447 for (i = 0; i < count; i++)
|
|
3448 {
|
|
3449 event.event.key.keysym = keys[i].keysym;
|
|
3450 event.event.key.modifiers = keys[i].modifiers;
|
|
3451 format_event_object (buf, &event, 1);
|
|
3452 buf += strlen (buf);
|
|
3453 if (i < count-1)
|
|
3454 buf[0] = ' ', buf++;
|
|
3455 }
|
|
3456 }
|
|
3457
|
|
3458
|
|
3459 /* definition is the thing to look for.
|
|
3460 map is a keymap.
|
|
3461 shadow is an array of shadow_count keymaps; if there is a different
|
|
3462 binding in any of the keymaps of a key that we are considering
|
|
3463 returning, then we reconsider.
|
|
3464 firstonly means give up after finding the first match;
|
|
3465 keys_so_far and modifiers_so_far describe which map we're looking in;
|
|
3466 If we're in the "meta" submap of the map that "C-x 4" is bound to,
|
|
3467 then keys_so_far will be {(control x), \4}, and modifiers_so_far
|
|
3468 will be MOD_META. That is, keys_so_far is the chain of keys that we
|
|
3469 have followed, and modifiers_so_far_so_far is the bits (partial keys)
|
|
3470 beyond that.
|
|
3471
|
|
3472 (keys_so_far is a global buffer and the keys_count arg says how much
|
|
3473 of it we're currently interested in.)
|
|
3474
|
|
3475 If target_buffer is provided, then we write a key-description into it,
|
|
3476 to avoid consing a string. This only works with firstonly on.
|
|
3477 */
|
|
3478
|
|
3479 struct where_is_closure
|
|
3480 {
|
|
3481 Lisp_Object definition;
|
|
3482 Lisp_Object *shadow;
|
|
3483 int shadow_count;
|
|
3484 int firstonly;
|
|
3485 int keys_count;
|
|
3486 unsigned int modifiers_so_far;
|
|
3487 char *target_buffer;
|
|
3488 struct key_data *keys_so_far;
|
|
3489 int keys_so_far_total_size;
|
|
3490 int keys_so_far_malloced;
|
|
3491 };
|
|
3492
|
|
3493 static Lisp_Object where_is_recursive_mapper (Lisp_Object map, void *arg);
|
|
3494
|
|
3495 static Lisp_Object
|
|
3496 where_is_recursive_mapper (Lisp_Object map, void *arg)
|
|
3497 {
|
|
3498 /* This function can GC */
|
|
3499 struct where_is_closure *c = arg;
|
|
3500 Lisp_Object definition = c->definition;
|
|
3501 CONST int firstonly = c->firstonly;
|
|
3502 CONST unsigned int keys_count = c->keys_count;
|
|
3503 CONST unsigned int modifiers_so_far = c->modifiers_so_far;
|
|
3504 char *target_buffer = c->target_buffer;
|
|
3505 Lisp_Object keys = Fgethash (definition,
|
|
3506 XKEYMAP (map)->inverse_table,
|
|
3507 Qnil);
|
|
3508 Lisp_Object submaps;
|
|
3509 Lisp_Object result = Qnil;
|
|
3510
|
|
3511 if (!NILP (keys))
|
|
3512 {
|
|
3513 /* One or more keys in this map match the definition we're looking
|
|
3514 for. Verify that these bindings aren't shadowed by other bindings
|
|
3515 in the shadow maps. Either nil or number as value from
|
|
3516 raw_lookup_key() means undefined.
|
|
3517 */
|
|
3518 struct key_data *so_far = c->keys_so_far;
|
|
3519
|
|
3520 for (;;) /* loop over all keys that match */
|
|
3521 {
|
|
3522 Lisp_Object k = ((CONSP (keys)) ? XCAR (keys) : keys);
|
|
3523 int i;
|
|
3524
|
|
3525 so_far [keys_count].keysym = k;
|
|
3526 so_far [keys_count].modifiers = modifiers_so_far;
|
|
3527
|
|
3528 /* now loop over all shadow maps */
|
|
3529 for (i = 0; i < c->shadow_count; i++)
|
|
3530 {
|
|
3531 Lisp_Object shadowed = raw_lookup_key (c->shadow[i],
|
|
3532 so_far,
|
|
3533 keys_count + 1,
|
|
3534 0, 1);
|
|
3535
|
|
3536 if (NILP (shadowed) || CHARP (shadowed) ||
|
|
3537 EQ (shadowed, definition))
|
|
3538 continue; /* we passed this test; it's not shadowed here. */
|
|
3539 else
|
|
3540 /* ignore this key binding, since it actually has a
|
|
3541 different binding in a shadowing map */
|
|
3542 goto c_doesnt_have_proper_loop_exit_statements;
|
|
3543 }
|
|
3544
|
|
3545 /* OK, the key is for real */
|
|
3546 if (target_buffer)
|
|
3547 {
|
|
3548 if (!firstonly) abort ();
|
|
3549 format_raw_keys (so_far, keys_count + 1, target_buffer);
|
|
3550 return (make_int (1));
|
|
3551 }
|
|
3552 else if (firstonly)
|
|
3553 return raw_keys_to_keys (so_far, keys_count + 1);
|
|
3554 else
|
|
3555 result = Fcons (raw_keys_to_keys (so_far, keys_count + 1),
|
|
3556 result);
|
|
3557
|
|
3558 c_doesnt_have_proper_loop_exit_statements:
|
|
3559 /* now on to the next matching key ... */
|
|
3560 if (!CONSP (keys)) break;
|
|
3561 keys = XCDR (keys);
|
|
3562 }
|
|
3563 }
|
|
3564
|
|
3565 /* Now search the sub-keymaps of this map.
|
|
3566 If we're in "firstonly" mode and have already found one, this
|
|
3567 point is not reached. If we get one from lower down, either
|
|
3568 return it immediately (in firstonly mode) or tack it onto the
|
|
3569 end of the ones we've gotten so far.
|
|
3570 */
|
|
3571 for (submaps = keymap_submaps (map);
|
|
3572 !NILP (submaps);
|
|
3573 submaps = XCDR (submaps))
|
|
3574 {
|
|
3575 Lisp_Object key = XCAR (XCAR (submaps));
|
|
3576 Lisp_Object submap = XCDR (XCAR (submaps));
|
|
3577 unsigned int lower_modifiers;
|
|
3578 int lower_keys_count = keys_count;
|
|
3579 unsigned int bucky;
|
|
3580
|
|
3581 submap = get_keymap (submap, 0, 1);
|
|
3582
|
|
3583 if (EQ (submap, map))
|
|
3584 /* Arrgh! Some loser has introduced a loop... */
|
|
3585 continue;
|
|
3586
|
|
3587 /* If this is not a keymap, then that's probably because someone
|
|
3588 did an `fset' of a symbol that used to point to a map such that
|
|
3589 it no longer does. Sigh. Ignore this, and invalidate the cache
|
|
3590 so that it doesn't happen to us next time too.
|
|
3591 */
|
|
3592 if (NILP (submap))
|
|
3593 {
|
|
3594 XKEYMAP (map)->sub_maps_cache = Qt;
|
|
3595 continue;
|
|
3596 }
|
|
3597
|
|
3598 /* If the map is a "bucky" map, then add a bit to the
|
|
3599 modifiers_so_far list.
|
|
3600 Otherwise, add a new raw_key onto the end of keys_so_far.
|
|
3601 */
|
|
3602 bucky = MODIFIER_HASH_KEY_BITS (key);
|
|
3603 if (bucky != 0)
|
|
3604 lower_modifiers = (modifiers_so_far | bucky);
|
|
3605 else
|
|
3606 {
|
|
3607 struct key_data *so_far = c->keys_so_far;
|
|
3608 lower_modifiers = 0;
|
|
3609 so_far [lower_keys_count].keysym = key;
|
|
3610 so_far [lower_keys_count].modifiers = modifiers_so_far;
|
|
3611 lower_keys_count++;
|
|
3612 }
|
|
3613
|
|
3614 if (lower_keys_count >= c->keys_so_far_total_size)
|
|
3615 {
|
|
3616 int size = lower_keys_count + 50;
|
|
3617 if (! c->keys_so_far_malloced)
|
|
3618 {
|
|
3619 struct key_data *new = xmalloc (size * sizeof (struct key_data));
|
|
3620 memcpy ((void *)new, (const void *)c->keys_so_far,
|
|
3621 c->keys_so_far_total_size * sizeof (struct key_data));
|
|
3622 }
|
|
3623 else
|
|
3624 c->keys_so_far = xrealloc (c->keys_so_far,
|
|
3625 size * sizeof (struct key_data));
|
|
3626
|
|
3627 c->keys_so_far_total_size = size;
|
|
3628 c->keys_so_far_malloced = 1;
|
|
3629 }
|
|
3630
|
|
3631 {
|
|
3632 Lisp_Object lower;
|
|
3633
|
|
3634 c->keys_count = lower_keys_count;
|
|
3635 c->modifiers_so_far = lower_modifiers;
|
|
3636
|
|
3637 lower = traverse_keymaps (submap, Qnil, where_is_recursive_mapper,
|
|
3638 c);
|
|
3639 c->keys_count = keys_count;
|
|
3640 c->modifiers_so_far = modifiers_so_far;
|
|
3641
|
|
3642 if (!firstonly)
|
|
3643 result = nconc2 (lower, result);
|
|
3644 else if (!NILP (lower))
|
|
3645 return (lower);
|
|
3646 }
|
|
3647 }
|
|
3648 return (result);
|
|
3649 }
|
|
3650
|
|
3651
|
|
3652 static Lisp_Object
|
|
3653 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
|
|
3654 Lisp_Object firstonly, char *target_buffer)
|
|
3655 {
|
|
3656 /* This function can GC */
|
|
3657 Lisp_Object result = Qnil;
|
|
3658 int i;
|
|
3659 struct key_data raw[20];
|
|
3660 struct where_is_closure c;
|
|
3661
|
|
3662 c.definition = definition;
|
|
3663 c.shadow = maps;
|
|
3664 c.firstonly = !NILP (firstonly);
|
|
3665 c.target_buffer = target_buffer;
|
|
3666 c.keys_so_far = raw;
|
|
3667 c.keys_so_far_total_size = countof (raw);
|
|
3668 c.keys_so_far_malloced = 0;
|
|
3669
|
|
3670 /* Loop over each of the maps, accumulating the keys found.
|
|
3671 For each map searched, all previous maps shadow this one
|
|
3672 so that bogus keys aren't listed. */
|
|
3673 for (i = 0; i < nmaps; i++)
|
|
3674 {
|
|
3675 Lisp_Object this_result;
|
|
3676 c.shadow_count = i;
|
|
3677 /* Reset the things set in each iteration */
|
|
3678 c.keys_count = 0;
|
|
3679 c.modifiers_so_far = 0;
|
|
3680
|
|
3681 this_result = traverse_keymaps (maps[i], Qnil, where_is_recursive_mapper,
|
|
3682 &c);
|
|
3683 if (!NILP (firstonly))
|
|
3684 {
|
|
3685 result = this_result;
|
|
3686 if (!NILP (result))
|
|
3687 break;
|
|
3688 }
|
|
3689 else
|
|
3690 result = nconc2 (this_result, result);
|
|
3691 }
|
|
3692
|
|
3693 if (NILP (firstonly))
|
|
3694 result = Fnreverse (result);
|
|
3695
|
|
3696 if (c.keys_so_far_malloced)
|
|
3697 xfree (c.keys_so_far);
|
|
3698 return (result);
|
|
3699 }
|
|
3700
|
|
3701
|
|
3702 /************************************************************************/
|
|
3703 /* Describing keymaps */
|
|
3704 /************************************************************************/
|
|
3705
|
|
3706 DEFUN ("describe-bindings-internal",
|
|
3707 Fdescribe_bindings_internal, Sdescribe_bindings_internal, 1, 5, 0 /*
|
|
3708 Insert a list of all defined keys and their definitions in MAP.
|
|
3709 Optional second argument ALL says whether to include even \"uninteresting\"
|
|
3710 definitions (ie symbols with a non-nil `suppress-keymap' property.
|
|
3711 Third argument SHADOW is a list of keymaps whose bindings shadow those
|
|
3712 of map; if a binding is present in any shadowing map, it is not printed.
|
|
3713 Fourth argument PREFIX, if non-nil, should be a key sequence;
|
|
3714 only bindings which start with that key sequence will be printed.
|
|
3715 Fifth argument MOUSE-ONLY-P says to only print bindings for mouse clicks.
|
|
3716 */ )
|
|
3717 (map, all, shadow, prefix, mouse_only_p)
|
|
3718 Lisp_Object map, all, shadow, prefix, mouse_only_p;
|
|
3719 {
|
|
3720 /* This function can GC */
|
|
3721 describe_map_tree (map, NILP (all), shadow, prefix,
|
|
3722 !NILP (mouse_only_p));
|
|
3723 return (Qnil);
|
|
3724 }
|
|
3725
|
|
3726
|
|
3727 /* Insert a desription of the key bindings in STARTMAP,
|
|
3728 followed by those of all maps reachable through STARTMAP.
|
|
3729 If PARTIAL is nonzero, omit certain "uninteresting" commands
|
|
3730 (such as `undefined').
|
|
3731 If SHADOW is non-nil, it is a list of other maps;
|
|
3732 don't mention keys which would be shadowed by any of them
|
|
3733 If PREFIX is non-nil, only list bindings which start with those keys
|
|
3734 */
|
|
3735
|
|
3736 void
|
|
3737 describe_map_tree (Lisp_Object startmap, int partial, Lisp_Object shadow,
|
|
3738 Lisp_Object prefix, int mice_only_p)
|
|
3739 {
|
|
3740 /* This function can GC */
|
|
3741 Lisp_Object maps = Qnil;
|
|
3742 struct gcpro gcpro1, gcpro2; /* get_keymap may autoload */
|
|
3743 GCPRO2 (maps, shadow);
|
|
3744
|
|
3745 maps = Faccessible_keymaps (startmap, prefix);
|
|
3746
|
|
3747 for (; !NILP (maps); maps = Fcdr (maps))
|
|
3748 {
|
|
3749 Lisp_Object sub_shadow = Qnil;
|
|
3750 Lisp_Object elt = Fcar (maps);
|
|
3751 Lisp_Object tail = shadow;
|
|
3752 int no_prefix = (VECTORP (Fcar (elt))
|
|
3753 && XINT (Flength (Fcar (elt))) == 0);
|
|
3754 struct gcpro ngcpro1, ngcpro2, ngcpro3;
|
|
3755 NGCPRO3 (sub_shadow, elt, tail);
|
|
3756
|
|
3757 for (; CONSP (tail); tail = XCDR (tail))
|
|
3758 {
|
|
3759 Lisp_Object sh = XCAR (tail);
|
|
3760
|
|
3761 /* If the sequence by which we reach this keymap is zero-length,
|
|
3762 then the shadow maps for this keymap are just SHADOW. */
|
|
3763 if (no_prefix)
|
|
3764 ;
|
|
3765 /* If the sequence by which we reach this keymap actually has
|
|
3766 some elements, then the sequence's definition in SHADOW is
|
|
3767 what we should use. */
|
|
3768 else
|
|
3769 {
|
|
3770 sh = Flookup_key (sh, Fcar (elt), Qt);
|
|
3771 if (CHARP (sh))
|
|
3772 sh = Qnil;
|
|
3773 }
|
|
3774
|
|
3775 if (!NILP (sh))
|
|
3776 {
|
|
3777 Lisp_Object shm = get_keymap (sh, 0, 1);
|
|
3778 if (!KEYMAPP (shm))
|
|
3779 /* If sh is not nil and not a keymap, it completely shadows
|
|
3780 this map, so don't describe this map at all. */
|
|
3781 goto SKIP;
|
|
3782 sub_shadow = Fcons (shm, sub_shadow);
|
|
3783 }
|
|
3784 }
|
|
3785
|
|
3786 {
|
|
3787 /* Describe the contents of map MAP, assuming that this map
|
|
3788 itself is reached by the sequence of prefix keys KEYS (a vector).
|
|
3789 PARTIAL and SHADOW are as in `describe_map_tree'. */
|
|
3790 Lisp_Object keysdesc
|
|
3791 = ((!no_prefix)
|
|
3792 ? concat2 (Fkey_description (Fcar (elt)), Vsingle_space_string)
|
|
3793 : Qnil);
|
|
3794 describe_map (Fcdr (elt), keysdesc,
|
|
3795 describe_command,
|
|
3796 partial,
|
|
3797 sub_shadow,
|
|
3798 mice_only_p);
|
|
3799 }
|
|
3800 SKIP:
|
|
3801 NUNGCPRO;
|
|
3802 }
|
|
3803 UNGCPRO;
|
|
3804 }
|
|
3805
|
|
3806
|
|
3807 static void
|
|
3808 describe_command (Lisp_Object definition)
|
|
3809 {
|
|
3810 /* This function can GC */
|
|
3811 Lisp_Object buffer;
|
|
3812 int keymapp = !NILP (Fkeymapp (definition));
|
|
3813 struct gcpro gcpro1, gcpro2;
|
|
3814 GCPRO2 (definition, buffer);
|
|
3815
|
|
3816 XSETBUFFER (buffer, current_buffer);
|
|
3817 Findent_to (make_int (16), make_int (3), buffer);
|
|
3818 if (keymapp)
|
|
3819 buffer_insert_c_string (XBUFFER (buffer), "<< ");
|
|
3820
|
|
3821 if (SYMBOLP (definition))
|
|
3822 {
|
|
3823 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (definition));
|
|
3824 }
|
|
3825 else if (STRINGP (definition) || VECTORP (definition))
|
|
3826 {
|
|
3827 buffer_insert_c_string (XBUFFER (buffer), "Kbd Macro: ");
|
|
3828 buffer_insert1 (XBUFFER (buffer), Fkey_description (definition));
|
|
3829 }
|
|
3830 else if (COMPILED_FUNCTIONP (definition))
|
|
3831 buffer_insert_c_string (XBUFFER (buffer), "Anonymous Compiled Function");
|
|
3832 else if (CONSP (definition) && EQ (XCAR (definition), Qlambda))
|
|
3833 buffer_insert_c_string (XBUFFER (buffer), "Anonymous Lambda");
|
|
3834 else if (KEYMAPP (definition))
|
|
3835 {
|
|
3836 Lisp_Object name = XKEYMAP (definition)->name;
|
|
3837 if (STRINGP (name) || (SYMBOLP (name) && !NILP (name)))
|
|
3838 {
|
|
3839 buffer_insert_c_string (XBUFFER (buffer), "Prefix command ");
|
|
3840 if (SYMBOLP (name)
|
|
3841 && EQ (find_symbol_value (name), definition))
|
|
3842 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (name));
|
|
3843 else
|
|
3844 {
|
|
3845 buffer_insert1 (XBUFFER (buffer), Fprin1_to_string (name, Qnil));
|
|
3846 }
|
|
3847 }
|
|
3848 else
|
|
3849 buffer_insert_c_string (XBUFFER (buffer), "Prefix Command");
|
|
3850 }
|
|
3851 else
|
|
3852 buffer_insert_c_string (XBUFFER (buffer), "??");
|
|
3853
|
|
3854 if (keymapp)
|
|
3855 buffer_insert_c_string (XBUFFER (buffer), " >>");
|
|
3856 buffer_insert_c_string (XBUFFER (buffer), "\n");
|
|
3857 UNGCPRO;
|
|
3858 }
|
|
3859
|
|
3860 struct describe_map_closure
|
|
3861 {
|
|
3862 Lisp_Object *list; /* pointer to the list to update */
|
|
3863 Lisp_Object partial; /* whether to ignore suppressed commands */
|
|
3864 Lisp_Object shadow; /* list of maps shadowing this one */
|
|
3865 Lisp_Object self; /* this map */
|
|
3866 Lisp_Object self_root; /* this map, or some map that has this map as
|
|
3867 a parent. this is the base of the tree */
|
|
3868 int mice_only_p; /* whether we are to display only button bindings */
|
|
3869 };
|
|
3870
|
|
3871 struct describe_map_shadow_closure
|
|
3872 {
|
|
3873 CONST struct key_data *raw_key;
|
|
3874 Lisp_Object self;
|
|
3875 };
|
|
3876
|
|
3877 static Lisp_Object
|
|
3878 describe_map_mapper_shadow_search (Lisp_Object map, void *arg)
|
|
3879 {
|
|
3880 struct describe_map_shadow_closure *c = arg;
|
|
3881
|
|
3882 if (EQ (map, c->self))
|
|
3883 return (Qzero); /* Not shadowed; terminate search */
|
|
3884 else if (!NILP (keymap_lookup_directly (map,
|
|
3885 c->raw_key->keysym,
|
|
3886 c->raw_key->modifiers)))
|
|
3887 return (Qt);
|
|
3888 else
|
|
3889 return (Qnil);
|
|
3890 }
|
|
3891
|
|
3892
|
|
3893 static Lisp_Object
|
|
3894 keymap_lookup_inherited_mapper (Lisp_Object km, void *arg)
|
|
3895 {
|
|
3896 struct key_data *k = arg;
|
|
3897 return (keymap_lookup_directly (km, k->keysym, k->modifiers));
|
|
3898 }
|
|
3899
|
|
3900
|
|
3901 static void
|
|
3902 describe_map_mapper (CONST struct key_data *key,
|
|
3903 Lisp_Object binding,
|
|
3904 void *describe_map_closure)
|
|
3905 {
|
|
3906 /* This function can GC */
|
|
3907 struct describe_map_closure *closure = describe_map_closure;
|
|
3908 Lisp_Object keysym = key->keysym;
|
|
3909 unsigned int modifiers = key->modifiers;
|
|
3910
|
|
3911 /* Dont mention suppressed commands. */
|
|
3912 if (SYMBOLP (binding)
|
|
3913 && !NILP (closure->partial)
|
|
3914 && !NILP (Fget (binding, closure->partial, Qnil)))
|
|
3915 return;
|
|
3916
|
|
3917 /* If we're only supposed to display mouse bindings and this isn't one,
|
|
3918 then bug out. */
|
|
3919 if (closure->mice_only_p &&
|
|
3920 (! (EQ (keysym, Qbutton0) || EQ (keysym, Qbutton1)
|
|
3921 || EQ (keysym, Qbutton2) || EQ (keysym, Qbutton3)
|
|
3922 || EQ (keysym, Qbutton4) || EQ (keysym, Qbutton5)
|
|
3923 || EQ (keysym, Qbutton6) || EQ (keysym, Qbutton7))))
|
|
3924 return;
|
|
3925
|
|
3926 /* If this command in this map is shadowed by some other map, ignore it. */
|
|
3927 {
|
|
3928 Lisp_Object tail;
|
|
3929
|
|
3930 for (tail = closure->shadow; CONSP (tail); tail = XCDR (tail))
|
|
3931 {
|
|
3932 QUIT;
|
|
3933 if (!NILP (traverse_keymaps (XCAR (tail), Qnil,
|
|
3934 keymap_lookup_inherited_mapper,
|
|
3935 /* Cast to discard `const' */
|
|
3936 (void *)key)))
|
|
3937 return;
|
|
3938 }
|
|
3939 }
|
|
3940
|
|
3941 /* If this key is in some map of which this map is a parent, then ignore
|
|
3942 it (in that case, it has been shadowed).
|
|
3943 */
|
|
3944 {
|
|
3945 Lisp_Object sh;
|
|
3946 struct describe_map_shadow_closure c;
|
|
3947 c.raw_key = key;
|
|
3948 c.self = closure->self;
|
|
3949
|
|
3950 sh = traverse_keymaps (closure->self_root, Qnil,
|
|
3951 describe_map_mapper_shadow_search, &c);
|
|
3952 if (!NILP (sh) && !ZEROP (sh))
|
|
3953 return;
|
|
3954 }
|
|
3955
|
|
3956 /* Otherwise add it to the list to be sorted. */
|
|
3957 *(closure->list) = Fcons (Fcons (Fcons (keysym, make_int (modifiers)),
|
|
3958 binding),
|
|
3959 *(closure->list));
|
|
3960 }
|
|
3961
|
|
3962
|
|
3963 static int
|
|
3964 describe_map_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
|
|
3965 Lisp_Object pred)
|
|
3966 {
|
|
3967 /* obj1 and obj2 are conses of the form
|
|
3968 ( ( <keysym> . <modifiers> ) . <binding> )
|
|
3969 keysym and modifiers are used, binding is ignored.
|
|
3970 */
|
|
3971 unsigned int bit1, bit2;
|
|
3972 obj1 = XCAR (obj1);
|
|
3973 obj2 = XCAR (obj2);
|
|
3974 bit1 = XINT (XCDR (obj1));
|
|
3975 bit2 = XINT (XCDR (obj2));
|
|
3976 if (bit1 != bit2)
|
|
3977 return ((bit1 < bit2) ? 1 : -1);
|
|
3978 else
|
|
3979 return map_keymap_sort_predicate (obj1, obj2, pred);
|
|
3980 }
|
|
3981
|
|
3982 /* Elide 2 or more consecutive numeric keysyms bound to the same thing,
|
|
3983 or 2 or more symbolic keysyms that are bound to the same thing and
|
|
3984 have consecutive character-set-properties.
|
|
3985 */
|
|
3986 static int
|
|
3987 elide_next_two_p (Lisp_Object list)
|
|
3988 {
|
|
3989 Lisp_Object s1, s2;
|
|
3990
|
|
3991 if (NILP (XCDR (list)))
|
|
3992 return 0;
|
|
3993
|
|
3994 /* next two bindings differ */
|
|
3995 if (!EQ (XCDR (XCAR (list)),
|
|
3996 XCDR (XCAR (XCDR (list)))))
|
|
3997 return 0;
|
|
3998
|
|
3999 /* next two modifier-sets differ */
|
|
4000 if (!EQ (XCDR (XCAR (XCAR (list))),
|
|
4001 XCDR (XCAR (XCAR (XCDR (list))))))
|
|
4002 return 0;
|
|
4003
|
|
4004 s1 = XCAR (XCAR (XCAR (list)));
|
|
4005 s2 = XCAR (XCAR (XCAR (XCDR (list))));
|
|
4006
|
|
4007 if (SYMBOLP (s1))
|
|
4008 {
|
|
4009 Lisp_Object code = Fget (s1, Vcharacter_set_property, Qnil);
|
|
4010 if (INTP (code)) s1 = code;
|
|
4011 else return 0;
|
|
4012 }
|
|
4013 if (SYMBOLP (s2))
|
|
4014 {
|
|
4015 Lisp_Object code = Fget (s2, Vcharacter_set_property, Qnil);
|
|
4016 if (INTP (code)) s2 = code;
|
|
4017 else return 0;
|
|
4018 }
|
|
4019
|
|
4020 if (XCHAR (s1) == XCHAR (s2) ||
|
|
4021 XCHAR (s1) + 1 == XCHAR (s2))
|
|
4022 return 1;
|
|
4023 return 0;
|
|
4024 }
|
|
4025
|
|
4026
|
|
4027 static Lisp_Object
|
|
4028 describe_map_parent_mapper (Lisp_Object keymap, void *arg)
|
|
4029 {
|
|
4030 /* This function can GC */
|
|
4031 struct describe_map_closure *describe_map_closure = arg;
|
|
4032 describe_map_closure->self = keymap;
|
|
4033 map_keymap (XKEYMAP (keymap)->table,
|
|
4034 0, /* don't sort: we'll do it later */
|
|
4035 describe_map_mapper, describe_map_closure);
|
|
4036 return (Qnil);
|
|
4037 }
|
|
4038
|
|
4039
|
|
4040 static void
|
|
4041 describe_map (Lisp_Object keymap, Lisp_Object elt_prefix,
|
|
4042 void (*elt_describer) (Lisp_Object),
|
|
4043 int partial,
|
|
4044 Lisp_Object shadow,
|
|
4045 int mice_only_p)
|
|
4046 {
|
|
4047 /* This function can GC */
|
|
4048 struct describe_map_closure describe_map_closure;
|
|
4049 Lisp_Object list = Qnil;
|
|
4050 struct buffer *buf = current_buffer;
|
|
4051 Emchar printable_min = (CHAR_OR_CHAR_INTP (buf->ctl_arrow)
|
|
4052 ? XCHAR_OR_CHAR_INT (buf->ctl_arrow)
|
|
4053 : ((EQ (buf->ctl_arrow, Qt)
|
|
4054 || EQ (buf->ctl_arrow, Qnil))
|
|
4055 ? 256 : 160));
|
|
4056 int elided = 0;
|
|
4057 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
4058
|
|
4059 keymap = get_keymap (keymap, 1, 1);
|
|
4060 describe_map_closure.partial = (partial ? Qsuppress_keymap : Qnil);
|
|
4061 describe_map_closure.shadow = shadow;
|
|
4062 describe_map_closure.list = &list;
|
|
4063 describe_map_closure.self_root = keymap;
|
|
4064 describe_map_closure.mice_only_p = mice_only_p;
|
|
4065
|
|
4066 GCPRO4 (keymap, elt_prefix, shadow, list);
|
|
4067
|
|
4068 traverse_keymaps (keymap, Qnil,
|
|
4069 describe_map_parent_mapper, &describe_map_closure);
|
|
4070
|
|
4071 if (!NILP (list))
|
|
4072 {
|
|
4073 list = list_sort (list, Qnil, describe_map_sort_predicate);
|
|
4074 buffer_insert_c_string (buf, "\n");
|
|
4075 while (!NILP (list))
|
|
4076 {
|
|
4077 Lisp_Object elt = XCAR (XCAR (list));
|
|
4078 Lisp_Object keysym = XCAR (elt);
|
|
4079 unsigned int modifiers = XINT (XCDR (elt));
|
|
4080
|
|
4081 if (!NILP (elt_prefix))
|
|
4082 buffer_insert_lisp_string (buf, elt_prefix);
|
|
4083
|
|
4084 if (modifiers & MOD_META) buffer_insert_c_string (buf, "M-");
|
|
4085 if (modifiers & MOD_CONTROL) buffer_insert_c_string (buf, "C-");
|
|
4086 if (modifiers & MOD_SUPER) buffer_insert_c_string (buf, "S-");
|
|
4087 if (modifiers & MOD_HYPER) buffer_insert_c_string (buf, "H-");
|
|
4088 if (modifiers & MOD_ALT) buffer_insert_c_string (buf, "Alt-");
|
|
4089 if (modifiers & MOD_SHIFT) buffer_insert_c_string (buf, "Sh-");
|
|
4090 if (SYMBOLP (keysym))
|
|
4091 {
|
|
4092 Lisp_Object code = Fget (keysym, Vcharacter_set_property, Qnil);
|
|
4093 Emchar c = (CHAR_OR_CHAR_INTP (code)
|
|
4094 ? XCHAR_OR_CHAR_INT (code) : -1);
|
|
4095 /* Calling Fsingle_key_description() would cons more */
|
|
4096 #if 0 /* This is bogus */
|
|
4097 if (EQ (keysym, QKlinefeed))
|
|
4098 buffer_insert_c_string (buf, "LFD");
|
|
4099 else if (EQ (keysym, QKtab))
|
|
4100 buffer_insert_c_string (buf, "TAB");
|
|
4101 else if (EQ (keysym, QKreturn))
|
|
4102 buffer_insert_c_string (buf, "RET");
|
|
4103 else if (EQ (keysym, QKescape))
|
|
4104 buffer_insert_c_string (buf, "ESC");
|
|
4105 else if (EQ (keysym, QKdelete))
|
|
4106 buffer_insert_c_string (buf, "DEL");
|
|
4107 else if (EQ (keysym, QKspace))
|
|
4108 buffer_insert_c_string (buf, "SPC");
|
|
4109 else if (EQ (keysym, QKbackspace))
|
|
4110 buffer_insert_c_string (buf, "BS");
|
|
4111 else
|
|
4112 #endif
|
|
4113 if (c >= printable_min)
|
|
4114 buffer_insert_emacs_char (buf, c);
|
|
4115 else buffer_insert1 (buf, Fsymbol_name (keysym));
|
|
4116 }
|
|
4117 else if (CHARP (keysym))
|
|
4118 buffer_insert_emacs_char (buf, XCHAR (keysym));
|
|
4119 else
|
|
4120 buffer_insert_c_string (buf, "---bad keysym---");
|
|
4121
|
|
4122 if (elided)
|
|
4123 elided = 0;
|
|
4124 else
|
|
4125 {
|
|
4126 int k = 0;
|
|
4127
|
|
4128 while (elide_next_two_p (list))
|
|
4129 {
|
|
4130 k++;
|
|
4131 list = XCDR (list);
|
|
4132 }
|
|
4133 if (k != 0)
|
|
4134 {
|
|
4135 if (k == 1)
|
|
4136 buffer_insert_c_string (buf, ", ");
|
|
4137 else
|
|
4138 buffer_insert_c_string (buf, " .. ");
|
|
4139 elided = 1;
|
|
4140 continue;
|
|
4141 }
|
|
4142 }
|
|
4143
|
|
4144 /* Print a description of the definition of this character. */
|
|
4145 (*elt_describer) (XCDR (XCAR (list)));
|
|
4146 list = XCDR (list);
|
|
4147 }
|
|
4148 }
|
|
4149 UNGCPRO;
|
|
4150 }
|
|
4151
|
|
4152
|
|
4153 void
|
|
4154 syms_of_keymap (void)
|
|
4155 {
|
|
4156 defsymbol (&Qminor_mode_map_alist, "minor-mode-map-alist");
|
|
4157
|
|
4158 defsymbol (&Qkeymapp, "keymapp");
|
|
4159
|
|
4160 defsymbol (&Qsuppress_keymap, "suppress-keymap");
|
|
4161
|
|
4162 defsymbol (&Qmodeline_map, "modeline-map");
|
|
4163 defsymbol (&Qtoolbar_map, "toolbar-map");
|
|
4164
|
|
4165 defsubr (&Skeymap_parents);
|
|
4166 defsubr (&Sset_keymap_parents);
|
|
4167 defsubr (&Skeymap_name);
|
|
4168 defsubr (&Sset_keymap_name);
|
|
4169 defsubr (&Skeymap_prompt);
|
|
4170 defsubr (&Sset_keymap_prompt);
|
|
4171 defsubr (&Skeymap_default_binding);
|
|
4172 defsubr (&Sset_keymap_default_binding);
|
|
4173
|
|
4174 defsubr (&Skeymapp);
|
|
4175 defsubr (&Smake_keymap);
|
|
4176 defsubr (&Smake_sparse_keymap);
|
|
4177
|
|
4178 defsubr (&Scopy_keymap);
|
|
4179 defsubr (&Skeymap_fullness);
|
|
4180 defsubr (&Smap_keymap);
|
|
4181 defsubr (&Sevent_matches_key_specifier_p);
|
|
4182 defsubr (&Sdefine_key);
|
|
4183 defsubr (&Slookup_key);
|
|
4184 defsubr (&Skey_binding);
|
|
4185 defsubr (&Suse_global_map);
|
|
4186 defsubr (&Suse_local_map);
|
|
4187 defsubr (&Scurrent_local_map);
|
|
4188 defsubr (&Scurrent_global_map);
|
|
4189 defsubr (&Scurrent_keymaps);
|
|
4190 defsubr (&Saccessible_keymaps);
|
|
4191 defsubr (&Skey_description);
|
|
4192 defsubr (&Ssingle_key_description);
|
|
4193 defsubr (&Swhere_is_internal);
|
|
4194 defsubr (&Sdescribe_bindings_internal);
|
|
4195
|
|
4196 defsubr (&Stext_char_description);
|
|
4197
|
|
4198 defsymbol (&Qcontrol, "control");
|
|
4199 defsymbol (&Qctrl, "ctrl");
|
|
4200 defsymbol (&Qmeta, "meta");
|
|
4201 defsymbol (&Qsuper, "super");
|
|
4202 defsymbol (&Qhyper, "hyper");
|
|
4203 defsymbol (&Qalt, "alt");
|
|
4204 defsymbol (&Qshift, "shift");
|
|
4205 defsymbol (&Qbutton0, "button0");
|
|
4206 defsymbol (&Qbutton1, "button1");
|
|
4207 defsymbol (&Qbutton2, "button2");
|
|
4208 defsymbol (&Qbutton3, "button3");
|
|
4209 defsymbol (&Qbutton4, "button4");
|
|
4210 defsymbol (&Qbutton5, "button5");
|
|
4211 defsymbol (&Qbutton6, "button6");
|
|
4212 defsymbol (&Qbutton7, "button7");
|
|
4213 defsymbol (&Qbutton0up, "button0up");
|
|
4214 defsymbol (&Qbutton1up, "button1up");
|
|
4215 defsymbol (&Qbutton2up, "button2up");
|
|
4216 defsymbol (&Qbutton3up, "button3up");
|
|
4217 defsymbol (&Qbutton4up, "button4up");
|
|
4218 defsymbol (&Qbutton5up, "button5up");
|
|
4219 defsymbol (&Qbutton6up, "button6up");
|
|
4220 defsymbol (&Qbutton7up, "button7up");
|
|
4221 defsymbol (&Qmenu_selection, "menu-selection");
|
|
4222 defsymbol (&QLFD, "LFD");
|
|
4223 defsymbol (&QTAB, "TAB");
|
|
4224 defsymbol (&QRET, "RET");
|
|
4225 defsymbol (&QESC, "ESC");
|
|
4226 defsymbol (&QDEL, "DEL");
|
|
4227 defsymbol (&QBS, "BS");
|
|
4228 }
|
|
4229
|
|
4230 void
|
|
4231 vars_of_keymap (void)
|
|
4232 {
|
|
4233 DEFVAR_LISP ("meta-prefix-char", &Vmeta_prefix_char /*
|
|
4234 Meta-prefix character.
|
|
4235 This character followed by some character `foo' turns into `Meta-foo'.
|
|
4236 This can be any form recognized as a single key specifier.
|
|
4237 To disable the meta-prefix-char, set it to a negative number.
|
|
4238 */ );
|
|
4239 Vmeta_prefix_char = make_char (033);
|
|
4240
|
|
4241 DEFVAR_LISP ("mouse-grabbed-buffer", &Vmouse_grabbed_buffer /*
|
|
4242 A buffer which should be consulted first for all mouse activity.
|
|
4243 When a mouse-click is processed, it will first be looked up in the
|
|
4244 local-map of this buffer, and then through the normal mechanism if there
|
|
4245 is no binding for that click. This buffer's value of `mode-motion-hook'
|
|
4246 will be consulted instead of the `mode-motion-hook' of the buffer of the
|
|
4247 window under the mouse. You should *bind* this, not set it.
|
|
4248 */ );
|
|
4249 Vmouse_grabbed_buffer = Qnil;
|
|
4250
|
|
4251 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map /*
|
|
4252 Keymap that overrides all other local keymaps.
|
|
4253 If this variable is non-nil, it is used as a keymap instead of the
|
|
4254 buffer's local map, and the minor mode keymaps and extent-local keymaps.
|
|
4255 You should *bind* this, not set it.
|
|
4256 */ );
|
|
4257 Voverriding_local_map = Qnil;
|
|
4258
|
|
4259 Fset (Qminor_mode_map_alist, Qnil);
|
|
4260
|
|
4261 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map /*
|
|
4262 Keymap of key translations that can override keymaps.
|
|
4263 This keymap works like `function-key-map', but comes after that,
|
|
4264 and applies even for keys that have ordinary bindings.
|
|
4265 */ );
|
|
4266
|
|
4267 DEFVAR_INT ("keymap-tick", &keymap_tick /*
|
|
4268 Incremented for each change to any keymap.
|
|
4269 */ );
|
|
4270 keymap_tick = 0;
|
|
4271
|
|
4272 staticpro (&Vcurrent_global_map);
|
|
4273
|
|
4274 Vsingle_space_string = make_pure_string ((CONST Bufbyte *) " ", 1, Qnil, 1);
|
|
4275 staticpro (&Vsingle_space_string);
|
|
4276 }
|
|
4277
|
|
4278 void
|
|
4279 complex_vars_of_keymap (void)
|
|
4280 {
|
|
4281 /* This function can GC */
|
|
4282 Lisp_Object ESC_prefix = intern ("ESC-prefix");
|
|
4283 Lisp_Object meta_disgustitute;
|
|
4284
|
|
4285 Vcurrent_global_map = Fmake_keymap (Qnil);
|
|
4286
|
|
4287 meta_disgustitute = Fmake_keymap (Qnil);
|
|
4288 Ffset (ESC_prefix, meta_disgustitute);
|
|
4289 /* no need to protect meta_disgustitute, though */
|
|
4290 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (MOD_META),
|
|
4291 XKEYMAP (Vcurrent_global_map),
|
|
4292 meta_disgustitute);
|
|
4293 XKEYMAP (Vcurrent_global_map)->sub_maps_cache = Qt;
|
|
4294
|
|
4295 Vkey_translation_map = Fmake_sparse_keymap (intern ("key-translation-map"));
|
|
4296 }
|