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