summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Pluim <rpluim@gmail.com>2023-01-10 19:55:50 +0100
committerRobert Pluim <rpluim@gmail.com>2023-02-15 13:51:47 +0100
commit571558e460059b3756f592abaaf2a9a67778db66 (patch)
tree9d99d584bf5f9d729f83302001f01309cd354b17
parentb9ef710dd3b46bdfe7a0352873a0f2be5b9e4ce4 (diff)
downloademacs-571558e460059b3756f592abaaf2a9a67778db66.tar.gz
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.
-rw-r--r--doc/emacs/files.texi3
-rw-r--r--etc/NEWS8
-rw-r--r--lisp/vc/diff-mode.el21
3 files changed, 27 insertions, 5 deletions
diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
index 664b9d5d9a3..6586998e179 100644
--- a/doc/emacs/files.texi
+++ b/doc/emacs/files.texi
@@ -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
diff --git a/etc/NEWS b/etc/NEWS
index 2d63593ff17..624bbdf98f9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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
---
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index eb01dede56e..6d8a868aa48 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -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)