You can copy the following Elisp snippet into your init file.
Disclaimer: The code comes without any guaranty. It references internal functions of ediff. So use it with caution.
The newly defined command ediff-files-wordwise
just runs ediff-files
with two main modifications:
(ediff-word-mode . word-mode)
is added to the SETUP-PARAMETERS
of ediff-setup
.
The buffer contents of buf-A
and buf-B
is wordified and saved in temporary files that are used for the diff-program.
(eval-after-load "ediff"
(progn
(eval
`(defun ediff-files-wordwise (file-A file-B &optional startup-hooks)
,(concat (documentation 'ediff-files)
"\nComparison is done wordwise.")
,(interactive-form 'ediff-files)
(cl-letf* ((oldfun (symbol-function 'ediff-setup))
((symbol-function 'ediff-setup)
(lambda (buffer-A file-A buffer-B file-B buffer-C file-C startup-hooks setup-parameters &optional merge-buffer-file)
(let* ((tmp-buffer (get-buffer-create ediff-tmp-buffer)))
(with-current-buffer buffer-A
(ediff-wordify (point-min) (point-max) buffer-A tmp-buffer))
(setq file-A (ediff-make-temp-file tmp-buffer "regA"))
(with-current-buffer buffer-B
(ediff-wordify (point-min) (point-max) buffer-B tmp-buffer))
(setq file-B (ediff-make-temp-file tmp-buffer "regB"))
(setq overl-A (with-current-buffer buffer-A
(ediff-make-bullet-proof-overlay (point-min) (point-max) buffer-A))
overl-B (with-current-buffer buffer-B
(ediff-make-bullet-proof-overlay (point-min) (point-max) buffer-B)))
(funcall oldfun
buffer-A file-A buffer-B file-B buffer-C file-C startup-hooks
(append
(list (cons 'ediff-word-mode 'word-mode)
(cons 'ediff-narrow-bounds (list overl-A overl-B)))
setup-parameters)
merge-buffer-file)))))
(ediff-files file-A file-B startup-hooks))))
(require 'easymenu)
(easy-menu-add-item
menu-bar-tools-menu
'("Compare (Ediff)")
["Two Files Word-by-word..." ediff-files-wordwise t]
"Two Buffers...")))