Here is the working solution I ultimately wound up using npostavs' idea of advising. It is based on magit-mode-bury-buffer
tarsius' advice, and that at first it seemed to work fine....
Here'swho deserves all the code:credit.
(defun kill-magit-diff-buffersbuffer-in-current-repo (&rest _)
"Delete allthe magit-diff buffers"buffer related to the current repo"
(mapclet ((magit-diff-buffer-in-current-repo
(lambda (magit-mode-get-buffer 'magit-diff-mode)))
(with-currentkill-buffer magit-diff-buffer-in-current-repo)))
;;
;; When 'C-c C-c' is pressed in (when
the magit commit message buffer,
;; delete the magit-diff buffer related to (eqthe majorcurrent repo.
;;
(add-modehook 'magit'git-diffcommit-mode)setup-hook
(kill-bufferlambda buffer)))()
(buffer-list)))
(advice-add-hook 'magit'with-modeeditor-burypost-bufferfinish-hook
:after #'kill-magit-diff-buffersbuffer-in-current-repo
nil t))) ; the t is important
WARNING: I think the magit-mode-bury-buffer
is called by magit not just when you hit q
from the magit-status
buffer, but in other places as well. Unfortunately, it occasionally causes Git failed...
errors (such as when trying to commit from the magit-status
buffer by typing c c
and answering y
to the question "Stage and commit everything?"). So I've reverted this change and am still looking for another solution.