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.
This commit is contained in:
Robert Pluim 2023-02-15 14:31:43 +01:00
parent 80b34d165d
commit 6a677fd3b6
3 changed files with 22 additions and 2 deletions

View file

@ -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

View file

@ -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
---

View file

@ -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)))