tools/magit: revise default window management for magit

The former default display function would strive to open windows below
the current magit window (splitting it), but this would stack and
quickly become cramped. The behavior is now to reuse the same
window *unless* you're opening the process buffer or from the commit
window.
This commit is contained in:
Henrik Lissner 2019-07-21 19:44:08 +02:00
parent ba26ce39fe
commit ce4b8940ca
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -2,37 +2,33 @@
;;;###autoload ;;;###autoload
(defun +magit-display-buffer-fn (buffer) (defun +magit-display-buffer-fn (buffer)
"Marries `magit-display-buffer-fullcolumn-most-v1' with "Same as `magit-display-buffer-traditional', except...
`magit-display-buffer-same-window-except-diff-v1', except:
1. Magit sub-buffers that aren't spawned from a status screen are opened as - If opened from a commit window, it will open below it.
popups. - Magit process windows are always opened in small windows below the current.
2. The status screen isn't buried when viewing diffs or logs from the status - Everything else will reuse the same window."
screen."
(let ((buffer-mode (buffer-local-value 'major-mode buffer))) (let ((buffer-mode (buffer-local-value 'major-mode buffer)))
(display-buffer (display-buffer
buffer (cond buffer (cond
;; If opened from an eshell window or popup, use the same window. ;; Any magit buffers opened from a commit window should open below
((or (derived-mode-p 'eshell-mode) ;; it. Also open magit process windows below.
(eq (window-dedicated-p) 'side))
'(display-buffer-same-window))
;; Open target buffers below the current one (we want previous
;; magit windows to be visible; especially magit-status).
((or (bound-and-true-p git-commit-mode) ((or (bound-and-true-p git-commit-mode)
(derived-mode-p 'magit-mode)) (eq buffer-mode 'magit-process-mode))
(let ((size (if (eq buffer-mode 'magit-process-mode) (let ((size (if (eq buffer-mode 'magit-process-mode)
0.35 0.35
0.7))) 0.7)))
`(display-buffer-below-selected `(display-buffer-below-selected
. ((window-height . ,(truncate (* (window-height) size))))))) . ((window-height . ,(truncate (* (window-height) size)))))))
;; log/stash/process buffers, unless opened from a magit-status
;; window, should be opened in popups. ;; Everything else should reuse the current window.
((memq buffer-mode '(magit-process-mode ((or (not (derived-mode-p 'magit-mode))
magit-log-mode (not (memq (with-current-buffer buffer major-mode)
magit-stash-mode)) '(magit-process-mode
'(display-buffer-below-selected)) magit-revision-mode
;; Last resort: use current window magit-diff-mode
('(display-buffer-same-window)))))) magit-stash-mode
magit-status-mode))))
'(display-buffer-same-window))))))
;; ;;