# HG changeset patch # User Stefan Monnier # Date 1003099502 0 # Node ID a6ced7cb88d9ab93d37e6687656c36a3d772ef42 # Parent 758ba590ccfe380e30c24c0c10467b4223ec0e71 (access_keymap): Unify handling of `t' and generic-char. If a parent is reached and noinherit is set, exit immediately. Use AREF and ASIZE macros. Call get_keyelt before checking KEYMAPP. diff -r 758ba590ccfe -r a6ced7cb88d9 src/keymap.c --- a/src/keymap.c Sun Oct 14 20:23:38 2001 +0000 +++ b/src/keymap.c Sun Oct 14 22:45:02 2001 +0000 @@ -476,8 +476,7 @@ int noinherit; int autoload; { - int noprefix = 0; - Lisp_Object val; + Lisp_Object val = Qunbound; /* If idx is a list (some sort of mouse click, perhaps?), the index we want to use is the car of the list, which @@ -517,12 +516,13 @@ { Lisp_Object tail; - Lisp_Object t_binding; - Lisp_Object generic_binding; - - t_binding = Qnil; - generic_binding = Qnil; - + Lisp_Object t_binding = Qnil; + + /* If `t_ok' is 2, both `t' and generic-char bindings are accepted. + If it is 1, only generic-char bindings are accepted. + Otherwise, neither are. */ + t_ok = t_ok ? 2 : 0; + for (tail = XCDR (map); (CONSP (tail) || (tail = get_keymap (tail, 0, autoload), CONSP (tail))); @@ -536,7 +536,7 @@ /* If NOINHERIT, stop finding prefix definitions after we pass a second occurrence of the `keymap' symbol. */ if (noinherit && EQ (binding, Qkeymap)) - noprefix = 1; + return Qnil; } else if (CONSP (binding)) { @@ -544,15 +544,9 @@ int c1, c2, charset; if (EQ (key, idx)) - { - val = XCDR (binding); - if (noprefix && KEYMAPP (val)) - return Qnil; - if (CONSP (val)) - fix_submap_inheritance (map, idx, val); - return get_keyelt (val, autoload); - } - else if (INTEGERP (idx) + val = XCDR (binding); + else if (t_ok + && INTEGERP (idx) && (XINT (idx) & CHAR_MODIFIER_MASK) == 0 && INTEGERP (key) && (XINT (key) & CHAR_MODIFIER_MASK) == 0 @@ -566,22 +560,19 @@ /* KEY is the generic character of the charset of IDX. Use KEY's binding if there isn't a binding for IDX itself. */ - generic_binding = XCDR (binding); + t_binding = XCDR (binding); + t_ok = 0; } - else if (t_ok && EQ (XCAR (binding), Qt)) - t_binding = XCDR (binding); + else if (t_ok > 1 && EQ (key, Qt)) + { + t_binding = XCDR (binding); + t_ok = 1; + } } else if (VECTORP (binding)) { - if (NATNUMP (idx) && XFASTINT (idx) < XVECTOR (binding)->size) - { - val = XVECTOR (binding)->contents[XFASTINT (idx)]; - if (noprefix && KEYMAPP (val)) - return Qnil; - if (CONSP (val)) - fix_submap_inheritance (map, idx, val); - return get_keyelt (val, autoload); - } + if (NATNUMP (idx) && XFASTINT (idx) < ASIZE (binding)) + val = AREF (binding, XFASTINT (idx)); } else if (CHAR_TABLE_P (binding)) { @@ -590,22 +581,20 @@ All character codes without modifiers are included. */ if (NATNUMP (idx) && (XFASTINT (idx) & CHAR_MODIFIER_MASK) == 0) - { - val = Faref (binding, idx); - if (noprefix && KEYMAPP (val)) - return Qnil; - if (CONSP (val)) - fix_submap_inheritance (map, idx, val); - return get_keyelt (val, autoload); - } + val = Faref (binding, idx); } + /* If we found a binding, clean it up and return it. */ + if (!EQ (val, Qunbound)) + { + val = get_keyelt (val, autoload); + if (KEYMAPP (val)) + fix_submap_inheritance (map, idx, val); + return val; + } QUIT; } - if (!NILP (generic_binding)) - return get_keyelt (generic_binding, autoload); - return get_keyelt (t_binding, autoload); } }