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

From: Eli Zaretskii <[email-masked]>
Date: Sat, 11 Nov 2017 11:44:25 +0200

> From: Olaf Rogalsky <[email-masked]>
> Date: Tue, 07 Nov 2017 00:47:28 +0100
> 
> My patch takes place after a key translation has been performed.  It
> checks, that the key translation is not empty, (or more precisely, that
> the current event sequence is not empty),
> 
>            first_event = mock_input > 0 ? keybuf[0] : Qnil;  
>                          ^^^^^^^^^^^^^^
> 
> and if so, sets the variable first_event to the first event in the
> sequence.
> 
>            first_event = mock_input > 0 ? keybuf[0] : Qnil;  
>                                           ^^^^^^^^^
> 
> Here, all key translations where allready replaced by their
> corresponding binding.  If the current event sequence is empty,
> first_event is set to Qnil, which means that the default active keymaps
> should be used. This would be the case, if the raw key sequence was
> bound to an empty vector in a translation map.
> 
>            first_event = mock_input > 0 ? keybuf[0] : Qnil;  
>                                                       ^^^^
> 
> Now back to my original problem: mouse clicks in the mode line do not
> work correctly. xterm-mouse-mode uses the input-decode-map to translate
> special character sequences coming from xterm (starting with "\e[") into
> proper mouse events.  Without the patch, first_event is set to ?\e.
> Therefore the esc-map is used to find a binding for the mouse event,
> which of cause does not work as intended. With the patch, first_event is
> set to the mouse event and the binding in the local-map property will be
> found.
> 
> Et vola, mouse clicks in the mode line will work :-)

Thanks for the detailed explanations, they help a lot.

I have a few questions.  First, why did you need this hunk:

> @@ -9669,6 +9672,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
>  	      indec.start += diff;
>  	      fkey.end += diff;
>  	      fkey.start += diff;
> +              first_event = mock_input > 0 ? keybuf[0] : Qnil;
>  
>  	      goto replay_sequence;
>  	    }

This is no longer about input-decode-map, it's about
key-translation-map.  And xterm-mouse-mode doesn't use
key-translation-map, so why change this part?

The next question is whether this patch caters correctly to features
other than xterm-mouse-mode.  The input-decode-map is used by
terminal-specific support in xterm.el and rxvt.el -- does it still
make sense to use keybuf[0] as first_event for replaying their
sequences?