This answer takes the other answers and the comments into account, offering better ways of doing the same things. Your original question was about deleting the diff buffer after committing, though the other answers concentrated on doing something when quitting the status buffer. So I will do that first too, but later also tell you how to do something when you are done committing.
All that magit-mode-bury-buffer
does is (funcall magit-bury-buffer-function kill-buffer)
. So there is no need to bind another home-made command to replace it or to advice it - just use the existing option intended to tweak the quitting behavior: magit-bury-buffer-function
. This is also documented in the manual.
This command's primary purpose is to make the previously current buffer "go away", but you can also use it to do something to other buffers.
Here is how to get to other relevant buffers:
magit-mode-get-buffers
lists the other Magit buffers belonging to the current repository.
magit-mode-get-buffer
returns a particular buffer belonging to the current repository, matching the provided arguments.
To do something when you press C-c C-c in a commit message buffer use with-editor-post-finish-hook
(a pre
variant also exists, as do two cancel
variants). These hooks are primarily intended for package authors who use the with-editor
library (like git-commit.el
does), so they are a bit under-documented and odd to use. To add something to such a hook for the benefit of git-commit-mode
do something like:
(add-hook 'git-commit-setup-hook
(lambda ()
(add-hook 'with-editor-post-finish-hook
(lambda ()
...) ; your stuff here
nil t))) ; the t is important
But use named functions instead of lambda
s.
magit-bury-buffer-function
(which is whatq
in magit buffers ends up calling).quit
magit-status buffer?