unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Pluim <rpluim@gmail.com>
To: "Daniel Martín" <mardani29@yahoo.es>
Cc: 58516@debbugs.gnu.org, gert <gertopc@proton.me>
Subject: bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
Date: Mon, 17 Oct 2022 14:27:42 +0200	[thread overview]
Message-ID: <87edv6y6rl.fsf@gmail.com> (raw)
In-Reply-To: <m1zgdy9wm9.fsf@yahoo.es> ("Daniel Martín via \"Bug reports for GNU Emacs, the Swiss army knife of text editors\""'s message of "Fri, 14 Oct 2022 18:51:42 +0200")

[-- Attachment #1: Type: text/plain, Size: 584 bytes --]

>>>>> On Fri, 14 Oct 2022 18:51:42 +0200, Daniel Martín via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org> said:

    Daniel> Robert Pluim <rpluim@gmail.com> writes:
    >> 
    >> Something like this, perhaps. I stuck it on a separate key, but we
    >> could put it on "C-u C-c C-w" instead.
    >> 

    Daniel> Looks good.  I agree that using a prefix argument is a better idea to
    Daniel> save some key bindings.

Hey, there are *loads* of bindings available. "C-c C-w" anyone? 😺

Comments welcome

Robert
-- 

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Teach-diff-ignore-whitespace-hunk-how-to-regenerate-.patch --]
[-- Type: text/x-diff, Size: 3962 bytes --]

From 8192b0ac043ce2f79189ec5473ad390fe0371dd8 Mon Sep 17 00:00:00 2001
From: Robert Pluim <rpluim@gmail.com>
Date: Mon, 17 Oct 2022 14:18:23 +0200
Subject: [PATCH] Teach 'diff-ignore-whitespace-hunk' how to regenerate all
 hunks
To: emacs-devel@gnu.org

This implements the request from Bug#58516.

* lisp/vc/diff-mode.el (diff-ignore-whitespace-hunk): Regenerate all
the hunks when called with a prefix arg.
(diff--iterate-hunks): Add optional arg for start of iteration.
(diff--ignore-whitespace-all-hunks): Iterate over all hunks, regenerate
ignoring whitespace.

* doc/emacs/files.texi (Diff Mode): Describe change in behaviour.
* etc/NEWS: Announce the change.
---
 doc/emacs/files.texi |  3 ++-
 etc/NEWS             |  6 ++++++
 lisp/vc/diff-mode.el | 21 ++++++++++++++++-----
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
index 1717c5c25b..7f8a30e9d9 100644
--- a/doc/emacs/files.texi
+++ b/doc/emacs/files.texi
@@ -1728,7 +1728,8 @@ Diff Mode
 
 @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 ca857056fd..8d8f1e3b7b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1507,6 +1507,12 @@ Sets the value of the buffer-local variable 'whitespace-style' in
 'diff-mode' buffers.  By default, this variable is '(face trailing)',
 which preserves behavior from previous Emacs versions.
 
++++
+*** '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.
+
 +++
 *** New user option 'diff-add-log-use-relative-names'.
 If non-nil insert file names in ChangeLog skeletons relative to the
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index a9591c9d82..5a8d25800c 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -2102,10 +2102,13 @@ diff-current-defun
               (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 (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."
@@ -2275,10 +2278,12 @@ diff--refine-hunk
                                   (match-end 0) end
                                   nil #'diff-refine-preproc props-r props-a)))))))
 
-(defun diff--iterate-hunks (max fun)
+(defun diff--iterate-hunks (max fun &optional min)
   "Iterate over all hunks between point and MAX.
 Call FUN with two args (BEG and END) for each hunk."
   (save-excursion
+      (when min
+      (goto-char min))
     (catch 'malformed
       (let* ((beg (or (ignore-errors (diff-beginning-of-hunk))
                       (ignore-errors (diff-hunk-next) (point))
@@ -2298,6 +2303,12 @@ diff--iterate-hunks
                         (or (ignore-errors (diff-hunk-next) (point))
                             max)))))))))
 
+(defun diff--ignore-whitespace-all-hunks ()
+  "Re-diff all the hunks, ignoring whitespace-differences."
+  (diff--iterate-hunks (point-max) (lambda (_ _)
+                                     (diff-refresh-hunk t))
+                       (point-min)))
+
 (defun diff--font-lock-refined (max)
   "Apply hunk refinement from font-lock."
   (when (eq diff-refine 'font-lock)
-- 
2.37.1.116.g9dd64cb4d3


  reply	other threads:[~2022-10-17 12:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14 11:15 bug#58516: 28.1; add option/key to rerun current diff without whitespace changes gert via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-14 15:35 ` Robert Pluim
2022-10-14 16:51   ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-17 12:27     ` Robert Pluim [this message]
2022-10-17 12:33       ` Lars Ingebrigtsen
2022-10-17 13:01         ` Robert Pluim
2022-10-15 10:19   ` Lars Ingebrigtsen
2023-02-15 13:11     ` Robert Pluim
2022-10-15 19:09   ` Juri Linkov
2022-10-17  8:49     ` Robert Pluim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87edv6y6rl.fsf@gmail.com \
    --to=rpluim@gmail.com \
    --cc=58516@debbugs.gnu.org \
    --cc=gertopc@proton.me \
    --cc=mardani29@yahoo.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).