Might be able to do it with the hooks that run on entry and exit of the magit-status buffer? Save the window configuration on entry, reload it on exit?
Emacs
A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!
Get Emacs
Rules
- Posts should be emacs related
- Be kind please
- Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.
Emacs Resources
Emacs Tutorials
- Beginner’s Guide to Emacs
- Absolute Beginner's Guide to Emacs
- How to Learn Emacs: A Hand-drawn One-pager for Beginners
Useful Emacs configuration files and distributions
Quick pain-saver tip
I think you need to define your requirements in more detail. What if you call magit-status while using Magit? Does that change what the "previous window configuration" should be? (I suspect it does, in which case it's not going to be "the previous window configuration" that you want). If I'm correct, you should clarify exactly which window configuration you want to restore, and when (in which specific circumstances) that should be captured.
Install package fullframe then (fullframe magit-status magit-mode-quit-window)
Others: bind q to this function
```elisp
(defun eat/quit ()
"Delete current window switch to prevous buffer."
(interactive)
(if (> (seq-length (window-list (selected-frame))) 1)
(delete-window)
(previous-buffer)))
```
u/unhammer commented this in another post that: https://www.reddit.com/r/emacs/comments/179t67l/window_management_share_your_displaybufferalist/k5b56i2/
(setq magit-display-buffer-function 'magit-display-buffer-fullframe-status-topleft-v1)
(setq magit-bury-buffer-function 'magit-restore-window-configuration)
That's the ticket! Thank you!
This configuration only buries the magit buffer which may or may not be what you want, I prefer to actually kill the buffer so this is what I use instead:
(use-package magit
:preface (defun my/magit-kill-buffers ()
"Restore window configuration and kill all Magit buffers."
(interactive)
(let ((buffers (magit-mode-get-buffers)))
(magit-restore-window-configuration)
(mapc #'kill-buffer buffers)))
:bind (:map magit-status-mode-map
("q" . #'my/magit-kill-buffers)
("C-x k" . #'my/magit-kill-buffers))
:custom ((magit-display-buffer-function 'magit-display-buffer-same-window-except-diff-v1)
(git-commit-summary-max-length 50)
(magit-diff-refine-hunk t) ; show granular diffs in selected hunk.
(magit-save-repository-buffers nil)
(magit-define-global-key-bindings nil)))
Curious why you prefer killing?
I just like to have a clean ibuffer
:)
After done with magit I want all magit buffers killed so that I can have a clean buffer list.
Makes sense. I tried to keep my buffer list clean at first, but kinda gave up cause so many things in emacs create buffers