Teach 'diff-ignore-whitespace-hunk' how to regenerate all hunks

This implements the request from Bug#58516.

* lisp/vc/diff-mode.el (diff--ignore-whitespace-all-hunks): New
function.  Iterate over all hunks, regenerate ignoring whitespace
changes.
(diff-ignore-whitespace-hunk): Call `diff--ignore-whitespace-all-hunks'
when called with a prefix arg.

* doc/emacs/files.texi (Diff Mode): Describe new functionality.
* etc/NEWS: Announce the change.
This commit is contained in:
Robert Pluim 2023-01-10 19:55:50 +01:00
parent b9ef710dd3
commit 571558e460
3 changed files with 27 additions and 5 deletions

View file

@ -1738,7 +1738,8 @@ Re-generate the current hunk (@code{diff-refresh-hunk}).
@item C-c C-w
@findex diff-ignore-whitespace-hunk
Re-generate the current hunk, disregarding changes in whitespace
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}).
@item C-x 4 A

View file

@ -98,6 +98,14 @@ This is a string or a list of strings that specifies the Git log
switches for shortlogs, such as the one produced by 'C-x v L'.
'vc-git-log-switches' is no longer used for shortlogs.
** Diff Mode
+++
*** 'diff-ignore-whitespace-hunk' can now be applied to all hunks.
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.
** Buffer Selection
---

View file

@ -2103,10 +2103,13 @@ For use in `add-log-current-defun-function'."
(goto-char (+ (car pos) (cdr src)))
(add-log-current-defun)))))))
(defun diff-ignore-whitespace-hunk ()
"Re-diff the current hunk, ignoring whitespace differences."
(interactive)
(diff-refresh-hunk t))
(defun diff-ignore-whitespace-hunk (&optional whole-buffer)
"Re-diff the current hunk, ignoring whitespace differences.
With non-nil prefix arg, re-diff all the hunks."
(interactive "P")
(if whole-buffer
(diff--ignore-whitespace-all-hunks)
(diff-refresh-hunk t)))
(defun diff-refresh-hunk (&optional ignore-whitespace)
"Re-diff the current hunk."
@ -2299,6 +2302,16 @@ Call FUN with two args (BEG and END) for each hunk."
(or (ignore-errors (diff-hunk-next) (point))
max)))))))))
;; This doesn't use `diff--iterate-hunks', since that assumes that
;; hunks don't change size.
(defun diff--ignore-whitespace-all-hunks ()
"Re-diff all the hunks, ignoring whitespace-differences."
(save-excursion
(goto-char (point-min))
(diff-hunk-next)
(while (looking-at diff-hunk-header-re)
(diff-refresh-hunk t))))
(defun diff--font-lock-refined (max)
"Apply hunk refinement from font-lock."
(when (eq diff-refine 'font-lock)