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
3086
+ − 1334 ("Invalid (GNU Emacs) key format (see doc of define-key)",
428
+ − 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.
3086
+ − 1783 KEYS is the key sequence to bind, described below.
428
+ − 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
3086
+ − 1796 A `key sequence' is a vector of one or more keystrokes.
+ − 1797 A `keystroke' is a list containing a key and zero or more modifiers. The
+ − 1798 key must be the last element of the list.
+ − 1799 A `key' is a symbol corresponding to a key on the keyboard, or to a mouse
+ − 1800 gesture. Mouse clicks are denoted by symbols prefixed with "button",
+ − 1801 followed by a digit for which button, and optionally "up". Thus `button1'
+ − 1802 means the down-stroke and `button1up' means the up-stroke when clicking
+ − 1803 mouse button 1.
+ − 1804 A `modifier' is a symbol naming a physical key which is only "noticed" by
+ − 1805 XEmacs when chorded with another key. The `shift' modifier is a special
+ − 1806 case. You cannot use `(meta shift a)' to mean `(meta A)', since for
+ − 1807 characters that have ASCII equivalents, the state of the shift key is
+ − 1808 implicit in the keysym (a vs. A). You also cannot say `(shift =)' to mean
+ − 1809 `+', as that correspondence varies from keyboard to keyboard. The shift
+ − 1810 modifier can only be applied to keys that do not have a second keysym on the
+ − 1811 same key, such as `backspace' and `tab'. A mouse click may be combined with
+ − 1812 modifiers to create a compound "keystroke".
+ − 1813
+ − 1814 The keys, mouse gestures, and modifiers that are available depend on your
+ − 1815 console and its driver. At a minimum the ASCII graphic characters will be
+ − 1816 available as keys, and shift, control, and meta as modifiers.
+ − 1817
+ − 1818 To find out programmatically what a key is bound to, use `key-binding' to
+ − 1819 check all applicable keymaps, or `lookup-key' to check a specific keymap.
+ − 1820 The documentation for `key-binding' also contains a description of which
+ − 1821 keymaps are applicable in various situations. `where-is-internal' does
+ − 1822 the opposite of `key-binding', i.e. searches keymaps for the keys that
+ − 1823 map to a particular binding.
+ − 1824
+ − 1825 If you are confused about why a particular key sequence is generating a
+ − 1826 particular binding, and looking through the keymaps doesn't help, setting
+ − 1827 the variable `debug-emacs-events' may help. If not, try checking
+ − 1828 what's in `function-key-map' and `key-translation-map'.
+ − 1829
+ − 1830 When running under a window system, typically the repertoire of keys is
+ − 1831 vastly expanded. XEmacs does its best to use the names defined on each
+ − 1832 platform. Also, when running under a window system, XEmacs can tell the
+ − 1833 difference between the keystrokes control-h, control-shift-h, and backspace.
+ − 1834 If the symbols differ, you can bind different actions to each. For mouse
+ − 1835 clicks, different commands may be bound to the up and down strokes, though
+ − 1836 that is probably not what you want, so be careful.
+ − 1837
+ − 1838 Variant representations:
+ − 1839
+ − 1840 Besides the canonical representation as a vector of lists of symbols,
+ − 1841 `define-key' also accepts a number of abbreviations, aliases, and variants
+ − 1842 for convenience, compatibility, and internal use.
+ − 1843
+ − 1844 A keystroke may be represented by a key; this is treated as though it were a
+ − 1845 list containing that key as the only element. A keystroke may also be
+ − 1846 represented by an event object, as returned by the `next-command-event' and
+ − 1847 `read-key-sequence' functions. A key sequence may be represented by a
+ − 1848 single keystroke; this is treated as a vector containing that keystroke as
+ − 1849 its only element.
+ − 1850
+ − 1851 A key may be represented by a character or its equivalent integer code,
+ − 1852 if and only if it is equivalent to a character with a code in the range
+ − 1853 32 - 255.
+ − 1854
+ − 1855 For backward compatibility, a key sequence may also be represented by a
+ − 1856 string. In this case, it represents the key sequence(s) that would
+ − 1857 produce that sequence of ASCII characters in a purely ASCII world. An
+ − 1858 alternative string representation is keyboard macro notation, which can
+ − 1859 be translated to the canonical representation with `kbd'.
+ − 1860
+ − 1861 Examples:
+ − 1862
+ − 1863 The key sequence `A' (which invokes `self-insert-command') is represented
+ − 1864 by all of these forms:
428
+ − 1865 A ?A 65 (A) (?A) (65)
+ − 1866 [A] [?A] [65] [(A)] [(?A)] [(65)]
+ − 1867
3086
+ − 1868 The key sequence `control-a' is represented by these forms:
428
+ − 1869 (control A) (control ?A) (control 65)
+ − 1870 [(control A)] [(control ?A)] [(control 65)]
3086
+ − 1871
+ − 1872 The key sequence `control-c control-a' is represented by these forms:
428
+ − 1873 [(control c) (control a)] [(control ?c) (control ?a)]
+ − 1874 [(control 99) (control 65)] etc.
+ − 1875
3086
+ − 1876 The keystroke `control-b' *may not* be represented by the number 2 (the
+ − 1877 ASCII code for ^B) or the character `?\^B'.
+ − 1878
+ − 1879 The `break' key may be represented only by the symbol `break'.
+ − 1880
428
+ − 1881 Mouse button clicks work just like keypresses: (control button1) means
+ − 1882 pressing the left mouse button while holding down the control key.
3086
+ − 1883
+ − 1884 A string containing the ASCII backspace character, "\\^H", would represent
+ − 1885 two key sequences: `(control h)' and `backspace'. Binding a
428
+ − 1886 command to this will actually bind both of those key sequences. Likewise
+ − 1887 for the following pairs:
+ − 1888
+ − 1889 control h backspace
+ − 1890 control i tab
+ − 1891 control m return
+ − 1892 control j linefeed
+ − 1893 control [ escape
+ − 1894 control @ control space
+ − 1895
+ − 1896 After binding a command to two key sequences with a form like
+ − 1897
+ − 1898 (define-key global-map "\\^X\\^I" \'command-1)
+ − 1899
+ − 1900 it is possible to redefine only one of those sequences like so:
+ − 1901
+ − 1902 (define-key global-map [(control x) (control i)] \'command-2)
+ − 1903 (define-key global-map [(control x) tab] \'command-3)
+ − 1904 */
+ − 1905 (keymap, keys, def))
+ − 1906 {
+ − 1907 /* This function can GC */
+ − 1908 int idx;
+ − 1909 int metized = 0;
+ − 1910 int len;
+ − 1911 int ascii_hack;
+ − 1912 struct gcpro gcpro1, gcpro2, gcpro3;
+ − 1913
+ − 1914 if (VECTORP (keys))
+ − 1915 len = XVECTOR_LENGTH (keys);
+ − 1916 else if (STRINGP (keys))
826
+ − 1917 len = string_char_length (keys);
428
+ − 1918 else if (CHAR_OR_CHAR_INTP (keys) || SYMBOLP (keys) || CONSP (keys))
+ − 1919 {
+ − 1920 if (!CONSP (keys)) keys = list1 (keys);
+ − 1921 len = 1;
+ − 1922 keys = make_vector (1, keys); /* this is kinda sleazy. */
+ − 1923 }
+ − 1924 else
+ − 1925 {
+ − 1926 keys = wrong_type_argument (Qsequencep, keys);
+ − 1927 len = XINT (Flength (keys));
+ − 1928 }
+ − 1929 if (len == 0)
+ − 1930 return Qnil;
+ − 1931
+ − 1932 GCPRO3 (keymap, keys, def);
+ − 1933
+ − 1934 /* ASCII grunge.
+ − 1935 When the user defines a key which, in a strictly ASCII world, would be
+ − 1936 produced by two different keys (^J and linefeed, or ^H and backspace,
+ − 1937 for example) then the binding will be made for both keysyms.
+ − 1938
+ − 1939 This is done if the user binds a command to a string, as in
3086
+ − 1940 (define-key map "\^H" 'something), but not when using the canonical
+ − 1941 syntax (define-key map '(control h) 'something).
428
+ − 1942 */
+ − 1943 ascii_hack = (STRINGP (keys));
+ − 1944
+ − 1945 keymap = get_keymap (keymap, 1, 1);
+ − 1946
+ − 1947 idx = 0;
+ − 1948 while (1)
+ − 1949 {
+ − 1950 Lisp_Object c;
934
+ − 1951 Lisp_Key_Data raw_key1;
+ − 1952 Lisp_Key_Data raw_key2;
428
+ − 1953 if (STRINGP (keys))
867
+ − 1954 c = make_char (string_ichar (keys, idx));
428
+ − 1955 else
+ − 1956 c = XVECTOR_DATA (keys) [idx];
+ − 1957
+ − 1958 define_key_parser (c, &raw_key1);
+ − 1959
+ − 1960 if (!metized && ascii_hack && meta_prefix_char_p (&raw_key1))
+ − 1961 {
+ − 1962 if (idx == (len - 1))
+ − 1963 {
+ − 1964 /* This is a hack to prevent a binding for the meta-prefix-char
+ − 1965 from being made in a map which already has a non-empty "meta"
+ − 1966 submap. That is, we can't let both "escape" and "meta" have
+ − 1967 a binding in the same keymap. This implies that the idiom
+ − 1968 (define-key my-map "\e" my-escape-map)
+ − 1969 (define-key my-escape-map "a" 'my-command)
+ − 1970 no longer works. That's ok. Instead the luser should do
+ − 1971 (define-key my-map "\ea" 'my-command)
+ − 1972 or, more correctly
+ − 1973 (define-key my-map "\M-a" 'my-command)
+ − 1974 and then perhaps
+ − 1975 (defvar my-escape-map (lookup-key my-map "\e"))
+ − 1976 if the luser really wants the map in a variable.
+ − 1977 */
440
+ − 1978 Lisp_Object meta_map;
428
+ − 1979 struct gcpro ngcpro1;
+ − 1980
+ − 1981 NGCPRO1 (c);
442
+ − 1982 meta_map = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META),
440
+ − 1983 XKEYMAP (keymap)->table, Qnil);
+ − 1984 if (!NILP (meta_map)
+ − 1985 && keymap_fullness (meta_map) != 0)
563
+ − 1986 invalid_operation_2
440
+ − 1987 ("Map contains meta-bindings, can't bind",
+ − 1988 Fsingle_key_description (Vmeta_prefix_char), keymap);
428
+ − 1989 NUNGCPRO;
+ − 1990 }
+ − 1991 else
+ − 1992 {
+ − 1993 metized = 1;
+ − 1994 idx++;
+ − 1995 continue;
+ − 1996 }
+ − 1997 }
+ − 1998
+ − 1999 if (ascii_hack)
+ − 2000 define_key_alternate_name (&raw_key1, &raw_key2);
+ − 2001 else
+ − 2002 {
+ − 2003 raw_key2.keysym = Qnil;
+ − 2004 raw_key2.modifiers = 0;
+ − 2005 }
+ − 2006
+ − 2007 if (metized)
+ − 2008 {
442
+ − 2009 raw_key1.modifiers |= XEMACS_MOD_META;
+ − 2010 raw_key2.modifiers |= XEMACS_MOD_META;
428
+ − 2011 metized = 0;
+ − 2012 }
+ − 2013
+ − 2014 /* This crap is to make sure that someone doesn't bind something like
+ − 2015 "C-x M-a" while "C-x ESC" has a non-keymap binding. */
442
+ − 2016 if (raw_key1.modifiers & XEMACS_MOD_META)
428
+ − 2017 ensure_meta_prefix_char_keymapp (keys, idx, keymap);
+ − 2018
+ − 2019 if (++idx == len)
+ − 2020 {
+ − 2021 keymap_store (keymap, &raw_key1, def);
+ − 2022 if (ascii_hack && !NILP (raw_key2.keysym))
+ − 2023 keymap_store (keymap, &raw_key2, def);
+ − 2024 UNGCPRO;
+ − 2025 return def;
+ − 2026 }
+ − 2027
+ − 2028 {
+ − 2029 Lisp_Object cmd;
+ − 2030 struct gcpro ngcpro1;
+ − 2031 NGCPRO1 (c);
+ − 2032
+ − 2033 cmd = keymap_lookup_1 (keymap, &raw_key1, 0);
+ − 2034 if (NILP (cmd))
+ − 2035 {
+ − 2036 cmd = Fmake_sparse_keymap (Qnil);
+ − 2037 XKEYMAP (cmd)->name /* for debugging */
+ − 2038 = list2 (make_key_description (&raw_key1, 1), keymap);
+ − 2039 keymap_store (keymap, &raw_key1, cmd);
+ − 2040 }
+ − 2041 if (NILP (Fkeymapp (cmd)))
563
+ − 2042 sferror_2 ("Invalid prefix keys in sequence",
428
+ − 2043 c, keys);
+ − 2044
+ − 2045 if (ascii_hack && !NILP (raw_key2.keysym) &&
+ − 2046 NILP (keymap_lookup_1 (keymap, &raw_key2, 0)))
+ − 2047 keymap_store (keymap, &raw_key2, cmd);
+ − 2048
+ − 2049 keymap = get_keymap (cmd, 1, 1);
+ − 2050 NUNGCPRO;
+ − 2051 }
+ − 2052 }
+ − 2053 }
+ − 2054
+ − 2055
+ − 2056 /************************************************************************/
+ − 2057 /* Looking up keys in keymaps */
+ − 2058 /************************************************************************/
+ − 2059
+ − 2060 /* We need a very fast (i.e., non-consing) version of lookup-key in order
+ − 2061 to make where-is-internal really fly. */
+ − 2062
+ − 2063 struct raw_lookup_key_mapper_closure
+ − 2064 {
+ − 2065 int remaining;
934
+ − 2066 const Lisp_Key_Data *raw_keys;
428
+ − 2067 int raw_keys_count;
+ − 2068 int keys_so_far;
+ − 2069 int accept_default;
+ − 2070 };
+ − 2071
+ − 2072 static Lisp_Object raw_lookup_key_mapper (Lisp_Object k, void *);
+ − 2073
+ − 2074 /* Caller should gc-protect args (keymaps may autoload) */
+ − 2075 static Lisp_Object
+ − 2076 raw_lookup_key (Lisp_Object keymap,
934
+ − 2077 const Lisp_Key_Data *raw_keys, int raw_keys_count,
428
+ − 2078 int keys_so_far, int accept_default)
+ − 2079 {
+ − 2080 /* This function can GC */
+ − 2081 struct raw_lookup_key_mapper_closure c;
+ − 2082 c.remaining = raw_keys_count - 1;
+ − 2083 c.raw_keys = raw_keys;
+ − 2084 c.raw_keys_count = raw_keys_count;
+ − 2085 c.keys_so_far = keys_so_far;
+ − 2086 c.accept_default = accept_default;
+ − 2087
+ − 2088 return traverse_keymaps (keymap, Qnil, raw_lookup_key_mapper, &c);
+ − 2089 }
+ − 2090
+ − 2091 static Lisp_Object
+ − 2092 raw_lookup_key_mapper (Lisp_Object k, void *arg)
+ − 2093 {
+ − 2094 /* This function can GC */
+ − 2095 struct raw_lookup_key_mapper_closure *c =
+ − 2096 (struct raw_lookup_key_mapper_closure *) arg;
+ − 2097 int accept_default = c->accept_default;
+ − 2098 int remaining = c->remaining;
+ − 2099 int keys_so_far = c->keys_so_far;
934
+ − 2100 const Lisp_Key_Data *raw_keys = c->raw_keys;
428
+ − 2101 Lisp_Object cmd;
+ − 2102
+ − 2103 if (! meta_prefix_char_p (&(raw_keys[0])))
+ − 2104 {
+ − 2105 /* Normal case: every case except the meta-hack (see below). */
+ − 2106 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
+ − 2107
+ − 2108 if (remaining == 0)
+ − 2109 /* Return whatever we found if we're out of keys */
+ − 2110 ;
+ − 2111 else if (NILP (cmd))
+ − 2112 /* Found nothing (though perhaps parent map may have binding) */
+ − 2113 ;
+ − 2114 else if (NILP (Fkeymapp (cmd)))
+ − 2115 /* Didn't find a keymap, and we have more keys.
+ − 2116 * Return a fixnum to indicate that keys were too long.
+ − 2117 */
+ − 2118 cmd = make_int (keys_so_far + 1);
+ − 2119 else
+ − 2120 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining,
+ − 2121 keys_so_far + 1, accept_default);
+ − 2122 }
+ − 2123 else
+ − 2124 {
+ − 2125 /* This is a hack so that looking up a key-sequence whose last
+ − 2126 * element is the meta-prefix-char will return the keymap that
+ − 2127 * the "meta" keys are stored in, if there is no binding for
+ − 2128 * the meta-prefix-char (and if this map has a "meta" submap).
+ − 2129 * If this map doesn't have a "meta" submap, then the
+ − 2130 * meta-prefix-char is looked up just like any other key.
+ − 2131 */
+ − 2132 if (remaining == 0)
+ − 2133 {
+ − 2134 /* First look for the prefix-char directly */
+ − 2135 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
+ − 2136 if (NILP (cmd))
+ − 2137 {
+ − 2138 /* Do kludgy return of the meta-map */
442
+ − 2139 cmd = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META),
428
+ − 2140 XKEYMAP (k)->table, Qnil);
+ − 2141 }
+ − 2142 }
+ − 2143 else
+ − 2144 {
+ − 2145 /* Search for the prefix-char-prefixed sequence directly */
+ − 2146 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default);
+ − 2147 cmd = get_keymap (cmd, 0, 1);
+ − 2148 if (!NILP (cmd))
+ − 2149 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining,
+ − 2150 keys_so_far + 1, accept_default);
442
+ − 2151 else if ((raw_keys[1].modifiers & XEMACS_MOD_META) == 0)
428
+ − 2152 {
934
+ − 2153 Lisp_Key_Data metified;
428
+ − 2154 metified.keysym = raw_keys[1].keysym;
442
+ − 2155 metified.modifiers = raw_keys[1].modifiers |
+ − 2156 (unsigned char) XEMACS_MOD_META;
428
+ − 2157
+ − 2158 /* Search for meta-next-char sequence directly */
+ − 2159 cmd = keymap_lookup_1 (k, &metified, accept_default);
+ − 2160 if (remaining == 1)
+ − 2161 ;
+ − 2162 else
+ − 2163 {
+ − 2164 cmd = get_keymap (cmd, 0, 1);
+ − 2165 if (!NILP (cmd))
+ − 2166 cmd = raw_lookup_key (cmd, raw_keys + 2, remaining - 1,
+ − 2167 keys_so_far + 2,
+ − 2168 accept_default);
+ − 2169 }
+ − 2170 }
+ − 2171 }
+ − 2172 }
+ − 2173 if (accept_default && NILP (cmd))
+ − 2174 cmd = XKEYMAP (k)->default_binding;
+ − 2175 return cmd;
+ − 2176 }
+ − 2177
+ − 2178 /* Value is number if `keys' is too long; NIL if valid but has no definition.*/
+ − 2179 /* Caller should gc-protect arguments */
+ − 2180 static Lisp_Object
+ − 2181 lookup_keys (Lisp_Object keymap, int nkeys, Lisp_Object *keys,
+ − 2182 int accept_default)
+ − 2183 {
+ − 2184 /* This function can GC */
934
+ − 2185 Lisp_Key_Data kkk[20];
+ − 2186 Lisp_Key_Data *raw_keys;
428
+ − 2187 int i;
+ − 2188
+ − 2189 if (nkeys == 0)
+ − 2190 return Qnil;
+ − 2191
438
+ − 2192 if (nkeys < countof (kkk))
428
+ − 2193 raw_keys = kkk;
+ − 2194 else
934
+ − 2195 raw_keys = alloca_array (Lisp_Key_Data, nkeys);
428
+ − 2196
+ − 2197 for (i = 0; i < nkeys; i++)
+ − 2198 {
+ − 2199 define_key_parser (keys[i], &(raw_keys[i]));
+ − 2200 }
+ − 2201 return raw_lookup_key (keymap, raw_keys, nkeys, 0, accept_default);
+ − 2202 }
+ − 2203
+ − 2204 static Lisp_Object
+ − 2205 lookup_events (Lisp_Object event_head, int nmaps, Lisp_Object keymaps[],
+ − 2206 int accept_default)
+ − 2207 {
+ − 2208 /* This function can GC */
934
+ − 2209 Lisp_Key_Data kkk[20];
428
+ − 2210 Lisp_Object event;
+ − 2211
+ − 2212 int nkeys;
934
+ − 2213 Lisp_Key_Data *raw_keys;
428
+ − 2214 Lisp_Object tem = Qnil;
+ − 2215 struct gcpro gcpro1, gcpro2;
+ − 2216 int iii;
+ − 2217
+ − 2218 CHECK_LIVE_EVENT (event_head);
+ − 2219
+ − 2220 nkeys = event_chain_count (event_head);
+ − 2221
438
+ − 2222 if (nkeys < countof (kkk))
428
+ − 2223 raw_keys = kkk;
+ − 2224 else
934
+ − 2225 raw_keys = alloca_array (Lisp_Key_Data, nkeys);
428
+ − 2226
+ − 2227 nkeys = 0;
+ − 2228 EVENT_CHAIN_LOOP (event, event_head)
+ − 2229 define_key_parser (event, &(raw_keys[nkeys++]));
+ − 2230 GCPRO2 (keymaps[0], event_head);
+ − 2231 gcpro1.nvars = nmaps;
+ − 2232 /* ####raw_keys[].keysym slots aren't gc-protected. We rely (but shouldn't)
+ − 2233 * on somebody else somewhere (obarray) having a pointer to all keysyms. */
+ − 2234 for (iii = 0; iii < nmaps; iii++)
+ − 2235 {
+ − 2236 tem = raw_lookup_key (keymaps[iii], raw_keys, nkeys, 0,
+ − 2237 accept_default);
+ − 2238 if (INTP (tem))
+ − 2239 {
+ − 2240 /* Too long in some local map means don't look at global map */
+ − 2241 tem = Qnil;
+ − 2242 break;
+ − 2243 }
+ − 2244 else if (!NILP (tem))
+ − 2245 break;
+ − 2246 }
+ − 2247 UNGCPRO;
+ − 2248 return tem;
+ − 2249 }
+ − 2250
+ − 2251 DEFUN ("lookup-key", Flookup_key, 2, 3, 0, /*
+ − 2252 In keymap KEYMAP, look up key-sequence KEYS. Return the definition.
+ − 2253 Nil is returned if KEYS is unbound. See documentation of `define-key'
+ − 2254 for valid key definitions and key-sequence specifications.
+ − 2255 A number is returned if KEYS is "too long"; that is, the leading
+ − 2256 characters fail to be a valid sequence of prefix characters in KEYMAP.
444
+ − 2257 The number is how many key strokes at the front of KEYS it takes to
+ − 2258 reach a non-prefix command.
428
+ − 2259 */
+ − 2260 (keymap, keys, accept_default))
+ − 2261 {
+ − 2262 /* This function can GC */
+ − 2263 if (VECTORP (keys))
+ − 2264 return lookup_keys (keymap,
+ − 2265 XVECTOR_LENGTH (keys),
+ − 2266 XVECTOR_DATA (keys),
+ − 2267 !NILP (accept_default));
+ − 2268 else if (SYMBOLP (keys) || CHAR_OR_CHAR_INTP (keys) || CONSP (keys))
+ − 2269 return lookup_keys (keymap, 1, &keys, !NILP (accept_default));
+ − 2270 else if (STRINGP (keys))
+ − 2271 {
826
+ − 2272 int length = string_char_length (keys);
428
+ − 2273 int i;
934
+ − 2274 Lisp_Key_Data *raw_keys = alloca_array (Lisp_Key_Data, length);
428
+ − 2275 if (length == 0)
+ − 2276 return Qnil;
+ − 2277
+ − 2278 for (i = 0; i < length; i++)
+ − 2279 {
867
+ − 2280 Ichar n = string_ichar (keys, i);
428
+ − 2281 define_key_parser (make_char (n), &(raw_keys[i]));
+ − 2282 }
+ − 2283 return raw_lookup_key (keymap, raw_keys, length, 0,
+ − 2284 !NILP (accept_default));
+ − 2285 }
+ − 2286 else
+ − 2287 {
+ − 2288 keys = wrong_type_argument (Qsequencep, keys);
+ − 2289 return Flookup_key (keymap, keys, accept_default);
+ − 2290 }
+ − 2291 }
+ − 2292
+ − 2293 /* Given a key sequence, returns a list of keymaps to search for bindings.
+ − 2294 Does all manner of semi-hairy heuristics, like looking in the current
+ − 2295 buffer's map before looking in the global map and looking in the local
+ − 2296 map of the buffer in which the mouse was clicked in event0 is a click.
+ − 2297
+ − 2298 It would be kind of nice if this were in Lisp so that this semi-hairy
+ − 2299 semi-heuristic command-lookup behavior could be readily understood and
+ − 2300 customised. However, this needs to be pretty fast, or performance of
+ − 2301 keyboard macros goes to shit; putting this in lisp slows macros down
+ − 2302 2-3x. And they're already slower than v18 by 5-6x.
+ − 2303 */
+ − 2304
+ − 2305 struct relevant_maps
+ − 2306 {
+ − 2307 int nmaps;
647
+ − 2308 int max_maps;
428
+ − 2309 Lisp_Object *maps;
+ − 2310 struct gcpro *gcpro;
+ − 2311 };
+ − 2312
+ − 2313 static void get_relevant_extent_keymaps (Lisp_Object pos,
+ − 2314 Lisp_Object buffer_or_string,
+ − 2315 Lisp_Object glyph,
+ − 2316 struct relevant_maps *closure);
+ − 2317 static void get_relevant_minor_maps (Lisp_Object buffer,
+ − 2318 struct relevant_maps *closure);
+ − 2319
+ − 2320 static void
+ − 2321 relevant_map_push (Lisp_Object map, struct relevant_maps *closure)
+ − 2322 {
647
+ − 2323 int nmaps = closure->nmaps;
428
+ − 2324
+ − 2325 if (!KEYMAPP (map))
+ − 2326 return;
+ − 2327 closure->nmaps = nmaps + 1;
+ − 2328 if (nmaps < closure->max_maps)
+ − 2329 {
+ − 2330 closure->maps[nmaps] = map;
+ − 2331 closure->gcpro->nvars = nmaps;
+ − 2332 }
+ − 2333 }
+ − 2334
+ − 2335 static int
+ − 2336 get_relevant_keymaps (Lisp_Object keys,
+ − 2337 int max_maps, Lisp_Object maps[])
+ − 2338 {
+ − 2339 /* This function can GC */
+ − 2340 Lisp_Object terminal = Qnil;
+ − 2341 struct gcpro gcpro1;
+ − 2342 struct relevant_maps closure;
+ − 2343 struct console *con;
+ − 2344
+ − 2345 GCPRO1 (*maps);
+ − 2346 gcpro1.nvars = 0;
+ − 2347 closure.nmaps = 0;
+ − 2348 closure.max_maps = max_maps;
+ − 2349 closure.maps = maps;
+ − 2350 closure.gcpro = &gcpro1;
+ − 2351
+ − 2352 if (EVENTP (keys))
+ − 2353 terminal = event_chain_tail (keys);
+ − 2354 else if (VECTORP (keys))
+ − 2355 {
+ − 2356 int len = XVECTOR_LENGTH (keys);
+ − 2357 if (len > 0)
+ − 2358 terminal = XVECTOR_DATA (keys)[len - 1];
+ − 2359 }
+ − 2360
+ − 2361 if (EVENTP (terminal))
+ − 2362 {
+ − 2363 CHECK_LIVE_EVENT (terminal);
+ − 2364 con = event_console_or_selected (terminal);
+ − 2365 }
+ − 2366 else
+ − 2367 con = XCONSOLE (Vselected_console);
+ − 2368
+ − 2369 if (KEYMAPP (con->overriding_terminal_local_map)
+ − 2370 || KEYMAPP (Voverriding_local_map))
+ − 2371 {
+ − 2372 if (KEYMAPP (con->overriding_terminal_local_map))
+ − 2373 relevant_map_push (con->overriding_terminal_local_map, &closure);
+ − 2374 if (KEYMAPP (Voverriding_local_map))
+ − 2375 relevant_map_push (Voverriding_local_map, &closure);
+ − 2376 }
+ − 2377 else if (!EVENTP (terminal)
+ − 2378 || (XEVENT (terminal)->event_type != button_press_event
+ − 2379 && XEVENT (terminal)->event_type != button_release_event))
+ − 2380 {
793
+ − 2381 Lisp_Object tem = wrap_buffer (current_buffer);
+ − 2382
428
+ − 2383 /* It's not a mouse event; order of keymaps searched is:
+ − 2384 o keymap of any/all extents under the mouse
+ − 2385 o minor-mode maps
+ − 2386 o local-map of current-buffer
771
+ − 2387 o global-tty-map or global-window-system-map
428
+ − 2388 o global-map
+ − 2389 */
+ − 2390 /* The terminal element of the lookup may be nil or a keysym.
+ − 2391 In those cases we don't want to check for an extent
+ − 2392 keymap. */
+ − 2393 if (EVENTP (terminal))
+ − 2394 {
+ − 2395 get_relevant_extent_keymaps (make_int (BUF_PT (current_buffer)),
+ − 2396 tem, Qnil, &closure);
+ − 2397 }
+ − 2398 get_relevant_minor_maps (tem, &closure);
+ − 2399
+ − 2400 tem = current_buffer->keymap;
+ − 2401 if (!NILP (tem))
+ − 2402 relevant_map_push (tem, &closure);
+ − 2403 }
+ − 2404 #ifdef HAVE_WINDOW_SYSTEM
+ − 2405 else
+ − 2406 {
+ − 2407 /* It's a mouse event; order of keymaps searched is:
+ − 2408 o vertical-divider-map, if event is over a divider
+ − 2409 o local-map of mouse-grabbed-buffer
+ − 2410 o keymap of any/all extents under the mouse
+ − 2411 if the mouse is over a modeline:
+ − 2412 o modeline-map of buffer corresponding to that modeline
+ − 2413 o else, local-map of buffer under the mouse
+ − 2414 o minor-mode maps
+ − 2415 o local-map of current-buffer
771
+ − 2416 o global-tty-map or global-window-system-map
428
+ − 2417 o global-map
+ − 2418 */
+ − 2419 Lisp_Object window = Fevent_window (terminal);
+ − 2420
+ − 2421 if (!NILP (Fevent_over_vertical_divider_p (terminal)))
+ − 2422 {
+ − 2423 if (KEYMAPP (Vvertical_divider_map))
+ − 2424 relevant_map_push (Vvertical_divider_map, &closure);
+ − 2425 }
+ − 2426
+ − 2427 if (BUFFERP (Vmouse_grabbed_buffer))
+ − 2428 {
+ − 2429 Lisp_Object map = XBUFFER (Vmouse_grabbed_buffer)->keymap;
+ − 2430
+ − 2431 get_relevant_minor_maps (Vmouse_grabbed_buffer, &closure);
+ − 2432 if (!NILP (map))
+ − 2433 relevant_map_push (map, &closure);
+ − 2434 }
+ − 2435
+ − 2436 if (!NILP (window))
+ − 2437 {
+ − 2438 Lisp_Object buffer = Fwindow_buffer (window);
+ − 2439
+ − 2440 if (!NILP (buffer))
+ − 2441 {
+ − 2442 if (!NILP (Fevent_over_modeline_p (terminal)))
+ − 2443 {
+ − 2444 Lisp_Object map = symbol_value_in_buffer (Qmodeline_map,
+ − 2445 buffer);
+ − 2446
+ − 2447 get_relevant_extent_keymaps
+ − 2448 (Fevent_modeline_position (terminal),
+ − 2449 XBUFFER (buffer)->generated_modeline_string,
438
+ − 2450 Fevent_glyph_extent (terminal), &closure);
428
+ − 2451
+ − 2452 if (!UNBOUNDP (map) && !NILP (map))
+ − 2453 relevant_map_push (get_keymap (map, 1, 1), &closure);
+ − 2454 }
+ − 2455 else
+ − 2456 {
+ − 2457 get_relevant_extent_keymaps (Fevent_point (terminal), buffer,
+ − 2458 Fevent_glyph_extent (terminal),
+ − 2459 &closure);
+ − 2460 }
+ − 2461
+ − 2462 if (!EQ (buffer, Vmouse_grabbed_buffer)) /* already pushed */
+ − 2463 {
+ − 2464 Lisp_Object map = XBUFFER (buffer)->keymap;
+ − 2465
+ − 2466 get_relevant_minor_maps (buffer, &closure);
+ − 2467 if (!NILP(map))
+ − 2468 relevant_map_push (map, &closure);
+ − 2469 }
+ − 2470 }
+ − 2471 }
+ − 2472 else if (!NILP (Fevent_over_toolbar_p (terminal)))
+ − 2473 {
+ − 2474 Lisp_Object map = Fsymbol_value (Qtoolbar_map);
+ − 2475
+ − 2476 if (!UNBOUNDP (map) && !NILP (map))
+ − 2477 relevant_map_push (map, &closure);
+ − 2478 }
+ − 2479 }
+ − 2480 #endif /* HAVE_WINDOW_SYSTEM */
+ − 2481
771
+ − 2482 if (CONSOLE_TTY_P (con))
+ − 2483 relevant_map_push (Vglobal_tty_map, &closure);
+ − 2484 else
+ − 2485 relevant_map_push (Vglobal_window_system_map, &closure);
+ − 2486
428
+ − 2487 {
+ − 2488 int nmaps = closure.nmaps;
+ − 2489 /* Silently truncate at 100 keymaps to prevent infinite lossage */
+ − 2490 if (nmaps >= max_maps && max_maps > 0)
+ − 2491 maps[max_maps - 1] = Vcurrent_global_map;
+ − 2492 else
+ − 2493 maps[nmaps] = Vcurrent_global_map;
+ − 2494 UNGCPRO;
+ − 2495 return nmaps + 1;
+ − 2496 }
+ − 2497 }
+ − 2498
+ − 2499 /* Returns a set of keymaps extracted from the extents at POS in
+ − 2500 BUFFER_OR_STRING. The GLYPH arg, if specified, is one more extent
+ − 2501 to look for a keymap in, and if it has one, its keymap will be the
+ − 2502 first element in the list returned. This is so we can correctly
+ − 2503 search the keymaps associated with glyphs which may be physically
+ − 2504 disjoint from their extents: for example, if a glyph is out in the
+ − 2505 margin, we should still consult the keymap of that glyph's extent,
+ − 2506 which may not itself be under the mouse.
+ − 2507 */
+ − 2508
+ − 2509 static void
+ − 2510 get_relevant_extent_keymaps (Lisp_Object pos, Lisp_Object buffer_or_string,
+ − 2511 Lisp_Object glyph,
+ − 2512 struct relevant_maps *closure)
+ − 2513 {
+ − 2514 /* This function can GC */
+ − 2515 /* the glyph keymap, if any, comes first.
+ − 2516 (Processing it twice is no big deal: noop.) */
+ − 2517 if (!NILP (glyph))
+ − 2518 {
+ − 2519 Lisp_Object keymap = Fextent_property (glyph, Qkeymap, Qnil);
+ − 2520 if (!NILP (keymap))
+ − 2521 relevant_map_push (get_keymap (keymap, 1, 1), closure);
+ − 2522 }
+ − 2523
+ − 2524 /* Next check the extents at the text position, if any */
+ − 2525 if (!NILP (pos))
+ − 2526 {
+ − 2527 Lisp_Object extent;
+ − 2528 for (extent = Fextent_at (pos, buffer_or_string, Qkeymap, Qnil, Qnil);
+ − 2529 !NILP (extent);
+ − 2530 extent = Fextent_at (pos, buffer_or_string, Qkeymap, extent, Qnil))
+ − 2531 {
+ − 2532 Lisp_Object keymap = Fextent_property (extent, Qkeymap, Qnil);
+ − 2533 if (!NILP (keymap))
+ − 2534 relevant_map_push (get_keymap (keymap, 1, 1), closure);
+ − 2535 QUIT;
+ − 2536 }
+ − 2537 }
+ − 2538 }
+ − 2539
+ − 2540 static Lisp_Object
+ − 2541 minor_mode_keymap_predicate (Lisp_Object assoc, Lisp_Object buffer)
+ − 2542 {
+ − 2543 /* This function can GC */
+ − 2544 if (CONSP (assoc))
+ − 2545 {
+ − 2546 Lisp_Object sym = XCAR (assoc);
+ − 2547 if (SYMBOLP (sym))
+ − 2548 {
+ − 2549 Lisp_Object val = symbol_value_in_buffer (sym, buffer);
+ − 2550 if (!NILP (val) && !UNBOUNDP (val))
+ − 2551 {
793
+ − 2552 return get_keymap (XCDR (assoc), 0, 1);
428
+ − 2553 }
+ − 2554 }
+ − 2555 }
+ − 2556 return Qnil;
+ − 2557 }
+ − 2558
+ − 2559 static void
+ − 2560 get_relevant_minor_maps (Lisp_Object buffer, struct relevant_maps *closure)
+ − 2561 {
+ − 2562 /* This function can GC */
+ − 2563 Lisp_Object alist;
+ − 2564
+ − 2565 /* Will you ever lose badly if you make this circular! */
+ − 2566 for (alist = symbol_value_in_buffer (Qminor_mode_map_alist, buffer);
+ − 2567 CONSP (alist);
+ − 2568 alist = XCDR (alist))
+ − 2569 {
+ − 2570 Lisp_Object m = minor_mode_keymap_predicate (XCAR (alist),
+ − 2571 buffer);
+ − 2572 if (!NILP (m)) relevant_map_push (m, closure);
+ − 2573 QUIT;
+ − 2574 }
+ − 2575 }
+ − 2576
+ − 2577 /* #### Would map-current-keymaps be a better thing?? */
+ − 2578 DEFUN ("current-keymaps", Fcurrent_keymaps, 0, 1, 0, /*
+ − 2579 Return a list of the current keymaps that will be searched for bindings.
+ − 2580 This lists keymaps such as the current local map and the minor-mode maps,
+ − 2581 but does not list the parents of those keymaps.
+ − 2582 EVENT-OR-KEYS controls which keymaps will be listed.
+ − 2583 If EVENT-OR-KEYS is a mouse event (or a vector whose last element is a
+ − 2584 mouse event), the keymaps for that mouse event will be listed (see
+ − 2585 `key-binding'). Otherwise, the keymaps for key presses will be listed.
771
+ − 2586 See `key-binding' for a description of which keymaps are searched in
+ − 2587 various situations.
428
+ − 2588 */
+ − 2589 (event_or_keys))
+ − 2590 {
+ − 2591 /* This function can GC */
+ − 2592 struct gcpro gcpro1;
+ − 2593 Lisp_Object maps[100];
+ − 2594 Lisp_Object *gubbish = maps;
+ − 2595 int nmaps;
+ − 2596
+ − 2597 GCPRO1 (event_or_keys);
+ − 2598 nmaps = get_relevant_keymaps (event_or_keys, countof (maps),
+ − 2599 gubbish);
+ − 2600 if (nmaps > countof (maps))
+ − 2601 {
+ − 2602 gubbish = alloca_array (Lisp_Object, nmaps);
+ − 2603 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
+ − 2604 }
+ − 2605 UNGCPRO;
+ − 2606 return Flist (nmaps, gubbish);
+ − 2607 }
+ − 2608
+ − 2609 DEFUN ("key-binding", Fkey_binding, 1, 2, 0, /*
+ − 2610 Return the binding for command KEYS in current keymaps.
+ − 2611 KEYS is a string, a vector of events, or a vector of key-description lists
+ − 2612 as described in the documentation for the `define-key' function.
+ − 2613 The binding is probably a symbol with a function definition; see
+ − 2614 the documentation for `lookup-key' for more information.
+ − 2615
+ − 2616 For key-presses, the order of keymaps searched is:
+ − 2617 - the `keymap' property of any extent(s) at point;
+ − 2618 - any applicable minor-mode maps;
444
+ − 2619 - the current local map of the current-buffer;
771
+ − 2620 - either `global-tty-map' or `global-window-system-map', depending on
+ − 2621 whether the current console is a TTY or non-TTY console;
428
+ − 2622 - the current global map.
+ − 2623
+ − 2624 For mouse-clicks, the order of keymaps searched is:
+ − 2625 - the current-local-map of the `mouse-grabbed-buffer' if any;
+ − 2626 - vertical-divider-map, if the event happened over a vertical divider
+ − 2627 - the `keymap' property of any extent(s) at the position of the click
+ − 2628 (this includes modeline extents);
+ − 2629 - the modeline-map of the buffer corresponding to the modeline under
+ − 2630 the mouse (if the click happened over a modeline);
444
+ − 2631 - the value of `toolbar-map' in the current-buffer (if the click
428
+ − 2632 happened over a toolbar);
444
+ − 2633 - the current local map of the buffer under the mouse (does not
428
+ − 2634 apply to toolbar clicks);
+ − 2635 - any applicable minor-mode maps;
771
+ − 2636 - either `global-tty-map' or `global-window-system-map', depending on
+ − 2637 whether the current console is a TTY or non-TTY console;
428
+ − 2638 - the current global map.
+ − 2639
+ − 2640 Note that if `overriding-local-map' or `overriding-terminal-local-map'
+ − 2641 is non-nil, *only* those two maps and the current global map are searched.
771
+ − 2642
+ − 2643 Note also that key sequences actually received from the keyboard driver
+ − 2644 may be processed in various ways to generate the key sequence that is
+ − 2645 actually looked up in the keymaps. In particular:
+ − 2646
+ − 2647 -- Keysyms are individually passed through `keyboard-translate-table' before
+ − 2648 any other processing.
+ − 2649 -- After this, key sequences as a whole are passed through
+ − 2650 `key-translation-map'.
+ − 2651 -- The resulting key sequence is actually looked up in the keymaps.
+ − 2652 -- If there's no binding found, the key sequence is passed through
+ − 2653 `function-key-map' and looked up again.
+ − 2654 -- If no binding is found and `retry-undefined-key-binding-unshifted' is
+ − 2655 set (it usually is) and the final keysym is an uppercase character,
+ − 2656 we lowercase it and start over from the `key-translation-map' stage.
+ − 2657 -- If no binding is found and we're on MS Windows and have international
+ − 2658 support, we successively remap the key sequence using the keyboard layouts
+ − 2659 of various default locales (current language environment, user default,
+ − 2660 system default, US ASCII) and try again. This makes (e.g.) sequences
+ − 2661 such as `C-x b' work in a Russian locale, where the alphabetic keys are
+ − 2662 actually generating Russian characters and not the Roman letters written
+ − 2663 on the keycaps. (Not yet implemented)
+ − 2664 -- Finally, if the last keystroke matches `help-char', we automatically
+ − 2665 generate and display a list of possible key sequences and bindings
+ − 2666 given the prefix so far generated.
428
+ − 2667 */
+ − 2668 (keys, accept_default))
+ − 2669 {
+ − 2670 /* This function can GC */
+ − 2671 int i;
+ − 2672 Lisp_Object maps[100];
+ − 2673 int nmaps;
+ − 2674 struct gcpro gcpro1, gcpro2;
+ − 2675 GCPRO2 (keys, accept_default); /* get_relevant_keymaps may autoload */
+ − 2676
+ − 2677 nmaps = get_relevant_keymaps (keys, countof (maps), maps);
+ − 2678
+ − 2679 UNGCPRO;
+ − 2680
+ − 2681 if (EVENTP (keys)) /* unadvertised "feature" for the future */
+ − 2682 return lookup_events (keys, nmaps, maps, !NILP (accept_default));
+ − 2683
+ − 2684 for (i = 0; i < nmaps; i++)
+ − 2685 {
+ − 2686 Lisp_Object tem = Flookup_key (maps[i], keys,
+ − 2687 accept_default);
+ − 2688 if (INTP (tem))
+ − 2689 {
+ − 2690 /* Too long in some local map means don't look at global map */
+ − 2691 return Qnil;
+ − 2692 }
+ − 2693 else if (!NILP (tem))
+ − 2694 return tem;
+ − 2695 }
+ − 2696 return Qnil;
+ − 2697 }
+ − 2698
+ − 2699 static Lisp_Object
+ − 2700 process_event_binding_result (Lisp_Object result)
+ − 2701 {
+ − 2702 if (EQ (result, Qundefined))
3025
+ − 2703 /* The suppress-keymap function binds keys to `undefined' - special-case
428
+ − 2704 that here, so that being bound to that has the same error-behavior as
+ − 2705 not being defined at all.
+ − 2706 */
+ − 2707 result = Qnil;
+ − 2708 if (!NILP (result))
+ − 2709 {
+ − 2710 Lisp_Object map;
+ − 2711 /* Snap out possible keymap indirections */
+ − 2712 map = get_keymap (result, 0, 1);
+ − 2713 if (!NILP (map))
+ − 2714 result = map;
+ − 2715 }
+ − 2716
+ − 2717 return result;
+ − 2718 }
+ − 2719
+ − 2720 /* Attempts to find a command corresponding to the event-sequence
+ − 2721 whose head is event0 (sequence is threaded though event_next).
+ − 2722
+ − 2723 The return value will be
+ − 2724
+ − 2725 -- nil (there is no binding; this will also be returned
+ − 2726 whenever the event chain is "too long", i.e. there
+ − 2727 is a non-nil, non-keymap binding for a prefix of
+ − 2728 the event chain)
+ − 2729 -- a keymap (part of a command has been specified)
+ − 2730 -- a command (anything that satisfies `commandp'; this includes
+ − 2731 some symbols, lists, subrs, strings, vectors, and
+ − 2732 compiled-function objects) */
+ − 2733 Lisp_Object
+ − 2734 event_binding (Lisp_Object event0, int accept_default)
+ − 2735 {
+ − 2736 /* This function can GC */
+ − 2737 Lisp_Object maps[100];
+ − 2738 int nmaps;
+ − 2739
+ − 2740 assert (EVENTP (event0));
+ − 2741
+ − 2742 nmaps = get_relevant_keymaps (event0, countof (maps), maps);
+ − 2743 if (nmaps > countof (maps))
+ − 2744 nmaps = countof (maps);
+ − 2745 return process_event_binding_result (lookup_events (event0, nmaps, maps,
+ − 2746 accept_default));
+ − 2747 }
+ − 2748
+ − 2749 /* like event_binding, but specify a keymap to search */
+ − 2750
+ − 2751 Lisp_Object
+ − 2752 event_binding_in (Lisp_Object event0, Lisp_Object keymap, int accept_default)
+ − 2753 {
+ − 2754 /* This function can GC */
+ − 2755 if (!KEYMAPP (keymap))
+ − 2756 return Qnil;
+ − 2757
+ − 2758 return process_event_binding_result (lookup_events (event0, 1, &keymap,
+ − 2759 accept_default));
+ − 2760 }
+ − 2761
+ − 2762 /* Attempts to find a function key mapping corresponding to the
+ − 2763 event-sequence whose head is event0 (sequence is threaded through
+ − 2764 event_next). The return value will be the same as for event_binding(). */
+ − 2765 Lisp_Object
+ − 2766 munging_key_map_event_binding (Lisp_Object event0,
+ − 2767 enum munge_me_out_the_door munge)
+ − 2768 {
+ − 2769 Lisp_Object keymap = (munge == MUNGE_ME_FUNCTION_KEY) ?
+ − 2770 CONSOLE_FUNCTION_KEY_MAP (event_console_or_selected (event0)) :
+ − 2771 Vkey_translation_map;
+ − 2772
+ − 2773 if (NILP (keymap))
+ − 2774 return Qnil;
+ − 2775
+ − 2776 return process_event_binding_result (lookup_events (event0, 1, &keymap, 1));
+ − 2777 }
+ − 2778
+ − 2779
+ − 2780 /************************************************************************/
+ − 2781 /* Setting/querying the global and local maps */
+ − 2782 /************************************************************************/
+ − 2783
+ − 2784 DEFUN ("use-global-map", Fuse_global_map, 1, 1, 0, /*
+ − 2785 Select KEYMAP as the global keymap.
+ − 2786 */
+ − 2787 (keymap))
+ − 2788 {
+ − 2789 /* This function can GC */
+ − 2790 keymap = get_keymap (keymap, 1, 1);
+ − 2791 Vcurrent_global_map = keymap;
+ − 2792 return Qnil;
+ − 2793 }
+ − 2794
+ − 2795 DEFUN ("use-local-map", Fuse_local_map, 1, 2, 0, /*
+ − 2796 Select KEYMAP as the local keymap in BUFFER.
+ − 2797 If KEYMAP is nil, that means no local keymap.
+ − 2798 If BUFFER is nil, the current buffer is assumed.
+ − 2799 */
+ − 2800 (keymap, buffer))
+ − 2801 {
+ − 2802 /* This function can GC */
+ − 2803 struct buffer *b = decode_buffer (buffer, 0);
+ − 2804 if (!NILP (keymap))
+ − 2805 keymap = get_keymap (keymap, 1, 1);
+ − 2806
+ − 2807 b->keymap = keymap;
+ − 2808
+ − 2809 return Qnil;
+ − 2810 }
+ − 2811
+ − 2812 DEFUN ("current-local-map", Fcurrent_local_map, 0, 1, 0, /*
+ − 2813 Return BUFFER's local keymap, or nil if it has none.
+ − 2814 If BUFFER is nil, the current buffer is assumed.
+ − 2815 */
+ − 2816 (buffer))
+ − 2817 {
+ − 2818 struct buffer *b = decode_buffer (buffer, 0);
+ − 2819 return b->keymap;
+ − 2820 }
+ − 2821
+ − 2822 DEFUN ("current-global-map", Fcurrent_global_map, 0, 0, 0, /*
+ − 2823 Return the current global keymap.
+ − 2824 */
+ − 2825 ())
+ − 2826 {
+ − 2827 return Vcurrent_global_map;
+ − 2828 }
+ − 2829
+ − 2830
+ − 2831 /************************************************************************/
+ − 2832 /* Mapping over keymap elements */
+ − 2833 /************************************************************************/
+ − 2834
+ − 2835 /* Since keymaps are arranged in a hierarchy, one keymap per bucky bit or
+ − 2836 prefix key, it's not entirely obvious what map-keymap should do, but
+ − 2837 what it does is: map over all keys in this map; then recursively map
+ − 2838 over all submaps of this map that are "bucky" submaps. This means that,
+ − 2839 when mapping over a keymap, it appears that "x" and "C-x" are in the
+ − 2840 same map, although "C-x" is really in the "control" submap of this one.
+ − 2841 However, since we don't recursively descend the submaps that are bound
+ − 2842 to prefix keys (like C-x, C-h, etc) the caller will have to recurse on
+ − 2843 those explicitly, if that's what they want.
+ − 2844
+ − 2845 So the end result of this is that the bucky keymaps (the ones indexed
+ − 2846 under the large integers returned from MAKE_MODIFIER_HASH_KEY()) are
+ − 2847 invisible from elisp. They're just an implementation detail that code
+ − 2848 outside of this file doesn't need to know about.
+ − 2849 */
+ − 2850
+ − 2851 struct map_keymap_unsorted_closure
+ − 2852 {
934
+ − 2853 void (*fn) (const Lisp_Key_Data *, Lisp_Object binding, void *arg);
428
+ − 2854 void *arg;
442
+ − 2855 int modifiers;
428
+ − 2856 };
+ − 2857
+ − 2858 /* used by map_keymap() */
+ − 2859 static int
+ − 2860 map_keymap_unsorted_mapper (Lisp_Object keysym, Lisp_Object value,
+ − 2861 void *map_keymap_unsorted_closure)
+ − 2862 {
+ − 2863 /* This function can GC */
+ − 2864 struct map_keymap_unsorted_closure *closure =
+ − 2865 (struct map_keymap_unsorted_closure *) map_keymap_unsorted_closure;
442
+ − 2866 int modifiers = closure->modifiers;
+ − 2867 int mod_bit;
428
+ − 2868 mod_bit = MODIFIER_HASH_KEY_BITS (keysym);
+ − 2869 if (mod_bit != 0)
+ − 2870 {
+ − 2871 int omod = modifiers;
+ − 2872 closure->modifiers = (modifiers | mod_bit);
+ − 2873 value = get_keymap (value, 1, 0);
+ − 2874 elisp_maphash (map_keymap_unsorted_mapper,
+ − 2875 XKEYMAP (value)->table,
+ − 2876 map_keymap_unsorted_closure);
+ − 2877 closure->modifiers = omod;
+ − 2878 }
+ − 2879 else
+ − 2880 {
934
+ − 2881 Lisp_Key_Data key;
428
+ − 2882 key.keysym = keysym;
+ − 2883 key.modifiers = modifiers;
+ − 2884 ((*closure->fn) (&key, value, closure->arg));
+ − 2885 }
+ − 2886 return 0;
+ − 2887 }
+ − 2888
+ − 2889
+ − 2890 struct map_keymap_sorted_closure
+ − 2891 {
+ − 2892 Lisp_Object *result_locative;
+ − 2893 };
+ − 2894
+ − 2895 /* used by map_keymap_sorted() */
+ − 2896 static int
+ − 2897 map_keymap_sorted_mapper (Lisp_Object key, Lisp_Object value,
+ − 2898 void *map_keymap_sorted_closure)
+ − 2899 {
+ − 2900 struct map_keymap_sorted_closure *cl =
+ − 2901 (struct map_keymap_sorted_closure *) map_keymap_sorted_closure;
+ − 2902 Lisp_Object *list = cl->result_locative;
+ − 2903 *list = Fcons (Fcons (key, value), *list);
+ − 2904 return 0;
+ − 2905 }
+ − 2906
+ − 2907
+ − 2908 /* used by map_keymap_sorted(), describe_map_sort_predicate(),
+ − 2909 and keymap_submaps().
+ − 2910 */
+ − 2911 static int
+ − 2912 map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
2286
+ − 2913 Lisp_Object UNUSED (pred))
428
+ − 2914 {
+ − 2915 /* obj1 and obj2 are conses with keysyms in their cars. Cdrs are ignored.
+ − 2916 */
442
+ − 2917 int bit1, bit2;
428
+ − 2918 int sym1_p = 0;
+ − 2919 int sym2_p = 0;
2828
+ − 2920 extern Lisp_Object Qcharacter_of_keysym;
+ − 2921
428
+ − 2922 obj1 = XCAR (obj1);
+ − 2923 obj2 = XCAR (obj2);
+ − 2924
+ − 2925 if (EQ (obj1, obj2))
+ − 2926 return -1;
+ − 2927 bit1 = MODIFIER_HASH_KEY_BITS (obj1);
+ − 2928 bit2 = MODIFIER_HASH_KEY_BITS (obj2);
+ − 2929
2828
+ − 2930 /* If either is a symbol with a Qcharacter_of_keysym property, then sort it by
428
+ − 2931 that code instead of alphabetically.
+ − 2932 */
+ − 2933 if (! bit1 && SYMBOLP (obj1))
+ − 2934 {
2828
+ − 2935 Lisp_Object code = Fget (obj1, Qcharacter_of_keysym, Qnil);
428
+ − 2936 if (CHAR_OR_CHAR_INTP (code))
+ − 2937 {
+ − 2938 obj1 = code;
+ − 2939 CHECK_CHAR_COERCE_INT (obj1);
+ − 2940 sym1_p = 1;
+ − 2941 }
+ − 2942 }
+ − 2943 if (! bit2 && SYMBOLP (obj2))
+ − 2944 {
2828
+ − 2945 Lisp_Object code = Fget (obj2, Qcharacter_of_keysym, Qnil);
428
+ − 2946 if (CHAR_OR_CHAR_INTP (code))
+ − 2947 {
+ − 2948 obj2 = code;
+ − 2949 CHECK_CHAR_COERCE_INT (obj2);
+ − 2950 sym2_p = 1;
+ − 2951 }
+ − 2952 }
+ − 2953
+ − 2954 /* all symbols (non-ASCIIs) come after characters (ASCIIs) */
+ − 2955 if (XTYPE (obj1) != XTYPE (obj2))
+ − 2956 return SYMBOLP (obj2) ? 1 : -1;
+ − 2957
+ − 2958 if (! bit1 && CHARP (obj1)) /* they're both ASCII */
+ − 2959 {
+ − 2960 int o1 = XCHAR (obj1);
+ − 2961 int o2 = XCHAR (obj2);
+ − 2962 if (o1 == o2 && /* If one started out as a symbol and the */
+ − 2963 sym1_p != sym2_p) /* other didn't, the symbol comes last. */
+ − 2964 return sym2_p ? 1 : -1;
+ − 2965
+ − 2966 return o1 < o2 ? 1 : -1; /* else just compare them */
+ − 2967 }
+ − 2968
+ − 2969 /* else they're both symbols. If they're both buckys, then order them. */
+ − 2970 if (bit1 && bit2)
+ − 2971 return bit1 < bit2 ? 1 : -1;
+ − 2972
+ − 2973 /* if only one is a bucky, then it comes later */
+ − 2974 if (bit1 || bit2)
+ − 2975 return bit2 ? 1 : -1;
+ − 2976
+ − 2977 /* otherwise, string-sort them. */
+ − 2978 {
867
+ − 2979 Ibyte *s1 = XSTRING_DATA (XSYMBOL (obj1)->name);
+ − 2980 Ibyte *s2 = XSTRING_DATA (XSYMBOL (obj2)->name);
793
+ − 2981 return 0 > qxestrcmp (s1, s2) ? 1 : -1;
428
+ − 2982 }
+ − 2983 }
+ − 2984
+ − 2985
+ − 2986 /* used by map_keymap() */
+ − 2987 static void
+ − 2988 map_keymap_sorted (Lisp_Object keymap_table,
442
+ − 2989 int modifiers,
934
+ − 2990 void (*function) (const Lisp_Key_Data *key,
428
+ − 2991 Lisp_Object binding,
+ − 2992 void *map_keymap_sorted_closure),
+ − 2993 void *map_keymap_sorted_closure)
+ − 2994 {
+ − 2995 /* This function can GC */
+ − 2996 struct gcpro gcpro1;
+ − 2997 Lisp_Object contents = Qnil;
+ − 2998
+ − 2999 if (XINT (Fhash_table_count (keymap_table)) == 0)
+ − 3000 return;
+ − 3001
+ − 3002 GCPRO1 (contents);
+ − 3003
+ − 3004 {
+ − 3005 struct map_keymap_sorted_closure c1;
+ − 3006 c1.result_locative = &contents;
+ − 3007 elisp_maphash (map_keymap_sorted_mapper, keymap_table, &c1);
+ − 3008 }
+ − 3009 contents = list_sort (contents, Qnil, map_keymap_sort_predicate);
+ − 3010 for (; !NILP (contents); contents = XCDR (contents))
+ − 3011 {
+ − 3012 Lisp_Object keysym = XCAR (XCAR (contents));
+ − 3013 Lisp_Object binding = XCDR (XCAR (contents));
442
+ − 3014 int sub_bits = MODIFIER_HASH_KEY_BITS (keysym);
428
+ − 3015 if (sub_bits != 0)
+ − 3016 map_keymap_sorted (XKEYMAP (get_keymap (binding,
+ − 3017 1, 1))->table,
+ − 3018 (modifiers | sub_bits),
+ − 3019 function,
+ − 3020 map_keymap_sorted_closure);
+ − 3021 else
+ − 3022 {
934
+ − 3023 Lisp_Key_Data k;
428
+ − 3024 k.keysym = keysym;
+ − 3025 k.modifiers = modifiers;
+ − 3026 ((*function) (&k, binding, map_keymap_sorted_closure));
+ − 3027 }
+ − 3028 }
+ − 3029 UNGCPRO;
+ − 3030 }
+ − 3031
+ − 3032
+ − 3033 /* used by Fmap_keymap() */
+ − 3034 static void
934
+ − 3035 map_keymap_mapper (const Lisp_Key_Data *key,
428
+ − 3036 Lisp_Object binding,
+ − 3037 void *function)
+ − 3038 {
+ − 3039 /* This function can GC */
+ − 3040 Lisp_Object fn;
826
+ − 3041 fn = VOID_TO_LISP (function);
428
+ − 3042 call2 (fn, make_key_description (key, 1), binding);
+ − 3043 }
+ − 3044
+ − 3045
+ − 3046 static void
+ − 3047 map_keymap (Lisp_Object keymap_table, int sort_first,
934
+ − 3048 void (*function) (const Lisp_Key_Data *key,
428
+ − 3049 Lisp_Object binding,
+ − 3050 void *fn_arg),
+ − 3051 void *fn_arg)
+ − 3052 {
+ − 3053 /* This function can GC */
+ − 3054 if (sort_first)
+ − 3055 map_keymap_sorted (keymap_table, 0, function, fn_arg);
+ − 3056 else
+ − 3057 {
+ − 3058 struct map_keymap_unsorted_closure map_keymap_unsorted_closure;
+ − 3059 map_keymap_unsorted_closure.fn = function;
+ − 3060 map_keymap_unsorted_closure.arg = fn_arg;
+ − 3061 map_keymap_unsorted_closure.modifiers = 0;
+ − 3062 elisp_maphash (map_keymap_unsorted_mapper, keymap_table,
+ − 3063 &map_keymap_unsorted_closure);
+ − 3064 }
+ − 3065 }
+ − 3066
+ − 3067 DEFUN ("map-keymap", Fmap_keymap, 2, 3, 0, /*
+ − 3068 Apply FUNCTION to each element of KEYMAP.
+ − 3069 FUNCTION will be called with two arguments: a key-description list, and
+ − 3070 the binding. The order in which the elements of the keymap are passed to
+ − 3071 the function is unspecified. If the function inserts new elements into
+ − 3072 the keymap, it may or may not be called with them later. No element of
+ − 3073 the keymap will ever be passed to the function more than once.
+ − 3074
+ − 3075 The function will not be called on elements of this keymap's parents
+ − 3076 \(see the function `keymap-parents') or upon keymaps which are contained
+ − 3077 within this keymap (multi-character definitions).
+ − 3078 It will be called on "meta" characters since they are not really
+ − 3079 two-character sequences.
+ − 3080
+ − 3081 If the optional third argument SORT-FIRST is non-nil, then the elements of
+ − 3082 the keymap will be passed to the mapper function in a canonical order.
+ − 3083 Otherwise, they will be passed in hash (that is, random) order, which is
+ − 3084 faster.
+ − 3085 */
+ − 3086 (function, keymap, sort_first))
+ − 3087 {
+ − 3088 /* This function can GC */
489
+ − 3089 struct gcpro gcpro1, gcpro2;
428
+ − 3090
+ − 3091 /* tolerate obviously transposed args */
+ − 3092 if (!NILP (Fkeymapp (function)))
+ − 3093 {
+ − 3094 Lisp_Object tmp = function;
+ − 3095 function = keymap;
+ − 3096 keymap = tmp;
+ − 3097 }
489
+ − 3098 GCPRO2 (function, keymap);
428
+ − 3099 keymap = get_keymap (keymap, 1, 1);
489
+ − 3100 map_keymap (XKEYMAP (keymap)->table, !NILP (sort_first),
428
+ − 3101 map_keymap_mapper, LISP_TO_VOID (function));
+ − 3102 UNGCPRO;
+ − 3103 return Qnil;
+ − 3104 }
+ − 3105
+ − 3106
+ − 3107
+ − 3108 /************************************************************************/
+ − 3109 /* Accessible keymaps */
+ − 3110 /************************************************************************/
+ − 3111
+ − 3112 struct accessible_keymaps_closure
+ − 3113 {
+ − 3114 Lisp_Object tail;
+ − 3115 };
+ − 3116
+ − 3117
+ − 3118 static void
+ − 3119 accessible_keymaps_mapper_1 (Lisp_Object keysym, Lisp_Object contents,
442
+ − 3120 int modifiers,
428
+ − 3121 struct accessible_keymaps_closure *closure)
+ − 3122 {
+ − 3123 /* This function can GC */
442
+ − 3124 int subbits = MODIFIER_HASH_KEY_BITS (keysym);
428
+ − 3125
+ − 3126 if (subbits != 0)
+ − 3127 {
+ − 3128 Lisp_Object submaps;
+ − 3129
+ − 3130 contents = get_keymap (contents, 1, 1);
+ − 3131 submaps = keymap_submaps (contents);
+ − 3132 for (; !NILP (submaps); submaps = XCDR (submaps))
+ − 3133 {
+ − 3134 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)),
+ − 3135 XCDR (XCAR (submaps)),
+ − 3136 (subbits | modifiers),
+ − 3137 closure);
+ − 3138 }
+ − 3139 }
+ − 3140 else
+ − 3141 {
+ − 3142 Lisp_Object thisseq = Fcar (Fcar (closure->tail));
+ − 3143 Lisp_Object cmd = get_keyelt (contents, 1);
+ − 3144 Lisp_Object vec;
+ − 3145 int j;
+ − 3146 int len;
934
+ − 3147 Lisp_Key_Data key;
428
+ − 3148 key.keysym = keysym;
+ − 3149 key.modifiers = modifiers;
+ − 3150
+ − 3151 if (NILP (cmd))
2500
+ − 3152 ABORT ();
428
+ − 3153 cmd = get_keymap (cmd, 0, 1);
+ − 3154 if (!KEYMAPP (cmd))
2500
+ − 3155 ABORT ();
428
+ − 3156
+ − 3157 vec = make_vector (XVECTOR_LENGTH (thisseq) + 1, Qnil);
+ − 3158 len = XVECTOR_LENGTH (thisseq);
+ − 3159 for (j = 0; j < len; j++)
+ − 3160 XVECTOR_DATA (vec) [j] = XVECTOR_DATA (thisseq) [j];
+ − 3161 XVECTOR_DATA (vec) [j] = make_key_description (&key, 1);
+ − 3162
+ − 3163 nconc2 (closure->tail, list1 (Fcons (vec, cmd)));
+ − 3164 }
+ − 3165 }
+ − 3166
+ − 3167
+ − 3168 static Lisp_Object
+ − 3169 accessible_keymaps_keymap_mapper (Lisp_Object thismap, void *arg)
+ − 3170 {
+ − 3171 /* This function can GC */
+ − 3172 struct accessible_keymaps_closure *closure =
+ − 3173 (struct accessible_keymaps_closure *) arg;
+ − 3174 Lisp_Object submaps = keymap_submaps (thismap);
+ − 3175
+ − 3176 for (; !NILP (submaps); submaps = XCDR (submaps))
+ − 3177 {
+ − 3178 accessible_keymaps_mapper_1 (XCAR (XCAR (submaps)),
+ − 3179 XCDR (XCAR (submaps)),
+ − 3180 0,
+ − 3181 closure);
+ − 3182 }
+ − 3183 return Qnil;
+ − 3184 }
+ − 3185
+ − 3186
+ − 3187 DEFUN ("accessible-keymaps", Faccessible_keymaps, 1, 2, 0, /*
+ − 3188 Find all keymaps accessible via prefix characters from KEYMAP.
+ − 3189 Returns a list of elements of the form (KEYS . MAP), where the sequence
+ − 3190 KEYS starting from KEYMAP gets you to MAP. These elements are ordered
+ − 3191 so that the KEYS increase in length. The first element is ([] . KEYMAP).
+ − 3192 An optional argument PREFIX, if non-nil, should be a key sequence;
+ − 3193 then the value includes only maps for prefixes that start with PREFIX.
+ − 3194 */
+ − 3195 (keymap, prefix))
+ − 3196 {
+ − 3197 /* This function can GC */
+ − 3198 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
+ − 3199 Lisp_Object accessible_keymaps = Qnil;
+ − 3200 struct accessible_keymaps_closure c;
+ − 3201 c.tail = Qnil;
+ − 3202 GCPRO4 (accessible_keymaps, c.tail, prefix, keymap);
+ − 3203
440
+ − 3204 keymap = get_keymap (keymap, 1, 1);
+ − 3205
428
+ − 3206 retry:
+ − 3207 if (NILP (prefix))
+ − 3208 {
440
+ − 3209 prefix = make_vector (0, Qnil);
428
+ − 3210 }
440
+ − 3211 else if (VECTORP (prefix) || STRINGP (prefix))
428
+ − 3212 {
+ − 3213 int len = XINT (Flength (prefix));
440
+ − 3214 Lisp_Object def;
428
+ − 3215 Lisp_Object p;
+ − 3216 int iii;
+ − 3217 struct gcpro ngcpro1;
+ − 3218
440
+ − 3219 if (len == 0)
+ − 3220 {
+ − 3221 prefix = Qnil;
+ − 3222 goto retry;
+ − 3223 }
+ − 3224
+ − 3225 def = Flookup_key (keymap, prefix, Qnil);
428
+ − 3226 def = get_keymap (def, 0, 1);
+ − 3227 if (!KEYMAPP (def))
+ − 3228 goto RETURN;
+ − 3229
+ − 3230 keymap = def;
+ − 3231 p = make_vector (len, Qnil);
+ − 3232 NGCPRO1 (p);
+ − 3233 for (iii = 0; iii < len; iii++)
+ − 3234 {
934
+ − 3235 Lisp_Key_Data key;
428
+ − 3236 define_key_parser (Faref (prefix, make_int (iii)), &key);
+ − 3237 XVECTOR_DATA (p)[iii] = make_key_description (&key, 1);
+ − 3238 }
+ − 3239 NUNGCPRO;
+ − 3240 prefix = p;
+ − 3241 }
440
+ − 3242 else
+ − 3243 {
+ − 3244 prefix = wrong_type_argument (Qarrayp, prefix);
+ − 3245 goto retry;
+ − 3246 }
428
+ − 3247
+ − 3248 accessible_keymaps = list1 (Fcons (prefix, keymap));
+ − 3249
440
+ − 3250 /* For each map in the list maps, look at any other maps it points
+ − 3251 to and stick them at the end if they are not already in the list */
428
+ − 3252
+ − 3253 for (c.tail = accessible_keymaps;
+ − 3254 !NILP (c.tail);
+ − 3255 c.tail = XCDR (c.tail))
+ − 3256 {
+ − 3257 Lisp_Object thismap = Fcdr (Fcar (c.tail));
+ − 3258 CHECK_KEYMAP (thismap);
+ − 3259 traverse_keymaps (thismap, Qnil,
+ − 3260 accessible_keymaps_keymap_mapper, &c);
+ − 3261 }
+ − 3262 RETURN:
+ − 3263 UNGCPRO;
+ − 3264 return accessible_keymaps;
+ − 3265 }
+ − 3266
+ − 3267
+ − 3268
+ − 3269 /************************************************************************/
+ − 3270 /* Pretty descriptions of key sequences */
+ − 3271 /************************************************************************/
+ − 3272
+ − 3273 DEFUN ("key-description", Fkey_description, 1, 1, 0, /*
+ − 3274 Return a pretty description of key-sequence KEYS.
+ − 3275 Control characters turn into "C-foo" sequences, meta into "M-foo",
+ − 3276 spaces are put between sequence elements, etc...
+ − 3277 */
+ − 3278 (keys))
+ − 3279 {
+ − 3280 if (CHAR_OR_CHAR_INTP (keys) || CONSP (keys) || SYMBOLP (keys)
+ − 3281 || EVENTP (keys))
+ − 3282 {
+ − 3283 return Fsingle_key_description (keys);
+ − 3284 }
+ − 3285 else if (VECTORP (keys) ||
+ − 3286 STRINGP (keys))
+ − 3287 {
+ − 3288 Lisp_Object string = Qnil;
+ − 3289 /* Lisp_Object sep = Qnil; */
+ − 3290 int size = XINT (Flength (keys));
+ − 3291 int i;
+ − 3292
+ − 3293 for (i = 0; i < size; i++)
+ − 3294 {
+ − 3295 Lisp_Object s2 = Fsingle_key_description
+ − 3296 (STRINGP (keys)
867
+ − 3297 ? make_char (string_ichar (keys, i))
428
+ − 3298 : XVECTOR_DATA (keys)[i]);
+ − 3299
+ − 3300 if (i == 0)
+ − 3301 string = s2;
+ − 3302 else
+ − 3303 {
+ − 3304 /* if (NILP (sep)) Lisp_Object sep = build_string (" ") */;
+ − 3305 string = concat2 (string, concat2 (Vsingle_space_string, s2));
+ − 3306 }
+ − 3307 }
+ − 3308 return string;
+ − 3309 }
+ − 3310 return Fkey_description (wrong_type_argument (Qsequencep, keys));
+ − 3311 }
+ − 3312
+ − 3313 DEFUN ("single-key-description", Fsingle_key_description, 1, 1, 0, /*
+ − 3314 Return a pretty description of command character KEY.
+ − 3315 Control characters turn into C-whatever, etc.
+ − 3316 This differs from `text-char-description' in that it returns a description
+ − 3317 of a key read from the user rather than a character from a buffer.
+ − 3318 */
+ − 3319 (key))
+ − 3320 {
+ − 3321 if (SYMBOLP (key))
+ − 3322 key = Fcons (key, Qnil); /* sleaze sleaze */
+ − 3323
+ − 3324 if (EVENTP (key) || CHAR_OR_CHAR_INTP (key))
+ − 3325 {
793
+ − 3326 DECLARE_EISTRING_MALLOC (buf);
+ − 3327 Lisp_Object str;
+ − 3328
428
+ − 3329 if (!EVENTP (key))
+ − 3330 {
934
+ − 3331 Lisp_Object event = Fmake_event (Qnil, Qnil);
+ − 3332 CHECK_CHAR_COERCE_INT (key);
1204
+ − 3333 character_to_event (XCHAR (key), XEVENT (event),
934
+ − 3334 XCONSOLE (Vselected_console), 0, 1);
+ − 3335 format_event_object (buf, event, 1);
1204
+ − 3336 Fdeallocate_event (event);
934
+ − 3337 }
+ − 3338 else
+ − 3339 format_event_object (buf, key, 1);
793
+ − 3340 str = eimake_string (buf);
+ − 3341 eifree (buf);
+ − 3342 return str;
428
+ − 3343 }
+ − 3344
+ − 3345 if (CONSP (key))
+ − 3346 {
793
+ − 3347 DECLARE_EISTRING (bufp);
+ − 3348
428
+ − 3349 Lisp_Object rest;
+ − 3350 LIST_LOOP (rest, key)
+ − 3351 {
+ − 3352 Lisp_Object keysym = XCAR (rest);
2421
+ − 3353 if (EQ (keysym, Qcontrol)) eicat_ascii (bufp, "C-");
+ − 3354 else if (EQ (keysym, Qctrl)) eicat_ascii (bufp, "C-");
+ − 3355 else if (EQ (keysym, Qmeta)) eicat_ascii (bufp, "M-");
+ − 3356 else if (EQ (keysym, Qsuper)) eicat_ascii (bufp, "S-");
+ − 3357 else if (EQ (keysym, Qhyper)) eicat_ascii (bufp, "H-");
+ − 3358 else if (EQ (keysym, Qalt)) eicat_ascii (bufp, "A-");
+ − 3359 else if (EQ (keysym, Qshift)) eicat_ascii (bufp, "Sh-");
428
+ − 3360 else if (CHAR_OR_CHAR_INTP (keysym))
793
+ − 3361 eicat_ch (bufp, XCHAR_OR_CHAR_INT (keysym));
428
+ − 3362 else
+ − 3363 {
+ − 3364 CHECK_SYMBOL (keysym);
+ − 3365 #if 0 /* This is bogus */
2421
+ − 3366 if (EQ (keysym, QKlinefeed)) eicat_ascii (bufp, "LFD");
+ − 3367 else if (EQ (keysym, QKtab)) eicat_ascii (bufp, "TAB");
+ − 3368 else if (EQ (keysym, QKreturn)) eicat_ascii (bufp, "RET");
+ − 3369 else if (EQ (keysym, QKescape)) eicat_ascii (bufp, "ESC");
+ − 3370 else if (EQ (keysym, QKdelete)) eicat_ascii (bufp, "DEL");
+ − 3371 else if (EQ (keysym, QKspace)) eicat_ascii (bufp, "SPC");
+ − 3372 else if (EQ (keysym, QKbackspace)) eicat_ascii (bufp, "BS");
428
+ − 3373 else
+ − 3374 #endif
793
+ − 3375 eicat_lstr (bufp, XSYMBOL (keysym)->name);
428
+ − 3376 if (!NILP (XCDR (rest)))
793
+ − 3377 invalid_argument ("Invalid key description", key);
428
+ − 3378 }
+ − 3379 }
793
+ − 3380 return eimake_string (bufp);
428
+ − 3381 }
+ − 3382 return Fsingle_key_description
+ − 3383 (wrong_type_argument (intern ("char-or-event-p"), key));
+ − 3384 }
+ − 3385
+ − 3386 DEFUN ("text-char-description", Ftext_char_description, 1, 1, 0, /*
+ − 3387 Return a pretty description of file-character CHR.
+ − 3388 Unprintable characters turn into "^char" or \\NNN, depending on the value
+ − 3389 of the `ctl-arrow' variable.
+ − 3390 This differs from `single-key-description' in that it returns a description
+ − 3391 of a character from a buffer rather than a key read from the user.
+ − 3392 */
+ − 3393 (chr))
+ − 3394 {
867
+ − 3395 Ibyte buf[200];
+ − 3396 Ibyte *p;
+ − 3397 Ichar c;
428
+ − 3398 Lisp_Object ctl_arrow = current_buffer->ctl_arrow;
+ − 3399 int ctl_p = !NILP (ctl_arrow);
867
+ − 3400 Ichar printable_min = (CHAR_OR_CHAR_INTP (ctl_arrow)
428
+ − 3401 ? XCHAR_OR_CHAR_INT (ctl_arrow)
+ − 3402 : ((EQ (ctl_arrow, Qt) || NILP (ctl_arrow))
+ − 3403 ? 256 : 160));
+ − 3404
+ − 3405 if (EVENTP (chr))
+ − 3406 {
2862
+ − 3407 Lisp_Object ch = Fevent_to_character (chr, Qnil, Qnil, Qnil);
428
+ − 3408 if (NILP (ch))
+ − 3409 return
563
+ − 3410 signal_continuable_error
+ − 3411 (Qinvalid_argument,
2828
+ − 3412 "key has no character equivalent (that we know of)",
+ − 3413 Fcopy_event (chr, Qnil));
428
+ − 3414 chr = ch;
+ − 3415 }
+ − 3416
+ − 3417 CHECK_CHAR_COERCE_INT (chr);
+ − 3418
+ − 3419 c = XCHAR (chr);
+ − 3420 p = buf;
+ − 3421
+ − 3422 if (c >= printable_min)
+ − 3423 {
867
+ − 3424 p += set_itext_ichar (p, c);
428
+ − 3425 }
+ − 3426 else if (c < 040 && ctl_p)
+ − 3427 {
+ − 3428 *p++ = '^';
+ − 3429 *p++ = c + 64; /* 'A' - 1 */
+ − 3430 }
+ − 3431 else if (c == 0177)
+ − 3432 {
+ − 3433 *p++ = '^';
+ − 3434 *p++ = '?';
+ − 3435 }
+ − 3436 else if (c >= 0200 || c < 040)
+ − 3437 {
+ − 3438 *p++ = '\\';
+ − 3439 #ifdef MULE
+ − 3440 /* !!#### This syntax is not readable. It will
+ − 3441 be interpreted as a 3-digit octal number rather
+ − 3442 than a 7-digit octal number. */
+ − 3443 if (c >= 0400)
+ − 3444 {
+ − 3445 *p++ = '0' + ((c & 07000000) >> 18);
+ − 3446 *p++ = '0' + ((c & 0700000) >> 15);
+ − 3447 *p++ = '0' + ((c & 070000) >> 12);
+ − 3448 *p++ = '0' + ((c & 07000) >> 9);
+ − 3449 }
+ − 3450 #endif
+ − 3451 *p++ = '0' + ((c & 0700) >> 6);
+ − 3452 *p++ = '0' + ((c & 0070) >> 3);
+ − 3453 *p++ = '0' + ((c & 0007));
+ − 3454 }
+ − 3455 else
+ − 3456 {
867
+ − 3457 p += set_itext_ichar (p, c);
428
+ − 3458 }
+ − 3459
+ − 3460 *p = 0;
+ − 3461 return build_string ((char *) buf);
+ − 3462 }
+ − 3463
+ − 3464
+ − 3465 /************************************************************************/
+ − 3466 /* where-is (mapping bindings to keys) */
+ − 3467 /************************************************************************/
+ − 3468
+ − 3469 static Lisp_Object
+ − 3470 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
793
+ − 3471 Lisp_Object firstonly, Eistring *target_buffer);
428
+ − 3472
+ − 3473 DEFUN ("where-is-internal", Fwhere_is_internal, 1, 5, 0, /*
+ − 3474 Return list of keys that invoke DEFINITION in KEYMAPS.
+ − 3475 KEYMAPS can be either a keymap (meaning search in that keymap and the
+ − 3476 current global keymap) or a list of keymaps (meaning search in exactly
3096
+ − 3477 those keymaps and no others).
428
+ − 3478
+ − 3479 If optional 3rd arg FIRSTONLY is non-nil, return a vector representing
+ − 3480 the first key sequence found, rather than a list of all possible key
+ − 3481 sequences.
+ − 3482
3096
+ − 3483 Optional 4th argument NOINDIRECT is ignored. (GNU Emacs uses it to allow
+ − 3484 searching for an indirect keymap by inhibiting following of indirections to
+ − 3485 keymaps or slots, but XEmacs doesn't need it because keymaps are a type.)
+ − 3486
+ − 3487 If optional 5th argument EVENT-OR-KEYS is non-nil and KEYMAPS is nil,
+ − 3488 search in the currently applicable maps for EVENT-OR-KEYS (this is
+ − 3489 equivalent to specifying `(current-keymaps EVENT-OR-KEYS)' as the
+ − 3490 argument to KEYMAPS).
428
+ − 3491 */
2286
+ − 3492 (definition, keymaps, firstonly, UNUSED (noindirect), event_or_keys))
428
+ − 3493 {
+ − 3494 /* This function can GC */
+ − 3495 Lisp_Object maps[100];
+ − 3496 Lisp_Object *gubbish = maps;
+ − 3497 int nmaps;
+ − 3498
+ − 3499 /* Get keymaps as an array */
+ − 3500 if (NILP (keymaps))
+ − 3501 {
+ − 3502 nmaps = get_relevant_keymaps (event_or_keys, countof (maps),
+ − 3503 gubbish);
+ − 3504 if (nmaps > countof (maps))
+ − 3505 {
+ − 3506 gubbish = alloca_array (Lisp_Object, nmaps);
+ − 3507 nmaps = get_relevant_keymaps (event_or_keys, nmaps, gubbish);
+ − 3508 }
+ − 3509 }
+ − 3510 else if (CONSP (keymaps))
+ − 3511 {
+ − 3512 Lisp_Object rest;
+ − 3513 int i;
+ − 3514
+ − 3515 nmaps = XINT (Flength (keymaps));
+ − 3516 if (nmaps > countof (maps))
+ − 3517 {
+ − 3518 gubbish = alloca_array (Lisp_Object, nmaps);
+ − 3519 }
+ − 3520 for (rest = keymaps, i = 0; !NILP (rest);
+ − 3521 rest = XCDR (keymaps), i++)
+ − 3522 {
+ − 3523 gubbish[i] = get_keymap (XCAR (keymaps), 1, 1);
+ − 3524 }
+ − 3525 }
+ − 3526 else
+ − 3527 {
+ − 3528 nmaps = 1;
+ − 3529 gubbish[0] = get_keymap (keymaps, 1, 1);
+ − 3530 if (!EQ (gubbish[0], Vcurrent_global_map))
+ − 3531 {
+ − 3532 gubbish[1] = Vcurrent_global_map;
+ − 3533 nmaps++;
+ − 3534 }
+ − 3535 }
+ − 3536
+ − 3537 return where_is_internal (definition, gubbish, nmaps, firstonly, 0);
+ − 3538 }
+ − 3539
+ − 3540 /* This function is like
+ − 3541 (key-description (where-is-internal definition nil t))
+ − 3542 except that it writes its output into a (char *) buffer that you
+ − 3543 provide; it doesn't cons (or allocate memory) at all, so it's
+ − 3544 very fast. This is used by menubar.c.
+ − 3545 */
+ − 3546 void
793
+ − 3547 where_is_to_char (Lisp_Object definition, Eistring *buffer)
428
+ − 3548 {
+ − 3549 /* This function can GC */
+ − 3550 Lisp_Object maps[100];
+ − 3551 Lisp_Object *gubbish = maps;
+ − 3552 int nmaps;
+ − 3553
+ − 3554 /* Get keymaps as an array */
+ − 3555 nmaps = get_relevant_keymaps (Qnil, countof (maps), gubbish);
+ − 3556 if (nmaps > countof (maps))
+ − 3557 {
+ − 3558 gubbish = alloca_array (Lisp_Object, nmaps);
+ − 3559 nmaps = get_relevant_keymaps (Qnil, nmaps, gubbish);
+ − 3560 }
+ − 3561
+ − 3562 where_is_internal (definition, maps, nmaps, Qt, buffer);
+ − 3563 }
+ − 3564
+ − 3565
+ − 3566 static Lisp_Object
934
+ − 3567 raw_keys_to_keys (Lisp_Key_Data *keys, int count)
428
+ − 3568 {
+ − 3569 Lisp_Object result = make_vector (count, Qnil);
+ − 3570 while (count--)
+ − 3571 XVECTOR_DATA (result) [count] = make_key_description (&(keys[count]), 1);
+ − 3572 return result;
+ − 3573 }
+ − 3574
+ − 3575
+ − 3576 static void
934
+ − 3577 format_raw_keys (Lisp_Key_Data *keys, int count, Eistring *buf)
428
+ − 3578 {
+ − 3579 int i;
934
+ − 3580 Lisp_Object event = Fmake_event (Qnil, Qnil);
+ − 3581 XSET_EVENT_TYPE (event, key_press_event);
+ − 3582 XSET_EVENT_CHANNEL (event, Vselected_console);
428
+ − 3583 for (i = 0; i < count; i++)
+ − 3584 {
1204
+ − 3585 XSET_EVENT_KEY_KEYSYM (event, keys[i].keysym);
+ − 3586 XSET_EVENT_KEY_MODIFIERS (event, KEY_DATA_MODIFIERS (&keys[i]));
934
+ − 3587 format_event_object (buf, event, 1);
793
+ − 3588 if (i < count - 1)
2421
+ − 3589 eicat_ascii (buf, " ");
428
+ − 3590 }
1204
+ − 3591 Fdeallocate_event (event);
428
+ − 3592 }
+ − 3593
+ − 3594
+ − 3595 /* definition is the thing to look for.
+ − 3596 map is a keymap.
+ − 3597 shadow is an array of shadow_count keymaps; if there is a different
+ − 3598 binding in any of the keymaps of a key that we are considering
+ − 3599 returning, then we reconsider.
+ − 3600 firstonly means give up after finding the first match;
+ − 3601 keys_so_far and modifiers_so_far describe which map we're looking in;
+ − 3602 If we're in the "meta" submap of the map that "C-x 4" is bound to,
+ − 3603 then keys_so_far will be {(control x), \4}, and modifiers_so_far
442
+ − 3604 will be XEMACS_MOD_META. That is, keys_so_far is the chain of keys that we
428
+ − 3605 have followed, and modifiers_so_far_so_far is the bits (partial keys)
+ − 3606 beyond that.
+ − 3607
+ − 3608 (keys_so_far is a global buffer and the keys_count arg says how much
+ − 3609 of it we're currently interested in.)
+ − 3610
+ − 3611 If target_buffer is provided, then we write a key-description into it,
+ − 3612 to avoid consing a string. This only works with firstonly on.
+ − 3613 */
+ − 3614
+ − 3615 struct where_is_closure
+ − 3616 {
+ − 3617 Lisp_Object definition;
+ − 3618 Lisp_Object *shadow;
+ − 3619 int shadow_count;
+ − 3620 int firstonly;
+ − 3621 int keys_count;
442
+ − 3622 int modifiers_so_far;
793
+ − 3623 Eistring *target_buffer;
934
+ − 3624 Lisp_Key_Data *keys_so_far;
428
+ − 3625 int keys_so_far_total_size;
+ − 3626 int keys_so_far_malloced;
+ − 3627 };
+ − 3628
+ − 3629 static Lisp_Object where_is_recursive_mapper (Lisp_Object map, void *arg);
+ − 3630
+ − 3631 static Lisp_Object
+ − 3632 where_is_recursive_mapper (Lisp_Object map, void *arg)
+ − 3633 {
+ − 3634 /* This function can GC */
+ − 3635 struct where_is_closure *c = (struct where_is_closure *) arg;
+ − 3636 Lisp_Object definition = c->definition;
442
+ − 3637 const int firstonly = c->firstonly;
+ − 3638 const int keys_count = c->keys_count;
+ − 3639 const int modifiers_so_far = c->modifiers_so_far;
793
+ − 3640 Eistring *target_buffer = c->target_buffer;
428
+ − 3641 Lisp_Object keys = Fgethash (definition,
+ − 3642 XKEYMAP (map)->inverse_table,
+ − 3643 Qnil);
+ − 3644 Lisp_Object submaps;
+ − 3645 Lisp_Object result = Qnil;
+ − 3646
+ − 3647 if (!NILP (keys))
+ − 3648 {
+ − 3649 /* One or more keys in this map match the definition we're looking for.
+ − 3650 Verify that these bindings aren't shadowed by other bindings
+ − 3651 in the shadow maps. Either nil or number as value from
+ − 3652 raw_lookup_key() means undefined. */
934
+ − 3653 Lisp_Key_Data *so_far = c->keys_so_far;
428
+ − 3654
+ − 3655 for (;;) /* loop over all keys that match */
+ − 3656 {
+ − 3657 Lisp_Object k = CONSP (keys) ? XCAR (keys) : keys;
+ − 3658 int i;
+ − 3659
+ − 3660 so_far [keys_count].keysym = k;
934
+ − 3661 SET_KEY_DATA_MODIFIERS (&so_far [keys_count], modifiers_so_far);
428
+ − 3662
+ − 3663 /* now loop over all shadow maps */
+ − 3664 for (i = 0; i < c->shadow_count; i++)
+ − 3665 {
+ − 3666 Lisp_Object shadowed = raw_lookup_key (c->shadow[i],
+ − 3667 so_far,
+ − 3668 keys_count + 1,
+ − 3669 0, 1);
+ − 3670
+ − 3671 if (NILP (shadowed) || CHARP (shadowed) ||
+ − 3672 EQ (shadowed, definition))
+ − 3673 continue; /* we passed this test; it's not shadowed here. */
+ − 3674 else
+ − 3675 /* ignore this key binding, since it actually has a
+ − 3676 different binding in a shadowing map */
+ − 3677 goto c_doesnt_have_proper_loop_exit_statements;
+ − 3678 }
+ − 3679
+ − 3680 /* OK, the key is for real */
+ − 3681 if (target_buffer)
+ − 3682 {
2500
+ − 3683 if (!firstonly) ABORT ();
428
+ − 3684 format_raw_keys (so_far, keys_count + 1, target_buffer);
+ − 3685 return make_int (1);
+ − 3686 }
+ − 3687 else if (firstonly)
+ − 3688 return raw_keys_to_keys (so_far, keys_count + 1);
+ − 3689 else
+ − 3690 result = Fcons (raw_keys_to_keys (so_far, keys_count + 1),
+ − 3691 result);
+ − 3692
+ − 3693 c_doesnt_have_proper_loop_exit_statements:
+ − 3694 /* now on to the next matching key ... */
+ − 3695 if (!CONSP (keys)) break;
+ − 3696 keys = XCDR (keys);
+ − 3697 }
+ − 3698 }
+ − 3699
+ − 3700 /* Now search the sub-keymaps of this map.
+ − 3701 If we're in "firstonly" mode and have already found one, this
+ − 3702 point is not reached. If we get one from lower down, either
+ − 3703 return it immediately (in firstonly mode) or tack it onto the
+ − 3704 end of the ones we've gotten so far.
+ − 3705 */
+ − 3706 for (submaps = keymap_submaps (map);
+ − 3707 !NILP (submaps);
+ − 3708 submaps = XCDR (submaps))
+ − 3709 {
+ − 3710 Lisp_Object key = XCAR (XCAR (submaps));
+ − 3711 Lisp_Object submap = XCDR (XCAR (submaps));
442
+ − 3712 int lower_modifiers;
428
+ − 3713 int lower_keys_count = keys_count;
442
+ − 3714 int bucky;
428
+ − 3715
+ − 3716 submap = get_keymap (submap, 0, 0);
+ − 3717
+ − 3718 if (EQ (submap, map))
+ − 3719 /* Arrgh! Some loser has introduced a loop... */
+ − 3720 continue;
+ − 3721
+ − 3722 /* If this is not a keymap, then that's probably because someone
+ − 3723 did an `fset' of a symbol that used to point to a map such that
+ − 3724 it no longer does. Sigh. Ignore this, and invalidate the cache
+ − 3725 so that it doesn't happen to us next time too.
+ − 3726 */
+ − 3727 if (NILP (submap))
+ − 3728 {
+ − 3729 XKEYMAP (map)->sub_maps_cache = Qt;
+ − 3730 continue;
+ − 3731 }
+ − 3732
+ − 3733 /* If the map is a "bucky" map, then add a bit to the
+ − 3734 modifiers_so_far list.
+ − 3735 Otherwise, add a new raw_key onto the end of keys_so_far.
+ − 3736 */
+ − 3737 bucky = MODIFIER_HASH_KEY_BITS (key);
+ − 3738 if (bucky != 0)
+ − 3739 lower_modifiers = (modifiers_so_far | bucky);
+ − 3740 else
+ − 3741 {
934
+ − 3742 Lisp_Key_Data *so_far = c->keys_so_far;
428
+ − 3743 lower_modifiers = 0;
+ − 3744 so_far [lower_keys_count].keysym = key;
934
+ − 3745 SET_KEY_DATA_MODIFIERS (&so_far [lower_keys_count], modifiers_so_far);
428
+ − 3746 lower_keys_count++;
+ − 3747 }
+ − 3748
+ − 3749 if (lower_keys_count >= c->keys_so_far_total_size)
+ − 3750 {
+ − 3751 int size = lower_keys_count + 50;
+ − 3752 if (! c->keys_so_far_malloced)
+ − 3753 {
3025
+ − 3754 Lisp_Key_Data *new_ = xnew_array (Lisp_Key_Data, size);
+ − 3755 memcpy ((void *)new_, (const void *)c->keys_so_far,
934
+ − 3756 c->keys_so_far_total_size * sizeof (Lisp_Key_Data));
3550
+ − 3757 xfree (c->keys_so_far, Lisp_Key_Data);
+ − 3758 c->keys_so_far = new_;
428
+ − 3759 }
+ − 3760 else
934
+ − 3761 XREALLOC_ARRAY (c->keys_so_far, Lisp_Key_Data, size);
428
+ − 3762
+ − 3763 c->keys_so_far_total_size = size;
+ − 3764 c->keys_so_far_malloced = 1;
+ − 3765 }
+ − 3766
+ − 3767 {
+ − 3768 Lisp_Object lower;
+ − 3769
+ − 3770 c->keys_count = lower_keys_count;
+ − 3771 c->modifiers_so_far = lower_modifiers;
+ − 3772
+ − 3773 lower = traverse_keymaps (submap, Qnil, where_is_recursive_mapper, c);
+ − 3774
+ − 3775 c->keys_count = keys_count;
+ − 3776 c->modifiers_so_far = modifiers_so_far;
+ − 3777
+ − 3778 if (!firstonly)
+ − 3779 result = nconc2 (lower, result);
+ − 3780 else if (!NILP (lower))
+ − 3781 return lower;
+ − 3782 }
+ − 3783 }
+ − 3784 return result;
+ − 3785 }
+ − 3786
+ − 3787
+ − 3788 static Lisp_Object
+ − 3789 where_is_internal (Lisp_Object definition, Lisp_Object *maps, int nmaps,
793
+ − 3790 Lisp_Object firstonly, Eistring *target_buffer)
428
+ − 3791 {
+ − 3792 /* This function can GC */
+ − 3793 Lisp_Object result = Qnil;
+ − 3794 int i;
934
+ − 3795 Lisp_Key_Data raw[20];
428
+ − 3796 struct where_is_closure c;
+ − 3797
+ − 3798 c.definition = definition;
+ − 3799 c.shadow = maps;
+ − 3800 c.firstonly = !NILP (firstonly);
+ − 3801 c.target_buffer = target_buffer;
+ − 3802 c.keys_so_far = raw;
+ − 3803 c.keys_so_far_total_size = countof (raw);
+ − 3804 c.keys_so_far_malloced = 0;
+ − 3805
+ − 3806 /* Loop over each of the maps, accumulating the keys found.
+ − 3807 For each map searched, all previous maps shadow this one
+ − 3808 so that bogus keys aren't listed. */
+ − 3809 for (i = 0; i < nmaps; i++)
+ − 3810 {
+ − 3811 Lisp_Object this_result;
+ − 3812 c.shadow_count = i;
+ − 3813 /* Reset the things set in each iteration */
+ − 3814 c.keys_count = 0;
+ − 3815 c.modifiers_so_far = 0;
+ − 3816
+ − 3817 this_result = traverse_keymaps (maps[i], Qnil, where_is_recursive_mapper,
+ − 3818 &c);
+ − 3819 if (!NILP (firstonly))
+ − 3820 {
+ − 3821 result = this_result;
+ − 3822 if (!NILP (result))
+ − 3823 break;
+ − 3824 }
+ − 3825 else
+ − 3826 result = nconc2 (this_result, result);
+ − 3827 }
+ − 3828
+ − 3829 if (NILP (firstonly))
+ − 3830 result = Fnreverse (result);
+ − 3831
+ − 3832 if (c.keys_so_far_malloced)
1726
+ − 3833 xfree (c.keys_so_far, Lisp_Key_Data *);
428
+ − 3834 return result;
+ − 3835 }
+ − 3836
+ − 3837
+ − 3838 /************************************************************************/
+ − 3839 /* Describing keymaps */
+ − 3840 /************************************************************************/
+ − 3841
+ − 3842 DEFUN ("describe-bindings-internal", Fdescribe_bindings_internal, 1, 5, 0, /*
+ − 3843 Insert a list of all defined keys and their definitions in MAP.
+ − 3844 Optional second argument ALL says whether to include even "uninteresting"
+ − 3845 definitions (ie symbols with a non-nil `suppress-keymap' property.
+ − 3846 Third argument SHADOW is a list of keymaps whose bindings shadow those
+ − 3847 of map; if a binding is present in any shadowing map, it is not printed.
+ − 3848 Fourth argument PREFIX, if non-nil, should be a key sequence;
+ − 3849 only bindings which start with that key sequence will be printed.
+ − 3850 Fifth argument MOUSE-ONLY-P says to only print bindings for mouse clicks.
+ − 3851 */
+ − 3852 (map, all, shadow, prefix, mouse_only_p))
+ − 3853 {
+ − 3854 /* This function can GC */
+ − 3855
+ − 3856 /* #### At some point, this function should be changed to accept a
+ − 3857 BUFFER argument. Currently, the BUFFER argument to
+ − 3858 describe_map_tree is being used only internally. */
+ − 3859 describe_map_tree (map, NILP (all), shadow, prefix,
+ − 3860 !NILP (mouse_only_p), Fcurrent_buffer ());
+ − 3861 return Qnil;
+ − 3862 }
+ − 3863
+ − 3864
+ − 3865 /* Insert a description of the key bindings in STARTMAP,
+ − 3866 followed by those of all maps reachable through STARTMAP.
+ − 3867 If PARTIAL is nonzero, omit certain "uninteresting" commands
+ − 3868 (such as `undefined').
+ − 3869 If SHADOW is non-nil, it is a list of other maps;
+ − 3870 don't mention keys which would be shadowed by any of them
+ − 3871 If PREFIX is non-nil, only list bindings which start with those keys.
+ − 3872 */
+ − 3873
+ − 3874 void
+ − 3875 describe_map_tree (Lisp_Object startmap, int partial, Lisp_Object shadow,
+ − 3876 Lisp_Object prefix, int mice_only_p, Lisp_Object buffer)
+ − 3877 {
+ − 3878 /* This function can GC */
+ − 3879 Lisp_Object maps = Qnil;
+ − 3880 struct gcpro gcpro1, gcpro2; /* get_keymap may autoload */
+ − 3881 GCPRO2 (maps, shadow);
+ − 3882
+ − 3883 maps = Faccessible_keymaps (startmap, prefix);
+ − 3884
+ − 3885 for (; !NILP (maps); maps = Fcdr (maps))
+ − 3886 {
+ − 3887 Lisp_Object sub_shadow = Qnil;
+ − 3888 Lisp_Object elt = Fcar (maps);
+ − 3889 Lisp_Object tail;
+ − 3890 int no_prefix = (VECTORP (Fcar (elt))
+ − 3891 && XINT (Flength (Fcar (elt))) == 0);
+ − 3892 struct gcpro ngcpro1, ngcpro2, ngcpro3;
+ − 3893 NGCPRO3 (sub_shadow, elt, tail);
+ − 3894
+ − 3895 for (tail = shadow; CONSP (tail); tail = XCDR (tail))
+ − 3896 {
+ − 3897 Lisp_Object shmap = XCAR (tail);
+ − 3898
+ − 3899 /* If the sequence by which we reach this keymap is zero-length,
+ − 3900 then the shadow maps for this keymap are just SHADOW. */
+ − 3901 if (no_prefix)
+ − 3902 ;
+ − 3903 /* If the sequence by which we reach this keymap actually has
+ − 3904 some elements, then the sequence's definition in SHADOW is
+ − 3905 what we should use. */
+ − 3906 else
+ − 3907 {
+ − 3908 shmap = Flookup_key (shmap, Fcar (elt), Qt);
+ − 3909 if (CHARP (shmap))
+ − 3910 shmap = Qnil;
+ − 3911 }
+ − 3912
+ − 3913 if (!NILP (shmap))
+ − 3914 {
+ − 3915 Lisp_Object shm = get_keymap (shmap, 0, 1);
+ − 3916 /* If shmap is not nil and not a keymap, it completely
+ − 3917 shadows this map, so don't describe this map at all. */
+ − 3918 if (!KEYMAPP (shm))
+ − 3919 goto SKIP;
+ − 3920 sub_shadow = Fcons (shm, sub_shadow);
+ − 3921 }
+ − 3922 }
+ − 3923
+ − 3924 {
+ − 3925 /* Describe the contents of map MAP, assuming that this map
+ − 3926 itself is reached by the sequence of prefix keys KEYS (a vector).
+ − 3927 PARTIAL and SHADOW are as in `describe_map_tree'. */
+ − 3928 Lisp_Object keysdesc
+ − 3929 = ((!no_prefix)
+ − 3930 ? concat2 (Fkey_description (Fcar (elt)), Vsingle_space_string)
+ − 3931 : Qnil);
+ − 3932 describe_map (Fcdr (elt), keysdesc,
+ − 3933 describe_command,
+ − 3934 partial,
+ − 3935 sub_shadow,
+ − 3936 mice_only_p,
+ − 3937 buffer);
+ − 3938 }
+ − 3939 SKIP:
+ − 3940 NUNGCPRO;
+ − 3941 }
+ − 3942 UNGCPRO;
+ − 3943 }
+ − 3944
+ − 3945
+ − 3946 static void
+ − 3947 describe_command (Lisp_Object definition, Lisp_Object buffer)
+ − 3948 {
+ − 3949 /* This function can GC */
+ − 3950 int keymapp = !NILP (Fkeymapp (definition));
+ − 3951 struct gcpro gcpro1;
+ − 3952 GCPRO1 (definition);
+ − 3953
+ − 3954 Findent_to (make_int (16), make_int (3), buffer);
+ − 3955 if (keymapp)
+ − 3956 buffer_insert_c_string (XBUFFER (buffer), "<< ");
+ − 3957
+ − 3958 if (SYMBOLP (definition))
+ − 3959 {
+ − 3960 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (definition));
+ − 3961 }
+ − 3962 else if (STRINGP (definition) || VECTORP (definition))
+ − 3963 {
+ − 3964 buffer_insert_c_string (XBUFFER (buffer), "Kbd Macro: ");
+ − 3965 buffer_insert1 (XBUFFER (buffer), Fkey_description (definition));
+ − 3966 }
+ − 3967 else if (COMPILED_FUNCTIONP (definition))
+ − 3968 buffer_insert_c_string (XBUFFER (buffer), "Anonymous Compiled Function");
+ − 3969 else if (CONSP (definition) && EQ (XCAR (definition), Qlambda))
+ − 3970 buffer_insert_c_string (XBUFFER (buffer), "Anonymous Lambda");
+ − 3971 else if (KEYMAPP (definition))
+ − 3972 {
+ − 3973 Lisp_Object name = XKEYMAP (definition)->name;
+ − 3974 if (STRINGP (name) || (SYMBOLP (name) && !NILP (name)))
+ − 3975 {
+ − 3976 buffer_insert_c_string (XBUFFER (buffer), "Prefix command ");
+ − 3977 if (SYMBOLP (name)
+ − 3978 && EQ (find_symbol_value (name), definition))
+ − 3979 buffer_insert1 (XBUFFER (buffer), Fsymbol_name (name));
+ − 3980 else
+ − 3981 {
+ − 3982 buffer_insert1 (XBUFFER (buffer), Fprin1_to_string (name, Qnil));
+ − 3983 }
+ − 3984 }
+ − 3985 else
+ − 3986 buffer_insert_c_string (XBUFFER (buffer), "Prefix Command");
+ − 3987 }
+ − 3988 else
+ − 3989 buffer_insert_c_string (XBUFFER (buffer), "??");
+ − 3990
+ − 3991 if (keymapp)
+ − 3992 buffer_insert_c_string (XBUFFER (buffer), " >>");
+ − 3993 buffer_insert_c_string (XBUFFER (buffer), "\n");
+ − 3994 UNGCPRO;
+ − 3995 }
+ − 3996
+ − 3997 struct describe_map_closure
+ − 3998 {
+ − 3999 Lisp_Object *list; /* pointer to the list to update */
+ − 4000 Lisp_Object partial; /* whether to ignore suppressed commands */
+ − 4001 Lisp_Object shadow; /* list of maps shadowing this one */
+ − 4002 Lisp_Object self; /* this map */
+ − 4003 Lisp_Object self_root; /* this map, or some map that has this map as
+ − 4004 a parent. this is the base of the tree */
+ − 4005 int mice_only_p; /* whether we are to display only button bindings */
+ − 4006 };
+ − 4007
+ − 4008 struct describe_map_shadow_closure
+ − 4009 {
934
+ − 4010 const Lisp_Key_Data *raw_key;
428
+ − 4011 Lisp_Object self;
+ − 4012 };
+ − 4013
+ − 4014 static Lisp_Object
+ − 4015 describe_map_mapper_shadow_search (Lisp_Object map, void *arg)
+ − 4016 {
+ − 4017 struct describe_map_shadow_closure *c =
+ − 4018 (struct describe_map_shadow_closure *) arg;
+ − 4019
+ − 4020 if (EQ (map, c->self))
+ − 4021 return Qzero; /* Not shadowed; terminate search */
+ − 4022
934
+ − 4023 return !NILP (keymap_lookup_directly (map,
+ − 4024 KEY_DATA_KEYSYM (c->raw_key),
+ − 4025 KEY_DATA_MODIFIERS (c->raw_key)))
428
+ − 4026 ? Qt : Qnil;
+ − 4027 }
+ − 4028
+ − 4029
+ − 4030 static Lisp_Object
+ − 4031 keymap_lookup_inherited_mapper (Lisp_Object km, void *arg)
+ − 4032 {
934
+ − 4033 Lisp_Key_Data *k = (Lisp_Key_Data *) arg;
+ − 4034 return keymap_lookup_directly (km, KEY_DATA_KEYSYM (k), KEY_DATA_MODIFIERS (k));
428
+ − 4035 }
+ − 4036
+ − 4037
+ − 4038 static void
934
+ − 4039 describe_map_mapper (const Lisp_Key_Data *key,
428
+ − 4040 Lisp_Object binding,
+ − 4041 void *describe_map_closure)
+ − 4042 {
+ − 4043 /* This function can GC */
+ − 4044 struct describe_map_closure *closure =
+ − 4045 (struct describe_map_closure *) describe_map_closure;
934
+ − 4046 Lisp_Object keysym = KEY_DATA_KEYSYM (key);
+ − 4047 int modifiers = KEY_DATA_MODIFIERS (key);
428
+ − 4048
+ − 4049 /* Don't mention suppressed commands. */
+ − 4050 if (SYMBOLP (binding)
+ − 4051 && !NILP (closure->partial)
+ − 4052 && !NILP (Fget (binding, closure->partial, Qnil)))
+ − 4053 return;
+ − 4054
+ − 4055 /* If we're only supposed to display mouse bindings and this isn't one,
+ − 4056 then bug out. */
+ − 4057 if (closure->mice_only_p &&
+ − 4058 (! (EQ (keysym, Qbutton0) ||
+ − 4059 EQ (keysym, Qbutton1) ||
+ − 4060 EQ (keysym, Qbutton2) ||
+ − 4061 EQ (keysym, Qbutton3) ||
+ − 4062 EQ (keysym, Qbutton4) ||
+ − 4063 EQ (keysym, Qbutton5) ||
+ − 4064 EQ (keysym, Qbutton6) ||
+ − 4065 EQ (keysym, Qbutton7) ||
+ − 4066 EQ (keysym, Qbutton0up) ||
+ − 4067 EQ (keysym, Qbutton1up) ||
+ − 4068 EQ (keysym, Qbutton2up) ||
+ − 4069 EQ (keysym, Qbutton3up) ||
+ − 4070 EQ (keysym, Qbutton4up) ||
+ − 4071 EQ (keysym, Qbutton5up) ||
+ − 4072 EQ (keysym, Qbutton6up) ||
+ − 4073 EQ (keysym, Qbutton7up))))
+ − 4074 return;
+ − 4075
+ − 4076 /* If this command in this map is shadowed by some other map, ignore it. */
+ − 4077 {
+ − 4078 Lisp_Object tail;
+ − 4079
+ − 4080 for (tail = closure->shadow; CONSP (tail); tail = XCDR (tail))
+ − 4081 {
+ − 4082 QUIT;
+ − 4083 if (!NILP (traverse_keymaps (XCAR (tail), Qnil,
+ − 4084 keymap_lookup_inherited_mapper,
+ − 4085 /* Cast to discard `const' */
+ − 4086 (void *)key)))
+ − 4087 return;
+ − 4088 }
+ − 4089 }
+ − 4090
+ − 4091 /* If this key is in some map of which this map is a parent, then ignore
+ − 4092 it (in that case, it has been shadowed).
+ − 4093 */
+ − 4094 {
+ − 4095 Lisp_Object sh;
+ − 4096 struct describe_map_shadow_closure c;
+ − 4097 c.raw_key = key;
+ − 4098 c.self = closure->self;
+ − 4099
+ − 4100 sh = traverse_keymaps (closure->self_root, Qnil,
+ − 4101 describe_map_mapper_shadow_search, &c);
+ − 4102 if (!NILP (sh) && !ZEROP (sh))
+ − 4103 return;
+ − 4104 }
+ − 4105
+ − 4106 /* Otherwise add it to the list to be sorted. */
+ − 4107 *(closure->list) = Fcons (Fcons (Fcons (keysym, make_int (modifiers)),
+ − 4108 binding),
+ − 4109 *(closure->list));
+ − 4110 }
+ − 4111
+ − 4112
+ − 4113 static int
+ − 4114 describe_map_sort_predicate (Lisp_Object obj1, Lisp_Object obj2,
+ − 4115 Lisp_Object pred)
+ − 4116 {
+ − 4117 /* obj1 and obj2 are conses of the form
+ − 4118 ( ( <keysym> . <modifiers> ) . <binding> )
+ − 4119 keysym and modifiers are used, binding is ignored.
+ − 4120 */
442
+ − 4121 int bit1, bit2;
428
+ − 4122 obj1 = XCAR (obj1);
+ − 4123 obj2 = XCAR (obj2);
+ − 4124 bit1 = XINT (XCDR (obj1));
+ − 4125 bit2 = XINT (XCDR (obj2));
+ − 4126 if (bit1 != bit2)
+ − 4127 return bit1 < bit2 ? 1 : -1;
+ − 4128 else
+ − 4129 return map_keymap_sort_predicate (obj1, obj2, pred);
+ − 4130 }
+ − 4131
+ − 4132 /* Elide 2 or more consecutive numeric keysyms bound to the same thing,
+ − 4133 or 2 or more symbolic keysyms that are bound to the same thing and
+ − 4134 have consecutive character-set-properties.
+ − 4135 */
+ − 4136 static int
+ − 4137 elide_next_two_p (Lisp_Object list)
+ − 4138 {
+ − 4139 Lisp_Object s1, s2;
2828
+ − 4140 extern Lisp_Object Qcharacter_of_keysym;
428
+ − 4141
+ − 4142 if (NILP (XCDR (list)))
+ − 4143 return 0;
+ − 4144
+ − 4145 /* next two bindings differ */
+ − 4146 if (!EQ (XCDR (XCAR (list)),
+ − 4147 XCDR (XCAR (XCDR (list)))))
+ − 4148 return 0;
+ − 4149
+ − 4150 /* next two modifier-sets differ */
+ − 4151 if (!EQ (XCDR (XCAR (XCAR (list))),
+ − 4152 XCDR (XCAR (XCAR (XCDR (list))))))
+ − 4153 return 0;
+ − 4154
+ − 4155 s1 = XCAR (XCAR (XCAR (list)));
+ − 4156 s2 = XCAR (XCAR (XCAR (XCDR (list))));
+ − 4157
+ − 4158 if (SYMBOLP (s1))
+ − 4159 {
2828
+ − 4160 Lisp_Object code = Fget (s1, Qcharacter_of_keysym, Qnil);
428
+ − 4161 if (CHAR_OR_CHAR_INTP (code))
+ − 4162 {
+ − 4163 s1 = code;
+ − 4164 CHECK_CHAR_COERCE_INT (s1);
+ − 4165 }
+ − 4166 else return 0;
+ − 4167 }
+ − 4168 if (SYMBOLP (s2))
+ − 4169 {
2828
+ − 4170 Lisp_Object code = Fget (s2, Qcharacter_of_keysym, Qnil);
428
+ − 4171 if (CHAR_OR_CHAR_INTP (code))
+ − 4172 {
+ − 4173 s2 = code;
+ − 4174 CHECK_CHAR_COERCE_INT (s2);
+ − 4175 }
+ − 4176 else return 0;
+ − 4177 }
+ − 4178
+ − 4179 return (XCHAR (s1) == XCHAR (s2) ||
+ − 4180 XCHAR (s1) + 1 == XCHAR (s2));
+ − 4181 }
+ − 4182
+ − 4183
+ − 4184 static Lisp_Object
+ − 4185 describe_map_parent_mapper (Lisp_Object keymap, void *arg)
+ − 4186 {
+ − 4187 /* This function can GC */
+ − 4188 struct describe_map_closure *describe_map_closure =
+ − 4189 (struct describe_map_closure *) arg;
+ − 4190 describe_map_closure->self = keymap;
+ − 4191 map_keymap (XKEYMAP (keymap)->table,
+ − 4192 0, /* don't sort: we'll do it later */
+ − 4193 describe_map_mapper, describe_map_closure);
+ − 4194 return Qnil;
+ − 4195 }
+ − 4196
+ − 4197
+ − 4198 /* Describe the contents of map MAP, assuming that this map itself is
+ − 4199 reached by the sequence of prefix keys KEYS (a string or vector).
+ − 4200 PARTIAL, SHADOW, NOMENU are as in `describe_map_tree' above. */
+ − 4201
+ − 4202 static void
+ − 4203 describe_map (Lisp_Object keymap, Lisp_Object elt_prefix,
+ − 4204 void (*elt_describer) (Lisp_Object, Lisp_Object),
+ − 4205 int partial,
+ − 4206 Lisp_Object shadow,
+ − 4207 int mice_only_p,
+ − 4208 Lisp_Object buffer)
+ − 4209 {
+ − 4210 /* This function can GC */
+ − 4211 struct describe_map_closure describe_map_closure;
+ − 4212 Lisp_Object list = Qnil;
+ − 4213 struct buffer *buf = XBUFFER (buffer);
867
+ − 4214 Ichar printable_min = (CHAR_OR_CHAR_INTP (buf->ctl_arrow)
428
+ − 4215 ? XCHAR_OR_CHAR_INT (buf->ctl_arrow)
+ − 4216 : ((EQ (buf->ctl_arrow, Qt)
+ − 4217 || EQ (buf->ctl_arrow, Qnil))
+ − 4218 ? 256 : 160));
+ − 4219 int elided = 0;
+ − 4220 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2828
+ − 4221 extern Lisp_Object Qcharacter_of_keysym;
428
+ − 4222
+ − 4223 keymap = get_keymap (keymap, 1, 1);
+ − 4224 describe_map_closure.partial = (partial ? Qsuppress_keymap : Qnil);
+ − 4225 describe_map_closure.shadow = shadow;
+ − 4226 describe_map_closure.list = &list;
+ − 4227 describe_map_closure.self_root = keymap;
+ − 4228 describe_map_closure.mice_only_p = mice_only_p;
+ − 4229
+ − 4230 GCPRO4 (keymap, elt_prefix, shadow, list);
+ − 4231
+ − 4232 traverse_keymaps (keymap, Qnil,
+ − 4233 describe_map_parent_mapper, &describe_map_closure);
+ − 4234
+ − 4235 if (!NILP (list))
+ − 4236 {
+ − 4237 list = list_sort (list, Qnil, describe_map_sort_predicate);
+ − 4238 buffer_insert_c_string (buf, "\n");
+ − 4239 while (!NILP (list))
+ − 4240 {
+ − 4241 Lisp_Object elt = XCAR (XCAR (list));
+ − 4242 Lisp_Object keysym = XCAR (elt);
442
+ − 4243 int modifiers = XINT (XCDR (elt));
428
+ − 4244
+ − 4245 if (!NILP (elt_prefix))
+ − 4246 buffer_insert_lisp_string (buf, elt_prefix);
+ − 4247
442
+ − 4248 if (modifiers & XEMACS_MOD_META)
+ − 4249 buffer_insert_c_string (buf, "M-");
+ − 4250 if (modifiers & XEMACS_MOD_CONTROL)
+ − 4251 buffer_insert_c_string (buf, "C-");
+ − 4252 if (modifiers & XEMACS_MOD_SUPER)
+ − 4253 buffer_insert_c_string (buf, "S-");
+ − 4254 if (modifiers & XEMACS_MOD_HYPER)
+ − 4255 buffer_insert_c_string (buf, "H-");
+ − 4256 if (modifiers & XEMACS_MOD_ALT)
+ − 4257 buffer_insert_c_string (buf, "Alt-");
+ − 4258 if (modifiers & XEMACS_MOD_SHIFT)
+ − 4259 buffer_insert_c_string (buf, "Sh-");
428
+ − 4260 if (SYMBOLP (keysym))
+ − 4261 {
2828
+ − 4262 Lisp_Object code = Fget (keysym, Qcharacter_of_keysym, Qnil);
867
+ − 4263 Ichar c = (CHAR_OR_CHAR_INTP (code)
+ − 4264 ? XCHAR_OR_CHAR_INT (code) : (Ichar) -1);
428
+ − 4265 /* Calling Fsingle_key_description() would cons more */
+ − 4266 #if 0 /* This is bogus */
+ − 4267 if (EQ (keysym, QKlinefeed))
+ − 4268 buffer_insert_c_string (buf, "LFD");
+ − 4269 else if (EQ (keysym, QKtab))
+ − 4270 buffer_insert_c_string (buf, "TAB");
+ − 4271 else if (EQ (keysym, QKreturn))
+ − 4272 buffer_insert_c_string (buf, "RET");
+ − 4273 else if (EQ (keysym, QKescape))
+ − 4274 buffer_insert_c_string (buf, "ESC");
+ − 4275 else if (EQ (keysym, QKdelete))
+ − 4276 buffer_insert_c_string (buf, "DEL");
+ − 4277 else if (EQ (keysym, QKspace))
+ − 4278 buffer_insert_c_string (buf, "SPC");
+ − 4279 else if (EQ (keysym, QKbackspace))
+ − 4280 buffer_insert_c_string (buf, "BS");
+ − 4281 else
+ − 4282 #endif
+ − 4283 if (c >= printable_min)
+ − 4284 buffer_insert_emacs_char (buf, c);
+ − 4285 else buffer_insert1 (buf, Fsymbol_name (keysym));
+ − 4286 }
+ − 4287 else if (CHARP (keysym))
+ − 4288 buffer_insert_emacs_char (buf, XCHAR (keysym));
+ − 4289 else
+ − 4290 buffer_insert_c_string (buf, "---bad keysym---");
+ − 4291
+ − 4292 if (elided)
+ − 4293 elided = 0;
+ − 4294 else
+ − 4295 {
+ − 4296 int k = 0;
+ − 4297
+ − 4298 while (elide_next_two_p (list))
+ − 4299 {
+ − 4300 k++;
+ − 4301 list = XCDR (list);
+ − 4302 }
+ − 4303 if (k != 0)
+ − 4304 {
+ − 4305 if (k == 1)
+ − 4306 buffer_insert_c_string (buf, ", ");
+ − 4307 else
+ − 4308 buffer_insert_c_string (buf, " .. ");
+ − 4309 elided = 1;
+ − 4310 continue;
+ − 4311 }
+ − 4312 }
+ − 4313
+ − 4314 /* Print a description of the definition of this character. */
+ − 4315 (*elt_describer) (XCDR (XCAR (list)), buffer);
+ − 4316 list = XCDR (list);
+ − 4317 }
+ − 4318 }
+ − 4319 UNGCPRO;
+ − 4320 }
+ − 4321
+ − 4322
+ − 4323 void
+ − 4324 syms_of_keymap (void)
+ − 4325 {
442
+ − 4326 INIT_LRECORD_IMPLEMENTATION (keymap);
+ − 4327
502
+ − 4328 DEFSYMBOL (Qminor_mode_map_alist);
+ − 4329
+ − 4330 DEFSYMBOL (Qkeymapp);
+ − 4331
+ − 4332 DEFSYMBOL (Qsuppress_keymap);
+ − 4333
+ − 4334 DEFSYMBOL (Qmodeline_map);
+ − 4335 DEFSYMBOL (Qtoolbar_map);
428
+ − 4336
+ − 4337 DEFSUBR (Fkeymap_parents);
+ − 4338 DEFSUBR (Fset_keymap_parents);
+ − 4339 DEFSUBR (Fkeymap_name);
+ − 4340 DEFSUBR (Fset_keymap_name);
+ − 4341 DEFSUBR (Fkeymap_prompt);
+ − 4342 DEFSUBR (Fset_keymap_prompt);
+ − 4343 DEFSUBR (Fkeymap_default_binding);
+ − 4344 DEFSUBR (Fset_keymap_default_binding);
+ − 4345
+ − 4346 DEFSUBR (Fkeymapp);
+ − 4347 DEFSUBR (Fmake_keymap);
+ − 4348 DEFSUBR (Fmake_sparse_keymap);
+ − 4349
+ − 4350 DEFSUBR (Fcopy_keymap);
+ − 4351 DEFSUBR (Fkeymap_fullness);
+ − 4352 DEFSUBR (Fmap_keymap);
+ − 4353 DEFSUBR (Fevent_matches_key_specifier_p);
+ − 4354 DEFSUBR (Fdefine_key);
+ − 4355 DEFSUBR (Flookup_key);
+ − 4356 DEFSUBR (Fkey_binding);
+ − 4357 DEFSUBR (Fuse_global_map);
+ − 4358 DEFSUBR (Fuse_local_map);
+ − 4359 DEFSUBR (Fcurrent_local_map);
+ − 4360 DEFSUBR (Fcurrent_global_map);
+ − 4361 DEFSUBR (Fcurrent_keymaps);
+ − 4362 DEFSUBR (Faccessible_keymaps);
+ − 4363 DEFSUBR (Fkey_description);
+ − 4364 DEFSUBR (Fsingle_key_description);
+ − 4365 DEFSUBR (Fwhere_is_internal);
+ − 4366 DEFSUBR (Fdescribe_bindings_internal);
+ − 4367
+ − 4368 DEFSUBR (Ftext_char_description);
+ − 4369
502
+ − 4370 DEFSYMBOL (Qcontrol);
+ − 4371 DEFSYMBOL (Qctrl);
+ − 4372 DEFSYMBOL (Qmeta);
+ − 4373 DEFSYMBOL (Qsuper);
+ − 4374 DEFSYMBOL (Qhyper);
+ − 4375 DEFSYMBOL (Qalt);
+ − 4376 DEFSYMBOL (Qshift);
+ − 4377 DEFSYMBOL (Qbutton0);
+ − 4378 DEFSYMBOL (Qbutton1);
+ − 4379 DEFSYMBOL (Qbutton2);
+ − 4380 DEFSYMBOL (Qbutton3);
+ − 4381 DEFSYMBOL (Qbutton4);
+ − 4382 DEFSYMBOL (Qbutton5);
+ − 4383 DEFSYMBOL (Qbutton6);
+ − 4384 DEFSYMBOL (Qbutton7);
+ − 4385 DEFSYMBOL (Qbutton0up);
+ − 4386 DEFSYMBOL (Qbutton1up);
+ − 4387 DEFSYMBOL (Qbutton2up);
+ − 4388 DEFSYMBOL (Qbutton3up);
+ − 4389 DEFSYMBOL (Qbutton4up);
+ − 4390 DEFSYMBOL (Qbutton5up);
+ − 4391 DEFSYMBOL (Qbutton6up);
+ − 4392 DEFSYMBOL (Qbutton7up);
+ − 4393 DEFSYMBOL (Qmouse_1);
+ − 4394 DEFSYMBOL (Qmouse_2);
+ − 4395 DEFSYMBOL (Qmouse_3);
+ − 4396 DEFSYMBOL (Qmouse_4);
+ − 4397 DEFSYMBOL (Qmouse_5);
+ − 4398 DEFSYMBOL (Qmouse_6);
+ − 4399 DEFSYMBOL (Qmouse_7);
+ − 4400 DEFSYMBOL (Qdown_mouse_1);
+ − 4401 DEFSYMBOL (Qdown_mouse_2);
+ − 4402 DEFSYMBOL (Qdown_mouse_3);
+ − 4403 DEFSYMBOL (Qdown_mouse_4);
+ − 4404 DEFSYMBOL (Qdown_mouse_5);
+ − 4405 DEFSYMBOL (Qdown_mouse_6);
+ − 4406 DEFSYMBOL (Qdown_mouse_7);
+ − 4407 DEFSYMBOL (Qmenu_selection);
+ − 4408 DEFSYMBOL (QLFD);
+ − 4409 DEFSYMBOL (QTAB);
+ − 4410 DEFSYMBOL (QRET);
+ − 4411 DEFSYMBOL (QESC);
+ − 4412 DEFSYMBOL (QDEL);
+ − 4413 DEFSYMBOL (QSPC);
+ − 4414 DEFSYMBOL (QBS);
428
+ − 4415 }
+ − 4416
+ − 4417 void
+ − 4418 vars_of_keymap (void)
+ − 4419 {
+ − 4420 DEFVAR_LISP ("meta-prefix-char", &Vmeta_prefix_char /*
+ − 4421 Meta-prefix character.
+ − 4422 This character followed by some character `foo' turns into `Meta-foo'.
+ − 4423 This can be any form recognized as a single key specifier.
+ − 4424 To disable the meta-prefix-char, set it to a negative number.
+ − 4425 */ );
+ − 4426 Vmeta_prefix_char = make_char (033);
+ − 4427
+ − 4428 DEFVAR_LISP ("mouse-grabbed-buffer", &Vmouse_grabbed_buffer /*
+ − 4429 A buffer which should be consulted first for all mouse activity.
+ − 4430 When a mouse-click is processed, it will first be looked up in the
+ − 4431 local-map of this buffer, and then through the normal mechanism if there
+ − 4432 is no binding for that click. This buffer's value of `mode-motion-hook'
+ − 4433 will be consulted instead of the `mode-motion-hook' of the buffer of the
+ − 4434 window under the mouse. You should *bind* this, not set it.
+ − 4435 */ );
+ − 4436 Vmouse_grabbed_buffer = Qnil;
+ − 4437
+ − 4438 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map /*
+ − 4439 Keymap that overrides all other local keymaps.
+ − 4440 If this variable is non-nil, it is used as a keymap instead of the
+ − 4441 buffer's local map, and the minor mode keymaps and extent-local keymaps.
+ − 4442 You should *bind* this, not set it.
+ − 4443 */ );
+ − 4444 Voverriding_local_map = Qnil;
+ − 4445
+ − 4446 Fset (Qminor_mode_map_alist, Qnil);
+ − 4447
+ − 4448 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map /*
+ − 4449 Keymap of key translations that can override keymaps.
2027
+ − 4450
+ − 4451 This keymap works like `function-key-map', but is searched before it,
428
+ − 4452 and applies even for keys that have ordinary bindings.
2027
+ − 4453
+ − 4454 The `read-key-sequence' function replaces any subsequence bound by
+ − 4455 `key-translation-map' with its binding. More precisely, when the active
+ − 4456 keymaps have no binding for the current key sequence but
+ − 4457 `key-translation-map' binds a suffix of the sequence to a vector or string,
+ − 4458 `read-key-sequence' replaces the matching suffix with its binding, and
+ − 4459 continues with the new sequence. See `key-binding' for details.
+ − 4460
+ − 4461 The events that come from bindings in `key-translation-map' are not
+ − 4462 themselves looked up in `key-translation-map'.
+ − 4463
+ − 4464 #### FIXME: stolen from `function-key-map'; need better example.
+ − 4465 #### I guess you could implement a Dvorak keyboard with this?
+ − 4466 For example, suppose `key-translation-map' binds `ESC O P' to [f1].
+ − 4467 Typing `ESC O P' to `read-key-sequence' would return
+ − 4468 \[#<keypress-event f1>]. Typing `C-x ESC O P' would return
+ − 4469 \[#<keypress-event control-X> #<keypress-event f1>]. If [f1]
+ − 4470 were a prefix key, typing `ESC O P x' would return
+ − 4471 \[#<keypress-event f1> #<keypress-event x>].
428
+ − 4472 */ );
+ − 4473 Vkey_translation_map = Qnil;
+ − 4474
771
+ − 4475 DEFVAR_LISP ("global-tty-map", &Vglobal_tty_map /*
+ − 4476 Global keymap that applies only to TTY's.
+ − 4477 Key bindings are looked up in this map just before looking in the global map,
+ − 4478 but only when the current console is a TTY console. See also
+ − 4479 `global-window-system-map'.
+ − 4480 */ );
+ − 4481 Vglobal_tty_map = Qnil;
+ − 4482
+ − 4483 DEFVAR_LISP ("global-window-system-map", &Vglobal_window_system_map /*
+ − 4484 Global keymap that applies only to window systems.
+ − 4485 Key bindings are looked up in this map just before looking in the global map,
+ − 4486 but only when the current console is not a TTY console. See also
+ − 4487 `global-tty-map'.
+ − 4488 */ );
+ − 4489 Vglobal_window_system_map = Qnil;
+ − 4490
428
+ − 4491 DEFVAR_LISP ("vertical-divider-map", &Vvertical_divider_map /*
+ − 4492 Keymap which handles mouse clicks over vertical dividers.
+ − 4493 */ );
+ − 4494 Vvertical_divider_map = Qnil;
+ − 4495
+ − 4496 DEFVAR_INT ("keymap-tick", &keymap_tick /*
+ − 4497 Incremented for each change to any keymap.
+ − 4498 */ );
+ − 4499 keymap_tick = 0;
+ − 4500
+ − 4501 staticpro (&Vcurrent_global_map);
+ − 4502
867
+ − 4503 Vsingle_space_string = make_string ((const Ibyte *) " ", 1);
428
+ − 4504 staticpro (&Vsingle_space_string);
+ − 4505 }
+ − 4506
+ − 4507 void
+ − 4508 complex_vars_of_keymap (void)
+ − 4509 {
+ − 4510 /* This function can GC */
+ − 4511 Lisp_Object ESC_prefix = intern ("ESC-prefix");
+ − 4512 Lisp_Object meta_disgustitute;
+ − 4513
+ − 4514 Vcurrent_global_map = Fmake_keymap (Qnil);
771
+ − 4515 Vglobal_tty_map = Fmake_keymap (intern ("global-tty-map"));
+ − 4516 Vglobal_window_system_map =
+ − 4517 Fmake_keymap (intern ("global-window-system-map"));
428
+ − 4518
+ − 4519 meta_disgustitute = Fmake_keymap (Qnil);
+ − 4520 Ffset (ESC_prefix, meta_disgustitute);
+ − 4521 /* no need to protect meta_disgustitute, though */
442
+ − 4522 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META),
428
+ − 4523 XKEYMAP (Vcurrent_global_map),
+ − 4524 meta_disgustitute);
+ − 4525 XKEYMAP (Vcurrent_global_map)->sub_maps_cache = Qt;
+ − 4526
+ − 4527 Vkey_translation_map = Fmake_sparse_keymap (intern ("key-translation-map"));
+ − 4528 }