Skip to content

Commit

Permalink
Restore window config like fullframe did, but much more simply
Browse files Browse the repository at this point in the history
  • Loading branch information
purcell committed Feb 1, 2024
1 parent 00cbf19 commit 5f26d55
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 0 additions & 1 deletion lisp/init-git.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 23 additions & 2 deletions lisp/init-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 5f26d55

Please sign in to comment.