Subject: Re: bug#29104: AW: bug#29104: [PATCH]: xterm-mouse-mode clicks in the modeline dont use the keymap properties of the modeline strings

From: Stefan Monnier <[email-masked]>
Date: Sat, 18 Nov 2017 23:24:49 -0500

> In a more radical approach and instead of my original patch, one can
> get rid off with the variable first_event all together, see patch
> below. It simplifies the code a little bit, but of course is
> more risky.

Indeed, I got a similar patch (see below) by simply moving your
assignment to first_event from "before the `goto replay_sequence`" to
after it (i.e. after the replay_sequence label).

Your patch looks about as good as mine.  I think they're both better
than your first patch because they fix the problem in a single place
(The Right Place).

I installed mine because it's shorter and looks more "obviously safe"
to me.  Thanks a lot for tracking it down!

        Stefan

diff --git a/src/keyboard.c b/src/keyboard.c
index 399149ae97..6b7a6bfa74 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -8919,7 +8919,6 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
   ptrdiff_t keys_start;
 
   Lisp_Object current_binding = Qnil;
-  Lisp_Object first_event = Qnil;
 
   /* Index of the first key that has no binding.
      It is useless to try fkey.start larger than that.  */
@@ -9029,6 +9028,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
 
   starting_buffer = current_buffer;
   first_unbound = bufsize + 1;
+  Lisp_Object first_event = mock_input > 0 ? keybuf[0] : Qnil;
 
   /* Build our list of keymaps.
      If we recognize a function key and replace its escape sequence in