Is there a keybind or a way of undoing each of ediff A-B change? I often want to revert the previous modification.
3 Answers
ediff-mode
has built-in bindings to apply and revert diff hunks.
Let's say you are running ediff between files/buffers A and B.
- To copy A's region to B, press
a
- To undo that, i.e. to restore the original region in buffer B, do
rb
Similarly
- To copy B's region to A, press
b
- To undo that, i.e. to restore the original region in buffer A, do
ra
While the ediff is in progress, you can hit ?
to know more bindings.
Move around | Toggle features | Manipulate
=====================|===========================|=============================
p,DEL -previous diff | | -vert/horiz split |a/b -copy A/B's region to B/A
n,SPC -next diff | h -highlighting | rx -restore buf X's old diff
j -jump to diff | @ -auto-refinement | * -refine current region
gx -goto X's point| ## -ignore whitespace | ! -update diff regions
C-l -recenter | #c -ignore case |
v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X
</> -scroll lt/rt | X -read-only in buf X | wd -save diff output
~ -swap variants | m -wide display |
=====================|===========================|=============================
R -show registry | = -compare regions | M -show session group
D -diff output | E -browse Ediff manual| G -send bug report
i -status info | ? -help off | z/q -suspend/quit
-------------------------------------------------------------------------------
For help on a specific command: Click Button 2 over it; or
Put the cursor over it and type RET.
-
This is exactly what I wanted! (I want to vote but couldn't due to the lower-than-15-reputation limits) Commented Jun 9, 2015 at 16:21
Select the buffer that was changed by the last modification (e.g. put the cursor there), and then hit C-_
(undo
).
Undo is per buffer. Each Ediff change affects one buffer. Go to that buffer and use undo
.
I managed to solve like below, thanks to Drew's answer.
;; use undo-tree.el
(defun my-ediff-undo-A ()
(interactive)
(save-window-excursion (with-selected-window ediff-window-A (undo-tree-undo))))
(defun my-ediff-undo-B ()
(interactive)
(save-window-excursion (with-selected-window ediff-window-B (undo-tree-undo))))
(defun my-ediff-redo-A ()
(interactive)
(save-window-excursion (with-selected-window ediff-window-A (undo-tree-redo))))
(defun my-ediff-redo-B ()
(interactive)
(save-window-excursion (with-selected-window ediff-window-B (undo-tree-redo))))
(defadvice ediff-setup-keymap (around my-ediff-undo activate)
ad-do-it
(define-key ediff-mode-map (kbd "C-a") 'my-ediff-undo-A)
(define-key ediff-mode-map (kbd "C-b") 'my-ediff-undo-B)
(define-key ediff-mode-map (kbd "M-a") 'my-ediff-redo-A)
(define-key ediff-mode-map (kbd "M-b") 'my-ediff-redo-B))