223 lines
9.5 KiB
HTML
223 lines
9.5 KiB
HTML
<!--startcut ==========================================================-->
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<title>EMACSulation LG #27</title>
|
|
<link rev="made"
|
|
href="mailto:emarsden@mail.dotcom.fr">
|
|
<meta name="keywords"
|
|
content="emacs, ediff, comparing, diff, cmp, patch"
|
|
<meta name="description"
|
|
content="Ediff is an Emacs interface to diff and patch. It provides
|
|
convenient functions for examining the differences between files and
|
|
directories, for merging files, and for applying patches
|
|
interactively.">
|
|
<meta name="author"
|
|
content="Eric Marsden">
|
|
<meta name="made"
|
|
content="with Emacs">
|
|
</head>
|
|
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
|
|
ALINK="#FF0000">
|
|
<!--endcut ============================================================-->
|
|
|
|
<H4>
|
|
"Linux Gazette...<I>making Linux just a little more fun!</I>"
|
|
</H4>
|
|
|
|
<P> <HR> <P>
|
|
<!--===================================================================-->
|
|
|
|
<center>
|
|
<h1>EMACSulation</h1>
|
|
<h4>by <a href="mailto:emarsden@mail.dotcom.fr">Eric Marsden</a>
|
|
</h4>
|
|
</center>
|
|
<p><HR> <P>
|
|
|
|
|
|
<blockquote><small>
|
|
|
|
This column is devoted to making the best use of Emacs, text editor
|
|
extraordinaire. Each issue I plan to present an Emacs extension
|
|
which can improve your productivity, make the sun shine more brightly
|
|
and the grass greener.
|
|
|
|
</small></blockquote>
|
|
|
|
|
|
<p> <p>
|
|
|
|
<h2>Ediff: an Emacs interface to diff and patch</h2>
|
|
|
|
<blockquote><font face="Helvetica">
|
|
Never read that diff output again! <br>
|
|
Apply patches interactively! <br>
|
|
Merge with ease! <br>
|
|
</font></blockquote>
|
|
|
|
|
|
<p> <strong>Ediff</strong> is a powerful package by <a
|
|
href="http://www.cs.sunysb.edu/~kifer/">Michael Kifer</a> which lets
|
|
you browse through the differences between files and directories, merge
|
|
files which have been revised by coworkers, and apply patches
|
|
interactively. Let's start with the simplest use : eyeballing the
|
|
differences between two versions of a text file. Either type <tt>M-x
|
|
ediff</tt>, or from the menubar go to Tools -> Compare -> Two files
|
|
(yes, it's something else on the XEmacs menubar). Ediff will prompt you
|
|
for two files to compare, open them and ponder a bit (while running <a
|
|
href="http://www.new.ox.ac.uk/jargon/jargon_19.html#TAG468">diff</a> as
|
|
a subprocess). Emacs will open a small control window, and show you
|
|
something like this
|
|
|
|
<p> <img src="./gx/marsden/ediff-compare-two.gif"
|
|
alt="Comparison of two files [21 kB]"
|
|
width="538" height="587">
|
|
|
|
<p> (for the curious, the window manager is a slighly modified version of
|
|
Chris Cannam's almost-minimal <a
|
|
href="http://www.netcomuk.co.uk/~cannam/wmx.html">wmx</a>). Differing
|
|
lines --or <em>hunks</em> in diff parlance-- in the two files are
|
|
highlighted in grey, and you can step through them by typing <tt>n</tt>
|
|
(next) or <tt>p</tt> (previous) into the control window. The active
|
|
hunk is highlighted in color, with the exact words which differ
|
|
displayed in a separate color (this process is called refining, and is
|
|
done by Emacs itself, not by diff). Naturally Ediff works best when run
|
|
under a windowing system, but it does work in degraded mode in the
|
|
console.
|
|
|
|
<p> You can use all your normal keybindings in the two buffers being
|
|
compared; ediff-specific commands must be typed into the control panel.
|
|
To obtain help, type <tt>?</tt> while focus is in the ediff control
|
|
panel; it should warp into a reassuring help window something like
|
|
|
|
<p> <img src="./gx/marsden/ediff-help.gif"
|
|
alt="Ediff help window [7 kB]"
|
|
width="512" height="239">
|
|
|
|
|
|
<h3>Merging files</h3>
|
|
|
|
<p> Ediff can help you merge two files into a third file, a little like the
|
|
command-line tools <em>sdiff</em> and <em>merge</em>. Type <tt>M-x
|
|
ediff-merge</tt> to enter merge mode and be prompted for two filenames.
|
|
The Emacs frame will then be split in three, with the two files to be
|
|
merged side by side in windows named respectively A and B, above a
|
|
buffer containing their merge. It should look a little like <a
|
|
href="./gx/marsden/ediff-merge.gif">this</a> <i>(23 kB)</i>. The normal width of
|
|
your Emacs frame may be a little limiting for two files side by side;
|
|
you can type <tt>m</tt> to widen the frame.
|
|
|
|
<p> For each hunk you will then be able to choose which files to make
|
|
authoritative (ie which version to include in the merge). Type
|
|
<tt>a</tt> to choose the version in the buffer labelled A, <tt>b</tt>
|
|
for the other buffer, or <tt>+</tt> to include both (you can then edit
|
|
the merge buffer to select bits of both). You can also merge files with
|
|
respect to an ancestor, if for example two people have made independent
|
|
changes to a common original.
|
|
|
|
|
|
<h3>Interactive Patching</h3>
|
|
|
|
<p> We come to one of the most amusing uses of Ediff: applying a <a
|
|
href="http://www.new.ox.ac.uk/jargon/jargon_31.html#TAG1335">patch</a>
|
|
interactively from the comfort of Emacs. No more reading diffs ``by
|
|
hand'', no more fiddling around with rejects. Type <tt>M-x
|
|
ediff-patch-file</tt> to start the fun and be prompted for a patch file
|
|
and a filename. The Emacs frame will be split vertically with the
|
|
original file above, and the patched file below. You step from hunk to
|
|
hunk like for a diff, and can selectively restore certain regions from
|
|
the original file (undo parts of the patch) by typing <tt>a</tt>.
|
|
|
|
<p> Ediff also has an excellent integration with Emacs' <a
|
|
href="http://www.cl.cam.ac.uk/texinfodoc/emacs_18.html#SEC114">version
|
|
control interfaces</a>, which lets you compare different revisions of a
|
|
file. Open a file under version control (Emacs detects this
|
|
automatically) and type <tt>M-x ediff-revision</tt>; you will be
|
|
prompted for the two version numbers to compare. Ediff will check out
|
|
the two revisions and run diff on them. This seamless integration is
|
|
extended to remote and compressed files : your patches can be
|
|
compressed or on a distant machine, and Ediff will work things out all
|
|
by itself. You can even (not tested!) apply a gzipped remote patch to
|
|
an old version of a compressed file on another machine, so there.
|
|
|
|
<p> I've only described the most common uses of Ediff : it can also
|
|
compare three files (<tt>ediff3</tt>), compare buffers, compare
|
|
directory contents, and apply multi-file patches. Many aspects of the
|
|
presentation can be customized. It has a registry of current ediff
|
|
sessions which may be useful if you're a heavy user. Read the <a
|
|
href="http://subzero.campus.luth.se/FreeDocs/emacs-19.34/ediff/ediff_toc.html">online
|
|
documentation</a> to know all about it.
|
|
|
|
|
|
<blockquote>
|
|
<font face="Helvetica">
|
|
For they have entertained cause enough
|
|
<br>
|
|
To draw their swords. But how the fear of us
|
|
<br>
|
|
May cement their divisions, and bind up
|
|
<br>
|
|
The petty difference we yet not know. <br>
|
|
Be't as our gods will have't! It only stands
|
|
<br>
|
|
Our lives upon to use our strongest hands.
|
|
<br>
|
|
</font>
|
|
|
|
<p> William Shakespeare,
|
|
<a
|
|
href="http://the-tech.mit.edu/Shakespeare/Tragedy/antonyandcleopatra/antonyandcleopatra.2.1.html"><i>Antony
|
|
and Cleopatra</i></a>
|
|
|
|
</blockquote>
|
|
|
|
|
|
|
|
<h2>Feedback</h2>
|
|
|
|
<p> A few people pointed out to me that <strong>ffap</strong> is not
|
|
included with both Emacsen as I claimed in last month's column, but
|
|
only with GNU Emacs. XEmacs users can obtain the latest version from
|
|
Michelangelo Grigni (the author)'s <a
|
|
href="ftp://ftp.mathcs.emory.edu/pub/mic/emacs/">ftp site</a>. I also
|
|
incorrectly attributed a message from Christopher B. Smith to another
|
|
Linux user, Christopher B. Browne; my apologies to both Christophers.
|
|
|
|
|
|
<h2>Next time ...</h2>
|
|
|
|
<p> In the next issue I'll review emacsclient/gnuserv, a mechanism for
|
|
sending messages to a running Emacs process. Don't hesitate to contact
|
|
me at <tt><emarsden@mail.dotcom.fr></tt> with comments,
|
|
corrections or suggestions (what's <em>your</em> favorite
|
|
couldn't-do-without Emacs extension package?). <code>C-u 1000 M-x
|
|
hail-emacs</code> !
|
|
|
|
<p> <b>PS</b> : Emacs isn't in any way limited to Linux, since
|
|
implementations exist for many other operating systems (and some
|
|
systems which only halfway operate). However, as one of the leading
|
|
bits of <a href="http://www.open-source.org/">open-source</a> software,
|
|
one of the most powerful, complex and customizable, I feel it has its
|
|
place in the <i>Linux Gazette</i>.
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<center><H4>Previous ``EMACSulation'' Columns</H4></center>
|
|
<P>
|
|
<A HREF="../issue25/marsden.html">EMACSulation #1, February 1998</A> <BR>
|
|
<A HREF="../issue26/marsden.html">EMACSulation #2, March 1998</A>
|
|
<P> <hr> <P>
|
|
<center><H5>Copyright © 1998, Eric Marsden <BR>
|
|
Published in Issue 27 of <i>Linux Gazette</i>, April 1998</H5></center>
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
|
|
ALT="[ TABLE OF CONTENTS ]"></A>
|
|
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
|
|
ALT="[ FRONT PAGE ]"></A>
|
|
<A HREF="./little.html"><IMG SRC="../gx/back2.gif"
|
|
ALT=" Back "></A>
|
|
<A HREF="./wagle.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
|
|
<P> <hr> <P>
|
|
<!--startcut ==========================================================-->
|
|
</BODY>
|
|
</HTML>
|
|
<!--endcut ============================================================-->
|