13

Since ediff-files and ediff-buffers result in apply: Searching for program: no such file or directory, diff error on windows machines.

How to compare two files using Emacs on a windows system?

11
  • 1
    By installing GetGnuWin32, you have access to a lot of gnu software (diff but alos wget, sed…). If you only care for diff, you could go with gnu.org/software/diffutils Commented Jun 3, 2015 at 7:36
  • The error message tells you what's wrong: You don't have diff installed. Go get Cygwin and try again.
    – itsjeyd
    Commented Jun 3, 2015 at 7:37
  • @itsjeyd Cygwin is already installed on system
    – Empty_Mind
    Commented Jun 3, 2015 at 7:49
  • @fredtantini After installing GetGnuWin32 i get the same error
    – Empty_Mind
    Commented Jun 3, 2015 at 8:06
  • 2
    Is it in your path? I think the directory should at least be on the exec-path variable. Commented Jun 3, 2015 at 8:27

5 Answers 5

10

As @nanny said in comments, solution is having installed Cygwin with diffutils. Here is how to do it:

  1. Download Cygwin from its homepage.
  2. Install Cygwin with diffutils: A GNU collection of diff utilities package. This package can be found in Utils section in one of few steps of Cygwin installation. installing Cygwin with diffutils
  3. Add Cygwin directories to the PATH windows system variable. This could be done by:
    a) adding your own CYGWIN variable, to keep the order. creating CYGWIN system variable;
    b) and adding variable you just created to the system PATH variable.adding CYGWIN variable to PATH system variable

After this you are able to call ediff-buffers, ediff-files and others successfully. Which looks something like this:running ediff

Enjoy!

8

If you have git for windows installed, then it is enough to add

C:\Program Files\Git\usr\bin\

to your PATH, because it already ships with a diff executable and installs it in that folder.

3

This may save people some time so I will answer here. If you do not wish to add the cygwin bin directory to your path (or any of the other ones suggested in the other answers), you can set the path of the program ediff uses by setting the variable ediff-diff-program. For example you could set it to C:\cygwin\bin (or whatever the actual path is in your case) if using cygwin. It took me some time to figure out which variable to set. Some that DID NOT work were: ediff-custom-diff-program and diff-command.

For example:

(setq ediff-diff-program "c:/CYGWIN64/bin/diff.exe")

does it.

3
  • IIRC, you can't call cygwin binaries outside of the shell, because they fail to load some libraries. I think this will only work when Emacs is run from Cygwin, which should have the PATH variable set correctly. Correct me if I'm wrong.
    – user12563
    Commented May 29, 2019 at 16:07
  • 1
    @DoMiNeLa10 I tested it on a Windows 10 machine with Emacs 26.1 by starting emacs from the taskbar without knowing about Cygwin... works fine. In addition, the solution adding it to the path would have the same issue you describe if it were really an issue.
    – sturgman
    Commented May 29, 2019 at 16:46
  • 1
    I am sorry, the last part of my comment is incorrect. Adding it to the path would not have the same issue you suggest, since it would be able to find the libraries. That said, I tested the approach in the answer and it works well.
    – sturgman
    Commented May 30, 2019 at 11:54
1

If you use the command line installer https://scoop.sh/ you can get diff by typing scoop install diffutils in your prompt.

0

If you don't need to produce a diff, but just want to find the differences between the files, one way to do it is to use M-x compare-windows instead.

Open the two files such that you see both of them at the same time, move point to the beginning in both buffers, and run M-x compare-windows. It will move point to the first place where the files differ. This should work without any external executable.

1
  • 1
    This stops the point before first differing character in both files.
    – Empty_Mind
    Commented Jun 3, 2015 at 11:10

Your Answer

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

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