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