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