Mercurial > emacs
comparison src/keyboard.c @ 45753:402855ebf092
(read_key_sequence):
Remove prev_(fkey|keytran}_(map|start|end) since we don't want to pass
things through those maps after downcasing events.
Enforce that keytran_end <= fkey_start, i.e. that key-translation-map
applies after function-key-map.
Make sure that keytran can be done in the middle in the sequence.
Be careful not to throw away events past the one we downcase.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 11 Jun 2002 19:50:45 +0000 |
parents | 7318ee0c9772 |
children | 9484de301252 |
comparison
equal
deleted
inserted
replaced
45752:55eeb73a3227 | 45753:402855ebf092 |
---|---|
8057 volatile int key_translation_possible = 0; | 8057 volatile int key_translation_possible = 0; |
8058 | 8058 |
8059 /* List of events for which a fake prefix key has been generated. */ | 8059 /* List of events for which a fake prefix key has been generated. */ |
8060 volatile Lisp_Object fake_prefixed_keys = Qnil; | 8060 volatile Lisp_Object fake_prefixed_keys = Qnil; |
8061 | 8061 |
8062 /* Save the status of key translation before each step, | |
8063 so that we can restore this after downcasing. */ | |
8064 Lisp_Object prev_fkey_map; | |
8065 int prev_fkey_start; | |
8066 int prev_fkey_end; | |
8067 | |
8068 Lisp_Object prev_keytran_map; | |
8069 int prev_keytran_start; | |
8070 int prev_keytran_end; | |
8071 | |
8072 #if defined (GOBBLE_FIRST_EVENT) | 8062 #if defined (GOBBLE_FIRST_EVENT) |
8073 int junk; | 8063 int junk; |
8074 #endif | 8064 #endif |
8075 | 8065 |
8076 struct gcpro gcpro1; | 8066 struct gcpro gcpro1; |
8228 while those allow us to restart the entire key sequence, | 8218 while those allow us to restart the entire key sequence, |
8229 echo_local_start and keys_local_start allow us to throw away | 8219 echo_local_start and keys_local_start allow us to throw away |
8230 just one key. */ | 8220 just one key. */ |
8231 volatile int echo_local_start, keys_local_start, local_first_binding; | 8221 volatile int echo_local_start, keys_local_start, local_first_binding; |
8232 | 8222 |
8223 /* key-translation-map is applied *after* function-key-map. */ | |
8224 eassert (keytran_end <= fkey_start); | |
8233 | 8225 |
8234 if (first_unbound < fkey_start && first_unbound < keytran_start) | 8226 if (first_unbound < fkey_start && first_unbound < keytran_start) |
8235 { /* The prefix upto first_unbound has no binding and has | 8227 { /* The prefix upto first_unbound has no binding and has |
8236 no translation left to do either, so we know it's unbound. | 8228 no translation left to do either, so we know it's unbound. |
8237 If we don't stop now, we risk staying here indefinitely | 8229 If we don't stop now, we risk staying here indefinitely |
8764 last_nonmenu_event = key; | 8756 last_nonmenu_event = key; |
8765 | 8757 |
8766 /* Record what part of this_command_keys is the current key sequence. */ | 8758 /* Record what part of this_command_keys is the current key sequence. */ |
8767 this_single_command_key_start = this_command_key_count - t; | 8759 this_single_command_key_start = this_command_key_count - t; |
8768 | 8760 |
8769 prev_fkey_map = fkey_map; | |
8770 prev_fkey_start = fkey_start; | |
8771 prev_fkey_end = fkey_end; | |
8772 | |
8773 prev_keytran_map = keytran_map; | |
8774 prev_keytran_start = keytran_start; | |
8775 prev_keytran_end = keytran_end; | |
8776 | |
8777 /* If the sequence is unbound, see if we can hang a function key | 8761 /* If the sequence is unbound, see if we can hang a function key |
8778 off the end of it. We only want to scan real keyboard input | 8762 off the end of it. We only want to scan real keyboard input |
8779 for function key sequences, so if mock_input says that we're | 8763 for function key sequences, so if mock_input says that we're |
8780 re-reading old events, don't examine it. */ | 8764 re-reading old events, don't examine it. */ |
8781 if (first_binding >= nmaps | 8765 if (first_binding >= nmaps |
8888 fkey_map = Vfunction_key_map; | 8872 fkey_map = Vfunction_key_map; |
8889 function_key_possible = 0; | 8873 function_key_possible = 0; |
8890 } | 8874 } |
8891 } | 8875 } |
8892 } | 8876 } |
8877 else if (NILP (submaps[first_binding])) | |
8878 /* There is a global binding and it's not a prefix. | |
8879 There is thus no function-key in this sequence. | |
8880 We can probably show that there can't be any afterwards either | |
8881 but I can't seem to find a clear reason why not, so I'll | |
8882 be conservative. | |
8883 Moving fkey.start is important in this case to allow keytran.start | |
8884 to go over the sequence before we return (since we keep the | |
8885 invariant that keytran.end <= fkey.start). */ | |
8886 (fkey_start = max (fkey_start, t), fkey_end = max (fkey_end, t)); | |
8893 | 8887 |
8894 /* Look for this sequence in key-translation-map. */ | 8888 /* Look for this sequence in key-translation-map. */ |
8895 { | 8889 { |
8896 Lisp_Object keytran_next; | 8890 Lisp_Object keytran_next; |
8897 | 8891 |
8898 /* Scan from keytran_end until we find a bound suffix. */ | 8892 /* Scan from keytran_end until we find a bound suffix. */ |
8899 while (keytran_end < t) | 8893 while (keytran_end < fkey_start) |
8900 { | 8894 { |
8901 Lisp_Object key; | 8895 Lisp_Object key; |
8902 | 8896 |
8903 key = keybuf[keytran_end++]; | 8897 key = keybuf[keytran_end++]; |
8904 keytran_next | 8898 keytran_next |
8919 keytran_next = XSYMBOL (keytran_next)->function; | 8913 keytran_next = XSYMBOL (keytran_next)->function; |
8920 | 8914 |
8921 /* If the key translation map gives a function, not an | 8915 /* If the key translation map gives a function, not an |
8922 array, then call the function with one arg and use | 8916 array, then call the function with one arg and use |
8923 its value instead. */ | 8917 its value instead. */ |
8924 if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) | 8918 if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next))) |
8925 && keytran_end == t) | |
8926 { | 8919 { |
8927 struct gcpro gcpro1, gcpro2, gcpro3; | 8920 struct gcpro gcpro1, gcpro2, gcpro3; |
8928 Lisp_Object tem; | 8921 Lisp_Object tem; |
8929 tem = keytran_next; | 8922 tem = keytran_next; |
8930 | 8923 |
8943 | 8936 |
8944 /* If keybuf[keytran_start..keytran_end] is bound in the | 8937 /* If keybuf[keytran_start..keytran_end] is bound in the |
8945 key translation map and it's a suffix of the current | 8938 key translation map and it's a suffix of the current |
8946 sequence (i.e. keytran_end == t), replace it with | 8939 sequence (i.e. keytran_end == t), replace it with |
8947 the binding and restart with keytran_start at the end. */ | 8940 the binding and restart with keytran_start at the end. */ |
8948 if ((VECTORP (keytran_next) || STRINGP (keytran_next)) | 8941 if ((VECTORP (keytran_next) || STRINGP (keytran_next))) |
8949 && keytran_end == t) | |
8950 { | 8942 { |
8951 int len = XFASTINT (Flength (keytran_next)); | 8943 int len = XFASTINT (Flength (keytran_next)); |
8952 | 8944 int i, diff = len - (keytran_end - keytran_start); |
8953 t = keytran_start + len; | 8945 |
8954 if (t >= bufsize) | 8946 mock_input = max (t, mock_input); |
8947 if (mock_input + diff >= bufsize) | |
8955 error ("Key sequence too long"); | 8948 error ("Key sequence too long"); |
8956 | 8949 |
8957 if (VECTORP (keytran_next)) | 8950 /* Shift the keys that are after keytran_end. */ |
8958 bcopy (XVECTOR (keytran_next)->contents, | 8951 if (diff < 0) |
8959 keybuf + keytran_start, | 8952 for (i = keytran_end; i < mock_input; i++) |
8960 (t - keytran_start) * sizeof (keybuf[0])); | 8953 keybuf[i + diff] = keybuf[i]; |
8961 else if (STRINGP (keytran_next)) | 8954 else if (diff > 0) |
8962 { | 8955 for (i = mock_input - 1; i >= keytran_end; i--) |
8963 int i; | 8956 keybuf[i + diff] = keybuf[i]; |
8964 | 8957 /* Replace the keys between keytran_start and keytran_end |
8965 for (i = 0; i < len; i++) | 8958 with those from keytran_next. */ |
8966 XSETFASTINT (keybuf[keytran_start + i], | 8959 for (i = 0; i < len; i++) |
8967 XSTRING (keytran_next)->data[i]); | 8960 keybuf[keytran_start + i] |
8968 } | 8961 = Faref (keytran_next, make_number (i)); |
8969 | 8962 |
8970 mock_input = t; | 8963 mock_input += diff; |
8971 keytran_start = keytran_end = t; | 8964 keytran_start = keytran_end += diff; |
8972 keytran_map = Vkey_translation_map; | 8965 keytran_map = Vkey_translation_map; |
8973 | 8966 |
8974 /* Don't pass the results of key-translation-map | 8967 /* Adjust the function-key-map counters. */ |
8975 through function-key-map. */ | 8968 fkey_start += diff; |
8976 fkey_start = fkey_end = t; | 8969 fkey_end += diff; |
8977 fkey_map = Vfunction_key_map; | |
8978 | 8970 |
8979 goto replay_sequence; | 8971 goto replay_sequence; |
8980 } | 8972 } |
8981 | 8973 |
8982 keytran_map = get_keymap (keytran_next, 0, 1); | 8974 keytran_map = get_keymap (keytran_next, 0, 1); |
9017 | 9009 |
9018 /* We have to do this unconditionally, regardless of whether | 9010 /* We have to do this unconditionally, regardless of whether |
9019 the lower-case char is defined in the keymaps, because they | 9011 the lower-case char is defined in the keymaps, because they |
9020 might get translated through function-key-map. */ | 9012 might get translated through function-key-map. */ |
9021 keybuf[t - 1] = new_key; | 9013 keybuf[t - 1] = new_key; |
9022 mock_input = t; | 9014 mock_input = max (t, mock_input); |
9023 | |
9024 fkey_map = prev_fkey_map; | |
9025 fkey_start = prev_fkey_start; | |
9026 fkey_end = prev_fkey_end; | |
9027 | |
9028 keytran_map = prev_keytran_map; | |
9029 keytran_start = prev_keytran_start; | |
9030 keytran_end = prev_keytran_end; | |
9031 | 9015 |
9032 goto replay_sequence; | 9016 goto replay_sequence; |
9033 } | 9017 } |
9034 /* If KEY is not defined in any of the keymaps, | 9018 /* If KEY is not defined in any of the keymaps, |
9035 and cannot be part of a function key or translation, | 9019 and cannot be part of a function key or translation, |
9054 modifiers &= ~shift_modifier; | 9038 modifiers &= ~shift_modifier; |
9055 new_key = apply_modifiers (modifiers, | 9039 new_key = apply_modifiers (modifiers, |
9056 XCAR (breakdown)); | 9040 XCAR (breakdown)); |
9057 | 9041 |
9058 keybuf[t - 1] = new_key; | 9042 keybuf[t - 1] = new_key; |
9059 mock_input = t; | 9043 mock_input = max (t, mock_input); |
9060 | |
9061 fkey_map = prev_fkey_map; | |
9062 fkey_start = prev_fkey_start; | |
9063 fkey_end = prev_fkey_end; | |
9064 | |
9065 keytran_map = prev_keytran_map; | |
9066 keytran_start = prev_keytran_start; | |
9067 keytran_end = prev_keytran_end; | |
9068 | 9044 |
9069 goto replay_sequence; | 9045 goto replay_sequence; |
9070 } | 9046 } |
9071 } | 9047 } |
9072 } | 9048 } |