How can I get ediff mode to stop highlighting lines that differ only by whitespace?

4.2k Views Asked by At

I have two similar functions in C++ that I want to carefully compare. I'm using the emacs function ediff-regions-linewise to compare them line-by-line. Many of the lines have small differences in their whitespace, for example:

//Line from first function
somefunc(i,j);
//Line from second function
somefunc(i, j);

Ediff-mode is smart enough to know which sections only differ by whitespace: the command ## nominally means "ignore whitespace". It only causes the cursor to skip sections that differ, but still highlights lines that differ only by whitespace in the same way it highlights lines that differ in some way that matters.

Is there a way to get ediff-mode to stop highlighting lines that are only different because of whitespace?

3

There are 3 best solutions below

0
On BEST ANSWER

I have got the following setting in my Emacs config to disable whitespace when diffing (see man diff for what it does):

(setq ediff-diff-options "-w")
1
On

While (setq ediff-diff-options "-w") may hit the nail it may hide bug other days.

ediff menu suggest to use ## to toggle whitespace difference.

With enabled whitespace ignorance movement commands (n / p) skips hunks with only whitespace differences.

Emacs has commands to highlight non-whitespace difference by different faces (C-c C-b or M-x diff-refine-hunk). It places overlays with same colors as diff cases:

diff-removed-face
diff-added-face
diff-indicator-added-face
diff-indicator-removed-face

To make difference visible use something like:

(set-face-foreground 'diff-refine-added "DarkGreen")
(set-face-foreground 'diff-refine-removed "DarkRed")
(set-face-background 'diff-refine-changed "LightBlue1")

Also try h command in ediff control buffer.

This doesn't answer your direct question, but makes it meaningless.

2
On

I have these two settings which have the net effect of doing what you're asking:

(setq-default ediff-ignore-similar-regions t)
(setq-default ediff-highlight-all-diffs nil)