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