Subject: Re: bug#75219: 31.0.50; mouse-2 mode-line binding overridden by mouse-1-click-follows-link

From: Stefan Monnier <[email-masked]>
Date: Sun, 05 Jan 2025 13:10:45 -0500

> The reason why key-binding considers the local keymap at point is this
> part of current-active-maps (which key-binding calls):
>
>       ptrdiff_t pt = click_position (position);  <<<<<<<<<<<<<<<<<<<<<
>       /* This usually returns the buffer's local map,
> 	 but that can be overridden by a `local-map' property.  */
>       Lisp_Object local_map = get_local_map (pt, current_buffer, Qlocal_map);
>       /* This returns nil unless there is a `keymap' property.  */
>       Lisp_Object keymap = get_local_map (pt, current_buffer, Qkeymap);
>       Lisp_Object otlp = KVAR (current_kboard, Voverriding_terminal_local_map);
>
> and click_position does this:
>
>   static ptrdiff_t
>   click_position (Lisp_Object position)
>   {
>     EMACS_INT pos = (FIXNUMP (position) ? XFIXNUM (position)
> 		     : MARKERP (position) ? marker_position (position)
> 		     : PT);
>     if (! (BEGV <= pos && pos <= ZV))
>       args_out_of_range (Fcurrent_buffer (), position);
>     return pos;
>   }
>
> So if POSITION is a mouse click event, click_position will always
> return the position of point.

Yeah, we pay attention to the "window" part of the posn but not the
rest.  🙁

> Stefan, any ideas or suggestions?

Maybe something like the patch below, but maybe we should call
`posn-point` instead?

        Stefan

diff --git a/src/keymap.c b/src/keymap.c
index e3461243cdd..7393495b41a 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -1659,6 +1659,10 @@ click_position (Lisp_Object position)
 {
   EMACS_INT pos = (FIXNUMP (position) ? XFIXNUM (position)
 		   : MARKERP (position) ? marker_position (position)
+		       /* FIXME: POSN_POSN seems to be less thorough
+		          than `posn-point'! */
+		   : CONSP (position) && INTEGERP (POSN_POSN (position))
+		     ?  POSN_POSN (position)
 		   : PT);
   if (! (BEGV <= pos && pos <= ZV))
     args_out_of_range (Fcurrent_buffer (), position);