From ce4b8940cae7e4edce103950b7234ccf33455c09 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 21 Jul 2019 19:44:08 +0200 Subject: [PATCH] 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. --- modules/tools/magit/autoload.el | 38 +++++++++++++++------------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/modules/tools/magit/autoload.el b/modules/tools/magit/autoload.el index 8b0b3fd4b..9a9dc4107 100644 --- a/modules/tools/magit/autoload.el +++ b/modules/tools/magit/autoload.el @@ -2,37 +2,33 @@ ;;;###autoload (defun +magit-display-buffer-fn (buffer) - "Marries `magit-display-buffer-fullcolumn-most-v1' with -`magit-display-buffer-same-window-except-diff-v1', except: + "Same as `magit-display-buffer-traditional', except... -1. Magit sub-buffers that aren't spawned from a status screen are opened as - popups. -2. The status screen isn't buried when viewing diffs or logs from the status - screen." +- If opened from a commit window, it will open below it. +- Magit process windows are always opened in small windows below the current. +- Everything else will reuse the same window." (let ((buffer-mode (buffer-local-value 'major-mode buffer))) (display-buffer buffer (cond - ;; If opened from an eshell window or popup, use the same window. - ((or (derived-mode-p 'eshell-mode) - (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). + ;; Any magit buffers opened from a commit window should open below + ;; it. Also open magit process windows below. ((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) 0.35 0.7))) `(display-buffer-below-selected . ((window-height . ,(truncate (* (window-height) size))))))) - ;; log/stash/process buffers, unless opened from a magit-status - ;; window, should be opened in popups. - ((memq buffer-mode '(magit-process-mode - magit-log-mode - magit-stash-mode)) - '(display-buffer-below-selected)) - ;; Last resort: use current window - ('(display-buffer-same-window)))))) + + ;; Everything else should reuse the current window. + ((or (not (derived-mode-p 'magit-mode)) + (not (memq (with-current-buffer buffer major-mode) + '(magit-process-mode + magit-revision-mode + magit-diff-mode + magit-stash-mode + magit-status-mode)))) + '(display-buffer-same-window)))))) ;;