aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Colascione2018-06-09 17:45:01 -0700
committerDaniel Colascione2018-06-09 17:46:05 -0700
commitd12924cacb86c53a0547f73af35169db8e44d628 (patch)
treef808e11c5930db544fbf76b89a0a018443a66e4b /src
parentaaffae8458dcd774540e7e6b4219c8b5a9902075 (diff)
downloademacs-d12924cacb86c53a0547f73af35169db8e44d628.tar.gz
emacs-d12924cacb86c53a0547f73af35169db8e44d628.zip
Correctly set last_nonmenu_event when replaying
read_key_sequence can, in various circumstances, play back recorded events. Make sure that we set last_nonmenu_event as if we weren't replaying. Without this change, we leave last_nonmenu_event set to whatever it was before we started replaying, leading to spurious random keymap menu prompts appearing after reading terminal control sequences, the translation of which sometimes causes event replays. * src/keyboard.c: (grow_bool_vector): New function (read_key_sequence): Remember menu event history per-event.
Diffstat (limited to 'src')
-rw-r--r--src/keyboard.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index c0c863f0d3e..bd9292c2652 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -8858,6 +8858,31 @@ void init_raw_keybuf_count (void)
8858 raw_keybuf_count = 0; 8858 raw_keybuf_count = 0;
8859} 8859}
8860 8860
8861/* Grow a vector to fit.
8862
8863 On entry, *VECTOR is nil or a bool vector. Upon return, *VECTOR
8864 contains a bool vector of size at least NEEDED_LENGTH, with any new
8865 values to false. Return the new value of *VECTOR. */
8866static Lisp_Object
8867grow_bool_vector (Lisp_Object *vector, int needed_length)
8868{
8869 EMACS_INT old_length = NILP (*vector) ? 0 : bool_vector_size (*vector);
8870 if (NILP (*vector) || old_length < needed_length)
8871 {
8872 EMACS_INT new_length = old_length ? old_length : 64;
8873 while (new_length < needed_length)
8874 new_length *= 2;
8875 Lisp_Object new_vector =
8876 Fmake_bool_vector (make_number (needed_length), Qnil);
8877 if (old_length)
8878 memcpy (bool_vector_data (new_vector),
8879 bool_vector_data (*vector),
8880 bool_vector_bytes (old_length));
8881 *vector = new_vector;
8882 }
8883 return *vector;
8884}
8885
8861/* Read a sequence of keys that ends with a non prefix character, 8886/* Read a sequence of keys that ends with a non prefix character,
8862 storing it in KEYBUF, a buffer of size BUFSIZE. 8887 storing it in KEYBUF, a buffer of size BUFSIZE.
8863 Prompt with PROMPT. 8888 Prompt with PROMPT.
@@ -8934,6 +8959,11 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
8934 reading characters from the keyboard. */ 8959 reading characters from the keyboard. */
8935 int mock_input = 0; 8960 int mock_input = 0;
8936 8961
8962 /* This bool vector remembers whether each event in the mocked input
8963 came from a mouse menu. We ordinarily leave it nil and create it
8964 the first time we remember a mouse event. */
8965 Lisp_Object used_mouse_menu_history = Qnil;
8966
8937 /* If the sequence is unbound in submaps[], then 8967 /* If the sequence is unbound in submaps[], then
8938 keybuf[fkey.start..fkey.end-1] is a prefix in Vfunction_key_map, 8968 keybuf[fkey.start..fkey.end-1] is a prefix in Vfunction_key_map,
8939 and fkey.map is its binding. 8969 and fkey.map is its binding.
@@ -8974,8 +9004,6 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
8974 of raw_keybuf created by the outer call. */ 9004 of raw_keybuf created by the outer call. */
8975 /* raw_keybuf_count = 0; */ 9005 /* raw_keybuf_count = 0; */
8976 9006
8977 last_nonmenu_event = Qnil;
8978
8979 delayed_switch_frame = Qnil; 9007 delayed_switch_frame = Qnil;
8980 9008
8981 if (INTERACTIVE) 9009 if (INTERACTIVE)
@@ -9039,11 +9067,12 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
9039 9067
9040 /* Start from the beginning in keybuf. */ 9068 /* Start from the beginning in keybuf. */
9041 t = 0; 9069 t = 0;
9070 last_nonmenu_event = Qnil;
9042 9071
9043 /* These are no-ops the first time through, but if we restart, they 9072 /* These are no-ops the first time through, but if we restart, they
9044 revert the echo area and this_command_keys to their original state. */ 9073 revert the echo area and this_command_keys to their original state. */
9045 this_command_key_count = keys_start; 9074 this_command_key_count = keys_start;
9046 if (INTERACTIVE && t < mock_input) 9075 if (INTERACTIVE)
9047 echo_truncate (echo_start); 9076 echo_truncate (echo_start);
9048 9077
9049 /* If the best binding for the current key sequence is a keymap, or 9078 /* If the best binding for the current key sequence is a keymap, or
@@ -9137,6 +9166,9 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
9137 current_kboard->immediate_echo = false; 9166 current_kboard->immediate_echo = false;
9138 echo_now (); 9167 echo_now ();
9139 } 9168 }
9169 used_mouse_menu = !NILP (used_mouse_menu_history) &&
9170 t < bool_vector_size (used_mouse_menu_history) &&
9171 bool_vector_bitref (used_mouse_menu_history, t);
9140 } 9172 }
9141 9173
9142 /* If not, we should actually read a character. */ 9174 /* If not, we should actually read a character. */
@@ -9150,6 +9182,10 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
9150 key = read_char (prevent_redisplay ? -2 : NILP (prompt), 9182 key = read_char (prevent_redisplay ? -2 : NILP (prompt),
9151 current_binding, last_nonmenu_event, 9183 current_binding, last_nonmenu_event,
9152 &used_mouse_menu, NULL); 9184 &used_mouse_menu, NULL);
9185 if (used_mouse_menu || !NILP (used_mouse_menu_history))
9186 bool_vector_set (
9187 grow_bool_vector (&used_mouse_menu_history, t + 1),
9188 t, used_mouse_menu);
9153 if ((INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */ 9189 if ((INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */
9154 /* When switching to a new tty (with a new keyboard), 9190 /* When switching to a new tty (with a new keyboard),
9155 read_char returns the new buffer, rather than -2 9191 read_char returns the new buffer, rather than -2