comparison src/keyboard.c @ 105913:414b8a7a3334

(parse_menu_item): Handle `notreal' a bit earlier. Use `tem' less. Make sure KEYEQ holds a string or nil (bug#4879).
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 08 Nov 2009 15:06:50 +0000
parents 21bdda3ded62
children 7e842c6b6d18
comparison
equal deleted inserted replaced
105912:26de05188183 105913:414b8a7a3334
8066 The menu bar does not display equivalent key bindings anyway. 8066 The menu bar does not display equivalent key bindings anyway.
8067 ITEM_PROPERTY_DEF is already set up properly. */ 8067 ITEM_PROPERTY_DEF is already set up properly. */
8068 if (inmenubar > 0) 8068 if (inmenubar > 0)
8069 return 1; 8069 return 1;
8070 8070
8071 /* This is a command. See if there is an equivalent key binding. */
8072 tem = AREF (item_properties, ITEM_PROPERTY_KEYEQ);
8073 /* The previous code preferred :key-sequence to :keys, so we
8074 preserve this behavior. */
8075 if (STRINGP (tem) && !CONSP (keyhint))
8076 tem = Fsubstitute_command_keys (tem);
8077 else
8078 {
8079 Lisp_Object prefix = AREF (item_properties, ITEM_PROPERTY_KEYEQ);
8080 Lisp_Object keys = Qnil;
8081
8082 if (CONSP (prefix))
8083 {
8084 def = XCAR (prefix);
8085 prefix = XCDR (prefix);
8086 }
8087 else
8088 def = AREF (item_properties, ITEM_PROPERTY_DEF);
8089
8090 if (CONSP (keyhint) && !NILP (XCAR (keyhint)))
8091 {
8092 keys = XCAR (keyhint);
8093 tem = Fkey_binding (keys, Qnil, Qnil, Qnil);
8094
8095 /* We have a suggested key. Is it bound to the command? */
8096 if (NILP (tem)
8097 || (!EQ (tem, def)
8098 /* If the command is an alias for another
8099 (such as lmenu.el set it up), check if the
8100 original command matches the cached command. */
8101 && !(SYMBOLP (def) && EQ (tem, XSYMBOL (def)->function))))
8102 keys = Qnil;
8103 }
8104
8105 if (NILP (keys))
8106 keys = Fwhere_is_internal (def, Qnil, Qt, Qnil, Qnil);
8107
8108 if (!NILP (keys))
8109 {
8110 tem = Fkey_description (keys, Qnil);
8111 if (CONSP (prefix))
8112 {
8113 if (STRINGP (XCAR (prefix)))
8114 tem = concat2 (XCAR (prefix), tem);
8115 if (STRINGP (XCDR (prefix)))
8116 tem = concat2 (tem, XCDR (prefix));
8117 }
8118 tem = concat2 (build_string (" "), tem);
8119 /* tem = concat3 (build_string (" ("), tem, build_string (")")); */
8120 }
8121 }
8122 8071
8123 8072 /* If we only want to precompute equivalent key bindings (which we
8124 /* If we only want to precompute equivalent key bindings, stop here. */ 8073 don't even do any more anyway), stop here. */
8125 if (notreal) 8074 if (notreal)
8126 return 1; 8075 return 1;
8127 8076
8128 /* If we have an equivalent key binding, use that. */ 8077 { /* This is a command. See if there is an equivalent key binding. */
8129 ASET (item_properties, ITEM_PROPERTY_KEYEQ, tem); 8078 Lisp_Object keyeq = AREF (item_properties, ITEM_PROPERTY_KEYEQ);
8079
8080 /* The previous code preferred :key-sequence to :keys, so we
8081 preserve this behavior. */
8082 if (STRINGP (keyeq) && !CONSP (keyhint))
8083 keyeq = Fsubstitute_command_keys (keyeq);
8084 else
8085 {
8086 Lisp_Object prefix = keyeq;
8087 Lisp_Object keys = Qnil;
8088
8089 if (CONSP (prefix))
8090 {
8091 def = XCAR (prefix);
8092 prefix = XCDR (prefix);
8093 }
8094 else
8095 def = AREF (item_properties, ITEM_PROPERTY_DEF);
8096
8097 if (CONSP (keyhint) && !NILP (XCAR (keyhint)))
8098 {
8099 keys = XCAR (keyhint);
8100 tem = Fkey_binding (keys, Qnil, Qnil, Qnil);
8101
8102 /* We have a suggested key. Is it bound to the command? */
8103 if (NILP (tem)
8104 || (!EQ (tem, def)
8105 /* If the command is an alias for another
8106 (such as lmenu.el set it up), check if the
8107 original command matches the cached command. */
8108 && !(SYMBOLP (def) && EQ (tem, XSYMBOL (def)->function))))
8109 keys = Qnil;
8110 }
8111
8112 if (NILP (keys))
8113 keys = Fwhere_is_internal (def, Qnil, Qt, Qnil, Qnil);
8114
8115 if (!NILP (keys))
8116 {
8117 tem = Fkey_description (keys, Qnil);
8118 if (CONSP (prefix))
8119 {
8120 if (STRINGP (XCAR (prefix)))
8121 tem = concat2 (XCAR (prefix), tem);
8122 if (STRINGP (XCDR (prefix)))
8123 tem = concat2 (tem, XCDR (prefix));
8124 }
8125 keyeq = concat2 (build_string (" "), tem);
8126 /* keyeq = concat3(build_string(" ("),tem,build_string(")")); */
8127 }
8128 else
8129 keyeq = Qnil;
8130 }
8131
8132 /* If we have an equivalent key binding, use that. */
8133 ASET (item_properties, ITEM_PROPERTY_KEYEQ, keyeq);
8134 }
8130 8135
8131 /* Include this when menu help is implemented. 8136 /* Include this when menu help is implemented.
8132 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP]; 8137 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
8133 if (!(NILP (tem) || STRINGP (tem))) 8138 if (!(NILP (tem) || STRINGP (tem)))
8134 { 8139 {