diff --git a/modules/tools/magit/autoload.el b/modules/tools/magit/autoload.el index 805d8b740..90e7f7ee9 100644 --- a/modules/tools/magit/autoload.el +++ b/modules/tools/magit/autoload.el @@ -20,27 +20,42 @@ (let ((buffer-mode (buffer-local-value 'major-mode buffer))) (display-buffer buffer (cond + ;; Prevent opening multiple status windows for the same project. ((and (eq buffer-mode 'magit-status-mode) (get-buffer-window buffer)) '(display-buffer-reuse-window)) - ;; 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) - (eq buffer-mode 'magit-process-mode)) + + ((or + ;; Any magit buffers opened from a commit window should open + ;; below the selected one. + (bound-and-true-p git-commit-mode) + ;; ...Or process log buffers... + (eq buffer-mode 'magit-process-mode) + ;; Nothing should replace the log-select buffer (revision buffers + ;; during rebasing, in particular). + (eq major-mode 'magit-log-select-mode)) (let ((size (if (eq buffer-mode 'magit-process-mode) 0.35 0.7))) `(display-buffer-below-selected . ((window-height . ,(truncate (* (window-height) size))))))) - ;; 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)))) + ((or + ;; If triggered from outside of magit, open magit in the current + ;; window, rather than a far-away one. + (not (derived-mode-p 'magit-mode)) + ;; If invoking a diff from the status buffer, use that window. + (and (eq major-mode 'magit-status-mode) + (memq buffer-mode + '(magit-diff-mode + magit-stash-mode))) + ;; These buffers should open in another (but nearby) window, + ;; because they compliment the current one being visible. + (not (memq buffer-mode + '(magit-process-mode + magit-revision-mode + magit-stash-mode + magit-status-mode)))) '(display-buffer-same-window)) ('(+magit--display-buffer-in-direction))))))