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