Rewrite how magit windows/popups are managed
The old policy was to invoke magit in fullscreen, but in practice, I've found myself wanting to peek at other buffers (maybe even notes) while I manage my project in version control. So this change introduces two big changes and one fix: + Instead of a full-frame policy, we use full-column. e.g. Invoking magit-status will take up a full column of windows (and will restore them when you quit). + Popups are displayed below the current window if called from a magit buffer, otherwise as a popup at the bottom of the frame. + Fixes popups opening in a random window if called from a magit buffer in a popup. This is only a start and needs more testing.
This commit is contained in:
parent
391ac1cae5
commit
2cc5d223fe
2 changed files with 27 additions and 30 deletions
|
@ -1,7 +1,7 @@
|
|||
;;; tools/magit/autoload.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +magit-display-buffer-fullscreen (buffer)
|
||||
(defun +magit-display-buffer (buffer)
|
||||
"Like `magit-display-buffer-fullframe-status-v1' with two differences:
|
||||
|
||||
1. Magit sub-buffers that aren't spawned from a status screen are opened as
|
||||
|
@ -11,41 +11,37 @@
|
|||
(let ((buffer-mode (buffer-local-value 'major-mode buffer)))
|
||||
(display-buffer
|
||||
buffer (cond
|
||||
;; If opened from an eshell window, use the same window.
|
||||
((derived-mode-p 'eshell-mode)
|
||||
;; 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))
|
||||
;; If opened from a magit window from a popup, open the results
|
||||
;; full screen. We want to see it all.
|
||||
((eq (window-dedicated-p) 'side)
|
||||
'(magit--display-buffer-fullframe))
|
||||
;; From a commit or magit-log buffer, open detail buffers below
|
||||
;; this one.
|
||||
;; 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)
|
||||
(derived-mode-p 'magit-log-mode))
|
||||
'(display-buffer-below-selected . ((window-height . 0.7))))
|
||||
;; From a magit buffer, set aside the magit-status window if it
|
||||
;; exists (we want it always to be visible), then display the
|
||||
;; target buffer in the current window.
|
||||
((derived-mode-p 'magit-mode)
|
||||
(when (eq major-mode 'magit-status-mode)
|
||||
(display-buffer-in-side-window
|
||||
(current-buffer) '((side . left)
|
||||
(window-width . 0.35)
|
||||
(window-parameters (quit)))))
|
||||
'(display-buffer-same-window))
|
||||
;; If the target buffer opening is a commit, revision or diff, we
|
||||
;; want to see the whole thing.
|
||||
((or (buffer-local-value 'git-commit-mode buffer)
|
||||
(memq buffer-mode '(magit-revision-mode magit-diff-mode)))
|
||||
'(magit--display-buffer-fullframe))
|
||||
(derived-mode-p 'magit-mode))
|
||||
(let ((size (cond ((eq buffer-mode 'magit-process-mode) 0.35)
|
||||
((bound-and-true-p git-commit-mode) 0.7)
|
||||
(t 0.9))))
|
||||
`(display-buffer-below-selected . ((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-in-side-window))
|
||||
;; Last resort: plain old fullscreen.
|
||||
('(magit--display-buffer-fullframe))))))
|
||||
;; Last resort: plain old fullcolumn.
|
||||
('(magit--display-buffer-fullcolumn))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +magit-display-popup-buffer (buffer &optional alist)
|
||||
"TODO"
|
||||
(cond ((eq (window-dedicated-p) 'side)
|
||||
(if (fboundp '+popup-display-buffer-stacked-side-window)
|
||||
(+popup-display-buffer-stacked-side-window buffer alist)
|
||||
(display-buffer-in-side-window buffer alist)))
|
||||
((derived-mode-p 'magit-mode)
|
||||
(display-buffer-below-selected buffer alist))
|
||||
((display-buffer-in-side-window buffer alist))))
|
||||
|
||||
|
||||
;;
|
||||
|
|
|
@ -26,8 +26,8 @@ available.")
|
|||
#'magit-builtin-completing-read)
|
||||
magit-revision-show-gravatars '("^Author: " . "^Commit: ")
|
||||
magit-diff-refine-hunk t ; show word-granularity on selected hunk
|
||||
magit-display-buffer-function #'+magit-display-buffer-fullscreen
|
||||
magit-popup-display-buffer-action '((display-buffer-in-side-window)))
|
||||
magit-display-buffer-function #'+magit-display-buffer
|
||||
magit-popup-display-buffer-action '((+magit-display-popup-buffer)))
|
||||
|
||||
(set-popup-rule! "^\\(?:\\*magit\\|magit:\\)" :ignore t)
|
||||
;; so magit buffers can be switched to
|
||||
|
@ -50,6 +50,7 @@ available.")
|
|||
(def-package! magithub
|
||||
:after magit
|
||||
:preface
|
||||
;; Magithub is not well-behaved, so this needs to be set early
|
||||
(setq magithub-dir (concat doom-etc-dir "magithub/"))
|
||||
:init
|
||||
(setq magithub-clone-default-directory "~/"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue