diff --git a/lisp/init-git.el b/lisp/init-git.el index 8c1d5e8d3e..37ca281c49 100644 --- a/lisp/init-git.el +++ b/lisp/init-git.el @@ -18,7 +18,6 @@ (setq-default magit-diff-refine-hunk 'all) (sanityinc/fullframe-mode 'magit-status-mode) - (setq-default magit-bury-buffer-function 'magit-restore-window-configuration) ;; Hint: customize `magit-repository-directories' so that you can use C-u M-F12 to ;; quickly open magit on any one of your projects. diff --git a/lisp/init-utils.el b/lisp/init-utils.el index 9c93d7665e..6a392cb068 100644 --- a/lisp/init-utils.el +++ b/lisp/init-utils.el @@ -2,11 +2,32 @@ ;;; Commentary: ;;; Code: +(defun sanityinc/display-buffer-full-frame (buffer alist) + "If it's not visible, display buffer full-frame, saving the prior window config. +The saved config will be restored when the window is quit later. +BUFFER and ALIST are as for `display-buffer-full-frame'." + (let ((initial-window-configuration (current-window-configuration))) + (or (display-buffer-reuse-window buffer alist) + (let ((full-window (display-buffer-full-frame buffer alist))) + (prog1 + full-window + (set-window-parameter full-window 'sanityinc/previous-config initial-window-configuration)))))) + +(defun sanityinc/maybe-restore-window-configuration (orig &optional kill window) + (let* ((window (or window (selected-window))) + (to-restore (window-parameter window 'sanityinc/previous-config))) + (set-window-parameter window 'sanityinc/previous-config nil) + (funcall orig kill window) + (when to-restore + (set-window-configuration to-restore)))) + +(advice-add 'quit-window :around 'sanityinc/maybe-restore-window-configuration) + (defmacro sanityinc/fullframe-mode (mode) - "Configure buffers that open in MODE to start out full-frame." + "Configure buffers that open in MODE to display in full-frame." `(add-to-list 'display-buffer-alist (cons (cons 'major-mode ,mode) - (list 'display-buffer-full-frame)))) + (list 'sanityinc/display-buffer-full-frame)))) (sanityinc/fullframe-mode 'package-menu-mode)