Mercurial > emacs
comparison src/keyboard.c @ 45881:5c591efdb3bf
(read_key_sequence): Be more careful with first_unbound.
Lookup keys in function-key-map immediately so that key-translation-map
can be applied earlier.
Remove function_key_possible and key_translation_possible, replaced
by checking `keytran_start < t'.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 17 Jun 2002 18:45:44 +0000 |
parents | 9484de301252 |
children | afcc2cec9ba0 |
comparison
equal
deleted
inserted
replaced
45880:8108a2dd551c | 45881:5c591efdb3bf |
---|---|
8049 /* Gets around Microsoft compiler limitations. */ | 8049 /* Gets around Microsoft compiler limitations. */ |
8050 int dummyflag = 0; | 8050 int dummyflag = 0; |
8051 | 8051 |
8052 struct buffer *starting_buffer; | 8052 struct buffer *starting_buffer; |
8053 | 8053 |
8054 /* Nonzero if we seem to have got the beginning of a binding | |
8055 in function_key_map. */ | |
8056 volatile int function_key_possible = 0; | |
8057 volatile int key_translation_possible = 0; | |
8058 | |
8059 /* List of events for which a fake prefix key has been generated. */ | 8054 /* List of events for which a fake prefix key has been generated. */ |
8060 volatile Lisp_Object fake_prefixed_keys = Qnil; | 8055 volatile Lisp_Object fake_prefixed_keys = Qnil; |
8061 | 8056 |
8062 #if defined (GOBBLE_FIRST_EVENT) | 8057 #if defined (GOBBLE_FIRST_EVENT) |
8063 int junk; | 8058 int junk; |
8120 we need to rescan it starting from the beginning. When we jump here, | 8115 we need to rescan it starting from the beginning. When we jump here, |
8121 keybuf[0..mock_input] holds the sequence we should reread. */ | 8116 keybuf[0..mock_input] holds the sequence we should reread. */ |
8122 replay_sequence: | 8117 replay_sequence: |
8123 | 8118 |
8124 starting_buffer = current_buffer; | 8119 starting_buffer = current_buffer; |
8125 function_key_possible = 0; | |
8126 key_translation_possible = 0; | |
8127 first_unbound = bufsize + 1; | 8120 first_unbound = bufsize + 1; |
8128 | 8121 |
8129 /* Build our list of keymaps. | 8122 /* Build our list of keymaps. |
8130 If we recognize a function key and replace its escape sequence in | 8123 If we recognize a function key and replace its escape sequence in |
8131 keybuf with its symbol, or if the sequence starts with a mouse | 8124 keybuf with its symbol, or if the sequence starts with a mouse |
8191 | 8184 |
8192 /* If the best binding for the current key sequence is a keymap, or | 8185 /* If the best binding for the current key sequence is a keymap, or |
8193 we may be looking at a function key's escape sequence, keep on | 8186 we may be looking at a function key's escape sequence, keep on |
8194 reading. */ | 8187 reading. */ |
8195 while ((first_binding < nmaps && ! NILP (submaps[first_binding])) | 8188 while ((first_binding < nmaps && ! NILP (submaps[first_binding])) |
8196 || (first_binding >= nmaps | 8189 || (first_binding >= nmaps && fkey_start < t) |
8197 && fkey_start < t) | 8190 || (first_binding >= nmaps && keytran_start < t) |
8198 || (first_binding >= nmaps | |
8199 && keytran_start < t && key_translation_possible) | |
8200 /* Don't return in the middle of a possible function key sequence, | 8191 /* Don't return in the middle of a possible function key sequence, |
8201 if the only bindings we found were via case conversion. | 8192 if the only bindings we found were via case conversion. |
8202 Thus, if ESC O a has a function-key-map translation | 8193 Thus, if ESC O a has a function-key-map translation |
8203 and ESC o has a binding, don't return after ESC O, | 8194 and ESC o has a binding, don't return after ESC O, |
8204 so that we can translate ESC O plus the next character. */ | 8195 so that we can translate ESC O plus the next character. */ |
8624 defs + first_binding, | 8615 defs + first_binding, |
8625 submaps + first_binding) | 8616 submaps + first_binding) |
8626 + first_binding); | 8617 + first_binding); |
8627 | 8618 |
8628 /* If KEY wasn't bound, we'll try some fallbacks. */ | 8619 /* If KEY wasn't bound, we'll try some fallbacks. */ |
8629 if (first_binding >= nmaps) | 8620 if (first_binding < nmaps) |
8621 /* This is needed for the following scenario: | |
8622 event 0: a down-event that gets dropped by calling replay_key. | |
8623 event 1: some normal prefix like C-h. | |
8624 After event 0, first_unbound is 0, after event 1 fkey_start | |
8625 and keytran_start are both 1, so when we see that C-h is bound, | |
8626 we need to update first_unbound. */ | |
8627 first_unbound = max (t + 1, first_unbound); | |
8628 else | |
8630 { | 8629 { |
8631 Lisp_Object head; | 8630 Lisp_Object head; |
8632 | 8631 |
8633 /* Remember the position to put an upper bound on fkey_start. */ | 8632 /* Remember the position to put an upper bound on fkey_start. */ |
8634 first_unbound = min (t, first_unbound); | 8633 first_unbound = min (t, first_unbound); |
8704 Beyond that, only function key expansion could | 8703 Beyond that, only function key expansion could |
8705 create more than two keys, but that should never | 8704 create more than two keys, but that should never |
8706 generate mouse events, so it's okay to zero | 8705 generate mouse events, so it's okay to zero |
8707 mock_input in that case too. | 8706 mock_input in that case too. |
8708 | 8707 |
8708 FIXME: The above paragraph seems just plain | |
8709 wrong, if you consider things like | |
8710 xterm-mouse-mode. -stef | |
8711 | |
8709 Isn't this just the most wonderful code ever? */ | 8712 Isn't this just the most wonderful code ever? */ |
8710 if (t == last_real_key_start) | 8713 if (t == last_real_key_start) |
8711 { | 8714 { |
8712 mock_input = 0; | 8715 mock_input = 0; |
8713 goto replay_key; | 8716 goto replay_key; |
8756 last_nonmenu_event = key; | 8759 last_nonmenu_event = key; |
8757 | 8760 |
8758 /* Record what part of this_command_keys is the current key sequence. */ | 8761 /* Record what part of this_command_keys is the current key sequence. */ |
8759 this_single_command_key_start = this_command_key_count - t; | 8762 this_single_command_key_start = this_command_key_count - t; |
8760 | 8763 |
8761 /* If the sequence is unbound, see if we can hang a function key | 8764 if (first_binding < nmaps && NILP (submaps[first_binding])) |
8762 off the end of it. We only want to scan real keyboard input | 8765 /* There is a binding and it's not a prefix. |
8763 for function key sequences, so if mock_input says that we're | 8766 There is thus no function-key in this sequence. |
8764 re-reading old events, don't examine it. */ | 8767 Moving fkey.start is important in this case to allow keytran.start |
8765 if (first_binding >= nmaps | 8768 to go over the sequence before we return (since we keep the |
8766 && t >= mock_input) | 8769 invariant that keytran.end <= fkey.start). */ |
8770 { | |
8771 if (fkey_start < t) | |
8772 (fkey_start = fkey_end = t, fkey_map = Vfunction_key_map); | |
8773 } | |
8774 else | |
8775 /* If the sequence is unbound, see if we can hang a function key | |
8776 off the end of it. */ | |
8767 { | 8777 { |
8768 Lisp_Object fkey_next; | 8778 Lisp_Object fkey_next; |
8769 | 8779 |
8770 /* Continue scan from fkey_end until we find a bound suffix. | 8780 /* Continue scan from fkey_end until we find a bound suffix. |
8771 If we fail, increment fkey_start | 8781 If we fail, increment fkey_start and start over from there. */ |
8772 and start fkey_end from there. */ | |
8773 while (fkey_end < t) | 8782 while (fkey_end < t) |
8774 { | 8783 { |
8775 Lisp_Object key; | 8784 Lisp_Object key; |
8776 | 8785 |
8777 key = keybuf[fkey_end++]; | 8786 key = keybuf[fkey_end++]; |
8778 fkey_next | 8787 fkey_next = access_keymap (fkey_map, key, 1, 0, 1); |
8779 = access_keymap (fkey_map, key, 1, 0, 1); | |
8780 | 8788 |
8781 /* Handle symbol with autoload definition. */ | 8789 /* Handle symbol with autoload definition. */ |
8782 if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) | 8790 if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) |
8783 && CONSP (XSYMBOL (fkey_next)->function) | 8791 && CONSP (XSYMBOL (fkey_next)->function) |
8784 && EQ (XCAR (XSYMBOL (fkey_next)->function), Qautoload)) | 8792 && EQ (XCAR (XSYMBOL (fkey_next)->function), Qautoload)) |
8802 | 8810 |
8803 /* If the function key map gives a function, not an | 8811 /* If the function key map gives a function, not an |
8804 array, then call the function with no args and use | 8812 array, then call the function with no args and use |
8805 its value instead. */ | 8813 its value instead. */ |
8806 if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) | 8814 if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) |
8807 && fkey_end == t) | 8815 /* If there's a binding (i.e. first_binding >= nmaps) |
8816 we don't want to apply this function-key-mapping. */ | |
8817 && fkey_end == t && first_binding >= nmaps) | |
8808 { | 8818 { |
8809 struct gcpro gcpro1, gcpro2, gcpro3; | 8819 struct gcpro gcpro1, gcpro2, gcpro3; |
8810 Lisp_Object tem; | 8820 Lisp_Object tem; |
8811 tem = fkey_next; | 8821 tem = fkey_next; |
8812 | 8822 |
8819 other variables.) */ | 8829 other variables.) */ |
8820 if (! (VECTORP (fkey_next) || STRINGP (fkey_next))) | 8830 if (! (VECTORP (fkey_next) || STRINGP (fkey_next))) |
8821 error ("Function in key-translation-map returns invalid key sequence"); | 8831 error ("Function in key-translation-map returns invalid key sequence"); |
8822 } | 8832 } |
8823 | 8833 |
8824 function_key_possible = ! NILP (fkey_next); | |
8825 | |
8826 /* If keybuf[fkey_start..fkey_end] is bound in the | 8834 /* If keybuf[fkey_start..fkey_end] is bound in the |
8827 function key map and it's a suffix of the current | 8835 function key map and it's a suffix of the current |
8828 sequence (i.e. fkey_end == t), replace it with | 8836 sequence (i.e. fkey_end == t), replace it with |
8829 the binding and restart with fkey_start at the end. */ | 8837 the binding and restart with fkey_start at the end. */ |
8830 if ((VECTORP (fkey_next) || STRINGP (fkey_next)) | 8838 if ((VECTORP (fkey_next) || STRINGP (fkey_next)) |
8831 && fkey_end == t) | 8839 /* If there's a binding (i.e. first_binding >= nmaps) |
8840 we don't want to apply this function-key-mapping. */ | |
8841 && fkey_end == t && first_binding >= nmaps) | |
8832 { | 8842 { |
8833 int len = XFASTINT (Flength (fkey_next)); | 8843 int len = XFASTINT (Flength (fkey_next)); |
8834 | 8844 |
8835 t = fkey_start + len; | 8845 t = fkey_start + len; |
8836 if (t >= bufsize) | 8846 if (t >= bufsize) |
8868 fkey_start. */ | 8878 fkey_start. */ |
8869 if (!CONSP (fkey_map)) | 8879 if (!CONSP (fkey_map)) |
8870 { | 8880 { |
8871 fkey_end = ++fkey_start; | 8881 fkey_end = ++fkey_start; |
8872 fkey_map = Vfunction_key_map; | 8882 fkey_map = Vfunction_key_map; |
8873 function_key_possible = 0; | |
8874 } | 8883 } |
8875 } | 8884 } |
8876 } | 8885 } |
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)); | |
8887 | 8886 |
8888 /* Look for this sequence in key-translation-map. */ | 8887 /* Look for this sequence in key-translation-map. */ |
8889 { | 8888 { |
8890 Lisp_Object keytran_next; | 8889 Lisp_Object keytran_next; |
8891 | 8890 |
8930 other variables.) */ | 8929 other variables.) */ |
8931 if (! (VECTORP (keytran_next) || STRINGP (keytran_next))) | 8930 if (! (VECTORP (keytran_next) || STRINGP (keytran_next))) |
8932 error ("Function in key-translation-map returns invalid key sequence"); | 8931 error ("Function in key-translation-map returns invalid key sequence"); |
8933 } | 8932 } |
8934 | 8933 |
8935 key_translation_possible = ! NILP (keytran_next); | |
8936 | |
8937 /* If keybuf[keytran_start..keytran_end] is bound in the | 8934 /* If keybuf[keytran_start..keytran_end] is bound in the |
8938 key translation map and it's a suffix of the current | 8935 key translation map and it's a suffix of the current |
8939 sequence (i.e. keytran_end == t), replace it with | 8936 sequence (i.e. keytran_end == t), replace it with |
8940 the binding and restart with keytran_start at the end. */ | 8937 the binding and restart with keytran_start at the end. */ |
8941 if ((VECTORP (keytran_next) || STRINGP (keytran_next))) | 8938 if ((VECTORP (keytran_next) || STRINGP (keytran_next))) |
8977 keytran_start. */ | 8974 keytran_start. */ |
8978 if (!CONSP (keytran_map)) | 8975 if (!CONSP (keytran_map)) |
8979 { | 8976 { |
8980 keytran_end = ++keytran_start; | 8977 keytran_end = ++keytran_start; |
8981 keytran_map = Vkey_translation_map; | 8978 keytran_map = Vkey_translation_map; |
8982 key_translation_possible = 0; | |
8983 } | 8979 } |
8984 } | 8980 } |
8985 } | 8981 } |
8986 | 8982 |
8987 /* If KEY is not defined in any of the keymaps, | 8983 /* If KEY is not defined in any of the keymaps, |
8988 and cannot be part of a function key or translation, | 8984 and cannot be part of a function key or translation, |
8989 and is an upper case letter | 8985 and is an upper case letter |
8990 use the corresponding lower-case letter instead. */ | 8986 use the corresponding lower-case letter instead. */ |
8991 if (first_binding == nmaps && ! function_key_possible | 8987 if (first_binding >= nmaps |
8992 && ! key_translation_possible | 8988 && fkey_start >= t && keytran_start >= t |
8993 && INTEGERP (key) | 8989 && INTEGERP (key) |
8994 && ((((XINT (key) & 0x3ffff) | 8990 && ((((XINT (key) & 0x3ffff) |
8995 < XCHAR_TABLE (current_buffer->downcase_table)->size) | 8991 < XCHAR_TABLE (current_buffer->downcase_table)->size) |
8996 && UPPERCASEP (XINT (key) & 0x3ffff)) | 8992 && UPPERCASEP (XINT (key) & 0x3ffff)) |
8997 || (XINT (key) & shift_modifier))) | 8993 || (XINT (key) & shift_modifier))) |
9017 } | 9013 } |
9018 /* If KEY is not defined in any of the keymaps, | 9014 /* If KEY is not defined in any of the keymaps, |
9019 and cannot be part of a function key or translation, | 9015 and cannot be part of a function key or translation, |
9020 and is a shifted function key, | 9016 and is a shifted function key, |
9021 use the corresponding unshifted function key instead. */ | 9017 use the corresponding unshifted function key instead. */ |
9022 if (first_binding == nmaps && ! function_key_possible | 9018 if (first_binding >= nmaps |
9023 && ! key_translation_possible | 9019 && fkey_start >= t && keytran_start >= t |
9024 && SYMBOLP (key)) | 9020 && SYMBOLP (key)) |
9025 { | 9021 { |
9026 Lisp_Object breakdown; | 9022 Lisp_Object breakdown; |
9027 int modifiers; | 9023 int modifiers; |
9028 | 9024 |