# Add an option to ignore all whitespace to ediff. # Shortcut key is #b. The difference with ## is that by using #b, # whitespace is fully ignored in the diff. (while ## will mark whitespace but skip over it.) # This option was added to handle a few whitespace issues that are not handled correctly # by emacs ediff. --- lisp/vc/ediff-help.el.orig 2022-12-08 10:49:03.115864594 +0000 +++ lisp/vc/ediff-help.el 2022-12-07 17:40:28.404161562 +0000 @@ -67,7 +67,8 @@ p,DEL -previous diff | | -vert/horiz split |a/b -copy A/B's region to B/A n,SPC -next diff | h -highlighting | rx -restore buf X's old diff j -jump to diff | @ -auto-refinement | * -refine current region - gx -goto X's point| ## -ignore whitespace | ! -update diff regions + gx -goto X's point| ## -skip whitespace | ! -update diff regions + | #b -ignore whitespace | C-l -recenter | #c -ignore case | v/V -scroll up/dn | #f/#h -focus/hide regions | wx -save buf X -scroll lt/rt | X -read-only in buf X | wd -save diff output --- lisp/vc/ediff-diff.el.orig 2022-12-07 15:59:16.654660650 +0000 +++ lisp/vc/ediff-diff.el 2022-12-08 10:51:14.611610065 +0000 @@ -104,6 +104,18 @@ GNU diff3 doesn't have such an option." :type 'string) +;;; Ignore whitespace at the diff program level by specifying -Bbw, +;;; before the diff regions are generated. +;;; This means that with this option active, ## (emacs built in ignore whitespace) has no effect. +(defcustom ediff-ignore-whitespace-option "-Bbw" + "Option that causes the diff program to ignore whitespace." + :type 'string) + +(defcustom ediff-ignore-whitespace-option3 "" + "Option that causes the diff3 program to ignore whitespace. +GNU diff3 doesn't have such an option." + :type 'string) + ;; the actual options used in comparison (ediff-defvar-local ediff-actual-diff-options ediff-diff-options "") @@ -153,7 +165,13 @@ This variable can be set either in .emacs or toggled interactively. Use `setq-default' if setting it in .emacs") -(ediff-defvar-local ediff-auto-refine-limit 14000 +(ediff-defvar-local ediff-ignore-whitespace nil + "If t, ignore all whitespace. This is done by passing options to ignore whitespace to the diff program +before difference regions are calculated in emacs. +This variable can be set either in .emacs or toggled interactively. +Use `setq-default' if setting it in .emacs") + +(ediff-defvar-local ediff-auto-refine-limit 150000 "Auto-refine only the regions of this size (in bytes) or less.") ;;; General @@ -1433,14 +1451,30 @@ (defun ediff-set-actual-diff-options () - (if ediff-ignore-case - (setq ediff-actual-diff-options - (concat ediff-diff-options " " ediff-ignore-case-option) - ediff-actual-diff3-options - (concat ediff-diff3-options " " ediff-ignore-case-option3)) - (setq ediff-actual-diff-options ediff-diff-options - ediff-actual-diff3-options ediff-diff3-options) - ) + (let ((ediff-extra-diff-options "") (ediff-extra-diff3-options "")) + + (if ediff-ignore-case + (setq ediff-extra-diff-options ediff-ignore-case-option + ediff-extra-diff3-options ediff-ignore-case-option3) + ) + + (if ediff-ignore-whitespace + (setq ediff-extra-diff-options + (concat ediff-extra-diff-options " " ediff-ignore-whitespace-option) + ediff-extra-diff3-options + (concat ediff-extra-diff3-options " " ediff-ignore-whitespace-option3)) + ) + + (if (or ediff-ignore-whitespace ediff-ignore-case-option) + (setq ediff-actual-diff-options + (concat ediff-diff-options " " ediff-extra-diff-options) + ediff-actual-diff3-options + (concat ediff-diff3-options " " ediff-extra-diff3-options)) + (setq ediff-actual-diff-options ediff-diff-options + ediff-actual-diff3-options ediff-diff3-options) + ) + ) + (setq-default ediff-actual-diff-options ediff-actual-diff-options ediff-actual-diff3-options ediff-actual-diff3-options) ) --- lisp/vc/ediff-util.el.orig 2022-12-07 15:59:29.911635997 +0000 +++ lisp/vc/ediff-util.el 2022-12-07 16:51:17.867825952 +0000 @@ -207,6 +207,7 @@ (define-key ediff-mode-map "#c" 'ediff-toggle-ignore-case) (or ediff-word-mode (define-key ediff-mode-map "##" 'ediff-toggle-skip-similar)) + (define-key ediff-mode-map "#b" 'ediff-toggle-ignore-whitespace) (define-key ediff-mode-map "o" nil) (define-key ediff-mode-map "A" 'ediff-toggle-read-only) (define-key ediff-mode-map "B" 'ediff-toggle-read-only) @@ -2270,6 +2271,21 @@ "Skipping regions that differ only in white space & line breaks") (message "Skipping over white-space differences turned off"))) +(defun ediff-toggle-ignore-whitespace () + "Toggle ignoring whitespace by specifying the relevant options to the diff program. +This means that if this is active, whitespace differences are ignored +before the diff regions are created in emacs, and so the ## option has no effect." + (interactive) + (ediff-barf-if-not-control-buffer) + (setq ediff-ignore-whitespace (not ediff-ignore-whitespace)) + (ediff-set-actual-diff-options) + (if ediff-ignore-whitespace + (message "Ignoring all whitespace differences") + (message "Ignoring all whitespace differences turned off")) + (sit-for 1) + (ediff-update-diffs) + ) + (defun ediff-focus-on-regexp-matches (n) "Focus on diffs that match regexp `ediff-regexp-focus-A/B'. Regions to be ignored according to this function are those where