Quickly ediff files from dired18 Mar 2017
ediff.el --- a comprehensive visual interface to diff & patch
The premise is quite simple: press e in
immediately ediff two marked files, no questions asked:
(define-key dired-mode-map "e" 'ora-ediff-files)
And here's the code, with a few bells and whistles:
;; -*- lexical-binding: t -*- (defun ora-ediff-files () (interactive) (let ((files (dired-get-marked-files)) (wnd (current-window-configuration))) (if (<= (length files) 2) (let ((file1 (car files)) (file2 (if (cdr files) (cadr files) (read-file-name "file: " (dired-dwim-target-directory))))) (if (file-newer-than-file-p file1 file2) (ediff-files file2 file1) (ediff-files file1 file2)) (add-hook 'ediff-after-quit-hook-internal (lambda () (setq ediff-after-quit-hook-internal nil) (set-window-configuration wnd)))) (error "no more than 2 files should be marked"))))
Some notes on how the extra code adds convenience:
In case no files are marked, the file at point is used as the first file, and
read-file-nameis used for the second file. Since I have the magic
(setq dired-dwim-target t)in my config, in case a second
diredbuffer is open,
dired-dwim-target-directorywill offer it as the starting directory during completion. Very useful to compare two files in two different directories.
Depending on the order of the arguments to
ediff-files, the changes will appear either as added or removed;
file-newer-than-file-ptries to put the arguments in a logical order by looking at the files' last change times.
ediff-after-quit-hook-internalis used to restore the previous window configuration after I quit
That's about it. Hopefully, it's useful. Happy hacking.