Mercurial > emacs
comparison src/keyboard.c @ 1515:8cc7bc81d2aa
* keyboard.c: #include dispextern.h.
(recursive_edit_unwind, command_loop, Fthis_command_keys): Declare
these to return Lisp_Objects at the very top of the file, to avoid
having them implicitly declared as ints.
(echo_char): Use EQ to compare C to help_char.
(read_char): Remember to apply XFASTINT to the return value of
Flength before using it. Apply XINT to c when clearing its high
bits and meta bits, and when writing it to the dribble file.
(read_char_menu_prompt): Use EQ to compare obj with
menu_prompt_more_char and its control-character analog.
(read_key_sequence): Declare PROMPT to be char *, not a
Lisp_Object. Use the appropriate accessors on keybuf when looking
for ASCII function key sequences.
* keyboard.c (echobuf): Make this 300 characters, not 100. This
isn't a real fix, but it's quick.
* keyboard.c (read_char): When returning an unread switch-frame
event, jump to reread_first to return it, rather than reread; this
makes sure the event gets echoed (if appropriate) and goes into
this_command_keys.
* keyboard.c (read_key_sequence): If the key sequence starts with
a mouse click, read the key sequence using the keymaps of the
buffer clicked on, not the current buffer.
* keyboard.c (unread_switch_frame): Make this static, to indicate
that nobody outside of this file uses it.
* keyboard.c (follow_key): Ask get_keymap_1 to perform autoloads.
(read_key_sequence): When pursuing potential bindings in the
function key map, ask get_keymap_1 to perform autoloading. This
is hardly important, but it's consistent.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sat, 31 Oct 1992 05:21:45 +0000 |
parents | 7f2b81dc2dd1 |
children | a681f63f93fa |
comparison
equal
deleted
inserted
replaced
1514:ceaecac6bf2e | 1515:8cc7bc81d2aa |
---|---|
31 #include "frame.h" | 31 #include "frame.h" |
32 #include "window.h" | 32 #include "window.h" |
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> |
39 | 40 |
40 #ifndef VMS | 41 #ifndef VMS |
154 /* If not Qnil, an object to be read as the next command input. */ | 155 /* If not Qnil, an object to be read as the next command input. */ |
155 Lisp_Object unread_command_char; | 156 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 |
160 Lisp_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. */ | |
163 static 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. */ |
164 | 167 |
165 Lisp_Object meta_prefix_char; | 168 Lisp_Object meta_prefix_char; |
321 | 324 |
322 /* Symbols to use for non-text mouse positions. */ | 325 /* Symbols to use for non-text mouse positions. */ |
323 Lisp_Object Qmode_line; | 326 Lisp_Object Qmode_line; |
324 Lisp_Object Qvertical_line; | 327 Lisp_Object Qvertical_line; |
325 | 328 |
329 Lisp_Object recursive_edit_unwind (), command_loop (); | |
330 Lisp_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. */ |
329 EMACS_TIME *input_available_clear_time; | 334 EMACS_TIME *input_available_clear_time; |
330 | 335 |
372 | 377 |
373 /* Nonzero means echo each character as typed. */ | 378 /* Nonzero means echo each character as typed. */ |
374 static int immediate_echo; | 379 static 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. */ |
378 static char echobuf[100]; | 383 static 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. */ |
381 static char *echoptr; | 386 static char *echoptr; |
382 | 387 |
383 #define min(a,b) ((a)<(b)?(a):(b)) | 388 #define min(a,b) ((a)<(b)?(a):(b)) |
433 return; | 438 return; |
434 bcopy (name->data, ptr, name->size); | 439 bcopy (name->data, ptr, name->size); |
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); |
442 } | 447 } |
443 | 448 |
561 record_auto_save () | 566 record_auto_save () |
562 { | 567 { |
563 last_auto_save = num_nonmacro_input_chars; | 568 last_auto_save = num_nonmacro_input_chars; |
564 } | 569 } |
565 | 570 |
566 Lisp_Object recursive_edit_unwind (), command_loop (); | |
567 | |
568 DEFUN ("recursive-edit", Frecursive_edit, Srecursive_edit, 0, 0, "", | 571 DEFUN ("recursive-edit", Frecursive_edit, Srecursive_edit, 0, 0, "", |
569 "Invoke the editor command loop recursively.\n\ | 572 "Invoke the editor command loop recursively.\n\ |
570 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\ | 573 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\ |
571 that tells this function to return.\n\ | 574 that tells this function to return.\n\ |
572 Alternately, `(throw 'exit t)' makes this function signal an error.\n\ | 575 Alternately, `(throw 'exit t)' makes this function signal an error.\n\ |
1141 came from. Normally, command_loop_1 selects | 1144 came from. Normally, command_loop_1 selects |
1142 Vlast_event_frame after each command is read, but events read | 1145 Vlast_event_frame after each command is read, but events read |
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; |
1150 } | 1153 } |
1151 | 1154 |
1159 { | 1162 { |
1160 c = unread_switch_frame; | 1163 c = unread_switch_frame; |
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. */ |
1169 save_getcjmp (save_jump); | 1172 save_getcjmp (save_jump); |
1170 | 1173 |
1297 /* If kbd_buffer_get_event gave us an EOF, return that. */ | 1300 /* If kbd_buffer_get_event gave us an EOF, return that. */ |
1298 if (XINT (c) < 0) | 1301 if (XINT (c) < 0) |
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++; |
1310 XVECTOR (recent_keys)->contents[recent_keys_index] = c; | 1313 XVECTOR (recent_keys)->contents[recent_keys_index] = c; |
1311 if (++recent_keys_index >= NUM_RECENT_KEYS) | 1314 if (++recent_keys_index >= NUM_RECENT_KEYS) |
1315 the event's symbol to the dribble file, in <brackets>. Bleaugh. | 1318 the event's symbol to the dribble file, in <brackets>. Bleaugh. |
1316 If you, dear reader, have a better idea, you've got the source. :-) */ | 1319 If you, dear reader, have a better idea, you've got the source. :-) */ |
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; |
1324 | 1327 |
1325 /* If it's a structured event, take the event header. */ | 1328 /* If it's a structured event, take the event header. */ |
2725 if (XTYPE (obj) != Lisp_Int) | 2728 if (XTYPE (obj) != Lisp_Int) |
2726 return obj; | 2729 return obj; |
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 } |
2736 | 2739 |
2737 /* Reading key sequences. */ | 2740 /* Reading key sequences. */ |
2775 get_keyelt (access_keymap (current[i], meta_prefix_char, 1)); | 2778 get_keyelt (access_keymap (current[i], meta_prefix_char, 1)); |
2776 | 2779 |
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; |
2784 | 2787 |
2785 current = next; | 2788 current = next; |
2823 } | 2826 } |
2824 | 2827 |
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 | 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. | |
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. */ | |
2847 static int | 2866 static int |
2848 read_key_sequence (keybuf, bufsize, prompt) | 2867 read_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 | |
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 | 2876 |
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 |
2887 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in | |
2888 the current keymaps. */ | |
2889 Lisp_Object *defs; | |
2890 | |
2871 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] | 2891 /* 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. */ | 2892 in the current keymaps, or nil where it is not a prefix. */ |
2873 Lisp_Object *submaps; | 2893 Lisp_Object *submaps; |
2874 | 2894 |
2875 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in | 2895 /* The index in defs[] of the first keymap that has a binding for |
2876 the current keymaps. */ | 2896 this key sequence. In other words, the lowest i such that |
2877 Lisp_Object *defs; | 2897 defs[i] is non-nil. */ |
2878 | |
2879 /* The index of the first keymap that has a binding for this key | |
2880 sequence. In other words, the lowest i such that defs[i] is | |
2881 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 | 2918 |
2902 hold off until t reaches them. */ | 2919 These might be > t, indicating that all function key scanning |
2903 | 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 |
2907 /* If we receive a ``switch-frame'' event in the middle of a key sequence, | 2926 /* If we receive a ``switch-frame'' event in the middle of a key sequence, |
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) |
2914 { | 2942 { |
2915 if (prompt) | 2943 if (prompt) |
2916 echo_prompt (prompt); | 2944 echo_prompt (prompt); |
2917 else if (cursor_in_echo_area) | 2945 else if (cursor_in_echo_area) |
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 (); | 2949 } |
2922 } | 2950 |
2923 | 2951 /* Record the initial state of the echo area and this_command_keys; |
2924 /* If there is no function key map, turn off function key scanning. */ | 2952 we will need to restore them if we replay a key sequence. */ |
2925 if (NILP (Fkeymapp (Vfunction_key_map))) | |
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 (); |
2936 | 2955 keys_start = this_command_key_count; |
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 |
2940 nmaps = current_minor_maps (0, &maps) + 2; | 2964 nmaps = current_minor_maps (0, &maps) + 2; |
2941 if (nmaps > nmaps_allocated) | 2965 if (nmaps > nmaps_allocated) |
2943 submaps = (Lisp_Object *) alloca (nmaps * sizeof (submaps[0])); | 2967 submaps = (Lisp_Object *) alloca (nmaps * sizeof (submaps[0])); |
2944 defs = (Lisp_Object *) alloca (nmaps * sizeof (defs[0])); | 2968 defs = (Lisp_Object *) alloca (nmaps * sizeof (defs[0])); |
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 |
2952 /* Find an accurate initial value for first_binding. */ | 2976 /* Find an accurate initial value for first_binding. */ |
2953 for (first_binding = 0; first_binding < nmaps; first_binding++) | 2977 for (first_binding = 0; first_binding < nmaps; first_binding++) |
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 { |
2960 Lisp_Object key; | 2999 Lisp_Object key; |
2961 int used_mouse_menu = 0; | 3000 int used_mouse_menu = 0; |
2962 | 3001 |
2963 /* These variables are analogous to echo_start and keys_start; | 3002 /* These variables are analogous to echo_start and keys_start; |
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]; |
2987 add_command_key (key); | 3030 add_command_key (key); |
2988 echo_char (key); | 3031 echo_char (key); |
2989 } | 3032 } |
2990 | 3033 |
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)); |
3019 | 3066 Lisp_Object posn = POSN_BUFFER_POSN (EVENT_START (key)); |
3020 if (XTYPE (posn) == Lisp_Symbol) | 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 } | |
3090 | |
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"); |
3024 keybuf[t] = posn; | 3098 keybuf[t] = posn; |
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)) |
3032 { | 3106 { |
3033 /* If we're at the beginning of a key sequence, go | 3107 /* If we're at the beginning of a key sequence, go |
3034 ahead and return this event. If we're in the | 3108 ahead and return this event. If we're in the |
3035 midst of a key sequence, delay it until the end. */ | 3109 midst of a key sequence, delay it until the end. */ |
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, |
3093 defs + first_binding, | 3124 defs + first_binding, |
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); |
3101 | 3132 |
3102 if (XTYPE (head) == Lisp_Symbol) | 3133 if (XTYPE (head) == Lisp_Symbol) |
3106 XINT (XCONS (XCONS (breakdown)->cdr)->car); | 3137 XINT (XCONS (XCONS (breakdown)->cdr)->car); |
3107 | 3138 |
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-' |
3123 events, if the click would be bound. */ | 3166 events, if the click would be bound. */ |
3124 else if (modifiers & drag_modifier) | 3167 else if (modifiers & drag_modifier) |
3157 last_nonmenu_event = key; | 3200 last_nonmenu_event = key; |
3158 | 3201 |
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 { |
3166 Lisp_Object fkey_next; | 3209 Lisp_Object fkey_next; |
3167 | 3210 |
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 |
3188 sequence (i.e. fkey_end == t), replace it with | 3237 sequence (i.e. fkey_end == t), replace it with |
3189 the binding and restart with fkey_start at the end. */ | 3238 the binding and restart with fkey_start at the end. */ |
3199 (t - fkey_start) * sizeof (keybuf[0])); | 3248 (t - fkey_start) * sizeof (keybuf[0])); |
3200 | 3249 |
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. */ |
3211 if (NILP (fkey_map)) | 3260 if (NILP (fkey_map)) |
3212 { | 3261 { |
3219 | 3268 |
3220 read_key_sequence_cmd = (first_binding < nmaps | 3269 read_key_sequence_cmd = (first_binding < nmaps |
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 |
3228 DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 2, 0, | 3279 DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 2, 0, |
3229 "Read a sequence of keystrokes and return as a string or vector.\n\ | 3280 "Read a sequence of keystrokes and return as a string or vector.\n\ |
3255 | 3306 |
3256 if (NILP (continue_echo)) | 3307 if (NILP (continue_echo)) |
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); |
3264 } | 3315 } |
3265 | 3316 |