Tuesday, December 12, 2000

Emacs Tip of the Day - ediff-mode

One of the most amazing modes in Emacs is "ediff-mode". It's a little
hard to learn, but is so powerful, once you learn it, it'll scare you.

ediff-mode is used to show the differences between 2 or 3 buffers, files
or directories, and can be used to either just look at the differences
between these, or can be used to merge changes between these.

This mode is really really useful when you have files that have small
differences, and you want to find out what and where these differences

To put this in practical terms, recently, I had two different versions of
FPC, one that had a bug, and one that didn't. There were lots of changed
files in different directories between the two version. A simple "diff"
of the files gave an output of about 1400 lines, too many to look at by

So, I used ediff-mode to help me isolate and look at the differences
between the two versions.

I started up with the command "M-x ediff-directories". This will ask for
two directories to compare. After selecting the directories, it asks for
a regular expression to filter through, usually, just press here.

It then pops up a buffer showing the files and directories that are
different, scroll down to one of these and press . Emacs will
then divide the window in half, showing the first version of the file in
the top window, and the second version of the file in the bottom window.
Emacs will also pop up a new tiny frame at the top of the screen in which
you can type ediff commands.

The most useful of these commands are "p" and "n", which jump to the
previous and next diff regions. When you press these keys in the command
frame, ediff will scroll both windows to where the difference region is,
and will highlight the region nicely to show you exactly where the
differences are.

Other cool commands are "V" and "v" which scroll both windows up and down
simultaneously, "|" which divides the windows vertically instead of
horizontally, "##" which makes ediff ignore whitespace regions, and "a"
and "b", which will copy the diff region from either the first window to
the second window, or vice versa.

There are so many more commands in this mode, press "?" in the little
command window to see some of them, and look at the Info documentation
"C-h i" for more.

Cool, eh?