7

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?

Dan
  • 12,157
  • 12
  • 50
  • 84

3 Answers3

6

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")
aerique
  • 982
  • 5
  • 21
1

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)
Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • This doesn't highlight all the lines that have non-whitespace differences, it only does it by diff. It works better than what I was using, but I'd still like all the non-whitespace differences highlighted (if that's possible). – Dan Nov 20 '12 at 01:01
  • 1
    @Dan Try only having the first line in your .emacs. – Trey Jackson Nov 20 '12 at 19:24
1

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-change "LightBlue1")

Also try h command in ediff control buffer.

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

gavenkoa
  • 45,285
  • 19
  • 251
  • 303
  • Can you maybe expand a bit on how the colors work in this case? The sentence before the color settings is a bit difficult to follow, at least for me. Thanks. – Alwyn Schoeman Feb 26 '20 at 22:55