tools/magit: split sub-windows to the side

When a log or diff buffer is opened from the magit status buffer, it
would display them in a random window (or split, if none were
available). This changes forces it to predictably open to the right of
the magit status window (using the next window over, if available).
This commit is contained in:
Henrik Lissner 2020-08-05 21:13:42 -04:00
parent 6f2471cda7
commit a16c40d493
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 31 additions and 1 deletions

View file

@ -53,7 +53,29 @@
magit-diff-mode
magit-stash-mode
magit-status-mode))))
'(display-buffer-same-window))))))
'(display-buffer-same-window))
('(+magit--display-buffer-in-direction))))))
(defun +magit--display-buffer-in-direction (buffer alist)
"`display-buffer-alist' handler that opens BUFFER in a direction.
This differs from `display-buffer-in-direction' in one way: it will try to use a
window that already exists in that direction. It will split otherwise."
(let ((direction (or (alist-get 'direction alist)
+magit-open-windows-in-direction)))
(if-let (window (window-in-direction direction))
(select-window window)
(if-let (window (window-in-direction
(pcase direction
(`right 'left)
(`left 'right)
((or `up `above) 'down)
((or `down `below) 'up))))
(select-window window)
(split-window-horizontally)))
(switch-to-buffer buffer)
(selected-window)))
;;