X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fkeymap.c;h=3752f0f06e73f3cd49c20efb9a8f29aa8860943d;hb=ea6bff0429fa9def5d23bb99b936916a8ca47deb;hp=49a9fec22a89f7a1c1995c26d6e7b9657ebe99b1;hpb=3e447015251ce6dcde843cbed10d9033d5538622;p=chise%2Fxemacs-chise.git.1 diff --git a/src/keymap.c b/src/keymap.c index 49a9fec..3752f0f 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -37,17 +37,6 @@ Boston, MA 02111-1307, USA. */ #include "insdel.h" #include "keymap.h" #include "window.h" - -#ifdef WINDOWSNT -/* Hmm, under unix we want X modifiers, under NT we want X modifiers if - we are running X and Windows modifiers otherwise. - gak. This is a kludge until we support multiple native GUIs! -*/ -#undef MOD_ALT -#undef MOD_CONTROL -#undef MOD_SHIFT -#endif - #include "events-mod.h" @@ -99,25 +88,25 @@ Boston, MA 02111-1307, USA. */ If the key `C-a' was bound to some command, the hierarchy would look like - keymap-1: associates the integer MOD_CONTROL with keymap-2 + keymap-1: associates the integer XEMACS_MOD_CONTROL with keymap-2 keymap-2: associates "a" with the command Similarly, if the key `C-H-a' was bound to some command, the hierarchy would look like - keymap-1: associates the integer (MOD_CONTROL | MOD_HYPER) + keymap-1: associates the integer (XEMACS_MOD_CONTROL | XEMACS_MOD_HYPER) with keymap-2 keymap-2: associates "a" with the command Note that a special exception is made for the meta modifier, in order to deal with ESC/meta lossage. Any key combination containing the meta modifier is first indexed off of the main map into the meta - submap (with hash key MOD_META) and then indexed off of the + submap (with hash key XEMACS_MOD_META) and then indexed off of the meta submap with the meta modifier removed from the key combination. For example, when associating a command with C-M-H-a, we'd have - keymap-1: associates the integer MOD_META with keymap-2 - keymap-2: associates the integer (MOD_CONTROL | MOD_HYPER) + keymap-1: associates the integer XEMACS_MOD_META with keymap-2 + keymap-2: associates the integer (XEMACS_MOD_CONTROL | XEMACS_MOD_HYPER) with keymap-3 keymap-3: associates "a" with the command @@ -131,7 +120,7 @@ Boston, MA 02111-1307, USA. */ Note that this new model of keymaps takes much of the magic away from the Escape key: the value of the variable `esc-map' is no longer indexed in the `global-map' under the ESC key. It's indexed under the integer - MOD_META. This is not user-visible, however; none of the "bucky" + XEMACS_MOD_META. This is not user-visible, however; none of the "bucky" maps are. There is a hack in Flookup_key() that makes (lookup-key global-map "\^[") @@ -200,7 +189,7 @@ static Lisp_Object Vvertical_divider_map; so that things which care (such as the menubar code) can recompute privately-cached data when the user has changed keybindings. */ -int keymap_tick; +Fixnum keymap_tick; /* Prefixing a key with this character is the same as sending a meta bit. */ Lisp_Object Vmeta_prefix_char; @@ -232,9 +221,13 @@ Lisp_Object Qbutton4up, Qbutton5up, Qbutton6up, Qbutton7up; Lisp_Object Qmenu_selection; /* Emacs compatibility */ -Lisp_Object Qdown_mouse_1, Qdown_mouse_2, Qdown_mouse_3, Qdown_mouse_4, - Qdown_mouse_5; -Lisp_Object Qmouse_1, Qmouse_2, Qmouse_3, Qmouse_4, Qmouse_5; +Lisp_Object Qdown_mouse_1, Qmouse_1; +Lisp_Object Qdown_mouse_2, Qmouse_2; +Lisp_Object Qdown_mouse_3, Qmouse_3; +Lisp_Object Qdown_mouse_4, Qmouse_4; +Lisp_Object Qdown_mouse_5, Qmouse_5; +Lisp_Object Qdown_mouse_6, Qmouse_6; +Lisp_Object Qdown_mouse_7, Qmouse_7; /* Kludge kludge kludge */ Lisp_Object QLFD, QTAB, QRET, QESC, QDEL, QSPC, QBS; @@ -406,32 +399,32 @@ traverse_keymaps (Lisp_Object start_keymap, Lisp_Object start_parents, /* Some low-level functions */ /************************************************************************/ -static unsigned int +static int bucky_sym_to_bucky_bit (Lisp_Object sym) { - if (EQ (sym, Qcontrol)) return MOD_CONTROL; - if (EQ (sym, Qmeta)) return MOD_META; - if (EQ (sym, Qsuper)) return MOD_SUPER; - if (EQ (sym, Qhyper)) return MOD_HYPER; - if (EQ (sym, Qalt)) return MOD_ALT; - if (EQ (sym, Qsymbol)) return MOD_ALT; /* #### - reverse compat */ - if (EQ (sym, Qshift)) return MOD_SHIFT; + if (EQ (sym, Qcontrol)) return XEMACS_MOD_CONTROL; + if (EQ (sym, Qmeta)) return XEMACS_MOD_META; + if (EQ (sym, Qsuper)) return XEMACS_MOD_SUPER; + if (EQ (sym, Qhyper)) return XEMACS_MOD_HYPER; + if (EQ (sym, Qalt)) return XEMACS_MOD_ALT; + if (EQ (sym, Qsymbol)) return XEMACS_MOD_ALT; /* #### - reverse compat */ + if (EQ (sym, Qshift)) return XEMACS_MOD_SHIFT; return 0; } static Lisp_Object -control_meta_superify (Lisp_Object frob, unsigned int modifiers) +control_meta_superify (Lisp_Object frob, int modifiers) { if (modifiers == 0) return frob; frob = Fcons (frob, Qnil); - if (modifiers & MOD_SHIFT) frob = Fcons (Qshift, frob); - if (modifiers & MOD_ALT) frob = Fcons (Qalt, frob); - if (modifiers & MOD_HYPER) frob = Fcons (Qhyper, frob); - if (modifiers & MOD_SUPER) frob = Fcons (Qsuper, frob); - if (modifiers & MOD_CONTROL) frob = Fcons (Qcontrol, frob); - if (modifiers & MOD_META) frob = Fcons (Qmeta, frob); + if (modifiers & XEMACS_MOD_SHIFT) frob = Fcons (Qshift, frob); + if (modifiers & XEMACS_MOD_ALT) frob = Fcons (Qalt, frob); + if (modifiers & XEMACS_MOD_HYPER) frob = Fcons (Qhyper, frob); + if (modifiers & XEMACS_MOD_SUPER) frob = Fcons (Qsuper, frob); + if (modifiers & XEMACS_MOD_CONTROL) frob = Fcons (Qcontrol, frob); + if (modifiers & XEMACS_MOD_META) frob = Fcons (Qmeta, frob); return frob; } @@ -439,7 +432,7 @@ static Lisp_Object make_key_description (const struct key_data *key, int prettify) { Lisp_Object keysym = key->keysym; - unsigned int modifiers = key->modifiers; + int modifiers = key->modifiers; if (prettify && CHARP (keysym)) { @@ -470,13 +463,16 @@ raw_lookup_key (Lisp_Object keymap, /* Relies on caller to gc-protect args */ static Lisp_Object keymap_lookup_directly (Lisp_Object keymap, - Lisp_Object keysym, unsigned int modifiers) + Lisp_Object keysym, int modifiers) { Lisp_Keymap *k; - if ((modifiers & ~(MOD_CONTROL | MOD_META | MOD_SUPER | MOD_HYPER - | MOD_ALT | MOD_SHIFT)) != 0) - abort (); + modifiers &= ~(XEMACS_MOD_BUTTON1 | XEMACS_MOD_BUTTON2 | XEMACS_MOD_BUTTON3 + | XEMACS_MOD_BUTTON4 | XEMACS_MOD_BUTTON5); + if ((modifiers & ~(XEMACS_MOD_CONTROL | XEMACS_MOD_META | XEMACS_MOD_SUPER + | XEMACS_MOD_HYPER | XEMACS_MOD_ALT | XEMACS_MOD_SHIFT)) + != 0) + ABORT (); k = XKEYMAP (keymap); @@ -488,14 +484,14 @@ keymap_lookup_directly (Lisp_Object keymap, keysym = i_fart_on_gcc; } - if (modifiers & MOD_META) /* Utterly hateful ESC lossage */ + if (modifiers & XEMACS_MOD_META) /* Utterly hateful ESC lossage */ { - Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META), + Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), k->table, Qnil); if (NILP (submap)) return Qnil; k = XKEYMAP (submap); - modifiers &= ~MOD_META; + modifiers &= ~XEMACS_MOD_META; } if (modifiers != 0) @@ -551,7 +547,7 @@ keymap_delete_inverse_internal (Lisp_Object inverse_table, Lisp_Object *prev; if (UNBOUNDP (keys)) - abort (); + ABORT (); for (prev = &new_keys, tail = new_keys; ; @@ -629,7 +625,7 @@ keymap_store_internal (Lisp_Object keysym, Lisp_Keymap *keymap, static Lisp_Object -create_bucky_submap (Lisp_Keymap *k, unsigned int modifiers, +create_bucky_submap (Lisp_Keymap *k, int modifiers, Lisp_Object parent_for_debugging_info) { Lisp_Object submap = Fmake_sparse_keymap (Qnil); @@ -649,24 +645,27 @@ keymap_store (Lisp_Object keymap, const struct key_data *key, Lisp_Object value) { Lisp_Object keysym = key->keysym; - unsigned int modifiers = key->modifiers; + int modifiers = key->modifiers; Lisp_Keymap *k = XKEYMAP (keymap); - assert ((modifiers & ~(MOD_CONTROL | MOD_META | MOD_SUPER | MOD_HYPER - | MOD_ALT | MOD_SHIFT)) == 0); + modifiers &= ~(XEMACS_MOD_BUTTON1 | XEMACS_MOD_BUTTON2 | XEMACS_MOD_BUTTON3 + | XEMACS_MOD_BUTTON4 | XEMACS_MOD_BUTTON5); + assert ((modifiers & ~(XEMACS_MOD_CONTROL | XEMACS_MOD_META + | XEMACS_MOD_SUPER | XEMACS_MOD_HYPER + | XEMACS_MOD_ALT | XEMACS_MOD_SHIFT)) == 0); /* If the keysym is a one-character symbol, use the char code instead. */ if (SYMBOLP (keysym) && string_char_length (XSYMBOL (keysym)->name) == 1) keysym = make_char (string_char (XSYMBOL (keysym)->name, 0)); - if (modifiers & MOD_META) /* Utterly hateful ESC lossage */ + if (modifiers & XEMACS_MOD_META) /* Utterly hateful ESC lossage */ { - Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META), + Lisp_Object submap = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), k->table, Qnil); if (NILP (submap)) - submap = create_bucky_submap (k, MOD_META, keymap); + submap = create_bucky_submap (k, XEMACS_MOD_META, keymap); k = XKEYMAP (submap); - modifiers &= ~MOD_META; + modifiers &= ~XEMACS_MOD_META; } if (modifiers != 0) @@ -800,9 +799,9 @@ it is not used except when printing the keymap. DEFUN ("make-sparse-keymap", Fmake_sparse_keymap, 0, 1, 0, /* Construct and return a new keymap object. All entries in it are nil, meaning "command undefined". The only -difference between this function and make-keymap is that this function +difference between this function and `make-keymap' is that this function returns a "smaller" keymap (one that is expected to contain fewer -entries). As keymaps dynamically resize, the distinction is not great. +entries). As keymaps dynamically resize, this distinction is not great. Optional argument NAME specifies a name to assign to the keymap, as in `set-keymap-name'. This name is only a debugging convenience; @@ -973,7 +972,7 @@ parents nor the current global map are searched for key bindings. } DEFUN ("keymapp", Fkeymapp, 1, 1, 0, /* -Return t if ARG is a keymap object. +Return t if OBJECT is a keymap object. The keymap may be autoloaded first if necessary. */ (object)) @@ -1016,10 +1015,8 @@ get_keymap (Lisp_Object object, int errorp, int autoload) && EQ (XCAR (tem), Qautoload) && EQ (Fcar (Fcdr (Fcdr (Fcdr (Fcdr (tem))))), Qkeymap)) { - struct gcpro gcpro1, gcpro2; - GCPRO2 (tem, object); + /* do_autoload GCPROs both arguments */ do_autoload (tem, object); - UNGCPRO; } else if (errorp) object = wrong_type_argument (Qkeymapp, object); @@ -1069,7 +1066,7 @@ get_keyelt (Lisp_Object object, int accept_default) if (!INTP (XCDR (idx))) return Qnil; indirection.keysym = XCAR (idx); - indirection.modifiers = XINT (XCDR (idx)); + indirection.modifiers = (unsigned char) XINT (XCDR (idx)); } else if (SYMBOLP (idx)) { @@ -1258,7 +1255,7 @@ Return the number of bindings in the keymap. static void define_key_check_and_coerce_keysym (Lisp_Object spec, Lisp_Object *keysym, - unsigned int modifiers) + int modifiers) { /* Now, check and massage the trailing keysym specifier. */ if (SYMBOLP (*keysym)) @@ -1281,7 +1278,7 @@ define_key_check_and_coerce_keysym (Lisp_Object spec, problems ... */ signal_simple_error ("keysym char must be printable", *keysym); /* #### This bites! I want to be able to write (control shift a) */ - if (modifiers & MOD_SHIFT) + if (modifiers & XEMACS_MOD_SHIFT) signal_simple_error ("The `shift' modifier may not be applied to ASCII keysyms", spec); @@ -1371,6 +1368,10 @@ define_key_check_and_coerce_keysym (Lisp_Object spec, *keysym = Qbutton4; else if (EQ(*keysym, Qdown_mouse_5)) *keysym = Qbutton5; + else if (EQ(*keysym, Qdown_mouse_6)) + *keysym = Qbutton6; + else if (EQ(*keysym, Qdown_mouse_7)) + *keysym = Qbutton7; else if (EQ(*keysym, Qmouse_1)) *keysym = Qbutton1up; else if (EQ(*keysym, Qmouse_2)) @@ -1381,6 +1382,10 @@ define_key_check_and_coerce_keysym (Lisp_Object spec, *keysym = Qbutton4up; else if (EQ(*keysym, Qmouse_5)) *keysym = Qbutton5up; + else if (EQ(*keysym, Qmouse_6)) + *keysym = Qbutton6up; + else if (EQ(*keysym, Qmouse_7)) + *keysym = Qbutton7up; } } @@ -1458,14 +1463,14 @@ define_key_parser (Lisp_Object spec, struct key_data *returned_value) } else if (CONSP (spec)) { - unsigned int modifiers = 0; + int modifiers = 0; Lisp_Object keysym = Qnil; Lisp_Object rest = spec; /* First, parse out the leading modifier symbols. */ while (CONSP (rest)) { - unsigned int modifier; + int modifier; keysym = XCAR (rest); modifier = bucky_sym_to_bucky_bit (keysym); @@ -1547,7 +1552,7 @@ key_desc_list_to_event (Lisp_Object list, Lisp_Object event, int event_matches_key_specifier_p (Lisp_Event *event, Lisp_Object key_specifier) { - Lisp_Object event2; + Lisp_Object event2 = Qnil; int retval; struct gcpro gcpro1; @@ -1635,14 +1640,14 @@ define_key_alternate_name (struct key_data *key, struct key_data *returned_value) { Lisp_Object keysym = key->keysym; - unsigned int modifiers = key->modifiers; - unsigned int modifiers_sans_control = (modifiers & (~MOD_CONTROL)); - unsigned int modifiers_sans_meta = (modifiers & (~MOD_META)); + int modifiers = key->modifiers; + int modifiers_sans_control = (modifiers & (~XEMACS_MOD_CONTROL)); + int modifiers_sans_meta = (modifiers & (~XEMACS_MOD_META)); returned_value->keysym = Qnil; /* By default, no "alternate" key */ returned_value->modifiers = 0; - if (modifiers_sans_meta == MOD_CONTROL) + if (modifiers_sans_meta == XEMACS_MOD_CONTROL) { - if EQ (keysym, QKspace) + if (EQ (keysym, QKspace)) MACROLET (make_char ('@'), modifiers); else if (!CHARP (keysym)) return; @@ -1667,15 +1672,15 @@ define_key_alternate_name (struct key_data *key, else if (modifiers_sans_meta != 0) return; else if (EQ (keysym, QKbackspace)) /* backspace => c-h */ - MACROLET (make_char ('h'), (modifiers | MOD_CONTROL)); + MACROLET (make_char ('h'), (modifiers | XEMACS_MOD_CONTROL)); else if (EQ (keysym, QKtab)) /* tab => c-i */ - MACROLET (make_char ('i'), (modifiers | MOD_CONTROL)); + MACROLET (make_char ('i'), (modifiers | XEMACS_MOD_CONTROL)); else if (EQ (keysym, QKlinefeed)) /* linefeed => c-j */ - MACROLET (make_char ('j'), (modifiers | MOD_CONTROL)); + MACROLET (make_char ('j'), (modifiers | XEMACS_MOD_CONTROL)); else if (EQ (keysym, QKreturn)) /* return => c-m */ - MACROLET (make_char ('m'), (modifiers | MOD_CONTROL)); + MACROLET (make_char ('m'), (modifiers | XEMACS_MOD_CONTROL)); else if (EQ (keysym, QKescape)) /* escape => c-[ */ - MACROLET (make_char ('['), (modifiers | MOD_CONTROL)); + MACROLET (make_char ('['), (modifiers | XEMACS_MOD_CONTROL)); else return; #undef MACROLET @@ -1712,7 +1717,10 @@ ensure_meta_prefix_char_keymapp (Lisp_Object keys, int indx, XVECTOR_DATA (new_keys) [i] = XVECTOR_DATA (keys) [i]; } else - abort (); + { + new_keys = Qnil; + ABORT (); + } if (EQ (keys, new_keys)) error_with_frob (mpc_binding, @@ -1908,7 +1916,7 @@ these features. struct gcpro ngcpro1; NGCPRO1 (c); - meta_map = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META), + meta_map = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), XKEYMAP (keymap)->table, Qnil); if (!NILP (meta_map) && keymap_fullness (meta_map) != 0) @@ -1935,14 +1943,14 @@ these features. if (metized) { - raw_key1.modifiers |= MOD_META; - raw_key2.modifiers |= MOD_META; + raw_key1.modifiers |= XEMACS_MOD_META; + raw_key2.modifiers |= XEMACS_MOD_META; metized = 0; } /* This crap is to make sure that someone doesn't bind something like "C-x M-a" while "C-x ESC" has a non-keymap binding. */ - if (raw_key1.modifiers & MOD_META) + if (raw_key1.modifiers & XEMACS_MOD_META) ensure_meta_prefix_char_keymapp (keys, idx, keymap); if (++idx == len) @@ -2065,7 +2073,7 @@ raw_lookup_key_mapper (Lisp_Object k, void *arg) if (NILP (cmd)) { /* Do kludgy return of the meta-map */ - cmd = Fgethash (MAKE_MODIFIER_HASH_KEY (MOD_META), + cmd = Fgethash (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), XKEYMAP (k)->table, Qnil); } } @@ -2077,11 +2085,12 @@ raw_lookup_key_mapper (Lisp_Object k, void *arg) if (!NILP (cmd)) cmd = raw_lookup_key (cmd, raw_keys + 1, remaining, keys_so_far + 1, accept_default); - else if ((raw_keys[1].modifiers & MOD_META) == 0) + else if ((raw_keys[1].modifiers & XEMACS_MOD_META) == 0) { struct key_data metified; metified.keysym = raw_keys[1].keysym; - metified.modifiers = raw_keys[1].modifiers | MOD_META; + metified.modifiers = raw_keys[1].modifiers | + (unsigned char) XEMACS_MOD_META; /* Search for meta-next-char sequence directly */ cmd = keymap_lookup_1 (k, &metified, accept_default); @@ -2182,8 +2191,8 @@ Nil is returned if KEYS is unbound. See documentation of `define-key' for valid key definitions and key-sequence specifications. A number is returned if KEYS is "too long"; that is, the leading characters fail to be a valid sequence of prefix characters in KEYMAP. -The number is how many characters at the front of KEYS -it takes to reach a non-prefix command. +The number is how many key strokes at the front of KEYS it takes to +reach a non-prefix command. */ (keymap, keys, accept_default)) { @@ -2536,7 +2545,7 @@ the documentation for `lookup-key' for more information. For key-presses, the order of keymaps searched is: - the `keymap' property of any extent(s) at point; - any applicable minor-mode maps; - - the current-local-map of the current-buffer; + - the current local map of the current-buffer; - the current global map. For mouse-clicks, the order of keymaps searched is: @@ -2546,9 +2555,9 @@ For mouse-clicks, the order of keymaps searched is: (this includes modeline extents); - the modeline-map of the buffer corresponding to the modeline under the mouse (if the click happened over a modeline); - - the value of toolbar-map in the current-buffer (if the click + - the value of `toolbar-map' in the current-buffer (if the click happened over a toolbar); - - the current-local-map of the buffer under the mouse (does not + - the current local map of the buffer under the mouse (does not apply to toolbar clicks); - any applicable minor-mode maps; - the current global map. @@ -2743,7 +2752,7 @@ struct map_keymap_unsorted_closure { void (*fn) (const struct key_data *, Lisp_Object binding, void *arg); void *arg; - unsigned int modifiers; + int modifiers; }; /* used by map_keymap() */ @@ -2754,8 +2763,8 @@ map_keymap_unsorted_mapper (Lisp_Object keysym, Lisp_Object value, /* This function can GC */ struct map_keymap_unsorted_closure *closure = (struct map_keymap_unsorted_closure *) map_keymap_unsorted_closure; - unsigned int modifiers = closure->modifiers; - unsigned int mod_bit; + int modifiers = closure->modifiers; + int mod_bit; mod_bit = MODIFIER_HASH_KEY_BITS (keysym); if (mod_bit != 0) { @@ -2805,7 +2814,7 @@ map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2, { /* obj1 and obj2 are conses with keysyms in their cars. Cdrs are ignored. */ - unsigned int bit1, bit2; + int bit1, bit2; int sym1_p = 0; int sym2_p = 0; obj1 = XCAR (obj1); @@ -2879,7 +2888,7 @@ map_keymap_sort_predicate (Lisp_Object obj1, Lisp_Object obj2, /* used by map_keymap() */ static void map_keymap_sorted (Lisp_Object keymap_table, - unsigned int modifiers, + int modifiers, void (*function) (const struct key_data *key, Lisp_Object binding, void *map_keymap_sorted_closure), @@ -2904,7 +2913,7 @@ map_keymap_sorted (Lisp_Object keymap_table, { Lisp_Object keysym = XCAR (XCAR (contents)); Lisp_Object binding = XCDR (XCAR (contents)); - unsigned int sub_bits = MODIFIER_HASH_KEY_BITS (keysym); + int sub_bits = MODIFIER_HASH_KEY_BITS (keysym); if (sub_bits != 0) map_keymap_sorted (XKEYMAP (get_keymap (binding, 1, 1))->table, @@ -2979,7 +2988,8 @@ faster. (function, keymap, sort_first)) { /* This function can GC */ - struct gcpro gcpro1, gcpro2; + struct gcpro gcpro1, gcpro2, gcpro3; + Lisp_Object table = Qnil; /* tolerate obviously transposed args */ if (!NILP (Fkeymapp (function))) @@ -2988,9 +2998,17 @@ faster. function = keymap; keymap = tmp; } - GCPRO2 (function, keymap); + + GCPRO3 (function, keymap, table); keymap = get_keymap (keymap, 1, 1); - map_keymap (XKEYMAP (keymap)->table, !NILP (sort_first), + + /* elisp_maphash does not allow mapping functions to modify the hash + table being mapped over. Since map-keymap explicitly allows a + mapping function to modify KEYMAP, we map over a copy of the hash + table instead. */ + table = Fcopy_hash_table (XKEYMAP (keymap)->table); + + map_keymap (table, !NILP (sort_first), map_keymap_mapper, LISP_TO_VOID (function)); UNGCPRO; return Qnil; @@ -3010,11 +3028,11 @@ struct accessible_keymaps_closure static void accessible_keymaps_mapper_1 (Lisp_Object keysym, Lisp_Object contents, - unsigned int modifiers, + int modifiers, struct accessible_keymaps_closure *closure) { /* This function can GC */ - unsigned int subbits = MODIFIER_HASH_KEY_BITS (keysym); + int subbits = MODIFIER_HASH_KEY_BITS (keysym); if (subbits != 0) { @@ -3042,10 +3060,10 @@ accessible_keymaps_mapper_1 (Lisp_Object keysym, Lisp_Object contents, key.modifiers = modifiers; if (NILP (cmd)) - abort (); + ABORT (); cmd = get_keymap (cmd, 0, 1); if (!KEYMAPP (cmd)) - abort (); + ABORT (); vec = make_vector (XVECTOR_LENGTH (thisseq) + 1, Qnil); len = XVECTOR_LENGTH (thisseq); @@ -3492,7 +3510,7 @@ format_raw_keys (struct key_data *keys, int count, char *buf) keys_so_far and modifiers_so_far describe which map we're looking in; If we're in the "meta" submap of the map that "C-x 4" is bound to, then keys_so_far will be {(control x), \4}, and modifiers_so_far - will be MOD_META. That is, keys_so_far is the chain of keys that we + will be XEMACS_MOD_META. That is, keys_so_far is the chain of keys that we have followed, and modifiers_so_far_so_far is the bits (partial keys) beyond that. @@ -3510,7 +3528,7 @@ struct where_is_closure int shadow_count; int firstonly; int keys_count; - unsigned int modifiers_so_far; + int modifiers_so_far; char *target_buffer; struct key_data *keys_so_far; int keys_so_far_total_size; @@ -3526,8 +3544,8 @@ where_is_recursive_mapper (Lisp_Object map, void *arg) struct where_is_closure *c = (struct where_is_closure *) arg; Lisp_Object definition = c->definition; const int firstonly = c->firstonly; - const unsigned int keys_count = c->keys_count; - const unsigned int modifiers_so_far = c->modifiers_so_far; + const int keys_count = c->keys_count; + const int modifiers_so_far = c->modifiers_so_far; char *target_buffer = c->target_buffer; Lisp_Object keys = Fgethash (definition, XKEYMAP (map)->inverse_table, @@ -3571,7 +3589,7 @@ where_is_recursive_mapper (Lisp_Object map, void *arg) /* OK, the key is for real */ if (target_buffer) { - if (!firstonly) abort (); + if (!firstonly) ABORT (); format_raw_keys (so_far, keys_count + 1, target_buffer); return make_int (1); } @@ -3600,9 +3618,9 @@ where_is_recursive_mapper (Lisp_Object map, void *arg) { Lisp_Object key = XCAR (XCAR (submaps)); Lisp_Object submap = XCDR (XCAR (submaps)); - unsigned int lower_modifiers; + int lower_modifiers; int lower_keys_count = keys_count; - unsigned int bucky; + int bucky; submap = get_keymap (submap, 0, 0); @@ -3645,6 +3663,8 @@ where_is_recursive_mapper (Lisp_Object map, void *arg) struct key_data *new = xnew_array (struct key_data, size); memcpy ((void *)new, (const void *)c->keys_so_far, c->keys_so_far_total_size * sizeof (struct key_data)); + xfree (c->keys_so_far); + c->keys_so_far = new; } else XREALLOC_ARRAY (c->keys_so_far, struct key_data, size); @@ -3933,7 +3953,7 @@ describe_map_mapper (const struct key_data *key, struct describe_map_closure *closure = (struct describe_map_closure *) describe_map_closure; Lisp_Object keysym = key->keysym; - unsigned int modifiers = key->modifiers; + int modifiers = key->modifiers; /* Don't mention suppressed commands. */ if (SYMBOLP (binding) @@ -4007,7 +4027,7 @@ describe_map_sort_predicate (Lisp_Object obj1, Lisp_Object obj2, ( ( . ) . ) keysym and modifiers are used, binding is ignored. */ - unsigned int bit1, bit2; + int bit1, bit2; obj1 = XCAR (obj1); obj2 = XCAR (obj2); bit1 = XINT (XCDR (obj1)); @@ -4127,17 +4147,23 @@ describe_map (Lisp_Object keymap, Lisp_Object elt_prefix, { Lisp_Object elt = XCAR (XCAR (list)); Lisp_Object keysym = XCAR (elt); - unsigned int modifiers = XINT (XCDR (elt)); + int modifiers = XINT (XCDR (elt)); if (!NILP (elt_prefix)) buffer_insert_lisp_string (buf, elt_prefix); - if (modifiers & MOD_META) buffer_insert_c_string (buf, "M-"); - if (modifiers & MOD_CONTROL) buffer_insert_c_string (buf, "C-"); - if (modifiers & MOD_SUPER) buffer_insert_c_string (buf, "S-"); - if (modifiers & MOD_HYPER) buffer_insert_c_string (buf, "H-"); - if (modifiers & MOD_ALT) buffer_insert_c_string (buf, "Alt-"); - if (modifiers & MOD_SHIFT) buffer_insert_c_string (buf, "Sh-"); + if (modifiers & XEMACS_MOD_META) + buffer_insert_c_string (buf, "M-"); + if (modifiers & XEMACS_MOD_CONTROL) + buffer_insert_c_string (buf, "C-"); + if (modifiers & XEMACS_MOD_SUPER) + buffer_insert_c_string (buf, "S-"); + if (modifiers & XEMACS_MOD_HYPER) + buffer_insert_c_string (buf, "H-"); + if (modifiers & XEMACS_MOD_ALT) + buffer_insert_c_string (buf, "Alt-"); + if (modifiers & XEMACS_MOD_SHIFT) + buffer_insert_c_string (buf, "Sh-"); if (SYMBOLP (keysym)) { Lisp_Object code = Fget (keysym, Vcharacter_set_property, Qnil); @@ -4204,6 +4230,8 @@ describe_map (Lisp_Object keymap, Lisp_Object elt_prefix, void syms_of_keymap (void) { + INIT_LRECORD_IMPLEMENTATION (keymap); + defsymbol (&Qminor_mode_map_alist, "minor-mode-map-alist"); defsymbol (&Qkeymapp, "keymapp"); @@ -4274,11 +4302,15 @@ syms_of_keymap (void) defsymbol (&Qmouse_3, "mouse-3"); defsymbol (&Qmouse_4, "mouse-4"); defsymbol (&Qmouse_5, "mouse-5"); + defsymbol (&Qmouse_6, "mouse-6"); + defsymbol (&Qmouse_7, "mouse-7"); defsymbol (&Qdown_mouse_1, "down-mouse-1"); defsymbol (&Qdown_mouse_2, "down-mouse-2"); defsymbol (&Qdown_mouse_3, "down-mouse-3"); defsymbol (&Qdown_mouse_4, "down-mouse-4"); defsymbol (&Qdown_mouse_5, "down-mouse-5"); + defsymbol (&Qdown_mouse_6, "down-mouse-6"); + defsymbol (&Qdown_mouse_7, "down-mouse-7"); defsymbol (&Qmenu_selection, "menu-selection"); defsymbol (&QLFD, "LFD"); defsymbol (&QTAB, "TAB"); @@ -4322,8 +4354,28 @@ You should *bind* this, not set it. DEFVAR_LISP ("key-translation-map", &Vkey_translation_map /* Keymap of key translations that can override keymaps. -This keymap works like `function-key-map', but comes after that, + +This keymap works like `function-key-map', but is searched before it, and applies even for keys that have ordinary bindings. + +The `read-key-sequence' function replaces any subsequence bound by +`key-translation-map' with its binding. More precisely, when the active +keymaps have no binding for the current key sequence but +`key-translation-map' binds a suffix of the sequence to a vector or string, +`read-key-sequence' replaces the matching suffix with its binding, and +continues with the new sequence. See `key-binding' for details. + +The events that come from bindings in `key-translation-map' are not +themselves looked up in `key-translation-map'. + +#### FIXME: stolen from `function-key-map'; need better example. +#### I guess you could implement a Dvorak keyboard with this? +For example, suppose `key-translation-map' binds `ESC O P' to [f1]. +Typing `ESC O P' to `read-key-sequence' would return +\[#]. Typing `C-x ESC O P' would return +\[# #]. If [f1] +were a prefix key, typing `ESC O P x' would return +\[# #]. */ ); Vkey_translation_map = Qnil; @@ -4355,7 +4407,7 @@ complex_vars_of_keymap (void) meta_disgustitute = Fmake_keymap (Qnil); Ffset (ESC_prefix, meta_disgustitute); /* no need to protect meta_disgustitute, though */ - keymap_store_internal (MAKE_MODIFIER_HASH_KEY (MOD_META), + keymap_store_internal (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), XKEYMAP (Vcurrent_global_map), meta_disgustitute); XKEYMAP (Vcurrent_global_map)->sub_maps_cache = Qt;