10

How to kill (C-x k) ediff's (A,B,C) buffers automatically on each ediff-quit?

tarsius
  • 25,298
  • 4
  • 69
  • 109
denys
  • 315
  • 1
  • 11

5 Answers5

2
(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.

Joakim Hårsman
  • 719
  • 5
  • 11
2

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)

Hoagie
  • 21
  • 5
2

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)
quimm2003
  • 131
  • 2
  • +10 for `(setq ediff-split-window-function 'split-window-horizontally)` alone! Was searching for a possibility to always split horizontally in `ztree-diff`. Thank you! – Ugur Jan 16 '21 at 16:39
0

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))))
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
djangoliv
  • 3,169
  • 16
  • 31
0

This is what I am using to close the windows:

(add-hook 'ediff-after-quit-hook-internal 'winner-undo)
clemera
  • 3,401
  • 13
  • 40