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 {
|
|
2384 get_relevant_minor_maps (buffer, &closure);
|
|
2385 relevant_map_push (XBUFFER (buffer)->keymap, &closure);
|
|
2386 }
|
|
2387 }
|
|
2388 }
|
|
2389 else if (!NILP (Fevent_over_toolbar_p (terminal)))
|
|
2390 {
|
|
2391 Lisp_Object map = Fsymbol_value (Qtoolbar_map);
|
|
2392
|
|
2393 if (!UNBOUNDP (map) && !NILP (map))
|
|
2394 relevant_map_push (map, &closure);
|
|
2395 }
|
|
2396 }
|
|
2397 #endif /* HAVE_WINDOW_SYSTEM */
|
|
2398
|
|
2399 {
|
|
2400 int nmaps = closure.nmaps;
|
|
2401 /* Silently truncate at 100 keymaps to prevent infinite losssage */
|
|
2402 if (nmaps >= max_maps && max_maps > 0)
|
|
2403 maps[max_maps - 1] = Vcurrent_global_map;
|
|
2404 else
|
|
2405 maps[nmaps] = Vcurrent_global_map;
|
|
2406 UNGCPRO;
|
|
2407 return (nmaps + 1);
|
|
2408 }
|
|
2409 }
|
|
2410
|
|
2411 /* Returns a set of keymaps extracted from the extents at POS in
|
|
2412 BUFFER_OR_STRING. The GLYPH arg, if specified, is one more extent
|
|
2413 to look for a keymap in, and if it has one, its keymap will be the
|
|
2414 first element in the list returned. This is so we can correctly
|
|
2415 search the keymaps associated with glyphs which may be physically
|
|
2416 disjoint from their extents: for example, if a glyph is out in the
|
|
2417 margin, we should still consult the kemyap of that glyph's extent,
|
|
2418 which may not itself be under the mouse.
|
|
2419 */
|
|
2420 static void
|
|
2421 get_relevant_extent_keymaps (Lisp_Object pos, Lisp_Object buffer_or_string,
|
|
2422 Lisp_Object glyph,
|
|
2423 struct relevant_maps *closure)
|
|
2424 {
|
|
2425 /* This function can GC */
|
|
2426 /* the glyph keymap, if any, comes first.
|
|
2427 (Processing it twice is no big deal: noop.) */
|
|
2428 if (!NILP (glyph))
|
|
2429 {
|
|
2430 Lisp_Object keymap = Fextent_property (glyph, Qkeymap, Qnil);
|
|
2431 if (!NILP (keymap))
|
|
2432 relevant_map_push (get_keymap (keymap, 1, 1), closure);
|
|
2433 }
|
|
2434
|
|
2435 /* Next check the extents at the text position, if any */
|
|
2436 if (!NILP (pos))
|
|
2437 {
|
|
2438 Lisp_Object extent;
|
|
2439 for (extent = Fextent_at (pos, buffer_or_string, Qkeymap, Qnil, Qnil);
|
|
2440 !NILP (extent);
|
|
2441 extent = Fextent_at (pos, buffer_or_string, Qkeymap, extent, Qnil))
|
|
2442 {
|
|
2443 Lisp_Object keymap = Fextent_property (extent, Qkeymap, Qnil);
|
|
2444 if (!NILP (keymap))
|
|
2445 relevant_map_push (get_keymap (keymap, 1, 1), closure);
|
|
2446 QUIT;
|
|
2447 }
|
|
2448 }
|
|
2449 }
|
|
2450
|
|
2451 static Lisp_Object
|
|
2452 minor_mode_keymap_predicate (Lisp_Object assoc, Lisp_Object buffer)
|
|
2453 {
|
|
2454 /* This function can GC */
|
|
2455 if (CONSP (assoc))
|
|
2456 {
|
|
2457 Lisp_Object sym = XCAR (assoc);
|
|
2458 if (SYMBOLP (sym))
|
|
2459 {
|
|
2460 Lisp_Object val = symbol_value_in_buffer (sym, buffer);
|
|
2461 if (!NILP (val) && !UNBOUNDP (val))
|
|
2462 {
|
|
2463 Lisp_Object map = get_keymap (XCDR (assoc), 0, 1);
|
|
2464 return (map);
|
|
2465 }
|
|
2466 }
|
|
2467 }
|
|
2468 return (Qnil);
|
|
2469 }
|
|
2470
|
|
2471 static void
|
|
2472 get_relevant_minor_maps (Lisp_Object buffer, struct relevant_maps *closure)
|
|
2473 {
|
|
2474 /* This function can GC */
|
|
2475 Lisp_Object alist;
|
|
2476
|
|
2477 /* Will you ever lose badly if you make this circular! */
|
|
2478 for (alist = symbol_value_in_buffer (Qminor_mode_map_alist, buffer);
|
|
2479 CONSP (alist);
|
|
2480 alist = XCDR (alist))
|
|
2481 {
|
|
2482 Lisp_Object m = minor_mode_keymap_predicate (XCAR (alist),
|
|
2483 buffer);
|
|
2484 if (!NILP (m)) relevant_map_push (m, closure);
|
|
2485 QUIT;
|
|
2486 }
|
|
2487 }
|
|
2488
|
|
2489 /* #### Would map-current-keymaps be a better thing?? */
|
20
|
2490 DEFUN ("current-keymaps", Fcurrent_keymaps, 0, 1, 0, /*
|
0
|
2491 Return a list of the current keymaps that will be searched for bindings.
|
|
2492 This lists keymaps such as the current local map and the minor-mode maps,
|
|
2493 but does not list the parents of those keymaps.
|
|
2494 EVENT-OR-KEYS controls which keymaps will be listed.
|
|
2495 If EVENT-OR-KEYS is a mouse event (or a vector whose last element is a
|
|
2496 mouse event), the keymaps for that mouse event will be listed (see
|
|
2497 `key-binding'). Otherwise, the keymaps for key presses will be listed.
|
20
|
2498 */
|
|
2499 (event_or_keys))
|
0
|
2500 {
|
|
2501 /* This function can GC */
|
|
2502 struct gcpro gcpro1;
|
|
2503 Lisp_Object maps[100];
|
|
2504 Lisp_Object *gubbish = maps;
|
|
2505 int nmaps;
|
|
2506
|
|
2507 GCPRO1 (event_or_keys);
|
|
2508 nmaps = get_relevant_keymaps (event_or_keys, countof (maps),
|
|
2509 gubbish);
|
|
2510 if (nmaps > countof (maps))
|
|
2511 {
|
|
2512 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
2513 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
|
|
2514 }
|
|
2515 UNGCPRO;
|
|
2516 return (Flist (nmaps, gubbish));
|
|
2517 }
|
|
2518
|
20
|
2519 DEFUN ("key-binding", Fkey_binding, 1, 2, 0, /*
|
0
|
2520 Return the binding for command KEYS in current keymaps.
|
|
2521 KEYS is a string, a vector of events, or a vector of key-description lists
|
|
2522 as described in the documentation for the `define-key' function.
|
|
2523 The binding is probably a symbol with a function definition; see
|
|
2524 the documentation for `lookup-key' for more information.
|
|
2525
|
|
2526 For key-presses, the order of keymaps searched is:
|
|
2527 - the `keymap' property of any extent(s) at point;
|
|
2528 - any applicable minor-mode maps;
|
|
2529 - the current-local-map of the current-buffer;
|
|
2530 - the current global map.
|
|
2531
|
|
2532 For mouse-clicks, the order of keymaps searched is:
|
|
2533 - the current-local-map of the `mouse-grabbed-buffer' if any;
|
|
2534 - the `keymap' property of any extent(s) at the position of the click
|
|
2535 (this includes modeline extents);
|
|
2536 - the modeline-map of the buffer corresponding to the modeline under
|
|
2537 the mouse (if the click happened over a modeline);
|
|
2538 - the value of toolbar-map in the current-buffer (if the click
|
|
2539 happened over a toolbar);
|
|
2540 - the current-local-map of the buffer under the mouse (does not
|
|
2541 apply to toolbar clicks);
|
|
2542 - any applicable minor-mode maps;
|
|
2543 - the current global map.
|
|
2544
|
|
2545 Note that if `overriding-local-map' or `overriding-terminal-local-map'
|
|
2546 is non-nil, *only* those two maps and the current global map are searched.
|
20
|
2547 */
|
|
2548 (keys, accept_default))
|
0
|
2549 {
|
|
2550 /* This function can GC */
|
|
2551 int i;
|
|
2552 Lisp_Object maps[100];
|
|
2553 int nmaps;
|
|
2554 struct gcpro gcpro1, gcpro2;
|
|
2555 GCPRO2 (keys, accept_default); /* get_relevant_keymaps may autoload */
|
|
2556
|
|
2557 nmaps = get_relevant_keymaps (keys, countof (maps), maps);
|
|
2558
|
|
2559 UNGCPRO;
|
|
2560
|
|
2561 if (EVENTP (keys)) /* unadvertised "feature" for the future */
|
|
2562 return (lookup_events (keys, nmaps, maps,
|
|
2563 !NILP (accept_default)));
|
|
2564
|
|
2565 for (i = 0; i < nmaps; i++)
|
|
2566 {
|
|
2567 Lisp_Object tem = Flookup_key (maps[i], keys,
|
|
2568 accept_default);
|
|
2569 if (INTP (tem))
|
|
2570 {
|
|
2571 /* Too long in some local map means don't look at global map */
|
|
2572 return (Qnil);
|
|
2573 }
|
|
2574 else if (!NILP (tem))
|
|
2575 return (tem);
|
|
2576 }
|
|
2577 return (Qnil);
|
|
2578 }
|
|
2579
|
|
2580 static Lisp_Object
|
|
2581 process_event_binding_result (Lisp_Object result)
|
|
2582 {
|
|
2583 if (EQ (result, Qundefined))
|
|
2584 /* The suppress-keymap function binds keys to 'undefined - special-case
|
|
2585 that here, so that being bound to that has the same error-behavior as
|
|
2586 not being defined at all.
|
|
2587 */
|
|
2588 result = Qnil;
|
|
2589 if (!NILP (result))
|
|
2590 {
|
|
2591 Lisp_Object map;
|
|
2592 /* Snap out possible keymap indirections */
|
|
2593 map = get_keymap (result, 0, 1);
|
|
2594 if (!NILP (map))
|
|
2595 result = map;
|
|
2596 }
|
|
2597
|
|
2598 return result;
|
|
2599 }
|
|
2600
|
|
2601 /* Attempts to find a command corresponding to the event-sequence
|
|
2602 whose head is event0 (sequence is threaded though event_next).
|
|
2603
|
|
2604 The return value will be
|
|
2605
|
|
2606 -- nil (there is no binding; this will also be returned
|
|
2607 whenever the event chain is "too long", i.e. there
|
|
2608 is a non-nil, non-keymap binding for a prefix of
|
|
2609 the event chain)
|
|
2610 -- a keymap (part of a command has been specified)
|
|
2611 -- a command (anything that satisfies `commandp'; this includes
|
|
2612 some symbols, lists, subrs, strings, vectors, and
|
|
2613 compiled-function objects) */
|
|
2614 Lisp_Object
|
|
2615 event_binding (Lisp_Object event0, int accept_default)
|
|
2616 {
|
|
2617 /* This function can GC */
|
|
2618 Lisp_Object maps[100];
|
|
2619 int nmaps;
|
|
2620
|
|
2621 assert (EVENTP (event0));
|
|
2622
|
|
2623 nmaps = get_relevant_keymaps (event0, countof (maps), maps);
|
|
2624 return (process_event_binding_result
|
|
2625 (lookup_events (event0, nmaps, maps, accept_default)));
|
|
2626 }
|
|
2627
|
|
2628 /* Attempts to find a function key mapping corresponding to the
|
|
2629 event-sequence whose head is event0 (sequence is threaded through
|
|
2630 event_next). The return value will be the same as for event_binding(). */
|
|
2631 Lisp_Object
|
|
2632 munging_key_map_event_binding (Lisp_Object event0,
|
|
2633 enum munge_me_out_the_door munge)
|
|
2634 {
|
|
2635 Lisp_Object the_map;
|
|
2636 Lisp_Object maps[1];
|
|
2637
|
|
2638 if (munge == MUNGE_ME_FUNCTION_KEY)
|
|
2639 {
|
|
2640 struct console *c = event_console_or_selected (event0);
|
|
2641
|
|
2642 the_map = CONSOLE_FUNCTION_KEY_MAP (c);
|
|
2643 }
|
|
2644 else
|
|
2645 the_map = Vkey_translation_map;
|
|
2646
|
|
2647 if (NILP (the_map))
|
|
2648 return Qnil;
|
|
2649
|
|
2650 maps[0] = the_map;
|
|
2651 return process_event_binding_result (lookup_events (event0, 1, maps, 1));
|
|
2652 }
|
|
2653
|
|
2654
|
|
2655 /************************************************************************/
|
|
2656 /* Setting/querying the global and local maps */
|
|
2657 /************************************************************************/
|
|
2658
|
20
|
2659 DEFUN ("use-global-map", Fuse_global_map, 1, 1, 0, /*
|
0
|
2660 Select KEYMAP as the global keymap.
|
20
|
2661 */
|
|
2662 (keymap))
|
0
|
2663 {
|
|
2664 /* This function can GC */
|
|
2665 keymap = get_keymap (keymap, 1, 1);
|
|
2666 Vcurrent_global_map = keymap;
|
|
2667 return Qnil;
|
|
2668 }
|
|
2669
|
20
|
2670 DEFUN ("use-local-map", Fuse_local_map, 1, 2, 0, /*
|
0
|
2671 Select KEYMAP as the local keymap in BUFFER.
|
|
2672 If KEYMAP is nil, that means no local keymap.
|
|
2673 If BUFFER is nil, the current buffer is assumed.
|
20
|
2674 */
|
|
2675 (keymap, buffer))
|
0
|
2676 {
|
|
2677 /* This function can GC */
|
|
2678 struct buffer *b = decode_buffer (buffer, 0);
|
|
2679 if (!NILP (keymap))
|
|
2680 keymap = get_keymap (keymap, 1, 1);
|
|
2681
|
|
2682 b->keymap = keymap;
|
|
2683
|
|
2684 return Qnil;
|
|
2685 }
|
|
2686
|
20
|
2687 DEFUN ("current-local-map", Fcurrent_local_map, 0, 1, 0, /*
|
0
|
2688 Return BUFFER's local keymap, or nil if it has none.
|
|
2689 If BUFFER is nil, the current buffer is assumed.
|
20
|
2690 */
|
|
2691 (buffer))
|
0
|
2692 {
|
|
2693 struct buffer *b = decode_buffer (buffer, 0);
|
|
2694 return b->keymap;
|
|
2695 }
|
|
2696
|
20
|
2697 DEFUN ("current-global-map", Fcurrent_global_map, 0, 0, 0, /*
|
0
|
2698 Return the current global keymap.
|
20
|
2699 */
|
|
2700 ())
|
0
|
2701 {
|
|
2702 return (Vcurrent_global_map);
|
|
2703 }
|
|
2704
|
|
2705
|
|
2706 /************************************************************************/
|
|
2707 /* Mapping over keymap elements */
|
|
2708 /************************************************************************/
|
|
2709
|
|
2710 /* Since keymaps are arranged in a hierarchy, one keymap per bucky bit or
|
|
2711 prefix key, it's not entirely objvious what map-keymap should do, but
|
|
2712 what it does is: map over all keys in this map; then recursively map
|
|
2713 over all submaps of this map that are "bucky" submaps. This means that,
|
|
2714 when mapping over a keymap, it appears that "x" and "C-x" are in the
|
|
2715 same map, although "C-x" is really in the "control" submap of this one.
|
|
2716 However, since we don't recursively descend the submaps that are bound
|
|
2717 to prefix keys (like C-x, C-h, etc) the caller will have to recurse on
|
|
2718 those explicitly, if that's what they want.
|
|
2719
|
|
2720 So the end result of this is that the bucky keymaps (the ones indexed
|
|
2721 under the large integers returned from MAKE_MODIFIER_HASH_KEY()) are
|
|
2722 invisible from elisp. They're just an implementation detail that code
|
|
2723 outside of this file doesn't need to know about.
|
|
2724 */
|
|
2725
|
|
2726 struct map_keymap_unsorted_closure
|
|
2727 {
|
|
2728 void (*fn) (CONST struct key_data *, Lisp_Object binding, void *arg);
|
|
2729 void *arg;
|
|
2730 unsigned int modifiers;
|
|
2731 };
|
|
2732
|
|
2733 /* used by map_keymap() */
|
|
2734 static void
|
|
2735 map_keymap_unsorted_mapper (CONST void *hash_key, void *hash_contents,
|
|
2736 void *map_keymap_unsorted_closure)
|
|
2737 {
|
|
2738 /* This function can GC */
|
|
2739 Lisp_Object keysym;
|
|
2740 Lisp_Object contents;
|
|
2741 struct map_keymap_unsorted_closure *closure = map_keymap_unsorted_closure;
|
|
2742 unsigned int modifiers = closure->modifiers;
|
|
2743 unsigned int mod_bit;
|
|
2744 CVOID_TO_LISP (keysym, hash_key);
|
|
2745 VOID_TO_LISP (contents, hash_contents);
|
|
2746 mod_bit = MODIFIER_HASH_KEY_BITS (keysym);
|
|
2747 if (mod_bit != 0)
|
|
2748 {
|
|
2749 int omod = modifiers;
|
|
2750 closure->modifiers = (modifiers | mod_bit);
|
|
2751 contents = get_keymap (contents, 1, 1);
|
|
2752 elisp_maphash (map_keymap_unsorted_mapper,
|
|
2753 XKEYMAP (contents)->table,
|
|
2754 map_keymap_unsorted_closure);
|
|
2755 closure->modifiers = omod;
|
|
2756 }
|
|
2757 else
|
|
2758 {
|
|
2759 struct key_data key;
|
|
2760 key.keysym = keysym;
|
|
2761 key.modifiers = modifiers;
|
|
2762 ((*closure->fn) (&key, contents, closure->arg));
|
|
2763 }
|
|
2764 }
|
|
2765
|
|
2766
|
|
2767 struct map_keymap_sorted_closure
|
|
2768 {
|
|
2769 Lisp_Object *result_locative;
|
|
2770 };
|
|
2771
|
|
2772 /* used by map_keymap_sorted() */
|
|
2773 static void
|
|
2774 map_keymap_sorted_mapper (CONST void *hash_key, void *hash_contents,
|
|
2775 void *map_keymap_sorted_closure)
|
|
2776 {
|
|
2777 struct map_keymap_sorted_closure *cl = map_keymap_sorted_closure;
|
|
2778 Lisp_Object key, contents;
|
|
2779 Lisp_Object *list = cl->result_locative;
|
|
2780 CVOID_TO_LISP (key, hash_key);
|
|
2781 VOID_TO_LISP (contents, hash_contents);
|
|
2782 *list = Fcons (Fcons (key, contents), *list);
|
|
2783 }
|
|
2784
|
|
2785
|
|
2786 /* used by map_keymap_sorted(), describe_map_sort_predicate(),
|
|
2787 and keymap_submaps().
|
|
2788 */
|
|
2789 static int
|
|
2790 map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
|
|
2791 Lisp_Object pred)
|
|
2792 {
|
|
2793 /* obj1 and obj2 are conses with keysyms in their cars. Cdrs are ignored.
|
|
2794 */
|
|
2795 unsigned int bit1, bit2;
|
|
2796 int sym1_p = 0;
|
|
2797 int sym2_p = 0;
|
|
2798 obj1 = XCAR (obj1);
|
|
2799 obj2 = XCAR (obj2);
|
|
2800
|
|
2801 if (EQ (obj1, obj2))
|
|
2802 return -1;
|
|
2803 bit1 = MODIFIER_HASH_KEY_BITS (obj1);
|
|
2804 bit2 = MODIFIER_HASH_KEY_BITS (obj2);
|
|
2805
|
|
2806 /* If either is a symbol with a character-set-property, then sort it by
|
|
2807 that code instead of alphabetically.
|
|
2808 */
|
|
2809 if (! bit1 && SYMBOLP (obj1))
|
|
2810 {
|
|
2811 Lisp_Object code = Fget (obj1, Vcharacter_set_property, Qnil);
|
|
2812 if (INTP (code))
|
|
2813 obj1 = code, sym1_p = 1;
|
|
2814 }
|
|
2815 if (! bit2 && SYMBOLP (obj2))
|
|
2816 {
|
|
2817 Lisp_Object code = Fget (obj2, Vcharacter_set_property, Qnil);
|
|
2818 if (INTP (code))
|
|
2819 obj2 = code, sym2_p = 1;
|
|
2820 }
|
|
2821
|
|
2822 /* all symbols (non-ASCIIs) come after characters (ASCIIs) */
|
|
2823 if (XTYPE (obj1) != XTYPE (obj2))
|
|
2824 return (SYMBOLP (obj2) ? 1 : -1);
|
|
2825
|
|
2826 if (! bit1 && CHARP (obj1)) /* they're both ASCII */
|
|
2827 {
|
|
2828 int o1 = XCHAR (obj1);
|
|
2829 int o2 = XCHAR (obj2);
|
|
2830 if (o1 == o2 && /* If one started out as a symbol and the */
|
|
2831 sym1_p != sym2_p) /* other didn't, the symbol comes last. */
|
|
2832 return (sym2_p ? 1 : -1);
|
|
2833
|
|
2834 return ((o1 < o2) ? 1 : -1); /* else just compare them */
|
|
2835 }
|
|
2836
|
|
2837 /* else they're both symbols. If they're both buckys, then order them. */
|
|
2838 if (bit1 && bit2)
|
|
2839 return ((bit1 < bit2) ? 1 : -1);
|
|
2840
|
|
2841 /* if only one is a bucky, then it comes later */
|
|
2842 if (bit1 || bit2)
|
|
2843 return (bit2 ? 1 : -1);
|
|
2844
|
|
2845 /* otherwise, string-sort them. */
|
|
2846 {
|
|
2847 char *s1 = (char *) string_data (XSYMBOL (obj1)->name);
|
|
2848 char *s2 = (char *) string_data (XSYMBOL (obj2)->name);
|
|
2849 return (
|
|
2850 #ifdef I18N2
|
|
2851 (0 > strcoll (s1, s2))
|
|
2852 #else
|
|
2853 (0 > strcmp (s1, s2))
|
|
2854 #endif
|
|
2855 ? 1 : -1);
|
|
2856 }
|
|
2857 }
|
|
2858
|
|
2859
|
|
2860 /* used by map_keymap() */
|
|
2861 static void
|
|
2862 map_keymap_sorted (Lisp_Object keymap_table,
|
|
2863 unsigned int modifiers,
|
|
2864 void (*function) (CONST struct key_data *key,
|
|
2865 Lisp_Object binding,
|
|
2866 void *map_keymap_sorted_closure),
|
|
2867 void *map_keymap_sorted_closure)
|
|
2868 {
|
|
2869 /* This function can GC */
|
|
2870 struct gcpro gcpro1;
|
|
2871 Lisp_Object contents = Qnil;
|
|
2872
|
|
2873 if (XINT (Fhashtable_fullness (keymap_table)) == 0)
|
|
2874 return;
|
|
2875
|
|
2876 GCPRO1 (contents);
|
|
2877
|
|
2878 {
|
|
2879 struct map_keymap_sorted_closure c1;
|
|
2880 c1.result_locative = &contents;
|
|
2881 elisp_maphash (map_keymap_sorted_mapper, keymap_table, &c1);
|
|
2882 }
|
|
2883 contents = list_sort (contents, Qnil, map_keymap_sort_predicate);
|
|
2884 for (; !NILP (contents); contents = XCDR (contents))
|
|
2885 {
|
|
2886 Lisp_Object keysym = XCAR (XCAR (contents));
|
|
2887 Lisp_Object binding = XCDR (XCAR (contents));
|
|
2888 unsigned int sub_bits = MODIFIER_HASH_KEY_BITS (keysym);
|
|
2889 if (sub_bits != 0)
|
|
2890 map_keymap_sorted (XKEYMAP (get_keymap (binding,
|
|
2891 1, 1))->table,
|
|
2892 (modifiers | sub_bits),
|
|
2893 function,
|
|
2894 map_keymap_sorted_closure);
|
|
2895 else
|
|
2896 {
|
|
2897 struct key_data k;
|
|
2898 k.keysym = keysym;
|
|
2899 k.modifiers = modifiers;
|
|
2900 ((*function) (&k, binding, map_keymap_sorted_closure));
|
|
2901 }
|
|
2902 }
|
|
2903 UNGCPRO;
|
|
2904 }
|
|
2905
|
|
2906
|
|
2907 /* used by Fmap_keymap() */
|
|
2908 static void
|
|
2909 map_keymap_mapper (CONST struct key_data *key,
|
|
2910 Lisp_Object binding,
|
|
2911 void *function)
|
|
2912 {
|
|
2913 /* This function can GC */
|
|
2914 Lisp_Object fn;
|
|
2915 VOID_TO_LISP (fn, function);
|
|
2916 call2 (fn, make_key_description (key, 1), binding);
|
|
2917 }
|
|
2918
|
|
2919
|
|
2920 static void
|
|
2921 map_keymap (Lisp_Object keymap_table, int sort_first,
|
|
2922 void (*function) (CONST struct key_data *key,
|
|
2923 Lisp_Object binding,
|
|
2924 void *fn_arg),
|
|
2925 void *fn_arg)
|
|
2926 {
|
|
2927 /* This function can GC */
|
|
2928 if (sort_first)
|
|
2929 map_keymap_sorted (keymap_table, 0, function, fn_arg);
|
|
2930 else
|
|
2931 {
|
|
2932 struct map_keymap_unsorted_closure map_keymap_unsorted_closure;
|
|
2933 map_keymap_unsorted_closure.fn = function;
|
|
2934 map_keymap_unsorted_closure.arg = fn_arg;
|
|
2935 map_keymap_unsorted_closure.modifiers = 0;
|
|
2936 elisp_maphash (map_keymap_unsorted_mapper, keymap_table,
|
|
2937 &map_keymap_unsorted_closure);
|
|
2938 }
|
|
2939 }
|
|
2940
|
20
|
2941 DEFUN ("map-keymap", Fmap_keymap, 2, 3, 0, /*
|
0
|
2942 Apply FUNCTION to each element of KEYMAP.
|
|
2943 FUNCTION will be called with two arguments: a key-description list, and
|
|
2944 the binding. The order in which the elements of the keymap are passed to
|
|
2945 the function is unspecified. If the function inserts new elements into
|
|
2946 the keymap, it may or may not be called with them later. No element of
|
|
2947 the keymap will ever be passed to the function more than once.
|
|
2948
|
|
2949 The function will not be called on elements of this keymap's parents
|
|
2950 (see the function `keymap-parents') or upon keymaps which are contained
|
|
2951 within this keymap (multi-character definitions).
|
|
2952 It will be called on \"meta\" characters since they are not really
|
|
2953 two-character sequences.
|
|
2954
|
|
2955 If the optional third argument SORT-FIRST is non-nil, then the elements of
|
|
2956 the keymap will be passed to the mapper function in a canonical order.
|
|
2957 Otherwise, they will be passed in hash (that is, random) order, which is
|
|
2958 faster.
|
20
|
2959 */
|
|
2960 (function, keymap, sort_first))
|
0
|
2961 {
|
|
2962 /* This function can GC */
|
|
2963 struct gcpro gcpro1, gcpro2;
|
|
2964
|
|
2965 /* tolerate obviously transposed args */
|
|
2966 if (!NILP (Fkeymapp (function)))
|
|
2967 {
|
|
2968 Lisp_Object tmp = function;
|
|
2969 function = keymap;
|
|
2970 keymap = tmp;
|
|
2971 }
|
|
2972 GCPRO2 (function, keymap);
|
|
2973 keymap = get_keymap (keymap, 1, 1);
|
|
2974 map_keymap (XKEYMAP (keymap)->table, !NILP (sort_first),
|
|
2975 map_keymap_mapper, LISP_TO_VOID (function));
|
|
2976 UNGCPRO;
|
|
2977 return Qnil;
|
|
2978 }
|
|
2979
|
|
2980
|
|
2981
|
|
2982 /************************************************************************/
|
|
2983 /* Accessible keymaps */
|
|
2984 /************************************************************************/
|
|
2985
|
|
2986 struct accessible_keymaps_closure
|
|
2987 {
|
|
2988 Lisp_Object tail;
|
|
2989 };
|
|
2990
|
|
2991
|
|
2992 static void
|
|
2993 accessible_keymaps_mapper_1 (Lisp_Object keysym, Lisp_Object contents,
|
|
2994 unsigned int modifiers,
|
|
2995 struct accessible_keymaps_closure *closure)
|
|
2996 {
|
|
2997 /* This function can GC */
|
|
2998 unsigned int subbits = MODIFIER_HASH_KEY_BITS (keysym);
|
|
2999
|
|
3000 if (subbits != 0)
|
|
3001 {
|
|
3002 Lisp_Object submaps;
|
|
3003
|
|
3004 contents = get_keymap (contents, 1, 1);
|
|
3005 submaps = keymap_submaps (contents);
|
|
3006 for (; !NILP (submaps); submaps = XCDR (submaps))
|
|
3007 {
|
|
3008 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)),
|
|
3009 XCDR (XCAR (submaps)),
|
|
3010 (subbits | modifiers),
|
|
3011 closure);
|
|
3012 }
|
|
3013 }
|
|
3014 else
|
|
3015 {
|
|
3016 Lisp_Object thisseq = Fcar (Fcar (closure->tail));
|
|
3017 Lisp_Object cmd = get_keyelt (contents, 1);
|
|
3018 Lisp_Object vec;
|
|
3019 int j;
|
|
3020 struct key_data key;
|
|
3021 key.keysym = keysym;
|
|
3022 key.modifiers = modifiers;
|
|
3023
|
|
3024 if (NILP (cmd))
|
|
3025 abort ();
|
|
3026 cmd = get_keymap (cmd, 0, 1);
|
|
3027 if (!KEYMAPP (cmd))
|
|
3028 abort ();
|
|
3029
|
|
3030 vec = make_vector (vector_length (XVECTOR (thisseq)) + 1, Qnil);
|
|
3031 for (j = 0; j < vector_length (XVECTOR (thisseq)); j++)
|
|
3032 vector_data (XVECTOR (vec)) [j] = vector_data (XVECTOR (thisseq)) [j];
|
|
3033 vector_data (XVECTOR (vec)) [j] = make_key_description (&key, 1);
|
|
3034
|
|
3035 nconc2 (closure->tail, list1 (Fcons (vec, cmd)));
|
|
3036 }
|
|
3037 }
|
|
3038
|
|
3039
|
|
3040 static Lisp_Object
|
|
3041 accessible_keymaps_keymap_mapper (Lisp_Object thismap, void *arg)
|
|
3042 {
|
|
3043 /* This function can GC */
|
|
3044 struct accessible_keymaps_closure *closure = arg;
|
|
3045 Lisp_Object submaps = keymap_submaps (thismap);
|
|
3046
|
|
3047 for (; !NILP (submaps); submaps = XCDR (submaps))
|
|
3048 {
|
|
3049 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)),
|
|
3050 XCDR (XCAR (submaps)),
|
|
3051 0,
|
|
3052 closure);
|
|
3053 }
|
|
3054 return (Qnil);
|
|
3055 }
|
|
3056
|
|
3057
|
20
|
3058 DEFUN ("accessible-keymaps", Faccessible_keymaps, 1, 2, 0, /*
|
0
|
3059 Find all keymaps accessible via prefix characters from STARTMAP.
|
|
3060 Returns a list of elements of the form (KEYS . MAP), where the sequence
|
|
3061 KEYS starting from STARTMAP gets you to MAP. These elements are ordered
|
|
3062 so that the KEYS increase in length. The first element is ([] . STARTMAP).
|
|
3063 An optional argument PREFIX, if non-nil, should be a key sequence;
|
|
3064 then the value includes only maps for prefixes that start with PREFIX.
|
20
|
3065 */
|
|
3066 (startmap, prefix))
|
0
|
3067 {
|
|
3068 /* This function can GC */
|
|
3069 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
3070 Lisp_Object accessible_keymaps = Qnil;
|
|
3071 struct accessible_keymaps_closure c;
|
|
3072 c.tail = Qnil;
|
|
3073 GCPRO4 (accessible_keymaps, c.tail, prefix, startmap);
|
|
3074
|
|
3075 retry:
|
|
3076 startmap = get_keymap (startmap, 1, 1);
|
|
3077 if (NILP (prefix))
|
|
3078 prefix = make_vector (0, Qnil);
|
|
3079 else if (!VECTORP (prefix) || STRINGP (prefix))
|
|
3080 {
|
|
3081 prefix = wrong_type_argument (Qarrayp, prefix);
|
|
3082 goto retry;
|
|
3083 }
|
|
3084 else
|
|
3085 {
|
|
3086 int len = XINT (Flength (prefix));
|
|
3087 Lisp_Object def = Flookup_key (startmap, prefix, Qnil);
|
|
3088 Lisp_Object p;
|
|
3089 int iii;
|
|
3090 struct gcpro ngcpro1;
|
|
3091
|
|
3092 def = get_keymap (def, 0, 1);
|
|
3093 if (!KEYMAPP (def))
|
|
3094 goto RETURN;
|
|
3095
|
|
3096 startmap = def;
|
|
3097 p = make_vector (len, Qnil);
|
|
3098 NGCPRO1 (p);
|
|
3099 for (iii = 0; iii < len; iii++)
|
|
3100 {
|
|
3101 struct key_data key;
|
|
3102 define_key_parser (Faref (prefix, make_int (iii)), &key);
|
|
3103 vector_data (XVECTOR (p))[iii] = make_key_description (&key, 1);
|
|
3104 }
|
|
3105 NUNGCPRO;
|
|
3106 prefix = p;
|
|
3107 }
|
|
3108
|
|
3109 accessible_keymaps = list1 (Fcons (prefix, startmap));
|
|
3110
|
|
3111 /* For each map in the list maps,
|
|
3112 look at any other maps it points to
|
|
3113 and stick them at the end if they are not already in the list */
|
|
3114
|
|
3115 for (c.tail = accessible_keymaps;
|
|
3116 !NILP (c.tail);
|
|
3117 c.tail = XCDR (c.tail))
|
|
3118 {
|
|
3119 Lisp_Object thismap = Fcdr (Fcar (c.tail));
|
|
3120 CHECK_KEYMAP (thismap);
|
|
3121 traverse_keymaps (thismap, Qnil,
|
|
3122 accessible_keymaps_keymap_mapper, &c);
|
|
3123 }
|
|
3124 RETURN:
|
|
3125 UNGCPRO;
|
|
3126 return (accessible_keymaps);
|
|
3127 }
|
|
3128
|
|
3129
|
|
3130
|
|
3131 /************************************************************************/
|
|
3132 /* Pretty descriptions of key sequences */
|
|
3133 /************************************************************************/
|
|
3134
|
20
|
3135 DEFUN ("key-description", Fkey_description, 1, 1, 0, /*
|
0
|
3136 Return a pretty description of key-sequence KEYS.
|
|
3137 Control characters turn into \"C-foo\" sequences, meta into \"M-foo\"
|
|
3138 spaces are put between sequence elements, etc.
|
20
|
3139 */
|
|
3140 (keys))
|
0
|
3141 {
|
|
3142 if (INTP (keys) || CONSP (keys) || SYMBOLP (keys) || EVENTP (keys))
|
|
3143 {
|
|
3144 return Fsingle_key_description (keys);
|
|
3145 }
|
|
3146 else if (VECTORP (keys) ||
|
|
3147 STRINGP (keys))
|
|
3148 {
|
|
3149 Lisp_Object string = Qnil;
|
|
3150 /* Lisp_Object sep = Qnil; */
|
|
3151 int size = XINT (Flength (keys));
|
|
3152 int i;
|
|
3153
|
|
3154 for (i = 0; i < size; i++)
|
|
3155 {
|
|
3156 Lisp_Object s2 = Fsingle_key_description
|
|
3157 (((STRINGP (keys))
|
|
3158 ? make_char (string_char (XSTRING (keys), i))
|
|
3159 : vector_data (XVECTOR (keys))[i]));
|
|
3160
|
|
3161 if (i == 0)
|
|
3162 string = s2;
|
|
3163 else
|
|
3164 {
|
|
3165 /* if (NILP (sep)) Lisp_Object sep = build_string (" ") */;
|
|
3166 string = concat2 (string, concat2 (Vsingle_space_string, s2));
|
|
3167 }
|
|
3168 }
|
|
3169 return (string);
|
|
3170 }
|
|
3171 return Fkey_description (wrong_type_argument (Qsequencep, keys));
|
|
3172 }
|
|
3173
|
20
|
3174 DEFUN ("single-key-description", Fsingle_key_description, 1, 1, 0, /*
|
0
|
3175 Return a pretty description of command character KEY.
|
|
3176 Control characters turn into C-whatever, etc.
|
|
3177 This differs from `text-char-description' in that it returns a description
|
|
3178 of a key read from the user rather than a character from a buffer.
|
20
|
3179 */
|
|
3180 (key))
|
0
|
3181 {
|
|
3182 if (SYMBOLP (key))
|
|
3183 key = Fcons (key, Qnil); /* sleaze sleaze */
|
|
3184
|
|
3185 if (EVENTP (key) || CHARP (key))
|
|
3186 {
|
|
3187 char buf [255];
|
|
3188 if (!EVENTP (key))
|
|
3189 {
|
|
3190 struct Lisp_Event event;
|
|
3191 event.event_type = empty_event;
|
|
3192 CHECK_CHAR_COERCE_INT (key);
|
|
3193 character_to_event (XCHAR (key), &event,
|
|
3194 XCONSOLE (Vselected_console), 0);
|
|
3195 format_event_object (buf, &event, 1);
|
|
3196 }
|
|
3197 else
|
|
3198 format_event_object (buf, XEVENT (key), 1);
|
|
3199 return (build_string (buf));
|
|
3200 }
|
|
3201
|
|
3202 if (CONSP (key))
|
|
3203 {
|
|
3204 char buf[255];
|
|
3205 char *bufp = buf;
|
|
3206 Lisp_Object rest;
|
|
3207 buf[0] = 0;
|
|
3208 LIST_LOOP (rest, key)
|
|
3209 {
|
|
3210 Lisp_Object keysym = XCAR (rest);
|
|
3211 if (EQ (keysym, Qcontrol)) strcpy (bufp, "C-"), bufp += 2;
|
|
3212 else if (EQ (keysym, Qctrl)) strcpy (bufp, "C-"), bufp += 2;
|
|
3213 else if (EQ (keysym, Qmeta)) strcpy (bufp, "M-"), bufp += 2;
|
|
3214 else if (EQ (keysym, Qsuper)) strcpy (bufp, "S-"), bufp += 2;
|
|
3215 else if (EQ (keysym, Qhyper)) strcpy (bufp, "H-"), bufp += 2;
|
|
3216 else if (EQ (keysym, Qalt)) strcpy (bufp, "A-"), bufp += 2;
|
|
3217 else if (EQ (keysym, Qshift)) strcpy (bufp, "Sh-"), bufp += 3;
|
|
3218 else if (INTP (keysym))
|
|
3219 *bufp = XINT (keysym), bufp++, *bufp = 0;
|
|
3220 else
|
|
3221 {
|
|
3222 CHECK_SYMBOL (keysym);
|
|
3223 #if 0 /* This is bogus */
|
|
3224 if (EQ (keysym, QKlinefeed)) strcpy (bufp, "LFD");
|
|
3225 else if (EQ (keysym, QKtab)) strcpy (bufp, "TAB");
|
|
3226 else if (EQ (keysym, QKreturn)) strcpy (bufp, "RET");
|
|
3227 else if (EQ (keysym, QKescape)) strcpy (bufp, "ESC");
|
|
3228 else if (EQ (keysym, QKdelete)) strcpy (bufp, "DEL");
|
|
3229 else if (EQ (keysym, QKspace)) strcpy (bufp, "SPC");
|
|
3230 else if (EQ (keysym, QKbackspace)) strcpy (bufp, "BS");
|
|
3231 else
|
|
3232 #endif
|
|
3233 strcpy (bufp, (char *) string_data (XSYMBOL (keysym)->name));
|
|
3234 if (!NILP (XCDR (rest)))
|
|
3235 signal_simple_error ("invalid key description",
|
|
3236 key);
|
|
3237 }
|
|
3238 }
|
|
3239 return build_string (buf);
|
|
3240 }
|
|
3241 return Fsingle_key_description
|
|
3242 (wrong_type_argument (intern ("char-or-event-p"), key));
|
|
3243 }
|
|
3244
|
20
|
3245 DEFUN ("text-char-description", Ftext_char_description, 1, 1, 0, /*
|
0
|
3246 Return a pretty description of file-character CHR.
|
|
3247 Unprintable characters turn into \"^char\" or \\NNN, depending on the value
|
|
3248 of the `ctl-arrow' variable.
|
|
3249 This differs from `single-key-description' in that it returns a description
|
|
3250 of a character from a buffer rather than a key read from the user.
|
20
|
3251 */
|
|
3252 (chr))
|
0
|
3253 {
|
|
3254 Bufbyte buf[200];
|
|
3255 Bufbyte *p;
|
|
3256 unsigned int c;
|
|
3257 Lisp_Object ctl_arrow = current_buffer->ctl_arrow;
|
|
3258 int ctl_p = !NILP (ctl_arrow);
|
|
3259 int printable_min = (INTP (ctl_arrow)
|
|
3260 ? XINT (ctl_arrow)
|
|
3261 : ((EQ (ctl_arrow, Qt) || EQ (ctl_arrow, Qnil))
|
|
3262 ? 256 : 160));
|
|
3263
|
|
3264 if (EVENTP (chr))
|
|
3265 {
|
|
3266 Lisp_Object ch = Fevent_to_character (chr, Qnil, Qnil, Qt);
|
|
3267 if (NILP (ch))
|
|
3268 return
|
|
3269 signal_simple_continuable_error
|
|
3270 ("character has no ASCII equivalent", Fcopy_event (chr, Qnil));
|
|
3271 chr = ch;
|
|
3272 }
|
|
3273
|
|
3274 CHECK_CHAR_COERCE_INT (chr);
|
|
3275
|
|
3276 c = XCHAR (chr);
|
|
3277 p = buf;
|
|
3278
|
|
3279 if (c >= printable_min)
|
|
3280 {
|
|
3281 p += set_charptr_emchar (p, c);
|
|
3282 }
|
|
3283 else if (c < 040 && ctl_p)
|
|
3284 {
|
|
3285 *p++ = '^';
|
|
3286 *p++ = c + 64; /* 'A' - 1 */
|
|
3287 }
|
|
3288 else if (c == 0177)
|
|
3289 {
|
|
3290 *p++ = '^';
|
|
3291 *p++ = '?';
|
|
3292 }
|
|
3293 else if (c >= 0200 || c < 040)
|
|
3294 {
|
|
3295 *p++ = '\\';
|
|
3296 *p++ = '0' + ((c & 0700) >> 6);
|
|
3297 *p++ = '0' + ((c & 0070) >> 3);
|
|
3298 *p++ = '0' + ((c & 0007));
|
|
3299 }
|
|
3300 else
|
|
3301 {
|
|
3302 p += set_charptr_emchar (p, c);
|
|
3303 }
|
|
3304
|
|
3305 *p = 0;
|
|
3306 return build_string ((char *) buf);
|
|
3307 }
|
|
3308
|
|
3309
|
|
3310 /************************************************************************/
|
|
3311 /* where-is (mapping bindings to keys) */
|
|
3312 /************************************************************************/
|
|
3313
|
|
3314 static Lisp_Object
|
|
3315 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
|
|
3316 Lisp_Object firstonly, char *target_buffer);
|
|
3317
|
20
|
3318 DEFUN ("where-is-internal", Fwhere_is_internal, 1, 5, 0, /*
|
0
|
3319 Return list of keys that invoke DEFINITION in KEYMAPS.
|
|
3320 KEYMAPS can be either a keymap (meaning search in that keymap and the
|
|
3321 current global keymap) or a list of keymaps (meaning search in exactly
|
|
3322 those keymaps and no others). If KEYMAPS is nil, search in the currently
|
|
3323 applicable maps for EVENT-OR-KEYS (this is equivalent to specifying
|
|
3324 `(current-keymaps EVENT-OR-KEYS)' as the argument to KEYMAPS).
|
|
3325
|
|
3326 If optional 3rd arg FIRSTONLY is non-nil, return a vector representing
|
|
3327 the first key sequence found, rather than a list of all possible key
|
|
3328 sequences.
|
|
3329
|
|
3330 If optional 4th arg NOINDIRECT is non-nil, don't follow indirections
|
|
3331 to other keymaps or slots. This makes it possible to search for an
|
|
3332 indirect definition itself.
|
20
|
3333 */
|
|
3334 (definition, keymaps, firstonly, noindirect, event_or_keys))
|
0
|
3335 {
|
|
3336 /* This function can GC */
|
|
3337 Lisp_Object maps[100];
|
|
3338 Lisp_Object *gubbish = maps;
|
|
3339 int nmaps;
|
|
3340
|
|
3341 /* Get keymaps as an array */
|
|
3342 if (NILP (keymaps))
|
|
3343 {
|
|
3344 nmaps = get_relevant_keymaps (event_or_keys, countof (maps),
|
|
3345 gubbish);
|
|
3346 if (nmaps > countof (maps))
|
|
3347 {
|
|
3348 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
3349 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
|
|
3350 }
|
|
3351 }
|
|
3352 else if (CONSP (keymaps))
|
|
3353 {
|
|
3354 Lisp_Object rest;
|
|
3355 int i;
|
|
3356
|
|
3357 nmaps = XINT (Flength (keymaps));
|
|
3358 if (nmaps > countof (maps))
|
|
3359 {
|
|
3360 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
3361 }
|
|
3362 for (rest = keymaps, i = 0; !NILP (rest);
|
|
3363 rest = XCDR (keymaps), i++)
|
|
3364 {
|
|
3365 gubbish[i] = get_keymap (XCAR (keymaps), 1, 1);
|
|
3366 }
|
|
3367 }
|
|
3368 else
|
|
3369 {
|
|
3370 nmaps = 1;
|
|
3371 gubbish[0] = get_keymap (keymaps, 1, 1);
|
|
3372 if (!EQ (gubbish[0], Vcurrent_global_map))
|
|
3373 {
|
|
3374 gubbish[1] = Vcurrent_global_map;
|
|
3375 nmaps++;
|
|
3376 }
|
|
3377 }
|
|
3378
|
|
3379 return where_is_internal (definition, gubbish, nmaps, firstonly, 0);
|
|
3380 }
|
|
3381
|
|
3382 /* This function is like
|
|
3383 (key-description (where-is-internal definition nil t))
|
|
3384 except that it writes its output into a (char *) buffer that you
|
|
3385 provide; it doesn't cons (or allocate memory) at all, so it's
|
|
3386 very fast. This is used by menubar.c.
|
|
3387 */
|
|
3388 void
|
|
3389 where_is_to_char (Lisp_Object definition, char *buffer)
|
|
3390 {
|
|
3391 /* This function can GC */
|
|
3392 Lisp_Object maps[100];
|
|
3393 Lisp_Object *gubbish = maps;
|
|
3394 int nmaps;
|
|
3395
|
|
3396 /* Get keymaps as an array */
|
|
3397 nmaps = get_relevant_keymaps (Qnil, countof (maps), gubbish);
|
|
3398 if (nmaps > countof (maps))
|
|
3399 {
|
|
3400 gubbish = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
|
|
3401 nmaps = get_relevant_keymaps (Qnil, nmaps, gubbish);
|
|
3402 }
|
|
3403
|
|
3404 buffer[0] = 0;
|
|
3405 where_is_internal (definition, maps, nmaps, Qt, buffer);
|
|
3406 }
|
|
3407
|
|
3408
|
|
3409 static Lisp_Object
|
|
3410 raw_keys_to_keys (struct key_data *keys, int count)
|
|
3411 {
|
|
3412 Lisp_Object result = make_vector (count, Qnil);
|
|
3413 while (count--)
|
|
3414 vector_data (XVECTOR (result)) [count] =
|
|
3415 make_key_description (&(keys[count]), 1);
|
|
3416 return (result);
|
|
3417 }
|
|
3418
|
|
3419
|
|
3420 static void
|
|
3421 format_raw_keys (struct key_data *keys, int count, char *buf)
|
|
3422 {
|
|
3423 int i;
|
|
3424 struct Lisp_Event event;
|
|
3425 event.event_type = key_press_event;
|
|
3426 event.channel = Vselected_console;
|
|
3427 for (i = 0; i < count; i++)
|
|
3428 {
|
|
3429 event.event.key.keysym = keys[i].keysym;
|
|
3430 event.event.key.modifiers = keys[i].modifiers;
|
|
3431 format_event_object (buf, &event, 1);
|
|
3432 buf += strlen (buf);
|
|
3433 if (i < count-1)
|
|
3434 buf[0] = ' ', buf++;
|
|
3435 }
|
|
3436 }
|
|
3437
|
|
3438
|
|
3439 /* definition is the thing to look for.
|
|
3440 map is a keymap.
|
|
3441 shadow is an array of shadow_count keymaps; if there is a different
|
|
3442 binding in any of the keymaps of a key that we are considering
|
|
3443 returning, then we reconsider.
|
|
3444 firstonly means give up after finding the first match;
|
|
3445 keys_so_far and modifiers_so_far describe which map we're looking in;
|
|
3446 If we're in the "meta" submap of the map that "C-x 4" is bound to,
|
|
3447 then keys_so_far will be {(control x), \4}, and modifiers_so_far
|
|
3448 will be MOD_META. That is, keys_so_far is the chain of keys that we
|
|
3449 have followed, and modifiers_so_far_so_far is the bits (partial keys)
|
|
3450 beyond that.
|
|
3451
|
|
3452 (keys_so_far is a global buffer and the keys_count arg says how much
|
|
3453 of it we're currently interested in.)
|
|
3454
|
|
3455 If target_buffer is provided, then we write a key-description into it,
|
|
3456 to avoid consing a string. This only works with firstonly on.
|
|
3457 */
|
|
3458
|
|
3459 struct where_is_closure
|
|
3460 {
|
|
3461 Lisp_Object definition;
|
|
3462 Lisp_Object *shadow;
|
|
3463 int shadow_count;
|
|
3464 int firstonly;
|
|
3465 int keys_count;
|
|
3466 unsigned int modifiers_so_far;
|
|
3467 char *target_buffer;
|
|
3468 struct key_data *keys_so_far;
|
|
3469 int keys_so_far_total_size;
|
|
3470 int keys_so_far_malloced;
|
|
3471 };
|
|
3472
|
|
3473 static Lisp_Object where_is_recursive_mapper (Lisp_Object map, void *arg);
|
|
3474
|
|
3475 static Lisp_Object
|
|
3476 where_is_recursive_mapper (Lisp_Object map, void *arg)
|
|
3477 {
|
|
3478 /* This function can GC */
|
|
3479 struct where_is_closure *c = arg;
|
|
3480 Lisp_Object definition = c->definition;
|
|
3481 CONST int firstonly = c->firstonly;
|
|
3482 CONST unsigned int keys_count = c->keys_count;
|
|
3483 CONST unsigned int modifiers_so_far = c->modifiers_so_far;
|
|
3484 char *target_buffer = c->target_buffer;
|
|
3485 Lisp_Object keys = Fgethash (definition,
|
|
3486 XKEYMAP (map)->inverse_table,
|
|
3487 Qnil);
|
|
3488 Lisp_Object submaps;
|
|
3489 Lisp_Object result = Qnil;
|
|
3490
|
|
3491 if (!NILP (keys))
|
|
3492 {
|
|
3493 /* One or more keys in this map match the definition we're looking
|
|
3494 for. Verify that these bindings aren't shadowed by other bindings
|
|
3495 in the shadow maps. Either nil or number as value from
|
|
3496 raw_lookup_key() means undefined.
|
|
3497 */
|
|
3498 struct key_data *so_far = c->keys_so_far;
|
|
3499
|
|
3500 for (;;) /* loop over all keys that match */
|
|
3501 {
|
|
3502 Lisp_Object k = ((CONSP (keys)) ? XCAR (keys) : keys);
|
|
3503 int i;
|
|
3504
|
|
3505 so_far [keys_count].keysym = k;
|
|
3506 so_far [keys_count].modifiers = modifiers_so_far;
|
|
3507
|
|
3508 /* now loop over all shadow maps */
|
|
3509 for (i = 0; i < c->shadow_count; i++)
|
|
3510 {
|
|
3511 Lisp_Object shadowed = raw_lookup_key (c->shadow[i],
|
|
3512 so_far,
|
|
3513 keys_count + 1,
|
|
3514 0, 1);
|
|
3515
|
|
3516 if (NILP (shadowed) || CHARP (shadowed) ||
|
|
3517 EQ (shadowed, definition))
|
|
3518 continue; /* we passed this test; it's not shadowed here. */
|
|
3519 else
|
|
3520 /* ignore this key binding, since it actually has a
|
|
3521 different binding in a shadowing map */
|
|
3522 goto c_doesnt_have_proper_loop_exit_statements;
|
|
3523 }
|
|
3524
|
|
3525 /* OK, the key is for real */
|
|
3526 if (target_buffer)
|
|
3527 {
|
|
3528 if (!firstonly) abort ();
|
|
3529 format_raw_keys (so_far, keys_count + 1, target_buffer);
|
|
3530 return (make_int (1));
|
|
3531 }
|
|
3532 else if (firstonly)
|
|
3533 return raw_keys_to_keys (so_far, keys_count + 1);
|
|
3534 else
|
|
3535 result = Fcons (raw_keys_to_keys (so_far, keys_count + 1),
|
|
3536 result);
|
|
3537
|
|
3538 c_doesnt_have_proper_loop_exit_statements:
|
|
3539 /* now on to the next matching key ... */
|
|
3540 if (!CONSP (keys)) break;
|
|
3541 keys = XCDR (keys);
|
|
3542 }
|
|
3543 }
|
|
3544
|
|
3545 /* Now search the sub-keymaps of this map.
|
|
3546 If we're in "firstonly" mode and have already found one, this
|
|
3547 point is not reached. If we get one from lower down, either
|
|
3548 return it immediately (in firstonly mode) or tack it onto the
|
|
3549 end of the ones we've gotten so far.
|
|
3550 */
|
|
3551 for (submaps = keymap_submaps (map);
|
|
3552 !NILP (submaps);
|
|
3553 submaps = XCDR (submaps))
|
|
3554 {
|
|
3555 Lisp_Object key = XCAR (XCAR (submaps));
|
|
3556 Lisp_Object submap = XCDR (XCAR (submaps));
|
|
3557 unsigned int lower_modifiers;
|
|
3558 int lower_keys_count = keys_count;
|
|
3559 unsigned int bucky;
|
|
3560
|
|
3561 submap = get_keymap (submap, 0, 1);
|
|
3562
|
|
3563 if (EQ (submap, map))
|
|
3564 /* Arrgh! Some loser has introduced a loop... */
|
|
3565 continue;
|
|
3566
|
|
3567 /* If this is not a keymap, then that's probably because someone
|
|
3568 did an `fset' of a symbol that used to point to a map such that
|
|
3569 it no longer does. Sigh. Ignore this, and invalidate the cache
|
|
3570 so that it doesn't happen to us next time too.
|
|
3571 */
|
|
3572 if (NILP (submap))
|
|
3573 {
|
|
3574 XKEYMAP (map)->sub_maps_cache = Qt;
|
|
3575 continue;
|
|
3576 }
|
|
3577
|
|
3578 /* If the map is a "bucky" map, then add a bit to the
|
|
3579 modifiers_so_far list.
|
|
3580 Otherwise, add a new raw_key onto the end of keys_so_far.
|
|
3581 */
|
|
3582 bucky = MODIFIER_HASH_KEY_BITS (key);
|
|
3583 if (bucky != 0)
|
|
3584 lower_modifiers = (modifiers_so_far | bucky);
|
|
3585 else
|
|
3586 {
|
|
3587 struct key_data *so_far = c->keys_so_far;
|
|
3588 lower_modifiers = 0;
|
|
3589 so_far [lower_keys_count].keysym = key;
|
|
3590 so_far [lower_keys_count].modifiers = modifiers_so_far;
|
|
3591 lower_keys_count++;
|
|
3592 }
|
|
3593
|
|
3594 if (lower_keys_count >= c->keys_so_far_total_size)
|
|
3595 {
|
|
3596 int size = lower_keys_count + 50;
|
|
3597 if (! c->keys_so_far_malloced)
|
|
3598 {
|
|
3599 struct key_data *new = xmalloc (size * sizeof (struct key_data));
|
|
3600 memcpy ((void *)new, (const void *)c->keys_so_far,
|
|
3601 c->keys_so_far_total_size * sizeof (struct key_data));
|
|
3602 }
|
|
3603 else
|
|
3604 c->keys_so_far = xrealloc (c->keys_so_far,
|
|
3605 size * sizeof (struct key_data));
|
|
3606
|
|
3607 c->keys_so_far_total_size = size;
|
|
3608 c->keys_so_far_malloced = 1;
|
|
3609 }
|
|
3610
|
|
3611 {
|
|
3612 Lisp_Object lower;
|
|
3613
|
|
3614 c->keys_count = lower_keys_count;
|
|
3615 c->modifiers_so_far = lower_modifiers;
|
|
3616
|
|
3617 lower = traverse_keymaps (submap, Qnil, where_is_recursive_mapper,
|
|
3618 c);
|
|
3619 c->keys_count = keys_count;
|
|
3620 c->modifiers_so_far = modifiers_so_far;
|
|
3621
|
|
3622 if (!firstonly)
|
|
3623 result = nconc2 (lower, result);
|
|
3624 else if (!NILP (lower))
|
|
3625 return (lower);
|
|
3626 }
|
|
3627 }
|
|
3628 return (result);
|
|
3629 }
|
|
3630
|
|
3631
|
|
3632 static Lisp_Object
|
|
3633 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
|
|
3634 Lisp_Object firstonly, char *target_buffer)
|
|
3635 {
|
|
3636 /* This function can GC */
|
|
3637 Lisp_Object result = Qnil;
|
|
3638 int i;
|
|
3639 struct key_data raw[20];
|
|
3640 struct where_is_closure c;
|
|
3641
|
|
3642 c.definition = definition;
|
|
3643 c.shadow = maps;
|
|
3644 c.firstonly = !NILP (firstonly);
|
|
3645 c.target_buffer = target_buffer;
|
|
3646 c.keys_so_far = raw;
|
|
3647 c.keys_so_far_total_size = countof (raw);
|
|
3648 c.keys_so_far_malloced = 0;
|
|
3649
|
|
3650 /* Loop over each of the maps, accumulating the keys found.
|
|
3651 For each map searched, all previous maps shadow this one
|
|
3652 so that bogus keys aren't listed. */
|
|
3653 for (i = 0; i < nmaps; i++)
|
|
3654 {
|
|
3655 Lisp_Object this_result;
|
|
3656 c.shadow_count = i;
|
|
3657 /* Reset the things set in each iteration */
|
|
3658 c.keys_count = 0;
|
|
3659 c.modifiers_so_far = 0;
|
|
3660
|
|
3661 this_result = traverse_keymaps (maps[i], Qnil, where_is_recursive_mapper,
|
|
3662 &c);
|
|
3663 if (!NILP (firstonly))
|
|
3664 {
|
|
3665 result = this_result;
|
|
3666 if (!NILP (result))
|
|
3667 break;
|
|
3668 }
|
|
3669 else
|
|
3670 result = nconc2 (this_result, result);
|
|
3671 }
|
|
3672
|
|
3673 if (NILP (firstonly))
|
|
3674 result = Fnreverse (result);
|
|
3675
|
|
3676 if (c.keys_so_far_malloced)
|
|
3677 xfree (c.keys_so_far);
|
|
3678 return (result);
|
|
3679 }
|
|
3680
|
|
3681
|
|
3682 /************************************************************************/
|
|
3683 /* Describing keymaps */
|
|
3684 /************************************************************************/
|
|
3685
|
20
|
3686 DEFUN ("describe-bindings-internal", Fdescribe_bindings_internal, 1, 5, 0, /*
|
0
|
3687 Insert a list of all defined keys and their definitions in MAP.
|
|
3688 Optional second argument ALL says whether to include even \"uninteresting\"
|
|
3689 definitions (ie symbols with a non-nil `suppress-keymap' property.
|
|
3690 Third argument SHADOW is a list of keymaps whose bindings shadow those
|
|
3691 of map; if a binding is present in any shadowing map, it is not printed.
|
|
3692 Fourth argument PREFIX, if non-nil, should be a key sequence;
|
|
3693 only bindings which start with that key sequence will be printed.
|
|
3694 Fifth argument MOUSE-ONLY-P says to only print bindings for mouse clicks.
|
20
|
3695 */
|
|
3696 (map, all, shadow, prefix, mouse_only_p))
|
0
|
3697 {
|
|
3698 /* This function can GC */
|
|
3699 describe_map_tree (map, NILP (all), shadow, prefix,
|
|
3700 !NILP (mouse_only_p));
|
|
3701 return (Qnil);
|
|
3702 }
|
|
3703
|
|
3704
|
|
3705 /* Insert a desription of the key bindings in STARTMAP,
|
|
3706 followed by those of all maps reachable through STARTMAP.
|
|
3707 If PARTIAL is nonzero, omit certain "uninteresting" commands
|
|
3708 (such as `undefined').
|
|
3709 If SHADOW is non-nil, it is a list of other maps;
|
|
3710 don't mention keys which would be shadowed by any of them
|
|
3711 If PREFIX is non-nil, only list bindings which start with those keys
|
|
3712 */
|
|
3713
|
|
3714 void
|
|
3715 describe_map_tree (Lisp_Object startmap, int partial, Lisp_Object shadow,
|
|
3716 Lisp_Object prefix, int mice_only_p)
|
|
3717 {
|
|
3718 /* This function can GC */
|
|
3719 Lisp_Object maps = Qnil;
|
|
3720 struct gcpro gcpro1, gcpro2; /* get_keymap may autoload */
|
|
3721 GCPRO2 (maps, shadow);
|
|
3722
|
|
3723 maps = Faccessible_keymaps (startmap, prefix);
|
|
3724
|
|
3725 for (; !NILP (maps); maps = Fcdr (maps))
|
|
3726 {
|
|
3727 Lisp_Object sub_shadow = Qnil;
|
|
3728 Lisp_Object elt = Fcar (maps);
|
|
3729 Lisp_Object tail = shadow;
|
|
3730 int no_prefix = (VECTORP (Fcar (elt))
|
|
3731 && XINT (Flength (Fcar (elt))) == 0);
|
|
3732 struct gcpro ngcpro1, ngcpro2, ngcpro3;
|
|
3733 NGCPRO3 (sub_shadow, elt, tail);
|
|
3734
|
|
3735 for (; CONSP (tail); tail = XCDR (tail))
|
|
3736 {
|
|
3737 Lisp_Object sh = XCAR (tail);
|
|
3738
|
|
3739 /* If the sequence by which we reach this keymap is zero-length,
|
|
3740 then the shadow maps for this keymap are just SHADOW. */
|
|
3741 if (no_prefix)
|
|
3742 ;
|
|
3743 /* If the sequence by which we reach this keymap actually has
|
|
3744 some elements, then the sequence's definition in SHADOW is
|
|
3745 what we should use. */
|
|
3746 else
|
|
3747 {
|
|
3748 sh = Flookup_key (sh, Fcar (elt), Qt);
|
|
3749 if (CHARP (sh))
|
|
3750 sh = Qnil;
|
|
3751 }
|
|
3752
|
|
3753 if (!NILP (sh))
|
|
3754 {
|
|
3755 Lisp_Object shm = get_keymap (sh, 0, 1);
|
|
3756 if (!KEYMAPP (shm))
|
|
3757 /* If sh is not nil and not a keymap, it completely shadows
|
|
3758 this map, so don't describe this map at all. */
|
|
3759 goto SKIP;
|
|
3760 sub_shadow = Fcons (shm, sub_shadow);
|
|
3761 }
|
|
3762 }
|
|
3763
|
|
3764 {
|
|
3765 /* Describe the contents of map MAP, assuming that this map
|
|
3766 itself is reached by the sequence of prefix keys KEYS (a vector).
|
|
3767 PARTIAL and SHADOW are as in `describe_map_tree'. */
|
|
3768 Lisp_Object keysdesc
|
|
3769 = ((!no_prefix)
|
|
3770 ? concat2 (Fkey_description (Fcar (elt)), Vsingle_space_string)
|
|
3771 : Qnil);
|
|
3772 describe_map (Fcdr (elt), keysdesc,
|
|
3773 describe_command,
|
|
3774 partial,
|
|
3775 sub_shadow,
|
|
3776 mice_only_p);
|
|
3777 }
|
|
3778 SKIP:
|
|
3779 NUNGCPRO;
|
|
3780 }
|
|
3781 UNGCPRO;
|
|
3782 }
|
|
3783
|
|
3784
|
|
3785 static void
|
|
3786 describe_command (Lisp_Object definition)
|
|
3787 {
|
|
3788 /* This function can GC */
|
|
3789 Lisp_Object buffer;
|
|
3790 int keymapp = !NILP (Fkeymapp (definition));
|
|
3791 struct gcpro gcpro1, gcpro2;
|
|
3792 GCPRO2 (definition, buffer);
|
|
3793
|
|
3794 XSETBUFFER (buffer, current_buffer);
|
|
3795 Findent_to (make_int (16), make_int (3), buffer);
|
|
3796 if (keymapp)
|
|
3797 buffer_insert_c_string (XBUFFER (buffer), "<< ");
|
|
3798
|
|
3799 if (SYMBOLP (definition))
|
|
3800 {
|
|
3801 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (definition));
|
|
3802 }
|
|
3803 else if (STRINGP (definition) || VECTORP (definition))
|
|
3804 {
|
|
3805 buffer_insert_c_string (XBUFFER (buffer), "Kbd Macro: ");
|
|
3806 buffer_insert1 (XBUFFER (buffer), Fkey_description (definition));
|
|
3807 }
|
|
3808 else if (COMPILED_FUNCTIONP (definition))
|
|
3809 buffer_insert_c_string (XBUFFER (buffer), "Anonymous Compiled Function");
|
|
3810 else if (CONSP (definition) && EQ (XCAR (definition), Qlambda))
|
|
3811 buffer_insert_c_string (XBUFFER (buffer), "Anonymous Lambda");
|
|
3812 else if (KEYMAPP (definition))
|
|
3813 {
|
|
3814 Lisp_Object name = XKEYMAP (definition)->name;
|
|
3815 if (STRINGP (name) || (SYMBOLP (name) && !NILP (name)))
|
|
3816 {
|
|
3817 buffer_insert_c_string (XBUFFER (buffer), "Prefix command ");
|
|
3818 if (SYMBOLP (name)
|
|
3819 && EQ (find_symbol_value (name), definition))
|
|
3820 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (name));
|
|
3821 else
|
|
3822 {
|
|
3823 buffer_insert1 (XBUFFER (buffer), Fprin1_to_string (name, Qnil));
|
|
3824 }
|
|
3825 }
|
|
3826 else
|
|
3827 buffer_insert_c_string (XBUFFER (buffer), "Prefix Command");
|
|
3828 }
|
|
3829 else
|
|
3830 buffer_insert_c_string (XBUFFER (buffer), "??");
|
|
3831
|
|
3832 if (keymapp)
|
|
3833 buffer_insert_c_string (XBUFFER (buffer), " >>");
|
|
3834 buffer_insert_c_string (XBUFFER (buffer), "\n");
|
|
3835 UNGCPRO;
|
|
3836 }
|
|
3837
|
|
3838 struct describe_map_closure
|
|
3839 {
|
|
3840 Lisp_Object *list; /* pointer to the list to update */
|
|
3841 Lisp_Object partial; /* whether to ignore suppressed commands */
|
|
3842 Lisp_Object shadow; /* list of maps shadowing this one */
|
|
3843 Lisp_Object self; /* this map */
|
|
3844 Lisp_Object self_root; /* this map, or some map that has this map as
|
|
3845 a parent. this is the base of the tree */
|
|
3846 int mice_only_p; /* whether we are to display only button bindings */
|
|
3847 };
|
|
3848
|
|
3849 struct describe_map_shadow_closure
|
|
3850 {
|
|
3851 CONST struct key_data *raw_key;
|
|
3852 Lisp_Object self;
|
|
3853 };
|
|
3854
|
|
3855 static Lisp_Object
|
|
3856 describe_map_mapper_shadow_search (Lisp_Object map, void *arg)
|
|
3857 {
|
|
3858 struct describe_map_shadow_closure *c = arg;
|
|
3859
|
|
3860 if (EQ (map, c->self))
|
|
3861 return (Qzero); /* Not shadowed; terminate search */
|
|
3862 else if (!NILP (keymap_lookup_directly (map,
|
|
3863 c->raw_key->keysym,
|
|
3864 c->raw_key->modifiers)))
|
|
3865 return (Qt);
|
|
3866 else
|
|
3867 return (Qnil);
|
|
3868 }
|
|
3869
|
|
3870
|
|
3871 static Lisp_Object
|
|
3872 keymap_lookup_inherited_mapper (Lisp_Object km, void *arg)
|
|
3873 {
|
|
3874 struct key_data *k = arg;
|
|
3875 return (keymap_lookup_directly (km, k->keysym, k->modifiers));
|
|
3876 }
|
|
3877
|
|
3878
|
|
3879 static void
|
|
3880 describe_map_mapper (CONST struct key_data *key,
|
|
3881 Lisp_Object binding,
|
|
3882 void *describe_map_closure)
|
|
3883 {
|
|
3884 /* This function can GC */
|
|
3885 struct describe_map_closure *closure = describe_map_closure;
|
|
3886 Lisp_Object keysym = key->keysym;
|
|
3887 unsigned int modifiers = key->modifiers;
|
|
3888
|
|
3889 /* Dont mention suppressed commands. */
|
|
3890 if (SYMBOLP (binding)
|
|
3891 && !NILP (closure->partial)
|
|
3892 && !NILP (Fget (binding, closure->partial, Qnil)))
|
|
3893 return;
|
|
3894
|
|
3895 /* If we're only supposed to display mouse bindings and this isn't one,
|
|
3896 then bug out. */
|
|
3897 if (closure->mice_only_p &&
|
|
3898 (! (EQ (keysym, Qbutton0) || EQ (keysym, Qbutton1)
|
|
3899 || EQ (keysym, Qbutton2) || EQ (keysym, Qbutton3)
|
|
3900 || EQ (keysym, Qbutton4) || EQ (keysym, Qbutton5)
|
|
3901 || EQ (keysym, Qbutton6) || EQ (keysym, Qbutton7))))
|
|
3902 return;
|
|
3903
|
|
3904 /* If this command in this map is shadowed by some other map, ignore it. */
|
|
3905 {
|
|
3906 Lisp_Object tail;
|
|
3907
|
|
3908 for (tail = closure->shadow; CONSP (tail); tail = XCDR (tail))
|
|
3909 {
|
|
3910 QUIT;
|
|
3911 if (!NILP (traverse_keymaps (XCAR (tail), Qnil,
|
|
3912 keymap_lookup_inherited_mapper,
|
|
3913 /* Cast to discard `const' */
|
|
3914 (void *)key)))
|
|
3915 return;
|
|
3916 }
|
|
3917 }
|
|
3918
|
|
3919 /* If this key is in some map of which this map is a parent, then ignore
|
|
3920 it (in that case, it has been shadowed).
|
|
3921 */
|
|
3922 {
|
|
3923 Lisp_Object sh;
|
|
3924 struct describe_map_shadow_closure c;
|
|
3925 c.raw_key = key;
|
|
3926 c.self = closure->self;
|
|
3927
|
|
3928 sh = traverse_keymaps (closure->self_root, Qnil,
|
|
3929 describe_map_mapper_shadow_search, &c);
|
|
3930 if (!NILP (sh) && !ZEROP (sh))
|
|
3931 return;
|
|
3932 }
|
|
3933
|
|
3934 /* Otherwise add it to the list to be sorted. */
|
|
3935 *(closure->list) = Fcons (Fcons (Fcons (keysym, make_int (modifiers)),
|
|
3936 binding),
|
|
3937 *(closure->list));
|
|
3938 }
|
|
3939
|
|
3940
|
|
3941 static int
|
|
3942 describe_map_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
|
|
3943 Lisp_Object pred)
|
|
3944 {
|
|
3945 /* obj1 and obj2 are conses of the form
|
|
3946 ( ( <keysym> . <modifiers> ) . <binding> )
|
|
3947 keysym and modifiers are used, binding is ignored.
|
|
3948 */
|
|
3949 unsigned int bit1, bit2;
|
|
3950 obj1 = XCAR (obj1);
|
|
3951 obj2 = XCAR (obj2);
|
|
3952 bit1 = XINT (XCDR (obj1));
|
|
3953 bit2 = XINT (XCDR (obj2));
|
|
3954 if (bit1 != bit2)
|
|
3955 return ((bit1 < bit2) ? 1 : -1);
|
|
3956 else
|
|
3957 return map_keymap_sort_predicate (obj1, obj2, pred);
|
|
3958 }
|
|
3959
|
|
3960 /* Elide 2 or more consecutive numeric keysyms bound to the same thing,
|
|
3961 or 2 or more symbolic keysyms that are bound to the same thing and
|
|
3962 have consecutive character-set-properties.
|
|
3963 */
|
|
3964 static int
|
|
3965 elide_next_two_p (Lisp_Object list)
|
|
3966 {
|
|
3967 Lisp_Object s1, s2;
|
|
3968
|
|
3969 if (NILP (XCDR (list)))
|
|
3970 return 0;
|
|
3971
|
|
3972 /* next two bindings differ */
|
|
3973 if (!EQ (XCDR (XCAR (list)),
|
|
3974 XCDR (XCAR (XCDR (list)))))
|
|
3975 return 0;
|
|
3976
|
|
3977 /* next two modifier-sets differ */
|
|
3978 if (!EQ (XCDR (XCAR (XCAR (list))),
|
|
3979 XCDR (XCAR (XCAR (XCDR (list))))))
|
|
3980 return 0;
|
|
3981
|
|
3982 s1 = XCAR (XCAR (XCAR (list)));
|
|
3983 s2 = XCAR (XCAR (XCAR (XCDR (list))));
|
|
3984
|
|
3985 if (SYMBOLP (s1))
|
|
3986 {
|
|
3987 Lisp_Object code = Fget (s1, Vcharacter_set_property, Qnil);
|
|
3988 if (INTP (code)) s1 = code;
|
|
3989 else return 0;
|
|
3990 }
|
|
3991 if (SYMBOLP (s2))
|
|
3992 {
|
|
3993 Lisp_Object code = Fget (s2, Vcharacter_set_property, Qnil);
|
|
3994 if (INTP (code)) s2 = code;
|
|
3995 else return 0;
|
|
3996 }
|
|
3997
|
|
3998 if (XCHAR (s1) == XCHAR (s2) ||
|
|
3999 XCHAR (s1) + 1 == XCHAR (s2))
|
|
4000 return 1;
|
|
4001 return 0;
|
|
4002 }
|
|
4003
|
|
4004
|
|
4005 static Lisp_Object
|
|
4006 describe_map_parent_mapper (Lisp_Object keymap, void *arg)
|
|
4007 {
|
|
4008 /* This function can GC */
|
|
4009 struct describe_map_closure *describe_map_closure = arg;
|
|
4010 describe_map_closure->self = keymap;
|
|
4011 map_keymap (XKEYMAP (keymap)->table,
|
|
4012 0, /* don't sort: we'll do it later */
|
|
4013 describe_map_mapper, describe_map_closure);
|
|
4014 return (Qnil);
|
|
4015 }
|
|
4016
|
|
4017
|
|
4018 static void
|
|
4019 describe_map (Lisp_Object keymap, Lisp_Object elt_prefix,
|
|
4020 void (*elt_describer) (Lisp_Object),
|
|
4021 int partial,
|
|
4022 Lisp_Object shadow,
|
|
4023 int mice_only_p)
|
|
4024 {
|
|
4025 /* This function can GC */
|
|
4026 struct describe_map_closure describe_map_closure;
|
|
4027 Lisp_Object list = Qnil;
|
|
4028 struct buffer *buf = current_buffer;
|
|
4029 Emchar printable_min = (CHAR_OR_CHAR_INTP (buf->ctl_arrow)
|
|
4030 ? XCHAR_OR_CHAR_INT (buf->ctl_arrow)
|
|
4031 : ((EQ (buf->ctl_arrow, Qt)
|
|
4032 || EQ (buf->ctl_arrow, Qnil))
|
|
4033 ? 256 : 160));
|
|
4034 int elided = 0;
|
|
4035 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
4036
|
|
4037 keymap = get_keymap (keymap, 1, 1);
|
|
4038 describe_map_closure.partial = (partial ? Qsuppress_keymap : Qnil);
|
|
4039 describe_map_closure.shadow = shadow;
|
|
4040 describe_map_closure.list = &list;
|
|
4041 describe_map_closure.self_root = keymap;
|
|
4042 describe_map_closure.mice_only_p = mice_only_p;
|
|
4043
|
|
4044 GCPRO4 (keymap, elt_prefix, shadow, list);
|
|
4045
|
|
4046 traverse_keymaps (keymap, Qnil,
|
|
4047 describe_map_parent_mapper, &describe_map_closure);
|
|
4048
|
|
4049 if (!NILP (list))
|
|
4050 {
|
|
4051 list = list_sort (list, Qnil, describe_map_sort_predicate);
|
|
4052 buffer_insert_c_string (buf, "\n");
|
|
4053 while (!NILP (list))
|
|
4054 {
|
|
4055 Lisp_Object elt = XCAR (XCAR (list));
|
|
4056 Lisp_Object keysym = XCAR (elt);
|
|
4057 unsigned int modifiers = XINT (XCDR (elt));
|
|
4058
|
|
4059 if (!NILP (elt_prefix))
|
|
4060 buffer_insert_lisp_string (buf, elt_prefix);
|
|
4061
|
|
4062 if (modifiers & MOD_META) buffer_insert_c_string (buf, "M-");
|
|
4063 if (modifiers & MOD_CONTROL) buffer_insert_c_string (buf, "C-");
|
|
4064 if (modifiers & MOD_SUPER) buffer_insert_c_string (buf, "S-");
|
|
4065 if (modifiers & MOD_HYPER) buffer_insert_c_string (buf, "H-");
|
|
4066 if (modifiers & MOD_ALT) buffer_insert_c_string (buf, "Alt-");
|
|
4067 if (modifiers & MOD_SHIFT) buffer_insert_c_string (buf, "Sh-");
|
|
4068 if (SYMBOLP (keysym))
|
|
4069 {
|
|
4070 Lisp_Object code = Fget (keysym, Vcharacter_set_property, Qnil);
|
|
4071 Emchar c = (CHAR_OR_CHAR_INTP (code)
|
|
4072 ? XCHAR_OR_CHAR_INT (code) : -1);
|
|
4073 /* Calling Fsingle_key_description() would cons more */
|
|
4074 #if 0 /* This is bogus */
|
|
4075 if (EQ (keysym, QKlinefeed))
|
|
4076 buffer_insert_c_string (buf, "LFD");
|
|
4077 else if (EQ (keysym, QKtab))
|
|
4078 buffer_insert_c_string (buf, "TAB");
|
|
4079 else if (EQ (keysym, QKreturn))
|
|
4080 buffer_insert_c_string (buf, "RET");
|
|
4081 else if (EQ (keysym, QKescape))
|
|
4082 buffer_insert_c_string (buf, "ESC");
|
|
4083 else if (EQ (keysym, QKdelete))
|
|
4084 buffer_insert_c_string (buf, "DEL");
|
|
4085 else if (EQ (keysym, QKspace))
|
|
4086 buffer_insert_c_string (buf, "SPC");
|
|
4087 else if (EQ (keysym, QKbackspace))
|
|
4088 buffer_insert_c_string (buf, "BS");
|
|
4089 else
|
|
4090 #endif
|
|
4091 if (c >= printable_min)
|
|
4092 buffer_insert_emacs_char (buf, c);
|
|
4093 else buffer_insert1 (buf, Fsymbol_name (keysym));
|
|
4094 }
|
|
4095 else if (CHARP (keysym))
|
|
4096 buffer_insert_emacs_char (buf, XCHAR (keysym));
|
|
4097 else
|
|
4098 buffer_insert_c_string (buf, "---bad keysym---");
|
|
4099
|
|
4100 if (elided)
|
|
4101 elided = 0;
|
|
4102 else
|
|
4103 {
|
|
4104 int k = 0;
|
|
4105
|
|
4106 while (elide_next_two_p (list))
|
|
4107 {
|
|
4108 k++;
|
|
4109 list = XCDR (list);
|
|
4110 }
|
|
4111 if (k != 0)
|
|
4112 {
|
|
4113 if (k == 1)
|
|
4114 buffer_insert_c_string (buf, ", ");
|
|
4115 else
|
|
4116 buffer_insert_c_string (buf, " .. ");
|
|
4117 elided = 1;
|
|
4118 continue;
|
|
4119 }
|
|
4120 }
|
|
4121
|
|
4122 /* Print a description of the definition of this character. */
|
|
4123 (*elt_describer) (XCDR (XCAR (list)));
|
|
4124 list = XCDR (list);
|
|
4125 }
|
|
4126 }
|
|
4127 UNGCPRO;
|
|
4128 }
|
|
4129
|
|
4130
|
|
4131 void
|
|
4132 syms_of_keymap (void)
|
|
4133 {
|
|
4134 defsymbol (&Qminor_mode_map_alist, "minor-mode-map-alist");
|
|
4135
|
|
4136 defsymbol (&Qkeymapp, "keymapp");
|
|
4137
|
|
4138 defsymbol (&Qsuppress_keymap, "suppress-keymap");
|
|
4139
|
|
4140 defsymbol (&Qmodeline_map, "modeline-map");
|
|
4141 defsymbol (&Qtoolbar_map, "toolbar-map");
|
|
4142
|
20
|
4143 DEFSUBR (Fkeymap_parents);
|
|
4144 DEFSUBR (Fset_keymap_parents);
|
|
4145 DEFSUBR (Fkeymap_name);
|
|
4146 DEFSUBR (Fset_keymap_name);
|
|
4147 DEFSUBR (Fkeymap_prompt);
|
|
4148 DEFSUBR (Fset_keymap_prompt);
|
|
4149 DEFSUBR (Fkeymap_default_binding);
|
|
4150 DEFSUBR (Fset_keymap_default_binding);
|
|
4151
|
|
4152 DEFSUBR (Fkeymapp);
|
|
4153 DEFSUBR (Fmake_keymap);
|
|
4154 DEFSUBR (Fmake_sparse_keymap);
|
|
4155
|
|
4156 DEFSUBR (Fcopy_keymap);
|
|
4157 DEFSUBR (Fkeymap_fullness);
|
|
4158 DEFSUBR (Fmap_keymap);
|
|
4159 DEFSUBR (Fevent_matches_key_specifier_p);
|
|
4160 DEFSUBR (Fdefine_key);
|
|
4161 DEFSUBR (Flookup_key);
|
|
4162 DEFSUBR (Fkey_binding);
|
|
4163 DEFSUBR (Fuse_global_map);
|
|
4164 DEFSUBR (Fuse_local_map);
|
|
4165 DEFSUBR (Fcurrent_local_map);
|
|
4166 DEFSUBR (Fcurrent_global_map);
|
|
4167 DEFSUBR (Fcurrent_keymaps);
|
|
4168 DEFSUBR (Faccessible_keymaps);
|
|
4169 DEFSUBR (Fkey_description);
|
|
4170 DEFSUBR (Fsingle_key_description);
|
|
4171 DEFSUBR (Fwhere_is_internal);
|
|
4172 DEFSUBR (Fdescribe_bindings_internal);
|
|
4173
|
|
4174 DEFSUBR (Ftext_char_description);
|
0
|
4175
|
|
4176 defsymbol (&Qcontrol, "control");
|
|
4177 defsymbol (&Qctrl, "ctrl");
|
|
4178 defsymbol (&Qmeta, "meta");
|
|
4179 defsymbol (&Qsuper, "super");
|
|
4180 defsymbol (&Qhyper, "hyper");
|
|
4181 defsymbol (&Qalt, "alt");
|
|
4182 defsymbol (&Qshift, "shift");
|
|
4183 defsymbol (&Qbutton0, "button0");
|
|
4184 defsymbol (&Qbutton1, "button1");
|
|
4185 defsymbol (&Qbutton2, "button2");
|
|
4186 defsymbol (&Qbutton3, "button3");
|
|
4187 defsymbol (&Qbutton4, "button4");
|
|
4188 defsymbol (&Qbutton5, "button5");
|
|
4189 defsymbol (&Qbutton6, "button6");
|
|
4190 defsymbol (&Qbutton7, "button7");
|
|
4191 defsymbol (&Qbutton0up, "button0up");
|
|
4192 defsymbol (&Qbutton1up, "button1up");
|
|
4193 defsymbol (&Qbutton2up, "button2up");
|
|
4194 defsymbol (&Qbutton3up, "button3up");
|
|
4195 defsymbol (&Qbutton4up, "button4up");
|
|
4196 defsymbol (&Qbutton5up, "button5up");
|
|
4197 defsymbol (&Qbutton6up, "button6up");
|
|
4198 defsymbol (&Qbutton7up, "button7up");
|
22
|
4199 defsymbol (&Qmouse_1, "mouse-1");
|
|
4200 defsymbol (&Qmouse_2, "mouse-2");
|
|
4201 defsymbol (&Qmouse_3, "mouse-3");
|
|
4202 defsymbol (&Qdown_mouse_1, "down-mouse-1");
|
|
4203 defsymbol (&Qdown_mouse_2, "down-mouse-2");
|
|
4204 defsymbol (&Qdown_mouse_3, "down-mouse-3");
|
0
|
4205 defsymbol (&Qmenu_selection, "menu-selection");
|
|
4206 defsymbol (&QLFD, "LFD");
|
|
4207 defsymbol (&QTAB, "TAB");
|
|
4208 defsymbol (&QRET, "RET");
|
|
4209 defsymbol (&QESC, "ESC");
|
|
4210 defsymbol (&QDEL, "DEL");
|
|
4211 defsymbol (&QBS, "BS");
|
|
4212 }
|
|
4213
|
|
4214 void
|
|
4215 vars_of_keymap (void)
|
|
4216 {
|
|
4217 DEFVAR_LISP ("meta-prefix-char", &Vmeta_prefix_char /*
|
|
4218 Meta-prefix character.
|
|
4219 This character followed by some character `foo' turns into `Meta-foo'.
|
|
4220 This can be any form recognized as a single key specifier.
|
|
4221 To disable the meta-prefix-char, set it to a negative number.
|
|
4222 */ );
|
|
4223 Vmeta_prefix_char = make_char (033);
|
|
4224
|
|
4225 DEFVAR_LISP ("mouse-grabbed-buffer", &Vmouse_grabbed_buffer /*
|
|
4226 A buffer which should be consulted first for all mouse activity.
|
|
4227 When a mouse-click is processed, it will first be looked up in the
|
|
4228 local-map of this buffer, and then through the normal mechanism if there
|
|
4229 is no binding for that click. This buffer's value of `mode-motion-hook'
|
|
4230 will be consulted instead of the `mode-motion-hook' of the buffer of the
|
|
4231 window under the mouse. You should *bind* this, not set it.
|
|
4232 */ );
|
|
4233 Vmouse_grabbed_buffer = Qnil;
|
|
4234
|
|
4235 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map /*
|
|
4236 Keymap that overrides all other local keymaps.
|
|
4237 If this variable is non-nil, it is used as a keymap instead of the
|
|
4238 buffer's local map, and the minor mode keymaps and extent-local keymaps.
|
|
4239 You should *bind* this, not set it.
|
|
4240 */ );
|
|
4241 Voverriding_local_map = Qnil;
|
|
4242
|
|
4243 Fset (Qminor_mode_map_alist, Qnil);
|
|
4244
|
|
4245 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map /*
|
|
4246 Keymap of key translations that can override keymaps.
|
|
4247 This keymap works like `function-key-map', but comes after that,
|
|
4248 and applies even for keys that have ordinary bindings.
|
|
4249 */ );
|
|
4250
|
|
4251 DEFVAR_INT ("keymap-tick", &keymap_tick /*
|
|
4252 Incremented for each change to any keymap.
|
|
4253 */ );
|
|
4254 keymap_tick = 0;
|
|
4255
|
|
4256 staticpro (&Vcurrent_global_map);
|
|
4257
|
|
4258 Vsingle_space_string = make_pure_string ((CONST Bufbyte *) " ", 1, Qnil, 1);
|
|
4259 staticpro (&Vsingle_space_string);
|
|
4260 }
|
|
4261
|
|
4262 void
|
|
4263 complex_vars_of_keymap (void)
|
|
4264 {
|
|
4265 /* This function can GC */
|
|
4266 Lisp_Object ESC_prefix = intern ("ESC-prefix");
|
|
4267 Lisp_Object meta_disgustitute;
|
|
4268
|
|
4269 Vcurrent_global_map = Fmake_keymap (Qnil);
|
|
4270
|
|
4271 meta_disgustitute = Fmake_keymap (Qnil);
|
|
4272 Ffset (ESC_prefix, meta_disgustitute);
|
|
4273 /* no need to protect meta_disgustitute, though */
|
|
4274 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (MOD_META),
|
|
4275 XKEYMAP (Vcurrent_global_map),
|
|
4276 meta_disgustitute);
|
|
4277 XKEYMAP (Vcurrent_global_map)->sub_maps_cache = Qt;
|
|
4278
|
|
4279 Vkey_translation_map = Fmake_sparse_keymap (intern ("key-translation-map"));
|
|
4280 }
|