Mercurial > hg > xemacs-beta
comparison src/keymap.c @ 404:2f8bb876ab1d r21-2-32
Import from CVS: tag r21-2-32
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:16:07 +0200 |
parents | a86b2b5e0111 |
children | b8cc9ab3f761 |
comparison
equal
deleted
inserted
replaced
403:9f011ab08d48 | 404:2f8bb876ab1d |
---|---|
35 #include "events.h" | 35 #include "events.h" |
36 #include "frame.h" | 36 #include "frame.h" |
37 #include "insdel.h" | 37 #include "insdel.h" |
38 #include "keymap.h" | 38 #include "keymap.h" |
39 #include "window.h" | 39 #include "window.h" |
40 | |
41 #ifdef WINDOWSNT | |
42 /* Hmm, under unix we want X modifiers, under NT we want X modifiers if | |
43 we are running X and Windows modifiers otherwise. | |
44 gak. This is a kludge until we support multiple native GUIs! | |
45 */ | |
46 #undef MOD_ALT | |
47 #undef MOD_CONTROL | |
48 #undef MOD_SHIFT | |
49 #endif | |
50 | |
51 #include "events-mod.h" | 40 #include "events-mod.h" |
52 | 41 |
53 | 42 |
54 /* A keymap contains six slots: | 43 /* A keymap contains six slots: |
55 | 44 |
97 off of the main map. The hash key for a modifier combination is | 86 off of the main map. The hash key for a modifier combination is |
98 an integer, computed by MAKE_MODIFIER_HASH_KEY(). | 87 an integer, computed by MAKE_MODIFIER_HASH_KEY(). |
99 | 88 |
100 If the key `C-a' was bound to some command, the hierarchy would look like | 89 If the key `C-a' was bound to some command, the hierarchy would look like |
101 | 90 |
102 keymap-1: associates the integer MOD_CONTROL with keymap-2 | 91 keymap-1: associates the integer XEMACS_MOD_CONTROL with keymap-2 |
103 keymap-2: associates "a" with the command | 92 keymap-2: associates "a" with the command |
104 | 93 |
105 Similarly, if the key `C-H-a' was bound to some command, the hierarchy | 94 Similarly, if the key `C-H-a' was bound to some command, the hierarchy |
106 would look like | 95 would look like |
107 | 96 |
108 keymap-1: associates the integer (MOD_CONTROL | MOD_HYPER) | 97 keymap-1: associates the integer (XEMACS_MOD_CONTROL | XEMACS_MOD_HYPER) |
109 with keymap-2 | 98 with keymap-2 |
110 keymap-2: associates "a" with the command | 99 keymap-2: associates "a" with the command |
111 | 100 |
112 Note that a special exception is made for the meta modifier, in order | 101 Note that a special exception is made for the meta modifier, in order |
113 to deal with ESC/meta lossage. Any key combination containing the | 102 to deal with ESC/meta lossage. Any key combination containing the |
114 meta modifier is first indexed off of the main map into the meta | 103 meta modifier is first indexed off of the main map into the meta |
115 submap (with hash key MOD_META) and then indexed off of the | 104 submap (with hash key XEMACS_MOD_META) and then indexed off of the |
116 meta submap with the meta modifier removed from the key combination. | 105 meta submap with the meta modifier removed from the key combination. |
117 For example, when associating a command with C-M-H-a, we'd have | 106 For example, when associating a command with C-M-H-a, we'd have |
118 | 107 |
119 keymap-1: associates the integer MOD_META with keymap-2 | 108 keymap-1: associates the integer XEMACS_MOD_META with keymap-2 |
120 keymap-2: associates the integer (MOD_CONTROL | MOD_HYPER) | 109 keymap-2: associates the integer (XEMACS_MOD_CONTROL | XEMACS_MOD_HYPER) |
121 with keymap-3 | 110 with keymap-3 |
122 keymap-3: associates "a" with the command | 111 keymap-3: associates "a" with the command |
123 | 112 |
124 Note that keymap-2 might have normal bindings in it; these would be | 113 Note that keymap-2 might have normal bindings in it; these would be |
125 for key combinations containing only the meta modifier, such as | 114 for key combinations containing only the meta modifier, such as |
129 then that would make the key "C-M-H-a" be a prefix character. | 118 then that would make the key "C-M-H-a" be a prefix character. |
130 | 119 |
131 Note that this new model of keymaps takes much of the magic away from | 120 Note that this new model of keymaps takes much of the magic away from |
132 the Escape key: the value of the variable `esc-map' is no longer indexed | 121 the Escape key: the value of the variable `esc-map' is no longer indexed |
133 in the `global-map' under the ESC key. It's indexed under the integer | 122 in the `global-map' under the ESC key. It's indexed under the integer |
134 MOD_META. This is not user-visible, however; none of the "bucky" | 123 XEMACS_MOD_META. This is not user-visible, however; none of the "bucky" |
135 maps are. | 124 maps are. |
136 | 125 |
137 There is a hack in Flookup_key() that makes (lookup-key global-map "\^[") | 126 There is a hack in Flookup_key() that makes (lookup-key global-map "\^[") |
138 and (define-key some-random-map "\^[" my-esc-map) work as before, for | 127 and (define-key some-random-map "\^[" my-esc-map) work as before, for |
139 compatibility. | 128 compatibility. |
404 | 393 |
405 /************************************************************************/ | 394 /************************************************************************/ |
406 /* Some low-level functions */ | 395 /* Some low-level functions */ |
407 /************************************************************************/ | 396 /************************************************************************/ |
408 | 397 |
409 static unsigned int | 398 static int |
410 bucky_sym_to_bucky_bit (Lisp_Object sym) | 399 bucky_sym_to_bucky_bit (Lisp_Object sym) |
411 { | 400 { |
412 if (EQ (sym, Qcontrol)) return MOD_CONTROL; | 401 if (EQ (sym, Qcontrol)) return XEMACS_MOD_CONTROL; |
413 if (EQ (sym, Qmeta)) return MOD_META; | 402 if (EQ (sym, Qmeta)) return XEMACS_MOD_META; |
414 if (EQ (sym, Qsuper)) return MOD_SUPER; | 403 if (EQ (sym, Qsuper)) return XEMACS_MOD_SUPER; |
415 if (EQ (sym, Qhyper)) return MOD_HYPER; | 404 if (EQ (sym, Qhyper)) return XEMACS_MOD_HYPER; |
416 if (EQ (sym, Qalt)) return MOD_ALT; | 405 if (EQ (sym, Qalt)) return XEMACS_MOD_ALT; |
417 if (EQ (sym, Qsymbol)) return MOD_ALT; /* #### - reverse compat */ | 406 if (EQ (sym, Qsymbol)) return XEMACS_MOD_ALT; /* #### - reverse compat */ |
418 if (EQ (sym, Qshift)) return MOD_SHIFT; | 407 if (EQ (sym, Qshift)) return XEMACS_MOD_SHIFT; |
419 | 408 |
420 return 0; | 409 return 0; |
421 } | 410 } |
422 | 411 |
423 static Lisp_Object | 412 static Lisp_Object |
424 control_meta_superify (Lisp_Object frob, unsigned int modifiers) | 413 control_meta_superify (Lisp_Object frob, int modifiers) |
425 { | 414 { |
426 if (modifiers == 0) | 415 if (modifiers == 0) |
427 return frob; | 416 return frob; |
428 frob = Fcons (frob, Qnil); | 417 frob = Fcons (frob, Qnil); |
429 if (modifiers & MOD_SHIFT) frob = Fcons (Qshift, frob); | 418 if (modifiers & XEMACS_MOD_SHIFT) frob = Fcons (Qshift, frob); |
430 if (modifiers & MOD_ALT) frob = Fcons (Qalt, frob); | 419 if (modifiers & XEMACS_MOD_ALT) frob = Fcons (Qalt, frob); |
431 if (modifiers & MOD_HYPER) frob = Fcons (Qhyper, frob); | 420 if (modifiers & XEMACS_MOD_HYPER) frob = Fcons (Qhyper, frob); |
432 if (modifiers & MOD_SUPER) frob = Fcons (Qsuper, frob); | 421 if (modifiers & XEMACS_MOD_SUPER) frob = Fcons (Qsuper, frob); |
433 if (modifiers & MOD_CONTROL) frob = Fcons (Qcontrol, frob); | 422 if (modifiers & XEMACS_MOD_CONTROL) frob = Fcons (Qcontrol, frob); |
434 if (modifiers & MOD_META) frob = Fcons (Qmeta, frob); | 423 if (modifiers & XEMACS_MOD_META) frob = Fcons (Qmeta, frob); |
435 return frob; | 424 return frob; |
436 } | 425 } |
437 | 426 |
438 static Lisp_Object | 427 static Lisp_Object |
439 make_key_description (const struct key_data *key, int prettify) | 428 make_key_description (const struct key_data *key, int prettify) |
440 { | 429 { |
441 Lisp_Object keysym = key->keysym; | 430 Lisp_Object keysym = key->keysym; |
442 unsigned int modifiers = key->modifiers; | 431 int modifiers = key->modifiers; |
443 | 432 |
444 if (prettify && CHARP (keysym)) | 433 if (prettify && CHARP (keysym)) |
445 { | 434 { |
446 /* This is a little slow, but (control a) is prettier than (control 65). | 435 /* This is a little slow, but (control a) is prettier than (control 65). |
447 It's now ok to do this for digit-chars too, since we've fixed the | 436 It's now ok to do this for digit-chars too, since we've fixed the |
468 int keys_so_far, int accept_default); | 457 int keys_so_far, int accept_default); |
469 | 458 |
470 /* Relies on caller to gc-protect args */ | 459 /* Relies on caller to gc-protect args */ |
471 static Lisp_Object | 460 static Lisp_Object |
472 keymap_lookup_directly (Lisp_Object keymap, | 461 keymap_lookup_directly (Lisp_Object keymap, |
473 Lisp_Object keysym, unsigned int modifiers) | 462 Lisp_Object keysym, int modifiers) |
474 { | 463 { |
475 Lisp_Keymap *k; | 464 Lisp_Keymap *k; |
476 | 465 |
477 if ((modifiers & ~(MOD_CONTROL | MOD_META | MOD_SUPER | MOD_HYPER | 466 if ((modifiers & ~(XEMACS_MOD_CONTROL | XEMACS_MOD_META | XEMACS_MOD_SUPER | XEMACS_MOD_HYPER |
478 | MOD_ALT | MOD_SHIFT)) != 0) | 467 | XEMACS_MOD_ALT | XEMACS_MOD_SHIFT)) != 0) |
479 abort (); | 468 abort (); |
480 | 469 |
481 k = XKEYMAP (keymap); | 470 k = XKEYMAP (keymap); |
482 | 471 |
483 /* If the keysym is a one-character symbol, use the char code instead. */ | 472 /* If the keysym is a one-character symbol, use the char code instead. */ |
486 Lisp_Object i_fart_on_gcc = | 475 Lisp_Object i_fart_on_gcc = |
487 make_char (string_char (XSYMBOL (keysym)->name, 0)); | 476 make_char (string_char (XSYMBOL (keysym)->name, 0)); |
488 keysym = i_fart_on_gcc; | 477 keysym = i_fart_on_gcc; |
489 } | 478 } |
490 | 479 |
491 if (modifiers & MOD_META) /* Utterly hateful ESC lossage */ | 480 if (modifiers & XEMACS_MOD_META) /* Utterly hateful ESC lossage */ |
492 { | 481 { |
493 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META), | 482 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), |
494 k->table, Qnil); | 483 k->table, Qnil); |
495 if (NILP (submap)) | 484 if (NILP (submap)) |
496 return Qnil; | 485 return Qnil; |
497 k = XKEYMAP (submap); | 486 k = XKEYMAP (submap); |
498 modifiers &= ~MOD_META; | 487 modifiers &= ~XEMACS_MOD_META; |
499 } | 488 } |
500 | 489 |
501 if (modifiers != 0) | 490 if (modifiers != 0) |
502 { | 491 { |
503 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (modifiers), | 492 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (modifiers), |
627 keymap_tick++; | 616 keymap_tick++; |
628 } | 617 } |
629 | 618 |
630 | 619 |
631 static Lisp_Object | 620 static Lisp_Object |
632 create_bucky_submap (Lisp_Keymap *k, unsigned int modifiers, | 621 create_bucky_submap (Lisp_Keymap *k, int modifiers, |
633 Lisp_Object parent_for_debugging_info) | 622 Lisp_Object parent_for_debugging_info) |
634 { | 623 { |
635 Lisp_Object submap = Fmake_sparse_keymap (Qnil); | 624 Lisp_Object submap = Fmake_sparse_keymap (Qnil); |
636 /* User won't see this, but it is nice for debugging Emacs */ | 625 /* User won't see this, but it is nice for debugging Emacs */ |
637 XKEYMAP (submap)->name | 626 XKEYMAP (submap)->name |
647 static void | 636 static void |
648 keymap_store (Lisp_Object keymap, const struct key_data *key, | 637 keymap_store (Lisp_Object keymap, const struct key_data *key, |
649 Lisp_Object value) | 638 Lisp_Object value) |
650 { | 639 { |
651 Lisp_Object keysym = key->keysym; | 640 Lisp_Object keysym = key->keysym; |
652 unsigned int modifiers = key->modifiers; | 641 int modifiers = key->modifiers; |
653 Lisp_Keymap *k = XKEYMAP (keymap); | 642 Lisp_Keymap *k = XKEYMAP (keymap); |
654 | 643 |
655 assert ((modifiers & ~(MOD_CONTROL | MOD_META | MOD_SUPER | MOD_HYPER | 644 assert ((modifiers & ~(XEMACS_MOD_CONTROL | XEMACS_MOD_META |
656 | MOD_ALT | MOD_SHIFT)) == 0); | 645 | XEMACS_MOD_SUPER | XEMACS_MOD_HYPER |
646 | XEMACS_MOD_ALT | XEMACS_MOD_SHIFT)) == 0); | |
657 | 647 |
658 /* If the keysym is a one-character symbol, use the char code instead. */ | 648 /* If the keysym is a one-character symbol, use the char code instead. */ |
659 if (SYMBOLP (keysym) && string_char_length (XSYMBOL (keysym)->name) == 1) | 649 if (SYMBOLP (keysym) && string_char_length (XSYMBOL (keysym)->name) == 1) |
660 keysym = make_char (string_char (XSYMBOL (keysym)->name, 0)); | 650 keysym = make_char (string_char (XSYMBOL (keysym)->name, 0)); |
661 | 651 |
662 if (modifiers & MOD_META) /* Utterly hateful ESC lossage */ | 652 if (modifiers & XEMACS_MOD_META) /* Utterly hateful ESC lossage */ |
663 { | 653 { |
664 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META), | 654 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), |
665 k->table, Qnil); | 655 k->table, Qnil); |
666 if (NILP (submap)) | 656 if (NILP (submap)) |
667 submap = create_bucky_submap (k, MOD_META, keymap); | 657 submap = create_bucky_submap (k, XEMACS_MOD_META, keymap); |
668 k = XKEYMAP (submap); | 658 k = XKEYMAP (submap); |
669 modifiers &= ~MOD_META; | 659 modifiers &= ~XEMACS_MOD_META; |
670 } | 660 } |
671 | 661 |
672 if (modifiers != 0) | 662 if (modifiers != 0) |
673 { | 663 { |
674 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (modifiers), | 664 Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (modifiers), |
1256 and perform any necessary canonicalization. */ | 1246 and perform any necessary canonicalization. */ |
1257 | 1247 |
1258 static void | 1248 static void |
1259 define_key_check_and_coerce_keysym (Lisp_Object spec, | 1249 define_key_check_and_coerce_keysym (Lisp_Object spec, |
1260 Lisp_Object *keysym, | 1250 Lisp_Object *keysym, |
1261 unsigned int modifiers) | 1251 int modifiers) |
1262 { | 1252 { |
1263 /* Now, check and massage the trailing keysym specifier. */ | 1253 /* Now, check and massage the trailing keysym specifier. */ |
1264 if (SYMBOLP (*keysym)) | 1254 if (SYMBOLP (*keysym)) |
1265 { | 1255 { |
1266 if (string_char_length (XSYMBOL (*keysym)->name) == 1) | 1256 if (string_char_length (XSYMBOL (*keysym)->name) == 1) |
1279 /* || (XCHAR (*keysym) >= 128 && XCHAR (*keysym) < 160) */) | 1269 /* || (XCHAR (*keysym) >= 128 && XCHAR (*keysym) < 160) */) |
1280 /* yuck! Can't make the above restriction; too many compatibility | 1270 /* yuck! Can't make the above restriction; too many compatibility |
1281 problems ... */ | 1271 problems ... */ |
1282 signal_simple_error ("keysym char must be printable", *keysym); | 1272 signal_simple_error ("keysym char must be printable", *keysym); |
1283 /* #### This bites! I want to be able to write (control shift a) */ | 1273 /* #### This bites! I want to be able to write (control shift a) */ |
1284 if (modifiers & MOD_SHIFT) | 1274 if (modifiers & XEMACS_MOD_SHIFT) |
1285 signal_simple_error | 1275 signal_simple_error |
1286 ("The `shift' modifier may not be applied to ASCII keysyms", | 1276 ("The `shift' modifier may not be applied to ASCII keysyms", |
1287 spec); | 1277 spec); |
1288 } | 1278 } |
1289 else | 1279 else |
1456 returned_value->keysym = spec; | 1446 returned_value->keysym = spec; |
1457 returned_value->modifiers = 0; | 1447 returned_value->modifiers = 0; |
1458 } | 1448 } |
1459 else if (CONSP (spec)) | 1449 else if (CONSP (spec)) |
1460 { | 1450 { |
1461 unsigned int modifiers = 0; | 1451 int modifiers = 0; |
1462 Lisp_Object keysym = Qnil; | 1452 Lisp_Object keysym = Qnil; |
1463 Lisp_Object rest = spec; | 1453 Lisp_Object rest = spec; |
1464 | 1454 |
1465 /* First, parse out the leading modifier symbols. */ | 1455 /* First, parse out the leading modifier symbols. */ |
1466 while (CONSP (rest)) | 1456 while (CONSP (rest)) |
1467 { | 1457 { |
1468 unsigned int modifier; | 1458 int modifier; |
1469 | 1459 |
1470 keysym = XCAR (rest); | 1460 keysym = XCAR (rest); |
1471 modifier = bucky_sym_to_bucky_bit (keysym); | 1461 modifier = bucky_sym_to_bucky_bit (keysym); |
1472 modifiers |= modifier; | 1462 modifiers |= modifier; |
1473 if (!NILP (XCDR (rest))) | 1463 if (!NILP (XCDR (rest))) |
1633 static void | 1623 static void |
1634 define_key_alternate_name (struct key_data *key, | 1624 define_key_alternate_name (struct key_data *key, |
1635 struct key_data *returned_value) | 1625 struct key_data *returned_value) |
1636 { | 1626 { |
1637 Lisp_Object keysym = key->keysym; | 1627 Lisp_Object keysym = key->keysym; |
1638 unsigned int modifiers = key->modifiers; | 1628 int modifiers = key->modifiers; |
1639 unsigned int modifiers_sans_control = (modifiers & (~MOD_CONTROL)); | 1629 int modifiers_sans_control = (modifiers & (~XEMACS_MOD_CONTROL)); |
1640 unsigned int modifiers_sans_meta = (modifiers & (~MOD_META)); | 1630 int modifiers_sans_meta = (modifiers & (~XEMACS_MOD_META)); |
1641 returned_value->keysym = Qnil; /* By default, no "alternate" key */ | 1631 returned_value->keysym = Qnil; /* By default, no "alternate" key */ |
1642 returned_value->modifiers = 0; | 1632 returned_value->modifiers = 0; |
1643 if (modifiers_sans_meta == MOD_CONTROL) | 1633 if (modifiers_sans_meta == XEMACS_MOD_CONTROL) |
1644 { | 1634 { |
1645 if EQ (keysym, QKspace) | 1635 if EQ (keysym, QKspace) |
1646 MACROLET (make_char ('@'), modifiers); | 1636 MACROLET (make_char ('@'), modifiers); |
1647 else if (!CHARP (keysym)) | 1637 else if (!CHARP (keysym)) |
1648 return; | 1638 return; |
1665 } | 1655 } |
1666 } | 1656 } |
1667 else if (modifiers_sans_meta != 0) | 1657 else if (modifiers_sans_meta != 0) |
1668 return; | 1658 return; |
1669 else if (EQ (keysym, QKbackspace)) /* backspace => c-h */ | 1659 else if (EQ (keysym, QKbackspace)) /* backspace => c-h */ |
1670 MACROLET (make_char ('h'), (modifiers | MOD_CONTROL)); | 1660 MACROLET (make_char ('h'), (modifiers | XEMACS_MOD_CONTROL)); |
1671 else if (EQ (keysym, QKtab)) /* tab => c-i */ | 1661 else if (EQ (keysym, QKtab)) /* tab => c-i */ |
1672 MACROLET (make_char ('i'), (modifiers | MOD_CONTROL)); | 1662 MACROLET (make_char ('i'), (modifiers | XEMACS_MOD_CONTROL)); |
1673 else if (EQ (keysym, QKlinefeed)) /* linefeed => c-j */ | 1663 else if (EQ (keysym, QKlinefeed)) /* linefeed => c-j */ |
1674 MACROLET (make_char ('j'), (modifiers | MOD_CONTROL)); | 1664 MACROLET (make_char ('j'), (modifiers | XEMACS_MOD_CONTROL)); |
1675 else if (EQ (keysym, QKreturn)) /* return => c-m */ | 1665 else if (EQ (keysym, QKreturn)) /* return => c-m */ |
1676 MACROLET (make_char ('m'), (modifiers | MOD_CONTROL)); | 1666 MACROLET (make_char ('m'), (modifiers | XEMACS_MOD_CONTROL)); |
1677 else if (EQ (keysym, QKescape)) /* escape => c-[ */ | 1667 else if (EQ (keysym, QKescape)) /* escape => c-[ */ |
1678 MACROLET (make_char ('['), (modifiers | MOD_CONTROL)); | 1668 MACROLET (make_char ('['), (modifiers | XEMACS_MOD_CONTROL)); |
1679 else | 1669 else |
1680 return; | 1670 return; |
1681 #undef MACROLET | 1671 #undef MACROLET |
1682 } | 1672 } |
1683 | 1673 |
1906 */ | 1896 */ |
1907 Lisp_Object meta_map; | 1897 Lisp_Object meta_map; |
1908 struct gcpro ngcpro1; | 1898 struct gcpro ngcpro1; |
1909 | 1899 |
1910 NGCPRO1 (c); | 1900 NGCPRO1 (c); |
1911 meta_map = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META), | 1901 meta_map = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), |
1912 XKEYMAP (keymap)->table, Qnil); | 1902 XKEYMAP (keymap)->table, Qnil); |
1913 if (!NILP (meta_map) | 1903 if (!NILP (meta_map) |
1914 && keymap_fullness (meta_map) != 0) | 1904 && keymap_fullness (meta_map) != 0) |
1915 signal_simple_error_2 | 1905 signal_simple_error_2 |
1916 ("Map contains meta-bindings, can't bind", | 1906 ("Map contains meta-bindings, can't bind", |
1933 raw_key2.modifiers = 0; | 1923 raw_key2.modifiers = 0; |
1934 } | 1924 } |
1935 | 1925 |
1936 if (metized) | 1926 if (metized) |
1937 { | 1927 { |
1938 raw_key1.modifiers |= MOD_META; | 1928 raw_key1.modifiers |= XEMACS_MOD_META; |
1939 raw_key2.modifiers |= MOD_META; | 1929 raw_key2.modifiers |= XEMACS_MOD_META; |
1940 metized = 0; | 1930 metized = 0; |
1941 } | 1931 } |
1942 | 1932 |
1943 /* This crap is to make sure that someone doesn't bind something like | 1933 /* This crap is to make sure that someone doesn't bind something like |
1944 "C-x M-a" while "C-x ESC" has a non-keymap binding. */ | 1934 "C-x M-a" while "C-x ESC" has a non-keymap binding. */ |
1945 if (raw_key1.modifiers & MOD_META) | 1935 if (raw_key1.modifiers & XEMACS_MOD_META) |
1946 ensure_meta_prefix_char_keymapp (keys, idx, keymap); | 1936 ensure_meta_prefix_char_keymapp (keys, idx, keymap); |
1947 | 1937 |
1948 if (++idx == len) | 1938 if (++idx == len) |
1949 { | 1939 { |
1950 keymap_store (keymap, &raw_key1, def); | 1940 keymap_store (keymap, &raw_key1, def); |
2063 /* First look for the prefix-char directly */ | 2053 /* First look for the prefix-char directly */ |
2064 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default); | 2054 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default); |
2065 if (NILP (cmd)) | 2055 if (NILP (cmd)) |
2066 { | 2056 { |
2067 /* Do kludgy return of the meta-map */ | 2057 /* Do kludgy return of the meta-map */ |
2068 cmd = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META), | 2058 cmd = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), |
2069 XKEYMAP (k)->table, Qnil); | 2059 XKEYMAP (k)->table, Qnil); |
2070 } | 2060 } |
2071 } | 2061 } |
2072 else | 2062 else |
2073 { | 2063 { |
2075 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default); | 2065 cmd = keymap_lookup_1 (k, &(raw_keys[0]), accept_default); |
2076 cmd = get_keymap (cmd, 0, 1); | 2066 cmd = get_keymap (cmd, 0, 1); |
2077 if (!NILP (cmd)) | 2067 if (!NILP (cmd)) |
2078 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining, | 2068 cmd = raw_lookup_key (cmd, raw_keys + 1, remaining, |
2079 keys_so_far + 1, accept_default); | 2069 keys_so_far + 1, accept_default); |
2080 else if ((raw_keys[1].modifiers & MOD_META) == 0) | 2070 else if ((raw_keys[1].modifiers & XEMACS_MOD_META) == 0) |
2081 { | 2071 { |
2082 struct key_data metified; | 2072 struct key_data metified; |
2083 metified.keysym = raw_keys[1].keysym; | 2073 metified.keysym = raw_keys[1].keysym; |
2084 metified.modifiers = raw_keys[1].modifiers | MOD_META; | 2074 metified.modifiers = raw_keys[1].modifiers | XEMACS_MOD_META; |
2085 | 2075 |
2086 /* Search for meta-next-char sequence directly */ | 2076 /* Search for meta-next-char sequence directly */ |
2087 cmd = keymap_lookup_1 (k, &metified, accept_default); | 2077 cmd = keymap_lookup_1 (k, &metified, accept_default); |
2088 if (remaining == 1) | 2078 if (remaining == 1) |
2089 ; | 2079 ; |
2741 | 2731 |
2742 struct map_keymap_unsorted_closure | 2732 struct map_keymap_unsorted_closure |
2743 { | 2733 { |
2744 void (*fn) (const struct key_data *, Lisp_Object binding, void *arg); | 2734 void (*fn) (const struct key_data *, Lisp_Object binding, void *arg); |
2745 void *arg; | 2735 void *arg; |
2746 unsigned int modifiers; | 2736 int modifiers; |
2747 }; | 2737 }; |
2748 | 2738 |
2749 /* used by map_keymap() */ | 2739 /* used by map_keymap() */ |
2750 static int | 2740 static int |
2751 map_keymap_unsorted_mapper (Lisp_Object keysym, Lisp_Object value, | 2741 map_keymap_unsorted_mapper (Lisp_Object keysym, Lisp_Object value, |
2752 void *map_keymap_unsorted_closure) | 2742 void *map_keymap_unsorted_closure) |
2753 { | 2743 { |
2754 /* This function can GC */ | 2744 /* This function can GC */ |
2755 struct map_keymap_unsorted_closure *closure = | 2745 struct map_keymap_unsorted_closure *closure = |
2756 (struct map_keymap_unsorted_closure *) map_keymap_unsorted_closure; | 2746 (struct map_keymap_unsorted_closure *) map_keymap_unsorted_closure; |
2757 unsigned int modifiers = closure->modifiers; | 2747 int modifiers = closure->modifiers; |
2758 unsigned int mod_bit; | 2748 int mod_bit; |
2759 mod_bit = MODIFIER_HASH_KEY_BITS (keysym); | 2749 mod_bit = MODIFIER_HASH_KEY_BITS (keysym); |
2760 if (mod_bit != 0) | 2750 if (mod_bit != 0) |
2761 { | 2751 { |
2762 int omod = modifiers; | 2752 int omod = modifiers; |
2763 closure->modifiers = (modifiers | mod_bit); | 2753 closure->modifiers = (modifiers | mod_bit); |
2803 map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2, | 2793 map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2, |
2804 Lisp_Object pred) | 2794 Lisp_Object pred) |
2805 { | 2795 { |
2806 /* obj1 and obj2 are conses with keysyms in their cars. Cdrs are ignored. | 2796 /* obj1 and obj2 are conses with keysyms in their cars. Cdrs are ignored. |
2807 */ | 2797 */ |
2808 unsigned int bit1, bit2; | 2798 int bit1, bit2; |
2809 int sym1_p = 0; | 2799 int sym1_p = 0; |
2810 int sym2_p = 0; | 2800 int sym2_p = 0; |
2811 obj1 = XCAR (obj1); | 2801 obj1 = XCAR (obj1); |
2812 obj2 = XCAR (obj2); | 2802 obj2 = XCAR (obj2); |
2813 | 2803 |
2877 | 2867 |
2878 | 2868 |
2879 /* used by map_keymap() */ | 2869 /* used by map_keymap() */ |
2880 static void | 2870 static void |
2881 map_keymap_sorted (Lisp_Object keymap_table, | 2871 map_keymap_sorted (Lisp_Object keymap_table, |
2882 unsigned int modifiers, | 2872 int modifiers, |
2883 void (*function) (const struct key_data *key, | 2873 void (*function) (const struct key_data *key, |
2884 Lisp_Object binding, | 2874 Lisp_Object binding, |
2885 void *map_keymap_sorted_closure), | 2875 void *map_keymap_sorted_closure), |
2886 void *map_keymap_sorted_closure) | 2876 void *map_keymap_sorted_closure) |
2887 { | 2877 { |
2902 contents = list_sort (contents, Qnil, map_keymap_sort_predicate); | 2892 contents = list_sort (contents, Qnil, map_keymap_sort_predicate); |
2903 for (; !NILP (contents); contents = XCDR (contents)) | 2893 for (; !NILP (contents); contents = XCDR (contents)) |
2904 { | 2894 { |
2905 Lisp_Object keysym = XCAR (XCAR (contents)); | 2895 Lisp_Object keysym = XCAR (XCAR (contents)); |
2906 Lisp_Object binding = XCDR (XCAR (contents)); | 2896 Lisp_Object binding = XCDR (XCAR (contents)); |
2907 unsigned int sub_bits = MODIFIER_HASH_KEY_BITS (keysym); | 2897 int sub_bits = MODIFIER_HASH_KEY_BITS (keysym); |
2908 if (sub_bits != 0) | 2898 if (sub_bits != 0) |
2909 map_keymap_sorted (XKEYMAP (get_keymap (binding, | 2899 map_keymap_sorted (XKEYMAP (get_keymap (binding, |
2910 1, 1))->table, | 2900 1, 1))->table, |
2911 (modifiers | sub_bits), | 2901 (modifiers | sub_bits), |
2912 function, | 2902 function, |
3008 }; | 2998 }; |
3009 | 2999 |
3010 | 3000 |
3011 static void | 3001 static void |
3012 accessible_keymaps_mapper_1 (Lisp_Object keysym, Lisp_Object contents, | 3002 accessible_keymaps_mapper_1 (Lisp_Object keysym, Lisp_Object contents, |
3013 unsigned int modifiers, | 3003 int modifiers, |
3014 struct accessible_keymaps_closure *closure) | 3004 struct accessible_keymaps_closure *closure) |
3015 { | 3005 { |
3016 /* This function can GC */ | 3006 /* This function can GC */ |
3017 unsigned int subbits = MODIFIER_HASH_KEY_BITS (keysym); | 3007 int subbits = MODIFIER_HASH_KEY_BITS (keysym); |
3018 | 3008 |
3019 if (subbits != 0) | 3009 if (subbits != 0) |
3020 { | 3010 { |
3021 Lisp_Object submaps; | 3011 Lisp_Object submaps; |
3022 | 3012 |
3490 returning, then we reconsider. | 3480 returning, then we reconsider. |
3491 firstonly means give up after finding the first match; | 3481 firstonly means give up after finding the first match; |
3492 keys_so_far and modifiers_so_far describe which map we're looking in; | 3482 keys_so_far and modifiers_so_far describe which map we're looking in; |
3493 If we're in the "meta" submap of the map that "C-x 4" is bound to, | 3483 If we're in the "meta" submap of the map that "C-x 4" is bound to, |
3494 then keys_so_far will be {(control x), \4}, and modifiers_so_far | 3484 then keys_so_far will be {(control x), \4}, and modifiers_so_far |
3495 will be MOD_META. That is, keys_so_far is the chain of keys that we | 3485 will be XEMACS_MOD_META. That is, keys_so_far is the chain of keys that we |
3496 have followed, and modifiers_so_far_so_far is the bits (partial keys) | 3486 have followed, and modifiers_so_far_so_far is the bits (partial keys) |
3497 beyond that. | 3487 beyond that. |
3498 | 3488 |
3499 (keys_so_far is a global buffer and the keys_count arg says how much | 3489 (keys_so_far is a global buffer and the keys_count arg says how much |
3500 of it we're currently interested in.) | 3490 of it we're currently interested in.) |
3508 Lisp_Object definition; | 3498 Lisp_Object definition; |
3509 Lisp_Object *shadow; | 3499 Lisp_Object *shadow; |
3510 int shadow_count; | 3500 int shadow_count; |
3511 int firstonly; | 3501 int firstonly; |
3512 int keys_count; | 3502 int keys_count; |
3513 unsigned int modifiers_so_far; | 3503 int modifiers_so_far; |
3514 char *target_buffer; | 3504 char *target_buffer; |
3515 struct key_data *keys_so_far; | 3505 struct key_data *keys_so_far; |
3516 int keys_so_far_total_size; | 3506 int keys_so_far_total_size; |
3517 int keys_so_far_malloced; | 3507 int keys_so_far_malloced; |
3518 }; | 3508 }; |
3524 { | 3514 { |
3525 /* This function can GC */ | 3515 /* This function can GC */ |
3526 struct where_is_closure *c = (struct where_is_closure *) arg; | 3516 struct where_is_closure *c = (struct where_is_closure *) arg; |
3527 Lisp_Object definition = c->definition; | 3517 Lisp_Object definition = c->definition; |
3528 const int firstonly = c->firstonly; | 3518 const int firstonly = c->firstonly; |
3529 const unsigned int keys_count = c->keys_count; | 3519 const int keys_count = c->keys_count; |
3530 const unsigned int modifiers_so_far = c->modifiers_so_far; | 3520 const int modifiers_so_far = c->modifiers_so_far; |
3531 char *target_buffer = c->target_buffer; | 3521 char *target_buffer = c->target_buffer; |
3532 Lisp_Object keys = Fgethash (definition, | 3522 Lisp_Object keys = Fgethash (definition, |
3533 XKEYMAP (map)->inverse_table, | 3523 XKEYMAP (map)->inverse_table, |
3534 Qnil); | 3524 Qnil); |
3535 Lisp_Object submaps; | 3525 Lisp_Object submaps; |
3598 !NILP (submaps); | 3588 !NILP (submaps); |
3599 submaps = XCDR (submaps)) | 3589 submaps = XCDR (submaps)) |
3600 { | 3590 { |
3601 Lisp_Object key = XCAR (XCAR (submaps)); | 3591 Lisp_Object key = XCAR (XCAR (submaps)); |
3602 Lisp_Object submap = XCDR (XCAR (submaps)); | 3592 Lisp_Object submap = XCDR (XCAR (submaps)); |
3603 unsigned int lower_modifiers; | 3593 int lower_modifiers; |
3604 int lower_keys_count = keys_count; | 3594 int lower_keys_count = keys_count; |
3605 unsigned int bucky; | 3595 int bucky; |
3606 | 3596 |
3607 submap = get_keymap (submap, 0, 0); | 3597 submap = get_keymap (submap, 0, 0); |
3608 | 3598 |
3609 if (EQ (submap, map)) | 3599 if (EQ (submap, map)) |
3610 /* Arrgh! Some loser has introduced a loop... */ | 3600 /* Arrgh! Some loser has introduced a loop... */ |
3931 { | 3921 { |
3932 /* This function can GC */ | 3922 /* This function can GC */ |
3933 struct describe_map_closure *closure = | 3923 struct describe_map_closure *closure = |
3934 (struct describe_map_closure *) describe_map_closure; | 3924 (struct describe_map_closure *) describe_map_closure; |
3935 Lisp_Object keysym = key->keysym; | 3925 Lisp_Object keysym = key->keysym; |
3936 unsigned int modifiers = key->modifiers; | 3926 int modifiers = key->modifiers; |
3937 | 3927 |
3938 /* Don't mention suppressed commands. */ | 3928 /* Don't mention suppressed commands. */ |
3939 if (SYMBOLP (binding) | 3929 if (SYMBOLP (binding) |
3940 && !NILP (closure->partial) | 3930 && !NILP (closure->partial) |
3941 && !NILP (Fget (binding, closure->partial, Qnil))) | 3931 && !NILP (Fget (binding, closure->partial, Qnil))) |
4005 { | 3995 { |
4006 /* obj1 and obj2 are conses of the form | 3996 /* obj1 and obj2 are conses of the form |
4007 ( ( <keysym> . <modifiers> ) . <binding> ) | 3997 ( ( <keysym> . <modifiers> ) . <binding> ) |
4008 keysym and modifiers are used, binding is ignored. | 3998 keysym and modifiers are used, binding is ignored. |
4009 */ | 3999 */ |
4010 unsigned int bit1, bit2; | 4000 int bit1, bit2; |
4011 obj1 = XCAR (obj1); | 4001 obj1 = XCAR (obj1); |
4012 obj2 = XCAR (obj2); | 4002 obj2 = XCAR (obj2); |
4013 bit1 = XINT (XCDR (obj1)); | 4003 bit1 = XINT (XCDR (obj1)); |
4014 bit2 = XINT (XCDR (obj2)); | 4004 bit2 = XINT (XCDR (obj2)); |
4015 if (bit1 != bit2) | 4005 if (bit1 != bit2) |
4125 buffer_insert_c_string (buf, "\n"); | 4115 buffer_insert_c_string (buf, "\n"); |
4126 while (!NILP (list)) | 4116 while (!NILP (list)) |
4127 { | 4117 { |
4128 Lisp_Object elt = XCAR (XCAR (list)); | 4118 Lisp_Object elt = XCAR (XCAR (list)); |
4129 Lisp_Object keysym = XCAR (elt); | 4119 Lisp_Object keysym = XCAR (elt); |
4130 unsigned int modifiers = XINT (XCDR (elt)); | 4120 int modifiers = XINT (XCDR (elt)); |
4131 | 4121 |
4132 if (!NILP (elt_prefix)) | 4122 if (!NILP (elt_prefix)) |
4133 buffer_insert_lisp_string (buf, elt_prefix); | 4123 buffer_insert_lisp_string (buf, elt_prefix); |
4134 | 4124 |
4135 if (modifiers & MOD_META) buffer_insert_c_string (buf, "M-"); | 4125 if (modifiers & XEMACS_MOD_META) buffer_insert_c_string (buf, "M-"); |
4136 if (modifiers & MOD_CONTROL) buffer_insert_c_string (buf, "C-"); | 4126 if (modifiers & XEMACS_MOD_CONTROL) buffer_insert_c_string (buf, "C-"); |
4137 if (modifiers & MOD_SUPER) buffer_insert_c_string (buf, "S-"); | 4127 if (modifiers & XEMACS_MOD_SUPER) buffer_insert_c_string (buf, "S-"); |
4138 if (modifiers & MOD_HYPER) buffer_insert_c_string (buf, "H-"); | 4128 if (modifiers & XEMACS_MOD_HYPER) buffer_insert_c_string (buf, "H-"); |
4139 if (modifiers & MOD_ALT) buffer_insert_c_string (buf, "Alt-"); | 4129 if (modifiers & XEMACS_MOD_ALT) buffer_insert_c_string (buf, "Alt-"); |
4140 if (modifiers & MOD_SHIFT) buffer_insert_c_string (buf, "Sh-"); | 4130 if (modifiers & XEMACS_MOD_SHIFT) buffer_insert_c_string (buf, "Sh-"); |
4141 if (SYMBOLP (keysym)) | 4131 if (SYMBOLP (keysym)) |
4142 { | 4132 { |
4143 Lisp_Object code = Fget (keysym, Vcharacter_set_property, Qnil); | 4133 Lisp_Object code = Fget (keysym, Vcharacter_set_property, Qnil); |
4144 Emchar c = (CHAR_OR_CHAR_INTP (code) | 4134 Emchar c = (CHAR_OR_CHAR_INTP (code) |
4145 ? XCHAR_OR_CHAR_INT (code) : (Emchar) -1); | 4135 ? XCHAR_OR_CHAR_INT (code) : (Emchar) -1); |
4355 Vcurrent_global_map = Fmake_keymap (Qnil); | 4345 Vcurrent_global_map = Fmake_keymap (Qnil); |
4356 | 4346 |
4357 meta_disgustitute = Fmake_keymap (Qnil); | 4347 meta_disgustitute = Fmake_keymap (Qnil); |
4358 Ffset (ESC_prefix, meta_disgustitute); | 4348 Ffset (ESC_prefix, meta_disgustitute); |
4359 /* no need to protect meta_disgustitute, though */ | 4349 /* no need to protect meta_disgustitute, though */ |
4360 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (MOD_META), | 4350 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), |
4361 XKEYMAP (Vcurrent_global_map), | 4351 XKEYMAP (Vcurrent_global_map), |
4362 meta_disgustitute); | 4352 meta_disgustitute); |
4363 XKEYMAP (Vcurrent_global_map)->sub_maps_cache = Qt; | 4353 XKEYMAP (Vcurrent_global_map)->sub_maps_cache = Qt; |
4364 | 4354 |
4365 Vkey_translation_map = Fmake_sparse_keymap (intern ("key-translation-map")); | 4355 Vkey_translation_map = Fmake_sparse_keymap (intern ("key-translation-map")); |