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