Fix #3726: respect +magit-open-windows-in-direction

Also fixes an issue where `q` would not delete a magit-dedicated split
window (leaving duplicate magit-status windows about).
This commit is contained in:
Henrik Lissner 2020-08-11 13:48:12 -04:00
parent 050ac73789
commit 95c5ebc01a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 19 additions and 10 deletions

View file

@ -63,18 +63,26 @@
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)))
+magit-open-windows-in-direction))
(origin-window (selected-window)))
(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))))
(if-let (window (and (not (one-window-p))
(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)
(let ((window (split-window nil nil direction)))
(when (memq direction '(right down below))
(select-window window))
(display-buffer-record-window 'reuse window buffer)
(set-window-buffer window buffer)
(set-window-parameter window 'quit-restore (list 'window 'window origin-window buffer))
(set-window-prev-buffers window nil))))
(switch-to-buffer buffer t t)
(selected-window)))