5

when executing magit-status and quickly focus out emacs, after the magit buffer pops up, emacs grabs the focus back. This is quite inconvenient. Is there a way to prevent that focus changing?

The way to reproduce this issue:

  1. emacs -Q and load magit.
  2. using magit-status command to load a middle size git project (which takes 1-2 seconds).
  3. in the meantime, quickly focus away from the Emacs frame, say clicking on a browser window.
  4. when magit-status buffer pops up, it grabs the focus back (which is what I'm trying to avoid)

Env:

Archlinux
i3wm
Emacs 27.0.50
magit d9ae466377b30d544fcbf5c57af1a60b350931af
Drew
  • 75,699
  • 9
  • 109
  • 225
Amos
  • 456
  • 3
  • 11
  • Maybe you can take a look at the variable `magit-display-buffer-noselect`, it seems when it is the default value, the function `magit-display-buffer` tries to raise the frame. FWIW, I can't reproduce the issue on Mac. – xuchunyang Mar 14 '18 at 19:21
  • @xuchunyang `magit-display-buffer-noselect` works! thank you. – Amos Mar 15 '18 at 02:17
  • 2
    Could one of you please turn this into an answer? – tarsius Mar 17 '18 at 12:41

2 Answers2

1

Set magit-display-buffer-noselect to t to prevent magit-display-buffer from calling select-window.

tarsius
  • 25,298
  • 4
  • 69
  • 109
1

Perhaps it has changed since the answer from March 2018, but setting magit-display-buffer-noselect didn’t work for me (i3 would still raise the Emacs window).

I found it necessary to configure Emacs like so:

;; By default, when e.g. M-x magit-status opens a new buffer, the frame is
;; raised, which focuses the X11 window in i3, thereby stealing focus.
;;
;; By setting inhibit-switch-frame to t, Emacs will not call raise-frame.
(add-to-list
 'display-buffer-alist
 '(".*" . (display-buffer-reuse-window
           . ((inhibit-switch-frame . t)))))
Michael
  • 156
  • 2