Mercurial > emacs
comparison src/keyboard.c @ 47759:b2674275598d
(keyremap): New struct.
(read_key_sequence): Use it: globally replace keytran_foo with
keytran.foo and fkey_foo with fkey.foo. Rename temp vars
keytran_next and fkey_next to just `next'.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 04 Oct 2002 21:49:47 +0000 |
parents | e6806bc4402e |
children | b61109579f17 |
comparison
equal
deleted
inserted
replaced
47758:687aaa7ac601 | 47759:b2674275598d |
---|---|
7986 next[i] = NILP (defs[i]) ? Qnil : get_keymap (defs[i], 0, 1); | 7986 next[i] = NILP (defs[i]) ? Qnil : get_keymap (defs[i], 0, 1); |
7987 | 7987 |
7988 return first_binding; | 7988 return first_binding; |
7989 } | 7989 } |
7990 | 7990 |
7991 /* Structure used to keep track of partial application of key remapping | |
7992 such as Vfunction_key_map and Vkey_translation_map. */ | |
7993 typedef struct keyremap | |
7994 { | |
7995 Lisp_Object map; | |
7996 int start, end; | |
7997 } keyremap; | |
7998 | |
7999 | |
7991 /* Read a sequence of keys that ends with a non prefix character, | 8000 /* Read a sequence of keys that ends with a non prefix character, |
7992 storing it in KEYBUF, a buffer of size BUFSIZE. | 8001 storing it in KEYBUF, a buffer of size BUFSIZE. |
7993 Prompt with PROMPT. | 8002 Prompt with PROMPT. |
7994 Return the length of the key sequence stored. | 8003 Return the length of the key sequence stored. |
7995 Return -1 if the user rejected a command menu. | 8004 Return -1 if the user rejected a command menu. |
8073 /* The index in defs[] of the first keymap that has a binding for | 8082 /* The index in defs[] of the first keymap that has a binding for |
8074 this key sequence. In other words, the lowest i such that | 8083 this key sequence. In other words, the lowest i such that |
8075 defs[i] is non-nil. */ | 8084 defs[i] is non-nil. */ |
8076 volatile int first_binding; | 8085 volatile int first_binding; |
8077 /* Index of the first key that has no binding. | 8086 /* Index of the first key that has no binding. |
8078 It is useless to try fkey_start larger than that. */ | 8087 It is useless to try fkey.start larger than that. */ |
8079 volatile int first_unbound; | 8088 volatile int first_unbound; |
8080 | 8089 |
8081 /* If t < mock_input, then KEYBUF[t] should be read as the next | 8090 /* If t < mock_input, then KEYBUF[t] should be read as the next |
8082 input key. | 8091 input key. |
8083 | 8092 |
8092 mock_input, thus rebuilding the state; and then it will resume | 8101 mock_input, thus rebuilding the state; and then it will resume |
8093 reading characters from the keyboard. */ | 8102 reading characters from the keyboard. */ |
8094 volatile int mock_input = 0; | 8103 volatile int mock_input = 0; |
8095 | 8104 |
8096 /* If the sequence is unbound in submaps[], then | 8105 /* If the sequence is unbound in submaps[], then |
8097 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map, | 8106 keybuf[fkey.start..fkey.end-1] is a prefix in Vfunction_key_map, |
8098 and fkey_map is its binding. | 8107 and fkey.map is its binding. |
8099 | 8108 |
8100 These might be > t, indicating that all function key scanning | 8109 These might be > t, indicating that all function key scanning |
8101 should hold off until t reaches them. We do this when we've just | 8110 should hold off until t reaches them. We do this when we've just |
8102 recognized a function key, to avoid searching for the function | 8111 recognized a function key, to avoid searching for the function |
8103 key's again in Vfunction_key_map. */ | 8112 key's again in Vfunction_key_map. */ |
8104 volatile int fkey_start = 0, fkey_end = 0; | 8113 volatile keyremap fkey; |
8105 volatile Lisp_Object fkey_map; | |
8106 | 8114 |
8107 /* Likewise, for key_translation_map. */ | 8115 /* Likewise, for key_translation_map. */ |
8108 volatile int keytran_start = 0, keytran_end = 0; | 8116 volatile keyremap keytran; |
8109 volatile Lisp_Object keytran_map; | |
8110 | 8117 |
8111 /* If we receive a ``switch-frame'' event in the middle of a key sequence, | 8118 /* If we receive a ``switch-frame'' event in the middle of a key sequence, |
8112 we put it off for later. While we're reading, we keep the event here. */ | 8119 we put it off for later. While we're reading, we keep the event here. */ |
8113 volatile Lisp_Object delayed_switch_frame; | 8120 volatile Lisp_Object delayed_switch_frame; |
8114 | 8121 |
8138 raw_keybuf_count = 0; | 8145 raw_keybuf_count = 0; |
8139 | 8146 |
8140 last_nonmenu_event = Qnil; | 8147 last_nonmenu_event = Qnil; |
8141 | 8148 |
8142 delayed_switch_frame = Qnil; | 8149 delayed_switch_frame = Qnil; |
8143 fkey_map = Vfunction_key_map; | 8150 fkey.map = Vfunction_key_map; |
8144 keytran_map = Vkey_translation_map; | 8151 keytran.map = Vkey_translation_map; |
8145 | 8152 /* If there is no translation-map, turn off scanning. */ |
8146 /* If there is no function-key-map, turn off function key scanning. */ | 8153 fkey.start = fkey.end = KEYMAPP (fkey.map) ? 0 : bufsize + 1; |
8147 if (!KEYMAPP (Vfunction_key_map)) | 8154 keytran.start = keytran.end = KEYMAPP (keytran.map) ? 0 : bufsize + 1; |
8148 fkey_start = fkey_end = bufsize + 1; | |
8149 | |
8150 /* If there is no key-translation-map, turn off scanning. */ | |
8151 if (!KEYMAPP (Vkey_translation_map)) | |
8152 keytran_start = keytran_end = bufsize + 1; | |
8153 | 8155 |
8154 if (INTERACTIVE) | 8156 if (INTERACTIVE) |
8155 { | 8157 { |
8156 if (!NILP (prompt)) | 8158 if (!NILP (prompt)) |
8157 echo_prompt (prompt); | 8159 echo_prompt (prompt); |
8257 echo_truncate (echo_start); | 8259 echo_truncate (echo_start); |
8258 | 8260 |
8259 /* If the best binding for the current key sequence is a keymap, or | 8261 /* If the best binding for the current key sequence is a keymap, or |
8260 we may be looking at a function key's escape sequence, keep on | 8262 we may be looking at a function key's escape sequence, keep on |
8261 reading. */ | 8263 reading. */ |
8262 while ((first_binding < nmaps && ! NILP (submaps[first_binding])) | 8264 while (first_binding < nmaps |
8263 || (first_binding >= nmaps && fkey_start < t) | 8265 /* Keep reading as long as there's a prefix binding. */ |
8264 || (first_binding >= nmaps && keytran_start < t) | 8266 ? !NILP (submaps[first_binding]) |
8265 /* Don't return in the middle of a possible function key sequence, | 8267 /* Don't return in the middle of a possible function key sequence, |
8266 if the only bindings we found were via case conversion. | 8268 if the only bindings we found were via case conversion. |
8267 Thus, if ESC O a has a function-key-map translation | 8269 Thus, if ESC O a has a function-key-map translation |
8268 and ESC o has a binding, don't return after ESC O, | 8270 and ESC o has a binding, don't return after ESC O, |
8269 so that we can translate ESC O plus the next character. */ | 8271 so that we can translate ESC O plus the next character. */ |
8270 ) | 8272 : (fkey.start < t || keytran.start < t)) |
8271 { | 8273 { |
8272 Lisp_Object key; | 8274 Lisp_Object key; |
8273 int used_mouse_menu = 0; | 8275 int used_mouse_menu = 0; |
8274 | 8276 |
8275 /* Where the last real key started. If we need to throw away a | 8277 /* Where the last real key started. If we need to throw away a |
8284 echo_local_start and keys_local_start allow us to throw away | 8286 echo_local_start and keys_local_start allow us to throw away |
8285 just one key. */ | 8287 just one key. */ |
8286 volatile int echo_local_start, keys_local_start, local_first_binding; | 8288 volatile int echo_local_start, keys_local_start, local_first_binding; |
8287 | 8289 |
8288 /* key-translation-map is applied *after* function-key-map. */ | 8290 /* key-translation-map is applied *after* function-key-map. */ |
8289 eassert (keytran_end <= fkey_start); | 8291 eassert (keytran.end <= fkey.start); |
8290 | 8292 |
8291 if (first_unbound < fkey_start && first_unbound < keytran_start) | 8293 if (first_unbound < fkey.start && first_unbound < keytran.start) |
8292 { /* The prefix upto first_unbound has no binding and has | 8294 { /* The prefix upto first_unbound has no binding and has |
8293 no translation left to do either, so we know it's unbound. | 8295 no translation left to do either, so we know it's unbound. |
8294 If we don't stop now, we risk staying here indefinitely | 8296 If we don't stop now, we risk staying here indefinitely |
8295 (if the user keeps entering fkey or keytran prefixes | 8297 (if the user keeps entering fkey or keytran prefixes |
8296 like C-c ESC ESC ESC ESC ...) */ | 8298 like C-c ESC ESC ESC ESC ...) */ |
8297 int i; | 8299 int i; |
8298 for (i = first_unbound + 1; i < t; i++) | 8300 for (i = first_unbound + 1; i < t; i++) |
8299 keybuf[i - first_unbound - 1] = keybuf[i]; | 8301 keybuf[i - first_unbound - 1] = keybuf[i]; |
8300 mock_input = t - first_unbound - 1; | 8302 mock_input = t - first_unbound - 1; |
8301 fkey_end = fkey_start -= first_unbound + 1; | 8303 fkey.end = fkey.start -= first_unbound + 1; |
8302 fkey_map = Vfunction_key_map; | 8304 fkey.map = Vfunction_key_map; |
8303 keytran_end = keytran_start -= first_unbound + 1; | 8305 keytran.end = keytran.start -= first_unbound + 1; |
8304 keytran_map = Vkey_translation_map; | 8306 keytran.map = Vkey_translation_map; |
8305 goto replay_sequence; | 8307 goto replay_sequence; |
8306 } | 8308 } |
8307 | 8309 |
8308 if (t >= bufsize) | 8310 if (t >= bufsize) |
8309 error ("Key sequence too long"); | 8311 error ("Key sequence too long"); |
8702 /* If KEY wasn't bound, we'll try some fallbacks. */ | 8704 /* If KEY wasn't bound, we'll try some fallbacks. */ |
8703 if (first_binding < nmaps) | 8705 if (first_binding < nmaps) |
8704 /* This is needed for the following scenario: | 8706 /* This is needed for the following scenario: |
8705 event 0: a down-event that gets dropped by calling replay_key. | 8707 event 0: a down-event that gets dropped by calling replay_key. |
8706 event 1: some normal prefix like C-h. | 8708 event 1: some normal prefix like C-h. |
8707 After event 0, first_unbound is 0, after event 1 fkey_start | 8709 After event 0, first_unbound is 0, after event 1 fkey.start |
8708 and keytran_start are both 1, so when we see that C-h is bound, | 8710 and keytran.start are both 1, so when we see that C-h is bound, |
8709 we need to update first_unbound. */ | 8711 we need to update first_unbound. */ |
8710 first_unbound = max (t + 1, first_unbound); | 8712 first_unbound = max (t + 1, first_unbound); |
8711 else | 8713 else |
8712 { | 8714 { |
8713 Lisp_Object head; | 8715 Lisp_Object head; |
8714 | 8716 |
8715 /* Remember the position to put an upper bound on fkey_start. */ | 8717 /* Remember the position to put an upper bound on fkey.start. */ |
8716 first_unbound = min (t, first_unbound); | 8718 first_unbound = min (t, first_unbound); |
8717 | 8719 |
8718 head = EVENT_HEAD (key); | 8720 head = EVENT_HEAD (key); |
8719 if (help_char_p (head) && t > 0) | 8721 if (help_char_p (head) && t > 0) |
8720 { | 8722 { |
8849 There is thus no function-key in this sequence. | 8851 There is thus no function-key in this sequence. |
8850 Moving fkey.start is important in this case to allow keytran.start | 8852 Moving fkey.start is important in this case to allow keytran.start |
8851 to go over the sequence before we return (since we keep the | 8853 to go over the sequence before we return (since we keep the |
8852 invariant that keytran.end <= fkey.start). */ | 8854 invariant that keytran.end <= fkey.start). */ |
8853 { | 8855 { |
8854 if (fkey_start < t) | 8856 if (fkey.start < t) |
8855 (fkey_start = fkey_end = t, fkey_map = Vfunction_key_map); | 8857 (fkey.start = fkey.end = t, fkey.map = Vfunction_key_map); |
8856 } | 8858 } |
8857 else | 8859 else |
8858 /* If the sequence is unbound, see if we can hang a function key | 8860 /* If the sequence is unbound, see if we can hang a function key |
8859 off the end of it. */ | 8861 off the end of it. */ |
8860 { | 8862 { |
8861 Lisp_Object fkey_next; | 8863 Lisp_Object next; |
8862 | 8864 |
8863 /* Continue scan from fkey_end until we find a bound suffix. | 8865 /* Continue scan from fkey.end until we find a bound suffix. |
8864 If we fail, increment fkey_start and start over from there. */ | 8866 If we fail, increment fkey.start and start over from there. */ |
8865 while (fkey_end < t) | 8867 while (fkey.end < t) |
8866 { | 8868 { |
8867 Lisp_Object key; | 8869 Lisp_Object key; |
8868 | 8870 |
8869 key = keybuf[fkey_end++]; | 8871 key = keybuf[fkey.end++]; |
8870 fkey_next = access_keymap (fkey_map, key, 1, 0, 1); | 8872 next = access_keymap (fkey.map, key, 1, 0, 1); |
8871 | 8873 |
8872 /* Handle symbol with autoload definition. */ | 8874 /* Handle symbol with autoload definition. */ |
8873 if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) | 8875 if (SYMBOLP (next) && ! NILP (Ffboundp (next)) |
8874 && CONSP (XSYMBOL (fkey_next)->function) | 8876 && CONSP (XSYMBOL (next)->function) |
8875 && EQ (XCAR (XSYMBOL (fkey_next)->function), Qautoload)) | 8877 && EQ (XCAR (XSYMBOL (next)->function), Qautoload)) |
8876 do_autoload (XSYMBOL (fkey_next)->function, | 8878 do_autoload (XSYMBOL (next)->function, next); |
8877 fkey_next); | |
8878 | 8879 |
8879 /* Handle a symbol whose function definition is a keymap | 8880 /* Handle a symbol whose function definition is a keymap |
8880 or an array. */ | 8881 or an array. */ |
8881 if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) | 8882 if (SYMBOLP (next) && ! NILP (Ffboundp (next)) |
8882 && (!NILP (Farrayp (XSYMBOL (fkey_next)->function)) | 8883 && (!NILP (Farrayp (XSYMBOL (next)->function)) |
8883 || KEYMAPP (XSYMBOL (fkey_next)->function))) | 8884 || KEYMAPP (XSYMBOL (next)->function))) |
8884 fkey_next = XSYMBOL (fkey_next)->function; | 8885 next = XSYMBOL (next)->function; |
8885 | 8886 |
8886 #if 0 /* I didn't turn this on, because it might cause trouble | 8887 #if 0 /* I didn't turn this on, because it might cause trouble |
8887 for the mapping of return into C-m and tab into C-i. */ | 8888 for the mapping of return into C-m and tab into C-i. */ |
8888 /* Optionally don't map function keys into other things. | 8889 /* Optionally don't map function keys into other things. |
8889 This enables the user to redefine kp- keys easily. */ | 8890 This enables the user to redefine kp- keys easily. */ |
8890 if (SYMBOLP (key) && !NILP (Vinhibit_function_key_mapping)) | 8891 if (SYMBOLP (key) && !NILP (Vinhibit_function_key_mapping)) |
8891 fkey_next = Qnil; | 8892 next = Qnil; |
8892 #endif | 8893 #endif |
8893 | 8894 |
8894 /* If the function key map gives a function, not an | 8895 /* If the function key map gives a function, not an |
8895 array, then call the function with no args and use | 8896 array, then call the function with no args and use |
8896 its value instead. */ | 8897 its value instead. */ |
8897 if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) | 8898 if (SYMBOLP (next) && ! NILP (Ffboundp (next)) |
8898 /* If there's a binding (i.e. first_binding >= nmaps) | 8899 /* If there's a binding (i.e. first_binding >= nmaps) |
8899 we don't want to apply this function-key-mapping. */ | 8900 we don't want to apply this function-key-mapping. */ |
8900 && fkey_end == t && first_binding >= nmaps) | 8901 && fkey.end == t && first_binding >= nmaps) |
8901 { | 8902 { |
8902 struct gcpro gcpro1, gcpro2, gcpro3; | 8903 struct gcpro gcpro1, gcpro2, gcpro3; |
8903 Lisp_Object tem; | 8904 Lisp_Object tem; |
8904 tem = fkey_next; | 8905 tem = next; |
8905 | 8906 |
8906 GCPRO3 (fkey_map, keytran_map, delayed_switch_frame); | 8907 GCPRO3 (fkey.map, keytran.map, delayed_switch_frame); |
8907 fkey_next = call1 (fkey_next, prompt); | 8908 next = call1 (next, prompt); |
8908 UNGCPRO; | 8909 UNGCPRO; |
8909 /* If the function returned something invalid, | 8910 /* If the function returned something invalid, |
8910 barf--don't ignore it. | 8911 barf--don't ignore it. |
8911 (To ignore it safely, we would need to gcpro a bunch of | 8912 (To ignore it safely, we would need to gcpro a bunch of |
8912 other variables.) */ | 8913 other variables.) */ |
8913 if (! (VECTORP (fkey_next) || STRINGP (fkey_next))) | 8914 if (! (VECTORP (next) || STRINGP (next))) |
8914 error ("Function in key-translation-map returns invalid key sequence"); | 8915 error ("Function in key-translation-map returns invalid key sequence"); |
8915 } | 8916 } |
8916 | 8917 |
8917 /* If keybuf[fkey_start..fkey_end] is bound in the | 8918 /* If keybuf[fkey.start..fkey.end] is bound in the |
8918 function key map and it's a suffix of the current | 8919 function key map and it's a suffix of the current |
8919 sequence (i.e. fkey_end == t), replace it with | 8920 sequence (i.e. fkey.end == t), replace it with |
8920 the binding and restart with fkey_start at the end. */ | 8921 the binding and restart with fkey.start at the end. */ |
8921 if ((VECTORP (fkey_next) || STRINGP (fkey_next)) | 8922 if ((VECTORP (next) || STRINGP (next)) |
8922 /* If there's a binding (i.e. first_binding >= nmaps) | 8923 /* If there's a binding (i.e. first_binding >= nmaps) |
8923 we don't want to apply this function-key-mapping. */ | 8924 we don't want to apply this function-key-mapping. */ |
8924 && fkey_end == t && first_binding >= nmaps) | 8925 && fkey.end == t && first_binding >= nmaps) |
8925 { | 8926 { |
8926 int len = XFASTINT (Flength (fkey_next)); | 8927 int len = XFASTINT (Flength (next)); |
8927 | 8928 |
8928 t = fkey_start + len; | 8929 t = fkey.start + len; |
8929 if (t >= bufsize) | 8930 if (t >= bufsize) |
8930 error ("Key sequence too long"); | 8931 error ("Key sequence too long"); |
8931 | 8932 |
8932 if (VECTORP (fkey_next)) | 8933 if (VECTORP (next)) |
8933 bcopy (XVECTOR (fkey_next)->contents, | 8934 bcopy (XVECTOR (next)->contents, |
8934 keybuf + fkey_start, | 8935 keybuf + fkey.start, |
8935 (t - fkey_start) * sizeof (keybuf[0])); | 8936 (t - fkey.start) * sizeof (keybuf[0])); |
8936 else if (STRINGP (fkey_next)) | 8937 else if (STRINGP (next)) |
8937 { | 8938 { |
8938 int i; | 8939 int i; |
8939 | 8940 |
8940 for (i = 0; i < len; i++) | 8941 for (i = 0; i < len; i++) |
8941 XSETFASTINT (keybuf[fkey_start + i], | 8942 XSETFASTINT (keybuf[fkey.start + i], SREF (next, i)); |
8942 SREF (fkey_next, i)); | |
8943 } | 8943 } |
8944 | 8944 |
8945 mock_input = t; | 8945 mock_input = t; |
8946 fkey_start = fkey_end = t; | 8946 fkey.start = fkey.end = t; |
8947 fkey_map = Vfunction_key_map; | 8947 fkey.map = Vfunction_key_map; |
8948 | 8948 |
8949 /* Do pass the results through key-translation-map. | 8949 /* Do pass the results through key-translation-map. |
8950 But don't retranslate what key-translation-map | 8950 But don't retranslate what key-translation-map |
8951 has already translated. */ | 8951 has already translated. */ |
8952 keytran_end = keytran_start; | 8952 keytran.end = keytran.start; |
8953 keytran_map = Vkey_translation_map; | 8953 keytran.map = Vkey_translation_map; |
8954 | 8954 |
8955 goto replay_sequence; | 8955 goto replay_sequence; |
8956 } | 8956 } |
8957 | 8957 |
8958 fkey_map = get_keymap (fkey_next, 0, 1); | 8958 fkey.map = get_keymap (next, 0, 1); |
8959 | 8959 |
8960 /* If we no longer have a bound suffix, try a new positions for | 8960 /* If we no longer have a bound suffix, try a new positions for |
8961 fkey_start. */ | 8961 fkey.start. */ |
8962 if (!CONSP (fkey_map)) | 8962 if (!CONSP (fkey.map)) |
8963 { | 8963 { |
8964 fkey_end = ++fkey_start; | 8964 fkey.end = ++fkey.start; |
8965 fkey_map = Vfunction_key_map; | 8965 fkey.map = Vfunction_key_map; |
8966 } | 8966 } |
8967 } | 8967 } |
8968 } | 8968 } |
8969 | 8969 |
8970 /* Look for this sequence in key-translation-map. */ | 8970 /* Look for this sequence in key-translation-map. */ |
8971 { | 8971 { |
8972 Lisp_Object keytran_next; | 8972 Lisp_Object next; |
8973 | 8973 |
8974 /* Scan from keytran_end until we find a bound suffix. */ | 8974 /* Scan from keytran.end until we find a bound suffix. */ |
8975 while (keytran_end < fkey_start) | 8975 while (keytran.end < fkey.start) |
8976 { | 8976 { |
8977 Lisp_Object key; | 8977 Lisp_Object key; |
8978 | 8978 |
8979 key = keybuf[keytran_end++]; | 8979 key = keybuf[keytran.end++]; |
8980 keytran_next | 8980 next = access_keymap (keytran.map, key, 1, 0, 1); |
8981 = access_keymap (keytran_map, key, 1, 0, 1); | |
8982 | 8981 |
8983 /* Handle symbol with autoload definition. */ | 8982 /* Handle symbol with autoload definition. */ |
8984 if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) | 8983 if (SYMBOLP (next) && ! NILP (Ffboundp (next)) |
8985 && CONSP (XSYMBOL (keytran_next)->function) | 8984 && CONSP (XSYMBOL (next)->function) |
8986 && EQ (XCAR (XSYMBOL (keytran_next)->function), Qautoload)) | 8985 && EQ (XCAR (XSYMBOL (next)->function), Qautoload)) |
8987 do_autoload (XSYMBOL (keytran_next)->function, | 8986 do_autoload (XSYMBOL (next)->function, next); |
8988 keytran_next); | |
8989 | 8987 |
8990 /* Handle a symbol whose function definition is a keymap | 8988 /* Handle a symbol whose function definition is a keymap |
8991 or an array. */ | 8989 or an array. */ |
8992 if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) | 8990 if (SYMBOLP (next) && ! NILP (Ffboundp (next)) |
8993 && (!NILP (Farrayp (XSYMBOL (keytran_next)->function)) | 8991 && (!NILP (Farrayp (XSYMBOL (next)->function)) |
8994 || KEYMAPP (XSYMBOL (keytran_next)->function))) | 8992 || KEYMAPP (XSYMBOL (next)->function))) |
8995 keytran_next = XSYMBOL (keytran_next)->function; | 8993 next = XSYMBOL (next)->function; |
8996 | 8994 |
8997 /* If the key translation map gives a function, not an | 8995 /* If the key translation map gives a function, not an |
8998 array, then call the function with one arg and use | 8996 array, then call the function with one arg and use |
8999 its value instead. */ | 8997 its value instead. */ |
9000 if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next))) | 8998 if (SYMBOLP (next) && ! NILP (Ffboundp (next))) |
9001 { | 8999 { |
9002 struct gcpro gcpro1, gcpro2, gcpro3; | 9000 struct gcpro gcpro1, gcpro2, gcpro3; |
9003 Lisp_Object tem; | 9001 Lisp_Object tem; |
9004 tem = keytran_next; | 9002 tem = next; |
9005 | 9003 |
9006 GCPRO3 (fkey_map, keytran_map, delayed_switch_frame); | 9004 GCPRO3 (fkey.map, keytran.map, delayed_switch_frame); |
9007 keytran_next = call1 (keytran_next, prompt); | 9005 next = call1 (next, prompt); |
9008 UNGCPRO; | 9006 UNGCPRO; |
9009 /* If the function returned something invalid, | 9007 /* If the function returned something invalid, |
9010 barf--don't ignore it. | 9008 barf--don't ignore it. |
9011 (To ignore it safely, we would need to gcpro a bunch of | 9009 (To ignore it safely, we would need to gcpro a bunch of |
9012 other variables.) */ | 9010 other variables.) */ |
9013 if (! (VECTORP (keytran_next) || STRINGP (keytran_next))) | 9011 if (! (VECTORP (next) || STRINGP (next))) |
9014 error ("Function in key-translation-map returns invalid key sequence"); | 9012 error ("Function in key-translation-map returns invalid key sequence"); |
9015 } | 9013 } |
9016 | 9014 |
9017 /* If keybuf[keytran_start..keytran_end] is bound in the | 9015 /* If keybuf[keytran.start..keytran.end] is bound in the |
9018 key translation map and it's a suffix of the current | 9016 key translation map and it's a suffix of the current |
9019 sequence (i.e. keytran_end == t), replace it with | 9017 sequence (i.e. keytran.end == t), replace it with |
9020 the binding and restart with keytran_start at the end. */ | 9018 the binding and restart with keytran.start at the end. */ |
9021 if ((VECTORP (keytran_next) || STRINGP (keytran_next))) | 9019 if ((VECTORP (next) || STRINGP (next))) |
9022 { | 9020 { |
9023 int len = XFASTINT (Flength (keytran_next)); | 9021 int len = XFASTINT (Flength (next)); |
9024 int i, diff = len - (keytran_end - keytran_start); | 9022 int i, diff = len - (keytran.end - keytran.start); |
9025 | 9023 |
9026 mock_input = max (t, mock_input); | 9024 mock_input = max (t, mock_input); |
9027 if (mock_input + diff >= bufsize) | 9025 if (mock_input + diff >= bufsize) |
9028 error ("Key sequence too long"); | 9026 error ("Key sequence too long"); |
9029 | 9027 |
9030 /* Shift the keys that are after keytran_end. */ | 9028 /* Shift the keys that are after keytran.end. */ |
9031 if (diff < 0) | 9029 if (diff < 0) |
9032 for (i = keytran_end; i < mock_input; i++) | 9030 for (i = keytran.end; i < mock_input; i++) |
9033 keybuf[i + diff] = keybuf[i]; | 9031 keybuf[i + diff] = keybuf[i]; |
9034 else if (diff > 0) | 9032 else if (diff > 0) |
9035 for (i = mock_input - 1; i >= keytran_end; i--) | 9033 for (i = mock_input - 1; i >= keytran.end; i--) |
9036 keybuf[i + diff] = keybuf[i]; | 9034 keybuf[i + diff] = keybuf[i]; |
9037 /* Replace the keys between keytran_start and keytran_end | 9035 /* Replace the keys between keytran.start and keytran.end |
9038 with those from keytran_next. */ | 9036 with those from next. */ |
9039 for (i = 0; i < len; i++) | 9037 for (i = 0; i < len; i++) |
9040 keybuf[keytran_start + i] | 9038 keybuf[keytran.start + i] |
9041 = Faref (keytran_next, make_number (i)); | 9039 = Faref (next, make_number (i)); |
9042 | 9040 |
9043 mock_input += diff; | 9041 mock_input += diff; |
9044 keytran_start = keytran_end += diff; | 9042 keytran.start = keytran.end += diff; |
9045 keytran_map = Vkey_translation_map; | 9043 keytran.map = Vkey_translation_map; |
9046 | 9044 |
9047 /* Adjust the function-key-map counters. */ | 9045 /* Adjust the function-key-map counters. */ |
9048 fkey_start += diff; | 9046 fkey.start += diff; |
9049 fkey_end += diff; | 9047 fkey.end += diff; |
9050 | 9048 |
9051 goto replay_sequence; | 9049 goto replay_sequence; |
9052 } | 9050 } |
9053 | 9051 |
9054 keytran_map = get_keymap (keytran_next, 0, 1); | 9052 keytran.map = get_keymap (next, 0, 1); |
9055 | 9053 |
9056 /* If we no longer have a bound suffix, try a new positions for | 9054 /* If we no longer have a bound suffix, try a new positions for |
9057 keytran_start. */ | 9055 keytran.start. */ |
9058 if (!CONSP (keytran_map)) | 9056 if (!CONSP (keytran.map)) |
9059 { | 9057 { |
9060 keytran_end = ++keytran_start; | 9058 keytran.end = ++keytran.start; |
9061 keytran_map = Vkey_translation_map; | 9059 keytran.map = Vkey_translation_map; |
9062 } | 9060 } |
9063 } | 9061 } |
9064 } | 9062 } |
9065 | 9063 |
9066 /* If KEY is not defined in any of the keymaps, | 9064 /* If KEY is not defined in any of the keymaps, |
9067 and cannot be part of a function key or translation, | 9065 and cannot be part of a function key or translation, |
9068 and is an upper case letter | 9066 and is an upper case letter |
9069 use the corresponding lower-case letter instead. */ | 9067 use the corresponding lower-case letter instead. */ |
9070 if (first_binding >= nmaps | 9068 if (first_binding >= nmaps |
9071 && fkey_start >= t && keytran_start >= t | 9069 && fkey.start >= t && keytran.start >= t |
9072 && INTEGERP (key) | 9070 && INTEGERP (key) |
9073 && ((((XINT (key) & 0x3ffff) | 9071 && ((((XINT (key) & 0x3ffff) |
9074 < XCHAR_TABLE (current_buffer->downcase_table)->size) | 9072 < XCHAR_TABLE (current_buffer->downcase_table)->size) |
9075 && UPPERCASEP (XINT (key) & 0x3ffff)) | 9073 && UPPERCASEP (XINT (key) & 0x3ffff)) |
9076 || (XINT (key) & shift_modifier))) | 9074 || (XINT (key) & shift_modifier))) |
9097 /* If KEY is not defined in any of the keymaps, | 9095 /* If KEY is not defined in any of the keymaps, |
9098 and cannot be part of a function key or translation, | 9096 and cannot be part of a function key or translation, |
9099 and is a shifted function key, | 9097 and is a shifted function key, |
9100 use the corresponding unshifted function key instead. */ | 9098 use the corresponding unshifted function key instead. */ |
9101 if (first_binding >= nmaps | 9099 if (first_binding >= nmaps |
9102 && fkey_start >= t && keytran_start >= t | 9100 && fkey.start >= t && keytran.start >= t |
9103 && SYMBOLP (key)) | 9101 && SYMBOLP (key)) |
9104 { | 9102 { |
9105 Lisp_Object breakdown; | 9103 Lisp_Object breakdown; |
9106 int modifiers; | 9104 int modifiers; |
9107 | 9105 |