2

I use Emacs 26.1 and try to compare two (long) buffers (opened side by side) by clicking Tools -> Compare (Ediff) -> Windows Word-by-word... Then I choose both Windows (A and B) by clicking on each opened buffer. However it looks like Emacs compares only the visible parts of the two buffers, not the whole buffers. Why?

I saw there is a command ediff-windows-wordwise... How is "Window" defined? - as "currently visible part of a buffer"? If yes, is there something like ediff-buffers-wordwise?

Update: I have git in exec-path, so maybe I can make ediff to display the output of git diff --word-diff file1 file2 in ediff style?

2
  • According to my understanding, a window is the visible part of a buffer. If so, the command is doing the right thing!
    – Dox
    Nov 23, 2018 at 8:55
  • If so, how do I compare two complete buffers word by word? Nov 24, 2018 at 19:06

1 Answer 1

3

You can use ediff-regions-wordwise for the whole buffers. The input of the regions is a bit daunting though.

The following elisp snippet defines ediff-buffers-wordwise working like ediff-buffers. A caveat is that it uses the internal function ediff-regions-internal. So it might be that it does not work with future emacs versions. But that is not very likely.

You can copy the elisp snippet to your init file if you want to use it. ediff-buffers-wordwise is available after the next restart of Emacs or after reevaluating the init file.

(eval `(defun ediff-buffers-wordwise (buffer-A buffer-B &optional startup-hooks job-name)
     ,(concat (documentation 'ediff-buffers) "\nComparison is done word-wise.")
     ,(interactive-form 'ediff-buffers)
     (setq bufA (get-buffer buffer-A)
           bufB (get-buffer buffer-B)
           job-name (or job-name 'ediff-buffers-wordwise))
     (cl-assert bufA nil
            "Not a live buffer: %s" buffer-A)
     (cl-assert bufB nil
            "Not a live buffer: %s" buffer-B)
     (ediff-regions-internal bufA
                 (with-current-buffer bufA
                   (point-min))
                 (with-current-buffer bufA
                   (point-max))
                 bufB
                 (with-current-buffer bufB
                   (point-min))
                 (with-current-buffer bufB
                   (point-max))
                 startup-hooks
                 job-name
                 'word-mode
                 nil)))

(require 'easymenu)

(easy-menu-add-item
 menu-bar-tools-menu
 '("Compare (Ediff)")
 ["Two Buffers Word-by-word..." ediff-buffers-wordwise t]
 "Three Files...")
5
  • It works very nice and fast actually! Could you, please, extend it so that a menu option "Tools -> Compare (Ediff) -> Buffers Word-by-word..." also appears... Thank you very much! Nov 25, 2018 at 10:00
  • FYI: I was told that ediff-windows-wordwise also relies on ediff-regions-internal internally, so your approach is consistent with the mainstream. Nov 25, 2018 at 10:06
  • Update: while everything seems to work fine, I get an error message in the mini-buffer: Args out of range: "nil", 6, nil . What can this be? Nov 25, 2018 at 12:13
  • 1
    @user1876484 I have corrected the problem with Args out of range and I have added the menu item.
    – Tobias
    Nov 25, 2018 at 14:33
  • Just excellent! Strange that it's not part of Emacs out of the box... Just for the sake of completeness: the same for two files. Thank you! Nov 25, 2018 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.