Oct 03,
2017

Hiding Emacs' Mouse Pointer

Greetings folks. Another afternoon spent shaving yaks.

Out of the box Emacs is configured to hide the mouse pointer when the keyboard is used, a sane default if you ask me, with only a small detail in its current implementation: the pointer is hidden only when is typed a self-inserting-character. In other words, moving the cursor with the keyboard doesn't hide the mouse pointer.

And in my case, the mouse pointer always lands where I want to read.

I've checked the available documentation and I can't find anything that can help me, so it seems that I need to hack the sources. So the other day I've tried to modify the move_point1 function in cmds.c with a tentative patch:

diff -u emacs-25.3/src/cmds.c emacs-25.3-mod/src/cmds.c
--- emacs-25.3/src/cmds.c
+++ emacs-25.3-mod/src/cmds.c
@@ -71,6 +71,8 @@
       xsignal0 (Qend_of_buffer);
     }

+  frame_make_pointer_invisible (SELECTED_FRAME ());
+
   SET_PT (new_point);
   return Qnil;
 }

Yay! It worked after the first attempt.

Well, it's not the cleanest solution as I've introduced at least one side effect: when used in combination with Gnome's windows sloppy focus mode2 the window focus event hide the pointer without touching the keyboard. For the moment it doesn't bother me and it's good enough, probably I need to put a condition to not hide the pointer if it's an X focus event.


  1. what other editors call cursor on Emacs is called point, in this post I've used the more used therm ↩︎

  2. I haven't tried with the other two modes ↩︎