, , , , Posted on 16 April 2025 by

Weekly Emacs tip #18: Emacs window management — “Focus follows mouse”

Back in tip #4 about mouse-yank-at-point, I made a side note about the fact that I’m a long-time user of “focus follows mouse”: whenever I move the mouse cursor over a window, that window gets the focus. Without my having to click in that window.

In the previous tip, I explained basics of Emacs’s window management and how the C-x o shortcut to switch between windows in a frame is too much “work” for me. As I hinted there, I do have some packages that make the window switching easier, but only a few weeks ago I found out that Emacs has its own setting for “focus-follows-mouse”. Setting the variable mouse-autoselect-window to t will enable this behaviour.

I have been using it for some time now, and so far, I like it. The only time it got in the way (somewhat) was when I wanted to use a mode-specific function from the menu bar for something that was in the lower window. As I moved over the top window to the menu bar, the menu item disappeared. I understand why, and it makes sense, but it did catch me off-guard. I worked around it by simply moving my mouse upwards outside of the Emacs frame.

Here’s the code from my ~/.emacs file. As you can see it’s part of the :custom settings of my (use-package emacs) block, but remember that in my actual config file, this block contains many more settings.

(use-package emacs
  :custom
  ;; Use "focus follows mouse" within Emacs too, so now moving the
  ;; mouse cursor will also switch between buffers in different Emacs
  ;; windows.
  (mouse-autoselect-window t)
  )

No Comments

Let us keep you updated!

Once a month we’ll send you an overview of our newest articles. No spam, we promise.

Thank you for signing up! We've send you an confirmation mail.