aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Pluim2023-01-10 19:55:50 +0100
committerRobert Pluim2023-02-15 13:51:47 +0100
commit571558e460059b3756f592abaaf2a9a67778db66 (patch)
tree9d99d584bf5f9d729f83302001f01309cd354b17
parentb9ef710dd3b46bdfe7a0352873a0f2be5b9e4ce4 (diff)
downloademacs-571558e460059b3756f592abaaf2a9a67778db66.tar.gz
emacs-571558e460059b3756f592abaaf2a9a67778db66.zip
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}).
1738 1738
1739@item C-c C-w 1739@item C-c C-w
1740@findex diff-ignore-whitespace-hunk 1740@findex diff-ignore-whitespace-hunk
1741Re-generate the current hunk, disregarding changes in whitespace 1741Re-generate the current hunk, disregarding changes in whitespace.
1742With a non-@code{nil} prefix arg, re-generate all the hunks
1742(@code{diff-ignore-whitespace-hunk}). 1743(@code{diff-ignore-whitespace-hunk}).
1743 1744
1744@item C-x 4 A 1745@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
98switches for shortlogs, such as the one produced by 'C-x v L'. 98switches for shortlogs, such as the one produced by 'C-x v L'.
99'vc-git-log-switches' is no longer used for shortlogs. 99'vc-git-log-switches' is no longer used for shortlogs.
100 100
101** Diff Mode
102
103+++
104*** 'diff-ignore-whitespace-hunk' can now be applied to all hunks.
105When called with a non-nil prefix argument
106'diff-ignore-whitespace-hunk' now iterates over all the hunks in the
107current diff, regenerating them without whitespace changes.
108
101** Buffer Selection 109** Buffer Selection
102 110
103--- 111---
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'."
2103 (goto-char (+ (car pos) (cdr src))) 2103 (goto-char (+ (car pos) (cdr src)))
2104 (add-log-current-defun))))))) 2104 (add-log-current-defun)))))))
2105 2105
2106(defun diff-ignore-whitespace-hunk () 2106(defun diff-ignore-whitespace-hunk (&optional whole-buffer)
2107 "Re-diff the current hunk, ignoring whitespace differences." 2107 "Re-diff the current hunk, ignoring whitespace differences.
2108 (interactive) 2108With non-nil prefix arg, re-diff all the hunks."
2109 (diff-refresh-hunk t)) 2109 (interactive "P")
2110 (if whole-buffer
2111 (diff--ignore-whitespace-all-hunks)
2112 (diff-refresh-hunk t)))
2110 2113
2111(defun diff-refresh-hunk (&optional ignore-whitespace) 2114(defun diff-refresh-hunk (&optional ignore-whitespace)
2112 "Re-diff the current hunk." 2115 "Re-diff the current hunk."
@@ -2299,6 +2302,16 @@ Call FUN with two args (BEG and END) for each hunk."
2299 (or (ignore-errors (diff-hunk-next) (point)) 2302 (or (ignore-errors (diff-hunk-next) (point))
2300 max))))))))) 2303 max)))))))))
2301 2304
2305;; This doesn't use `diff--iterate-hunks', since that assumes that
2306;; hunks don't change size.
2307(defun diff--ignore-whitespace-all-hunks ()
2308 "Re-diff all the hunks, ignoring whitespace-differences."
2309 (save-excursion
2310 (goto-char (point-min))
2311 (diff-hunk-next)
2312 (while (looking-at diff-hunk-header-re)
2313 (diff-refresh-hunk t))))
2314
2302(defun diff--font-lock-refined (max) 2315(defun diff--font-lock-refined (max)
2303 "Apply hunk refinement from font-lock." 2316 "Apply hunk refinement from font-lock."
2304 (when (eq diff-refine 'font-lock) 2317 (when (eq diff-refine 'font-lock)