Subject: Re: bug#42889: 28.0.50; make-pointer-invisible t should work also for navigation commands

From: Stefan Kangas <[email-masked]>
Date: Mon, 17 Aug 2020 15:34:48 +0000

Eli Zaretskii <[email-masked]> writes:

>> Please consider the following feature request:
>>
>> 0. emacs -Q
>> 1. (setq make-pointer-invisible t)
>> 2. M-x customize-group RET RET
>> 3. Move mouse pointer over e.g. "Editing" to highlight it
>> 4. C-n C-p C-f C-b
>>
>> Result: "Editing" is still highlighted.
>>
>> Desired result: "Editing" is _not_ highlighted.
>
> I think it should be very easy to add such a feature, and I'm willing
> to help by advice.  Want to give it a try?

Sure, why not?  Thanks for offering to help.

I had a first naive crack at it, and ended up with the attached.  It
covers the commands that often irks me, but it might need some more
adjusting.  I considered exposing this to Lisp, but it seemed better to
do this in the low-level primitives, maybe?

I did find one problem, which is that the mouse cursor disappears when I
scroll using the mouse wheel.  I tried fixing it using a simple
let-binding, but that didn't work for some reason I don't yet understand
(see patch).

Also, is this behaviour suitable as a default or should it be optional?

Best regards,
Stefan Kangas
diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index 8e2039ba9d..294835f16a 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -253,6 +253,7 @@ mwheel-scroll
          (mods
 	  (delq 'click (delq 'double (delq 'triple (event-modifiers event)))))
          (amt (assoc mods mouse-wheel-scroll-amount))
+         (make-pointer-invisible nil)
          saw-error)
     (unless (eq scroll-window selected-window)
       ;; Mark window to be scrolled for redisplay.
@@ -335,7 +336,8 @@ mouse-wheel-text-scale
   (interactive (list last-input-event))
   (let ((selected-window (selected-window))
         (scroll-window (mouse-wheel--get-scroll-window event))
-        (button (mwheel-event-button event)))
+        (button (mwheel-event-button event))
+        (make-pointer-invisible nil))
     (select-window scroll-window 'mark-for-redisplay)
     (unwind-protect
         (cond ((eq button mouse-wheel-down-event)
diff --git a/src/cmds.c b/src/cmds.c
index 90526612b7..c982187178 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -77,6 +77,7 @@ DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "^p",
 \\[right-char], which see.  */)
   (Lisp_Object n)
 {
+  frame_make_pointer_invisible (SELECTED_FRAME ());
   return move_point (n, 1);
 }
 
@@ -91,6 +92,7 @@ DEFUN ("backward-char", Fbackward_char, Sbackward_char, 0, 1, "^p",
 \\[left-char], which see.  */)
   (Lisp_Object n)
 {
+  frame_make_pointer_invisible (SELECTED_FRAME ());
   return move_point (n, 0);
 }
 
diff --git a/src/editfns.c b/src/editfns.c
index cb09ea8a31..ca64f11903 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -51,6 +51,7 @@ Copyright (C) 1985-1987, 1989, 1993-2020 Free Software Foundation, Inc.
 #include "buffer.h"
 #include "window.h"
 #include "blockinput.h"
+#include "frame.h"
 
 static void update_buffer_properties (ptrdiff_t, ptrdiff_t);
 static Lisp_Object styled_format (ptrdiff_t, Lisp_Object *, bool);
@@ -195,6 +196,7 @@ DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
 The return value is POSITION.  */)
   (register Lisp_Object position)
 {
+  frame_make_pointer_invisible (SELECTED_FRAME ());
   if (MARKERP (position))
     set_point_from_marker (position);
   else if (FIXNUMP (position))
diff --git a/src/window.c b/src/window.c
index ef58f43a0b..67fe873403 100644
--- a/src/window.c
+++ b/src/window.c
@@ -6612,6 +6612,8 @@ DEFUN ("recenter", Frecenter, Srecenter, 0, 2, "P\np",
       bytepos = pos.bytepos;
     }
 
+  frame_make_pointer_invisible (SELECTED_FRAME ());
+
   /* Set the new window start.  */
   set_marker_both (w->start, w->contents, charpos, bytepos);
   w->window_end_valid = false;
@@ -7896,6 +7898,8 @@ DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll,
     {
       int old_dy = w->vscroll;
 
+      frame_make_pointer_invisible (SELECTED_FRAME ());
+
       w->vscroll = - (NILP (pixels_p)
 		      ? FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll)
 		      : XFLOATINT (vscroll));