Mercurial > emacs
comparison src/keyboard.c @ 104920:566d2dc55a9d
* keyboard.c (Qmenu_alias, Vdefine_key_rebound_commands): Remove.
(parse_menu_item): Streamline since bindings are recomputed all the
time anyway. Don't bother checking Vdefine_key_rebound_commands any
more and don't support lmenu's menu-alias any more either.
* subr.el (define-key-rebound-commands): Mark obsolete.
* startup.el (precompute-menubar-bindings): Remove.
(normal-top-level): Remove obsolete code that tried to precompute
menubar bindings.
* loadup.el (define-key-rebound-commands): Don't bother fiddling with
define-key-rebound-commands and precompute-menubar-bindings.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 10 Sep 2009 18:19:03 +0000 |
parents | cd8d62c35d57 |
children | 496113ae8b94 |
comparison
equal
deleted
inserted
replaced
104919:ad7987e70109 | 104920:566d2dc55a9d |
---|---|
493 /* Properties of event headers. */ | 493 /* Properties of event headers. */ |
494 Lisp_Object Qevent_kind; | 494 Lisp_Object Qevent_kind; |
495 Lisp_Object Qevent_symbol_elements; | 495 Lisp_Object Qevent_symbol_elements; |
496 | 496 |
497 /* menu item parts */ | 497 /* menu item parts */ |
498 Lisp_Object Qmenu_alias; | |
499 Lisp_Object Qmenu_enable; | 498 Lisp_Object Qmenu_enable; |
500 Lisp_Object QCenable, QCvisible, QChelp, QCfilter, QCkeys, QCkey_sequence; | 499 Lisp_Object QCenable, QCvisible, QChelp, QCfilter, QCkeys, QCkey_sequence; |
501 Lisp_Object QCbutton, QCtoggle, QCradio; | 500 Lisp_Object QCbutton, QCtoggle, QCradio; |
502 extern Lisp_Object Vdefine_key_rebound_commands; | |
503 extern Lisp_Object Qmenu_item; | 501 extern Lisp_Object Qmenu_item; |
504 | 502 |
505 /* An event header symbol HEAD may have a property named | 503 /* An event header symbol HEAD may have a property named |
506 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS); | 504 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS); |
507 BASE is the base, unmodified version of HEAD, and MODIFIERS is the | 505 BASE is the base, unmodified version of HEAD, and MODIFIERS is the |
7881 parse_menu_item (item, notreal, inmenubar) | 7879 parse_menu_item (item, notreal, inmenubar) |
7882 Lisp_Object item; | 7880 Lisp_Object item; |
7883 int notreal, inmenubar; | 7881 int notreal, inmenubar; |
7884 { | 7882 { |
7885 Lisp_Object def, tem, item_string, start; | 7883 Lisp_Object def, tem, item_string, start; |
7886 Lisp_Object cachelist; | |
7887 Lisp_Object filter; | 7884 Lisp_Object filter; |
7888 Lisp_Object keyhint; | 7885 Lisp_Object keyhint; |
7889 int i; | 7886 int i; |
7890 int newcache = 0; | 7887 |
7891 | |
7892 cachelist = Qnil; | |
7893 filter = Qnil; | 7888 filter = Qnil; |
7894 keyhint = Qnil; | 7889 keyhint = Qnil; |
7895 | 7890 |
7896 if (!CONSP (item)) | 7891 if (!CONSP (item)) |
7897 return 0; | 7892 return 0; |
7924 ASET (item_properties, ITEM_PROPERTY_HELP, XCAR (item)); | 7919 ASET (item_properties, ITEM_PROPERTY_HELP, XCAR (item)); |
7925 start = item; | 7920 start = item; |
7926 item = XCDR (item); | 7921 item = XCDR (item); |
7927 } | 7922 } |
7928 | 7923 |
7929 /* Maybe key binding cache. */ | 7924 /* Maybe an obsolete key binding cache. */ |
7930 if (CONSP (item) && CONSP (XCAR (item)) | 7925 if (CONSP (item) && CONSP (XCAR (item)) |
7931 && (NILP (XCAR (XCAR (item))) | 7926 && (NILP (XCAR (XCAR (item))) |
7932 || VECTORP (XCAR (XCAR (item))))) | 7927 || VECTORP (XCAR (XCAR (item))))) |
7933 { | 7928 item = XCDR (item); |
7934 cachelist = XCAR (item); | |
7935 item = XCDR (item); | |
7936 } | |
7937 | 7929 |
7938 /* This is the real definition--the function to run. */ | 7930 /* This is the real definition--the function to run. */ |
7939 ASET (item_properties, ITEM_PROPERTY_DEF, item); | 7931 ASET (item_properties, ITEM_PROPERTY_DEF, item); |
7940 | 7932 |
7941 /* Get enable property, if any. */ | 7933 /* Get enable property, if any. */ |
7957 { | 7949 { |
7958 /* We have a real binding. */ | 7950 /* We have a real binding. */ |
7959 ASET (item_properties, ITEM_PROPERTY_DEF, XCAR (start)); | 7951 ASET (item_properties, ITEM_PROPERTY_DEF, XCAR (start)); |
7960 | 7952 |
7961 item = XCDR (start); | 7953 item = XCDR (start); |
7962 /* Is there a cache list with key equivalences. */ | 7954 /* Is there an obsolete cache list with key equivalences. */ |
7963 if (CONSP (item) && CONSP (XCAR (item))) | 7955 if (CONSP (item) && CONSP (XCAR (item))) |
7964 { | 7956 item = XCDR (item); |
7965 cachelist = XCAR (item); | |
7966 item = XCDR (item); | |
7967 } | |
7968 | 7957 |
7969 /* Parse properties. */ | 7958 /* Parse properties. */ |
7970 while (CONSP (item) && CONSP (XCDR (item))) | 7959 while (CONSP (item) && CONSP (XCDR (item))) |
7971 { | 7960 { |
7972 tem = XCAR (item); | 7961 tem = XCAR (item); |
7992 else if (EQ (tem, QCfilter)) | 7981 else if (EQ (tem, QCfilter)) |
7993 filter = item; | 7982 filter = item; |
7994 else if (EQ (tem, QCkey_sequence)) | 7983 else if (EQ (tem, QCkey_sequence)) |
7995 { | 7984 { |
7996 tem = XCAR (item); | 7985 tem = XCAR (item); |
7997 if (NILP (cachelist) | 7986 if (SYMBOLP (tem) || STRINGP (tem) || VECTORP (tem)) |
7998 && (SYMBOLP (tem) || STRINGP (tem) || VECTORP (tem))) | |
7999 /* Be GC protected. Set keyhint to item instead of tem. */ | 7987 /* Be GC protected. Set keyhint to item instead of tem. */ |
8000 keyhint = item; | 7988 keyhint = item; |
8001 } | 7989 } |
8002 else if (EQ (tem, QCkeys)) | 7990 else if (EQ (tem, QCkeys)) |
8003 { | 7991 { |
8004 tem = XCAR (item); | 7992 tem = XCAR (item); |
8005 if (CONSP (tem) || (STRINGP (tem) && NILP (cachelist))) | 7993 if (CONSP (tem) || STRINGP (tem)) |
8006 ASET (item_properties, ITEM_PROPERTY_KEYEQ, tem); | 7994 ASET (item_properties, ITEM_PROPERTY_KEYEQ, tem); |
8007 } | 7995 } |
8008 else if (EQ (tem, QCbutton) && CONSP (XCAR (item))) | 7996 else if (EQ (tem, QCbutton) && CONSP (XCAR (item))) |
8009 { | 7997 { |
8010 Lisp_Object type; | 7998 Lisp_Object type; |
8081 ITEM_PROPERTY_DEF is already set up properly. */ | 8069 ITEM_PROPERTY_DEF is already set up properly. */ |
8082 if (inmenubar > 0) | 8070 if (inmenubar > 0) |
8083 return 1; | 8071 return 1; |
8084 | 8072 |
8085 /* This is a command. See if there is an equivalent key binding. */ | 8073 /* This is a command. See if there is an equivalent key binding. */ |
8086 if (NILP (cachelist)) | 8074 tem = AREF (item_properties, ITEM_PROPERTY_KEYEQ); |
8087 { | 8075 /* The previous code preferred :key-sequence to :keys, so we |
8088 /* We have to create a cachelist. */ | 8076 preserve this behavior. */ |
8089 /* With the introduction of where_is_cache, the computation | 8077 if (STRINGP (tem) && !CONSP (keyhint)) |
8090 of equivalent key bindings is sufficiently fast that we | 8078 tem = Fsubstitute_command_keys (tem); |
8091 do not need to cache it here any more. */ | 8079 else |
8092 /* CHECK_IMPURE (start); | 8080 { |
8093 XSETCDR (start, Fcons (Fcons (Qnil, Qnil), XCDR (start))); | 8081 Lisp_Object prefix = AREF (item_properties, ITEM_PROPERTY_KEYEQ); |
8094 cachelist = XCAR (XCDR (start)); */ | 8082 Lisp_Object keys = Qnil; |
8095 cachelist = Fcons (Qnil, Qnil); | 8083 |
8096 newcache = 1; | |
8097 tem = AREF (item_properties, ITEM_PROPERTY_KEYEQ); | |
8098 if (!NILP (keyhint)) | |
8099 { | |
8100 XSETCAR (cachelist, XCAR (keyhint)); | |
8101 newcache = 0; | |
8102 } | |
8103 else if (STRINGP (tem)) | |
8104 { | |
8105 XSETCDR (cachelist, Fsubstitute_command_keys (tem)); | |
8106 XSETCAR (cachelist, Qt); | |
8107 } | |
8108 } | |
8109 | |
8110 tem = XCAR (cachelist); | |
8111 if (!EQ (tem, Qt)) | |
8112 { | |
8113 int chkcache = 0; | |
8114 Lisp_Object prefix; | |
8115 | |
8116 if (!NILP (tem)) | |
8117 tem = Fkey_binding (tem, Qnil, Qnil, Qnil); | |
8118 | |
8119 prefix = AREF (item_properties, ITEM_PROPERTY_KEYEQ); | |
8120 if (CONSP (prefix)) | 8084 if (CONSP (prefix)) |
8121 { | 8085 { |
8122 def = XCAR (prefix); | 8086 def = XCAR (prefix); |
8123 prefix = XCDR (prefix); | 8087 prefix = XCDR (prefix); |
8124 } | 8088 } |
8125 else | 8089 else |
8126 def = AREF (item_properties, ITEM_PROPERTY_DEF); | 8090 def = AREF (item_properties, ITEM_PROPERTY_DEF); |
8127 | 8091 |
8128 if (NILP (XCAR (cachelist))) /* Have no saved key. */ | 8092 if (CONSP (keyhint) && !NILP (XCAR (keyhint))) |
8129 { | 8093 { |
8130 if (newcache /* Always check first time. */ | 8094 keys = XCAR (keyhint); |
8131 /* Should we check everything when precomputing key | 8095 tem = Fkey_binding (keys, Qnil, Qnil, Qnil); |
8132 bindings? */ | 8096 |
8133 /* If something had no key binding before, don't recheck it | 8097 /* We have a suggested key. Is it bound to the command? */ |
8134 because that is too slow--except if we have a list of | 8098 if (NILP (tem) |
8135 rebound commands in Vdefine_key_rebound_commands, do | 8099 || (!EQ (tem, def) |
8136 recheck any command that appears in that list. */ | 8100 /* If the command is an alias for another |
8137 || (CONSP (Vdefine_key_rebound_commands) | 8101 (such as lmenu.el set it up), check if the |
8138 && !NILP (Fmemq (def, Vdefine_key_rebound_commands)))) | 8102 original command matches the cached command. */ |
8139 chkcache = 1; | 8103 && !(SYMBOLP (def) && EQ (tem, XSYMBOL (def)->function)))) |
8104 keys = Qnil; | |
8140 } | 8105 } |
8141 /* We had a saved key. Is it still bound to the command? */ | 8106 |
8142 else if (NILP (tem) | 8107 if (NILP (keys)) |
8143 || (!EQ (tem, def) | 8108 keys = Fwhere_is_internal (def, Qnil, Qt, Qnil, Qnil); |
8144 /* If the command is an alias for another | 8109 |
8145 (such as lmenu.el set it up), check if the | 8110 if (!NILP (keys)) |
8146 original command matches the cached command. */ | |
8147 && !(SYMBOLP (def) && EQ (tem, XSYMBOL (def)->function)))) | |
8148 chkcache = 1; /* Need to recompute key binding. */ | |
8149 | |
8150 if (chkcache) | |
8151 { | 8111 { |
8152 /* Recompute equivalent key binding. If the command is an alias | 8112 tem = Fkey_description (keys, Qnil); |
8153 for another (such as lmenu.el set it up), see if the original | |
8154 command name has equivalent keys. Otherwise look up the | |
8155 specified command itself. We don't try both, because that | |
8156 makes lmenu menus slow. */ | |
8157 if (SYMBOLP (def) | |
8158 && SYMBOLP (XSYMBOL (def)->function) | |
8159 && ! NILP (Fget (def, Qmenu_alias))) | |
8160 def = XSYMBOL (def)->function; | |
8161 tem = Fwhere_is_internal (def, Qnil, Qt, Qnil, Qnil); | |
8162 | |
8163 XSETCAR (cachelist, tem); | |
8164 if (NILP (tem)) | |
8165 { | |
8166 XSETCDR (cachelist, Qnil); | |
8167 chkcache = 0; | |
8168 } | |
8169 } | |
8170 else if (!NILP (keyhint) && !NILP (XCAR (cachelist))) | |
8171 { | |
8172 tem = XCAR (cachelist); | |
8173 chkcache = 1; | |
8174 } | |
8175 | |
8176 newcache = chkcache; | |
8177 if (chkcache) | |
8178 { | |
8179 tem = Fkey_description (tem, Qnil); | |
8180 if (CONSP (prefix)) | 8113 if (CONSP (prefix)) |
8181 { | 8114 { |
8182 if (STRINGP (XCAR (prefix))) | 8115 if (STRINGP (XCAR (prefix))) |
8183 tem = concat2 (XCAR (prefix), tem); | 8116 tem = concat2 (XCAR (prefix), tem); |
8184 if (STRINGP (XCDR (prefix))) | 8117 if (STRINGP (XCDR (prefix))) |
8185 tem = concat2 (tem, XCDR (prefix)); | 8118 tem = concat2 (tem, XCDR (prefix)); |
8186 } | 8119 } |
8187 XSETCDR (cachelist, tem); | 8120 tem = concat2 (build_string (" "), tem); |
8121 /* tem = concat3 (build_string (" ("), tem, build_string (")")); */ | |
8188 } | 8122 } |
8189 } | 8123 } |
8190 | 8124 |
8191 tem = XCDR (cachelist); | |
8192 if (newcache && !NILP (tem)) | |
8193 { | |
8194 tem = concat2 (build_string (" "), tem); | |
8195 /* tem = concat3 (build_string (" ("), tem, build_string (")")); */ | |
8196 XSETCDR (cachelist, tem); | |
8197 } | |
8198 | 8125 |
8199 /* If we only want to precompute equivalent key bindings, stop here. */ | 8126 /* If we only want to precompute equivalent key bindings, stop here. */ |
8200 if (notreal) | 8127 if (notreal) |
8201 return 1; | 8128 return 1; |
8202 | 8129 |
11868 staticpro (&Qdbus_event); | 11795 staticpro (&Qdbus_event); |
11869 #endif | 11796 #endif |
11870 | 11797 |
11871 Qmenu_enable = intern ("menu-enable"); | 11798 Qmenu_enable = intern ("menu-enable"); |
11872 staticpro (&Qmenu_enable); | 11799 staticpro (&Qmenu_enable); |
11873 Qmenu_alias = intern ("menu-alias"); | |
11874 staticpro (&Qmenu_alias); | |
11875 QCenable = intern (":enable"); | 11800 QCenable = intern (":enable"); |
11876 staticpro (&QCenable); | 11801 staticpro (&QCenable); |
11877 QCvisible = intern (":visible"); | 11802 QCvisible = intern (":visible"); |
11878 staticpro (&QCvisible); | 11803 staticpro (&QCvisible); |
11879 QChelp = intern (":help"); | 11804 QChelp = intern (":help"); |