gmc444
gmc444

Reputation: 251

Emacs technique for comparing sections of documents?

I'd like to be able to open two windows in Emacs, select a region of text in each window, and get a comparison of the difference between the two selections.

This would be very handy for a large-scale maintenance project, where I'm working on a version tree with multiple branches, lots of copy/paste, and code that is being moved around sporadically.

I've found a paid-for tool that does provide this function (Ultracompare), but it's windows-specific, and I need a solution that runs on Solaris/Linux.

Upvotes: 23

Views: 3508

Answers (2)

pajato0
pajato0

Reputation: 3676

I'd be inclined to use narrow-to-region (C-x n n) in both buffers followed by M-x compare-windows if only because it has worked for me for at least 100 years. :-)

EDIT: Adding some steps for any beginners ... I agree, this works solidly. Previously, I used ediff, but now emacs for windows doesn't have diff built in. The biggest reason I now like this is because I can focus on just the region I want, easily.

  1. C-space then arrows to highlight headings in buffer one
  2. C-x C-x n n to narrow to just those
  3. S-tab to expand all headings
  4. Repeat by moving to buffer two (C-x o)
  5. C-space then arrows to highlight headings in buffer two
  6. C-x C-x n n to narrow to just those
  7. S-tab to expand all headings
  8. M-x compare-windows This will stay in the first matching block
  9. M-x compare-windows again (or, better type C-x z to repeat previous command). This will go to the end of the first matching block
  10. And so on (type z or M-x compare-windows ) until the end of the file.
  11. If you want to ignore whitespaces, set the variable compare-ignore-whitespace to non-nil. To do this, Type M-x set-variable RET compare-ignore-whitespace RET non-nil RET (RET means to press the enter key of your keyboard).

Upvotes: 10

Dave Bacher
Dave Bacher

Reputation: 15982

I think M-x ediff-regions-wordwise does what you want.

Run ediff-regions-wordwise and Emacs will prompt for each buffer, then prompt you to select (or confirm) a region in the buffer.

And, bonus, Emacs runs on Windows too!

Upvotes: 36

Related Questions