How to kill (C-x k) ediff's (A,B,C) buffers automatically on each ediff-quit
?
-
Did you really mean close the buffers, as opposed to closing the windows, i.e. usually going back to a single window showing a single file (but leaving the files open)?– Gilles 'SO- stop being evil'Oct 12, 2015 at 21:58
-
Yes, I mean kill buffers (C-x k)– denysOct 13, 2015 at 6:50
-
Why do you wish to do this? Often when I do an ediff I need to continue work on one of the buffers afterwards.– Andrew SwannOct 16, 2015 at 7:09
-
In my case I'm using ztree-diff to view the diffs and I'm not interested in the files after the diff most of the time.– Alwyn SchoemanFeb 26, 2020 at 23:05
5 Answers
(defun my-kill-ediff-buffers ()
(kill-buffer ediff-buffer-A)
(kill-buffer ediff-buffer-B)
(kill-buffer ediff-buffer-C))
(add-hook 'ediff-quit-hook 'my-kill-ediff-buffers)
Note that this will always kill ediff-buffers, even if they weren't opened by ediff e.g. you called ediff-buffers
with some buffers you had open to start with.
If you want to you could also kill *ediff-errors*
, *ediff-diff*
, *Ediff-Registry*
and *ediff-fine-diff*
as well, but those generally don't bother me.
I'm adding an answer because this is the first link that popped up for me on this topic, and this is indeed way simpler.
You can pass a prefix to "q" and it will prompt to kill the ediff buffers.
C-u q
If you customize ediff-keep-variants
it will reverse the behaviour: prompt to kill the buffers on exit and if use the prefix will leave them open.
(got this from the ediff manual)
I'm using this code (GNU Emacs 25.3.1 x86_64-pc-linux-gnu), following https://emacs.stackexchange.com/a/17089/18662
As stated in the GNU Emacs Manual regarding ediff-quit-hook (https://www.gnu.org/software/emacs/manual/html_node/ediff/Hooks.html):
Keep in mind that hooks executing before ediff-cleanup-mess start in ediff-control-buffer; they should also leave ediff-control-buffer as the current buffer when they finish. Hooks that are executed after ediff-cleanup-mess should expect the current buffer be either buffer A or buffer B.
So, I kill also the *Ediff Control Panel* buffer. Other ediff buffers may be added too.
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
(setq ediff-split-window-function 'split-window-horizontally)
(defvar q-ediff-last-windows nil)
(defun q-store-pre-ediff-winconfig ()
(setq q-ediff-last-windows (current-window-configuration)))
(defun q-restore-pre-ediff-winconfig ()
(progn
(set-window-configuration q-ediff-last-windows)
(ediff-kill-buffer-carefully "*Ediff Control Panel*")))
(add-hook 'ediff-before-setup-hook #'q-store-pre-ediff-winconfig)
(add-hook 'ediff-quit-hook #'q-restore-pre-ediff-winconfig)
-
+10 for
(setq ediff-split-window-function 'split-window-horizontally)
alone! Was searching for a possibility to always split horizontally inztree-diff
. Thank you!– UgurJan 16, 2021 at 16:39
You can try this hook:
(add-hook 'ediff-load-hook
(lambda ()
(add-hook 'ediff-before-setup-hook
(lambda ()
(setq ediff-before-file (buffer-file-name))
(setq ediff-saved-window-configuration (current-window-configuration))))
(let ((restore-window-configuration
(lambda ()
(set-window-configuration ediff-saved-window-configuration))))
(add-hook 'ediff-quit-hook restore-window-configuration 'append)
(add-hook 'ediff-suspend-hook restore-window-configuration 'append))))
-
2It is not recommended to bind
lambda
functions to hooks (and advices). It makes reviewing the hook variables and removing functions from hooks painful. Oct 12, 2015 at 21:00 -
2This effectively closes the windows, but the question is asking to kill the buffers. Oct 13, 2015 at 12:15
This is what I am using to close the windows:
(add-hook 'ediff-after-quit-hook-internal 'winner-undo)
-
1This effectively closes the windows, but the question is asking to kill the buffers. Oct 13, 2015 at 12:15