aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/keyboard.c353
1 files changed, 202 insertions, 151 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index 7d377ea679e..b107c1cc3c8 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -33,6 +33,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
33#include "commands.h" 33#include "commands.h"
34#include "buffer.h" 34#include "buffer.h"
35#include "disptab.h" 35#include "disptab.h"
36#include "dispextern.h"
36#include "keyboard.h" 37#include "keyboard.h"
37#include <setjmp.h> 38#include <setjmp.h>
38#include <errno.h> 39#include <errno.h>
@@ -156,8 +157,10 @@ Lisp_Object unread_command_char;
156 157
157/* If not Qnil, this is a switch-frame event which we decided to put 158/* If not Qnil, this is a switch-frame event which we decided to put
158 off until the end of a key sequence. This should be read as the 159 off until the end of a key sequence. This should be read as the
159 next command input, after any unread_command_char. */ 160 next command input, after any unread_command_char. Only
160Lisp_Object unread_switch_frame; 161 read_key_sequence sets this; it uses it to delay switch-frame
162 events until the end of the key sequence. */
163static Lisp_Object unread_switch_frame;
161 164
162/* Char to use as prefix when a meta character is typed in. 165/* Char to use as prefix when a meta character is typed in.
163 This is bound on entry to minibuffer in case ESC is changed there. */ 166 This is bound on entry to minibuffer in case ESC is changed there. */
@@ -323,6 +326,8 @@ Lisp_Object Qmodifier_cache;
323Lisp_Object Qmode_line; 326Lisp_Object Qmode_line;
324Lisp_Object Qvertical_line; 327Lisp_Object Qvertical_line;
325 328
329Lisp_Object recursive_edit_unwind (), command_loop ();
330Lisp_Object Fthis_command_keys ();
326 331
327/* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt 332/* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
328 happens. */ 333 happens. */
@@ -374,8 +379,8 @@ static int echo_keystrokes;
374static int immediate_echo; 379static int immediate_echo;
375 380
376/* The text we're echoing in the modeline - partial key sequences, 381/* The text we're echoing in the modeline - partial key sequences,
377 usually. '\0'-terminated. */ 382 usually. '\0'-terminated. This really shouldn't have a fixed size. */
378static char echobuf[100]; 383static char echobuf[300];
379 384
380/* Where to append more text to echobuf if we want to. */ 385/* Where to append more text to echobuf if we want to. */
381static char *echoptr; 386static char *echoptr;
@@ -435,7 +440,7 @@ echo_char (c)
435 ptr += name->size; 440 ptr += name->size;
436 } 441 }
437 442
438 if (echoptr == echobuf && c == help_char) 443 if (echoptr == echobuf && EQ (c, help_char))
439 { 444 {
440 strcpy (ptr, " (Type ? for further options)"); 445 strcpy (ptr, " (Type ? for further options)");
441 ptr += strlen (ptr); 446 ptr += strlen (ptr);
@@ -563,8 +568,6 @@ record_auto_save ()
563 last_auto_save = num_nonmacro_input_chars; 568 last_auto_save = num_nonmacro_input_chars;
564} 569}
565 570
566Lisp_Object recursive_edit_unwind (), command_loop ();
567
568DEFUN ("recursive-edit", Frecursive_edit, Srecursive_edit, 0, 0, "", 571DEFUN ("recursive-edit", Frecursive_edit, Srecursive_edit, 0, 0, "",
569 "Invoke the editor command loop recursively.\n\ 572 "Invoke the editor command loop recursively.\n\
570To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\ 573To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
@@ -1143,7 +1146,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
1143 from a macro should never cause a new frame to be selected. */ 1146 from a macro should never cause a new frame to be selected. */
1144 Vlast_event_frame = Qmacro; 1147 Vlast_event_frame = Qmacro;
1145 1148
1146 if (executing_macro_index >= Flength (Vexecuting_macro)) 1149 if (executing_macro_index >= XFASTINT (Flength (Vexecuting_macro)))
1147 { 1150 {
1148 XSET (c, Lisp_Int, -1); 1151 XSET (c, Lisp_Int, -1);
1149 return c; 1152 return c;
@@ -1161,8 +1164,8 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
1161 unread_switch_frame = Qnil; 1164 unread_switch_frame = Qnil;
1162 1165
1163 /* This event should make it into this_command_keys, and get echoed 1166 /* This event should make it into this_command_keys, and get echoed
1164 again, so we go to reread, rather than reread_first. */ 1167 again, so we go to reread_first, rather than reread. */
1165 goto reread; 1168 goto reread_first;
1166 } 1169 }
1167 1170
1168 /* Save outer setjmp data, in case called recursively. */ 1171 /* Save outer setjmp data, in case called recursively. */
@@ -1299,11 +1302,11 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
1299 return c; 1302 return c;
1300 1303
1301 /* Strip the high bits, and maybe the meta bit too. */ 1304 /* Strip the high bits, and maybe the meta bit too. */
1302 XSETINT (c, c & (meta_key ? 0377 : 0177)); 1305 XSETINT (c, XINT (c) & (meta_key ? 0377 : 0177));
1303 1306
1304 if (XTYPE (Vkeyboard_translate_table) == Lisp_String 1307 if (XTYPE (Vkeyboard_translate_table) == Lisp_String
1305 && XSTRING (Vkeyboard_translate_table)->size > XINT (c)) 1308 && XSTRING (Vkeyboard_translate_table)->size > XFASTINT (c))
1306 XSETINT (c, XSTRING (Vkeyboard_translate_table)->data[c]); 1309 XSETINT (c, XSTRING (Vkeyboard_translate_table)->data[XFASTINT (c)]);
1307 } 1310 }
1308 1311
1309 total_keys++; 1312 total_keys++;
@@ -1317,7 +1320,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
1317 if (dribble) 1320 if (dribble)
1318 { 1321 {
1319 if (XTYPE (c) == Lisp_Int) 1322 if (XTYPE (c) == Lisp_Int)
1320 putc (c, dribble); 1323 putc (XINT (c), dribble);
1321 else 1324 else
1322 { 1325 {
1323 Lisp_Object dribblee = c; 1326 Lisp_Object dribblee = c;
@@ -2727,9 +2730,9 @@ read_char_menu_prompt (nmaps, maps, prev_event, used_mouse_menu)
2727 else 2730 else
2728 ch = XINT (obj); 2731 ch = XINT (obj);
2729 2732
2730 if (obj != menu_prompt_more_char 2733 if (! EQ (obj, menu_prompt_more_char)
2731 && (XTYPE (menu_prompt_more_char) != Lisp_Int 2734 && (XTYPE (menu_prompt_more_char) != Lisp_Int
2732 || obj != make_number (Ctl (XINT (menu_prompt_more_char))))) 2735 || ! EQ (obj, make_number (Ctl (XINT (menu_prompt_more_char))))))
2733 return obj; 2736 return obj;
2734 } 2737 }
2735} 2738}
@@ -2777,7 +2780,7 @@ follow_key (key, nmaps, current, defs, next)
2777 /* Note that since we pass the resulting bindings through 2780 /* Note that since we pass the resulting bindings through
2778 get_keymap_1, non-prefix bindings for meta-prefix-char 2781 get_keymap_1, non-prefix bindings for meta-prefix-char
2779 disappear. */ 2782 disappear. */
2780 next[i] = get_keymap_1 (next[i], 0); 2783 next[i] = get_keymap_1 (next[i], 0, 1);
2781 } 2784 }
2782 else 2785 else
2783 next[i] = Qnil; 2786 next[i] = Qnil;
@@ -2825,82 +2828,98 @@ follow_key (key, nmaps, current, defs, next)
2825 /* Given the set of bindings we've found, produce the next set of maps. */ 2828 /* Given the set of bindings we've found, produce the next set of maps. */
2826 if (first_binding < nmaps) 2829 if (first_binding < nmaps)
2827 for (i = 0; i < nmaps; i++) 2830 for (i = 0; i < nmaps; i++)
2828 next[i] = NILP (defs[i]) ? Qnil : get_keymap_1 (defs[i], 0); 2831 next[i] = NILP (defs[i]) ? Qnil : get_keymap_1 (defs[i], 0, 1);
2829 2832
2830 return first_binding; 2833 return first_binding;
2831} 2834}
2832 2835
2833/* Read a sequence of keys that ends with a non prefix character 2836/* Read a sequence of keys that ends with a non prefix character,
2834 according to the keymaps in KEYMAPS[0..nmaps-1]. Keymaps appearing 2837 storing it in KEYBUF, a buffer of size BUFSIZE.
2835 earlier in KEYMAPS take precidence over those appearing later. 2838 Prompt with PROMPT.
2836
2837 Store the sequence in KEYBUF, a buffer of size BUFSIZE. Prompt
2838 with PROMPT. Echo starting immediately unless `prompt' is 0.
2839 Return the length of the key sequence stored. 2839 Return the length of the key sequence stored.
2840 2840
2841 If the user switches frames in the midst of a key sequence, we 2841 Echo starting immediately unless `prompt' is 0.
2842 throw away any prefix we have read so far, and start afresh. For 2842
2843 mouse clicks, we look up the click in the keymap of the buffer 2843 Where a key sequence ends depends on the currently active keymaps.
2844 clicked on, throwing away any prefix if it is not the same buffer 2844 These include any minor mode keymaps active in the current buffer,
2845 we used to be reading from. */ 2845 the current buffer's local map, and the global map.
2846
2847 If a key sequence has no other bindings, we check Vfunction_key_map
2848 to see if some trailing subsequence might be the beginning of a
2849 function key's sequence. If so, we try to read the whole function
2850 key, and substitute its symbolic name into the key sequence.
2851
2852 We ignore unbound `down-' mouse clicks. We turn unbound `drag-'
2853 events into similar click events, if that would make them bound.
2854
2855 If we get a mouse click in a mode line, vertical divider, or other
2856 non-text area, we treat the click as if it were prefixed by the
2857 symbol denoting that area - `mode-line', `vertical-line', or
2858 whatever.
2859
2860 If the sequence starts with a mouse click, we read the key sequence
2861 with respect to the buffer clicked on, not the current buffer.
2846 2862
2863 If the user switches frames in the midst of a key sequence, we put
2864 off the switch-frame event until later; the next call to
2865 read_char will return it. */
2847static int 2866static int
2848read_key_sequence (keybuf, bufsize, prompt) 2867read_key_sequence (keybuf, bufsize, prompt)
2849 Lisp_Object *keybuf; 2868 Lisp_Object *keybuf;
2850 int bufsize; 2869 int bufsize;
2851 Lisp_Object prompt; 2870 char *prompt;
2852{ 2871{
2872 int count = specpdl_ptr - specpdl;
2873
2853 /* How many keys there are in the current key sequence. */ 2874 /* How many keys there are in the current key sequence. */
2854 int t; 2875 int t;
2855 2876
2856 /* The buffer that the most recently read event was typed at. This
2857 helps us read mouse clicks according to the buffer clicked in,
2858 and notice when the mouse has moved from one frame to another. */
2859 struct buffer *last_event_buffer = current_buffer;
2860
2861 /* The length of the echo buffer when we started reading, and 2877 /* The length of the echo buffer when we started reading, and
2862 the length of this_command_keys when we started reading. */ 2878 the length of this_command_keys when we started reading. */
2863 int echo_start; 2879 int echo_start;
2864 int keys_start = this_command_key_count; 2880 int keys_start;
2865 2881
2866 /* The number of keymaps we're scanning right now, and the number of 2882 /* The number of keymaps we're scanning right now, and the number of
2867 keymaps we have allocated space for. */ 2883 keymaps we have allocated space for. */
2868 int nmaps; 2884 int nmaps;
2869 int nmaps_allocated = 0; 2885 int nmaps_allocated = 0;
2870 2886
2871 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
2872 in the current keymaps, or nil where it is not a prefix. */
2873 Lisp_Object *submaps;
2874
2875 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in 2887 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
2876 the current keymaps. */ 2888 the current keymaps. */
2877 Lisp_Object *defs; 2889 Lisp_Object *defs;
2878 2890
2879 /* The index of the first keymap that has a binding for this key 2891 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
2880 sequence. In other words, the lowest i such that defs[i] is 2892 in the current keymaps, or nil where it is not a prefix. */
2881 non-nil.*/ 2893 Lisp_Object *submaps;
2894
2895 /* The index in defs[] of the first keymap that has a binding for
2896 this key sequence. In other words, the lowest i such that
2897 defs[i] is non-nil. */
2882 int first_binding; 2898 int first_binding;
2883 2899
2884 /* If mock_input > t, then KEYBUF[t] should be read as the next 2900 /* If t < mock_input, then KEYBUF[t] should be read as the next
2885 input key. 2901 input key.
2886 2902
2887 We use this to recover after recognizing a function key. Once we 2903 We use this to recover after recognizing a function key. Once we
2888 realize that a suffix of the current key sequence is actually a 2904 realize that a suffix of the current key sequence is actually a
2889 function key's escape sequence, we replace the suffix with the 2905 function key's escape sequence, we replace the suffix with the
2890 function key's binding from Vfunction_key_map. Now keybuf 2906 function key's binding from Vfunction_key_map. Now keybuf
2891 contains a new and different key sequence, so the echo area and 2907 contains a new and different key sequence, so the echo area,
2892 the submaps and defs arrays are wrong. In this situation, we set 2908 this_command_keys, and the submaps and defs arrays are wrong. In
2893 mock_input to t, set t to 0, and jump to restart; the loop will 2909 this situation, we set mock_input to t, set t to 0, and jump to
2894 read keys from keybuf up until mock_input, which rebuilds the 2910 restart_sequence; the loop will read keys from keybuf up until
2895 state, and then it will resume reading characters from the keyboard. */ 2911 mock_input, thus rebuilding the state; and then it will resume
2912 reading characters from the keyboard. */
2896 int mock_input = 0; 2913 int mock_input = 0;
2897 2914
2898 /* If the sequence is unbound in submaps[], then 2915 /* If the sequence is unbound in submaps[], then
2899 keymap[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map, 2916 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
2900 and fkey_map is its binding. If mock_input is in use, these 2917 and fkey_map is its binding.
2901 might be > t, indicating that all function key scanning should
2902 hold off until t reaches them. */
2903 2918
2919 These might be > t, indicating that all function key scanning
2920 should hold off until t reaches them. We do this when we've just
2921 recognized a function key, to avoid searching for the function
2922 key's again in Vfunction_key_map. */
2904 int fkey_start = 0, fkey_end = 0; 2923 int fkey_start = 0, fkey_end = 0;
2905 Lisp_Object fkey_map = Vfunction_key_map; 2924 Lisp_Object fkey_map = Vfunction_key_map;
2906 2925
@@ -2908,6 +2927,15 @@ read_key_sequence (keybuf, bufsize, prompt)
2908 we put it off for later. While we're reading, we keep the event here. */ 2927 we put it off for later. While we're reading, we keep the event here. */
2909 Lisp_Object delayed_switch_frame = Qnil; 2928 Lisp_Object delayed_switch_frame = Qnil;
2910 2929
2930
2931 /* If there is no function key map, turn off function key scanning. */
2932 if (NILP (Fkeymapp (Vfunction_key_map)))
2933 fkey_start = fkey_end = bufsize + 1;
2934
2935 /* We need to save the current buffer in case we switch buffers to
2936 find the right binding for a mouse click. */
2937 record_unwind_protect (save_excursion_restore, save_excursion_save ());
2938
2911 last_nonmenu_event = Qnil; 2939 last_nonmenu_event = Qnil;
2912 2940
2913 if (INTERACTIVE) 2941 if (INTERACTIVE)
@@ -2918,22 +2946,18 @@ read_key_sequence (keybuf, bufsize, prompt)
2918 /* This doesn't put in a dash if the echo buffer is empty, so 2946 /* This doesn't put in a dash if the echo buffer is empty, so
2919 you don't always see a dash hanging out in the minibuffer. */ 2947 you don't always see a dash hanging out in the minibuffer. */
2920 echo_dash (); 2948 echo_dash ();
2921 echo_start = echo_length ();
2922 } 2949 }
2923 2950
2924 /* If there is no function key map, turn off function key scanning. */ 2951 /* Record the initial state of the echo area and this_command_keys;
2925 if (NILP (Fkeymapp (Vfunction_key_map))) 2952 we will need to restore them if we replay a key sequence. */
2926 fkey_start = fkey_end = bufsize + 1;
2927
2928 restart:
2929 t = 0;
2930 this_command_key_count = keys_start;
2931
2932 /* This is a no-op the first time through, but if we restart, it
2933 reverts the echo area to its original state. */
2934 if (INTERACTIVE) 2953 if (INTERACTIVE)
2935 echo_truncate (echo_start); 2954 echo_start = echo_length ();
2955 keys_start = this_command_key_count;
2936 2956
2957 replay_sequence_new_buffer:
2958 /* Build our list of keymaps.
2959 If the sequence starts with a mouse click, we may need to switch buffers
2960 and jump back here; that's what replay_sequence_new_buffer is for. */
2937 { 2961 {
2938 Lisp_Object *maps; 2962 Lisp_Object *maps;
2939 2963
@@ -2945,7 +2969,7 @@ read_key_sequence (keybuf, bufsize, prompt)
2945 nmaps_allocated = nmaps; 2969 nmaps_allocated = nmaps;
2946 } 2970 }
2947 bcopy (maps, submaps, (nmaps - 2) * sizeof (submaps[0])); 2971 bcopy (maps, submaps, (nmaps - 2) * sizeof (submaps[0]));
2948 submaps[nmaps-2] = last_event_buffer->keymap; 2972 submaps[nmaps-2] = current_buffer->keymap;
2949 submaps[nmaps-1] = global_map; 2973 submaps[nmaps-1] = global_map;
2950 } 2974 }
2951 2975
@@ -2954,6 +2978,21 @@ read_key_sequence (keybuf, bufsize, prompt)
2954 if (! NILP (submaps[first_binding])) 2978 if (! NILP (submaps[first_binding]))
2955 break; 2979 break;
2956 2980
2981 replay_sequence:
2982 /* We jump here when a function key substitution has forced us to
2983 reprocess the current key sequence. keybuf[0..mock_input] is the
2984 sequence we want to reread. */
2985 t = 0;
2986
2987 /* These are no-ops the first time through, but if we restart, they
2988 revert the echo area and this_command_keys to their original state. */
2989 this_command_key_count = keys_start;
2990 if (INTERACTIVE)
2991 echo_truncate (echo_start);
2992
2993 /* If the best binding for the current key sequence is a keymap,
2994 or we may be looking at a function key's escape sequence, keep
2995 on reading. */
2957 while ((first_binding < nmaps && ! NILP (submaps[first_binding])) 2996 while ((first_binding < nmaps && ! NILP (submaps[first_binding]))
2958 || (first_binding >= nmaps && fkey_start < t)) 2997 || (first_binding >= nmaps && fkey_start < t))
2959 { 2998 {
@@ -2964,23 +3003,27 @@ read_key_sequence (keybuf, bufsize, prompt)
2964 while those allow us to restart the entire key sequence, 3003 while those allow us to restart the entire key sequence,
2965 echo_local_start and keys_local_start allow us to throw away 3004 echo_local_start and keys_local_start allow us to throw away
2966 just one key. */ 3005 just one key. */
2967 int echo_local_start = echo_length (); 3006 int echo_local_start, keys_local_start, local_first_binding;
2968 int keys_local_start = this_command_key_count; 3007
2969 int local_first_binding = first_binding;
2970
2971 if (t >= bufsize) 3008 if (t >= bufsize)
2972 error ("key sequence too long"); 3009 error ("key sequence too long");
2973 3010
2974 retry_key: 3011 if (INTERACTIVE)
3012 echo_local_start = echo_length ();
3013 keys_local_start = this_command_key_count;
3014 local_first_binding = first_binding;
3015
3016 replay_key:
2975 /* These are no-ops, unless we throw away a keystroke below and 3017 /* These are no-ops, unless we throw away a keystroke below and
2976 jumped back up to retry_key; in that case, these restore these 3018 jumped back up to replay_key; in that case, these restore the
2977 variables to their original state, allowing us to restart the 3019 variables to their original state, allowing us to replay the
2978 loop. */ 3020 loop. */
2979 echo_truncate (echo_local_start); 3021 if (INTERACTIVE)
3022 echo_truncate (echo_local_start);
2980 this_command_key_count = keys_local_start; 3023 this_command_key_count = keys_local_start;
2981 first_binding = local_first_binding; 3024 first_binding = local_first_binding;
2982 3025
2983 /* Are we re-reading a key sequence, as indicated by mock_input? */ 3026 /* Does mock_input indicate that we are re-reading a key sequence? */
2984 if (t < mock_input) 3027 if (t < mock_input)
2985 { 3028 {
2986 key = keybuf[t]; 3029 key = keybuf[t];
@@ -2991,33 +3034,64 @@ read_key_sequence (keybuf, bufsize, prompt)
2991 /* If not, we should actually read a character. */ 3034 /* If not, we should actually read a character. */
2992 else 3035 else
2993 { 3036 {
2994 struct buffer *buf;
2995
2996 key = read_char (!prompt, nmaps, submaps, last_nonmenu_event, 3037 key = read_char (!prompt, nmaps, submaps, last_nonmenu_event,
2997 &used_mouse_menu); 3038 &used_mouse_menu);
2998 3039
2999 /* The above routines return -1 at the end of a macro. 3040 /* read_char returns -1 at the end of a macro.
3000 Emacs 18 handles this by returning immediately with a 3041 Emacs 18 handles this by returning immediately with a
3001 zero, so that's what we'll do. */ 3042 zero, so that's what we'll do. */
3002 if (XTYPE (key) == Lisp_Int && XINT (key) < 0) 3043 if (XTYPE (key) == Lisp_Int && XINT (key) < 0)
3003 { 3044 {
3004 unread_switch_frame = delayed_switch_frame; 3045 t = 0;
3005 return 0; 3046 goto done;
3006 } 3047 }
3007 3048
3008 Vquit_flag = Qnil; 3049 Vquit_flag = Qnil;
3009 3050
3010 /* Clicks in non-text areas get prefixed by the symbol 3051 /* Clicks in non-text areas get prefixed by the symbol
3011 in their CHAR-ADDRESS field. For example, a click on 3052 in their CHAR-ADDRESS field. For example, a click on
3012 the mode line is prefixed by the symbol `mode-line'. */ 3053 the mode line is prefixed by the symbol `mode-line'.
3054
3055 Furthermore, key sequences beginning with mouse clicks
3056 are read using the keymaps of the buffer clicked on, not
3057 the current buffer. So we may have to switch the buffer
3058 here. */
3013 if (EVENT_HAS_PARAMETERS (key)) 3059 if (EVENT_HAS_PARAMETERS (key))
3014 { 3060 {
3015 Lisp_Object kind = EVENT_HEAD_KIND (EVENT_HEAD (key)); 3061 Lisp_Object kind = EVENT_HEAD_KIND (EVENT_HEAD (key));
3062
3016 if (EQ (kind, Qmouse_click)) 3063 if (EQ (kind, Qmouse_click))
3017 { 3064 {
3018 Lisp_Object posn = POSN_BUFFER_POSN (EVENT_START (key)); 3065 Lisp_Object window = POSN_WINDOW (EVENT_START (key));
3066 Lisp_Object posn = POSN_BUFFER_POSN (EVENT_START (key));
3067
3068 /* Key sequences beginning with mouse clicks are
3069 read using the keymaps in the buffer clicked on,
3070 not the current buffer. If we're at the
3071 beginning of a key sequence, switch buffers. */
3072 if (t == 0
3073 && XTYPE (window) == Lisp_Window
3074 && XTYPE (XWINDOW (window)->buffer) == Lisp_Buffer
3075 && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
3076 {
3077 if (XTYPE (posn) == Lisp_Symbol)
3078 {
3079 if (t + 1 >= bufsize)
3080 error ("key sequence too long");
3081 keybuf[t] = posn;
3082 keybuf[t+1] = key;
3083 mock_input = t + 2;
3084 }
3085 else
3086 {
3087 keybuf[t] = key;
3088 mock_input = t + 1;
3089 }
3019 3090
3020 if (XTYPE (posn) == Lisp_Symbol) 3091 set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
3092 goto replay_sequence_new_buffer;
3093 }
3094 else if (XTYPE (posn) == Lisp_Symbol)
3021 { 3095 {
3022 if (t + 1 >= bufsize) 3096 if (t + 1 >= bufsize)
3023 error ("key sequence too long"); 3097 error ("key sequence too long");
@@ -3025,7 +3099,7 @@ read_key_sequence (keybuf, bufsize, prompt)
3025 keybuf[t+1] = key; 3099 keybuf[t+1] = key;
3026 mock_input = t + 2; 3100 mock_input = t + 2;
3027 3101
3028 goto retry_key; 3102 goto replay_key;
3029 } 3103 }
3030 } 3104 }
3031 else if (EQ (kind, Qswitch_frame)) 3105 else if (EQ (kind, Qswitch_frame))
@@ -3036,57 +3110,14 @@ read_key_sequence (keybuf, bufsize, prompt)
3036 if (t > 0) 3110 if (t > 0)
3037 { 3111 {
3038 delayed_switch_frame = key; 3112 delayed_switch_frame = key;
3039 goto retry_key; 3113 goto replay_key;
3040 } 3114 }
3041 } 3115 }
3042 } 3116 }
3043
3044#if 0 /* This shouldn't be necessary any more, now that we have
3045 switch-frame events. */
3046#ifdef MULTI_FRAME
3047 /* What buffer was this event typed/moused at? */
3048 if (used_mouse_menu)
3049 /* Never change last_event_buffer for using a menu. */
3050 buf = last_event_buffer;
3051 else if (XTYPE (key) == Lisp_Int || XTYPE (key) == Lisp_Symbol)
3052 {
3053 buf = ((XTYPE (Vlast_event_frame) == Lisp_Frame)
3054 ? (XBUFFER
3055 (XWINDOW
3056 (FRAME_SELECTED_WINDOW
3057 (XFRAME (Vlast_event_frame)))->buffer))
3058 : last_event_buffer);
3059 }
3060 else if (EVENT_HAS_PARAMETERS (key))
3061 {
3062 Lisp_Object window = POSN_WINDOW (EVENT_START (key));
3063
3064 if (NILP (window))
3065 abort ();
3066
3067 buf = XBUFFER (XWINDOW (window)->buffer);
3068 }
3069 else
3070 abort ();
3071
3072 /* If this event came to a different buffer than the one
3073 we're currently in, switch buffers and start a new key
3074 sequence, starting with key. */
3075 if (buf != last_event_buffer)
3076 {
3077 last_event_buffer = buf;
3078 Fselect_frame (Vlast_event_frame, Qnil);
3079
3080 /* Arrange to read key as the next event. */
3081 keybuf[0] = key;
3082 mock_input = 1;
3083
3084 goto restart;
3085 }
3086#endif /* MULTI_FRAME */
3087#endif /* 0 */
3088 } 3117 }
3089 3118
3119 /* We have finally decided that KEY is something we might want
3120 to look up. */
3090 first_binding = (follow_key (key, 3121 first_binding = (follow_key (key,
3091 nmaps - first_binding, 3122 nmaps - first_binding,
3092 submaps + first_binding, 3123 submaps + first_binding,
@@ -3094,7 +3125,7 @@ read_key_sequence (keybuf, bufsize, prompt)
3094 submaps + first_binding) 3125 submaps + first_binding)
3095 + first_binding); 3126 + first_binding);
3096 3127
3097 /* If this key wasn't bound, we'll try some fallbacks. */ 3128 /* If KEY wasn't bound, we'll try some fallbacks. */
3098 if (first_binding >= nmaps) 3129 if (first_binding >= nmaps)
3099 { 3130 {
3100 Lisp_Object head = EVENT_HEAD (key); 3131 Lisp_Object head = EVENT_HEAD (key);
@@ -3108,15 +3139,27 @@ read_key_sequence (keybuf, bufsize, prompt)
3108 /* We drop unbound `down-' events altogether. */ 3139 /* We drop unbound `down-' events altogether. */
3109 if (modifiers & down_modifier) 3140 if (modifiers & down_modifier)
3110 { 3141 {
3111 /* Adding prefixes for non-textual mouse clicks creates 3142 /* To make sure that mock_input doesn't just give
3112 two characters of mock input, and this can't be the 3143 this event back to us; we want to delete this
3113 first, so it's okay to clear mock_input in that case. 3144 event from the mock input queue. We could delete
3114 Only function key expansion could create more than 3145 keybuf[t] and shift everything after that to the
3115 two keys, but that should never generate mouse events, 3146 left by one spot, but we'd also have to fix up
3116 so it's okay to nuke mock_input in that case too. 3147 any variable that points into keybuf, and shifting
3148 isn't really necessary anyway.
3149
3150 Adding prefixes for non-textual mouse clicks creates
3151 two characters of mock input, and this must be the
3152 second, so mock_input would be over anyway; it's okay
3153 to zero it.
3154
3155 Beyond that, only function key expansion could
3156 create more than two keys, but that should never
3157 generate mouse events, so it's okay to zero
3158 mock_input in that case too.
3159
3117 Isn't this just the most wonderful code ever? */ 3160 Isn't this just the most wonderful code ever? */
3118 mock_input = 0; 3161 mock_input = 0;
3119 goto retry_key; 3162 goto replay_key;
3120 } 3163 }
3121 3164
3122 /* We turn unbound `drag-' events into `click-' 3165 /* We turn unbound `drag-' events into `click-'
@@ -3159,7 +3202,7 @@ read_key_sequence (keybuf, bufsize, prompt)
3159 /* If the sequence is unbound, see if we can hang a function key 3202 /* If the sequence is unbound, see if we can hang a function key
3160 off the end of it. We only want to scan real keyboard input 3203 off the end of it. We only want to scan real keyboard input
3161 for function key sequences, so if mock_input says that we're 3204 for function key sequences, so if mock_input says that we're
3162 re-scanning after expanding a function key, don't examine it. */ 3205 re-reading old events, don't examine it. */
3163 if (first_binding >= nmaps 3206 if (first_binding >= nmaps
3164 && t >= mock_input) 3207 && t >= mock_input)
3165 { 3208 {
@@ -3168,20 +3211,26 @@ read_key_sequence (keybuf, bufsize, prompt)
3168 /* Scan from fkey_end until we find a bound suffix. */ 3211 /* Scan from fkey_end until we find a bound suffix. */
3169 while (fkey_end < t) 3212 while (fkey_end < t)
3170 { 3213 {
3214 Lisp_Object key;
3215
3216 key = keybuf[fkey_end++];
3171 /* Look up meta-characters by prefixing them 3217 /* Look up meta-characters by prefixing them
3172 with meta_prefix_char. I hate this. */ 3218 with meta_prefix_char. I hate this. */
3173 if (keybuf[fkey_end] & 0x80) 3219 if (XTYPE (key) == Lisp_Int && XINT (key) & 0x80)
3174 fkey_next = 3220 {
3175 get_keymap_1 3221 fkey_next =
3176 ((get_keyelt 3222 get_keymap_1
3177 (access_keymap (fkey_map, meta_prefix_char, 1))), 3223 (get_keyelt
3178 0); 3224 (access_keymap
3225 (fkey_map, meta_prefix_char, 1)),
3226 0, 1);
3227 XFASTINT (key) = XFASTINT (key) & 0x7f;
3228 }
3179 else 3229 else
3180 fkey_next = fkey_map; 3230 fkey_next = fkey_map;
3181 3231
3182 fkey_next = 3232 fkey_next =
3183 get_keyelt (access_keymap 3233 get_keyelt (access_keymap (fkey_next, key, 1));
3184 (fkey_next, keybuf[fkey_end++] & 0x7f, 1));
3185 3234
3186 /* If keybuf[fkey_start..fkey_end] is bound in the 3235 /* If keybuf[fkey_start..fkey_end] is bound in the
3187 function key map and it's a suffix of the current 3236 function key map and it's a suffix of the current
@@ -3201,10 +3250,10 @@ read_key_sequence (keybuf, bufsize, prompt)
3201 mock_input = t; 3250 mock_input = t;
3202 fkey_start = fkey_end = t; 3251 fkey_start = fkey_end = t;
3203 3252
3204 goto restart; 3253 goto replay_sequence;
3205 } 3254 }
3206 3255
3207 fkey_map = get_keymap_1 (fkey_next, 0); 3256 fkey_map = get_keymap_1 (fkey_next, 0, 1);
3208 3257
3209 /* If we no longer have a bound suffix, try a new positions for 3258 /* If we no longer have a bound suffix, try a new positions for
3210 fkey_start. */ 3259 fkey_start. */
@@ -3221,7 +3270,9 @@ read_key_sequence (keybuf, bufsize, prompt)
3221 ? defs[first_binding] 3270 ? defs[first_binding]
3222 : Qnil); 3271 : Qnil);
3223 3272
3273 done:
3224 unread_switch_frame = delayed_switch_frame; 3274 unread_switch_frame = delayed_switch_frame;
3275 unbind_to (count, Qnil);
3225 return t; 3276 return t;
3226} 3277}
3227 3278
@@ -3257,7 +3308,7 @@ typed while in this function is treated like any other character, and\n\
3257 this_command_key_count = 0; 3308 this_command_key_count = 0;
3258 3309
3259 i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), 3310 i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])),
3260 NILP (prompt) ? 0 : XSTRING (prompt)->data); 3311 NILP (prompt) ? 0 : XSTRING (prompt)->data);
3261 3312
3262 UNGCPRO; 3313 UNGCPRO;
3263 return make_array (i, keybuf); 3314 return make_array (i, keybuf);