From 6a677fd3b6677248a8bc1787b105879684289fa2 Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Wed, 15 Feb 2023 14:31:43 +0100 Subject: [PATCH] New option 'diff-ignore-whitespace-switches' Allows specifying the switches to use when ignoring whitespace for those of us who don't like "-b". * lisp/vc/diff-mode.el (diff-ignore-whitespace-switches): New defcustom. (diff-refresh-hunk): Use it when ignoring whitespace. * doc/emacs/files.texi (Diff Mode): Describe the new option. * etc/NEWS: Announce the new option. --- doc/emacs/files.texi | 5 ++++- etc/NEWS | 6 ++++++ lisp/vc/diff-mode.el | 13 ++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 6586998e179..a9ae4696a06 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1737,10 +1737,13 @@ only the hunks within the region. Re-generate the current hunk (@code{diff-refresh-hunk}). @item C-c C-w +@vindex diff-ignore-whitespace-switches @findex diff-ignore-whitespace-hunk Re-generate the current hunk, disregarding changes in whitespace. With a non-@code{nil} prefix arg, re-generate all the hunks -(@code{diff-ignore-whitespace-hunk}). +(@code{diff-ignore-whitespace-hunk}). This calls @code{diff-command} +with @code{diff-ignore-whitespace-switches}, which defaults to +@samp{-b}, meaning ignore changes in whitespace only. @item C-x 4 A @findex diff-add-change-log-entries-other-window diff --git a/etc/NEWS b/etc/NEWS index 624bbdf98f9..c635e1fbe87 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -106,6 +106,12 @@ When called with a non-nil prefix argument 'diff-ignore-whitespace-hunk' now iterates over all the hunks in the current diff, regenerating them without whitespace changes. ++++ +*** New user option 'diff-ignore-whitespace-switches'. +This allows changing which type of whitespace changes are ignored when +regenerating hunks with 'diff-ignore-whitespace-hunk'. Defaults to +the previously hard-coded "-b". + ** Buffer Selection --- diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 6d8a868aa48..d776375d681 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -153,6 +153,17 @@ and hunk-based syntax highlighting otherwise as a fallback." :type (get 'whitespace-style 'custom-type) :version "29.1") +(defcustom diff-ignore-whitespace-switches "-b" + "Switch or list of diff switches to use when ignoring whitespace. +The default \"-b\" means to ignore whitespace-only changes, +\"-w\" means ignore all whitespace changes." + :type '(choice + (string :tag "Ignore whitespace-only changes" :value "-b") + (string :tag "Ignore all whitespace changes" :value "-w") + (string :tag "Single switch") + (repeat :tag "Multiple switches" (string :tag "Switch"))) + :version "30.1") + (defvar diff-vc-backend nil "The VC backend that created the current Diff buffer, if any.") @@ -2130,7 +2141,7 @@ With non-nil prefix arg, re-diff all the hunks." (coding-system-for-read buffer-file-coding-system) opts old new) (when ignore-whitespace - (setq opts '("-b"))) + (setq opts (ensure-list diff-ignore-whitespace-switches))) (when opt-type (setq opts (cons opt-type opts))) -- 2.39.2