all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
@ 2022-10-14 11:15 gert via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-10-14 15:35 ` Robert Pluim
  0 siblings, 1 reply; 10+ messages in thread
From: gert via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-10-14 11:15 UTC (permalink / raw)
  To: 58516

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

Sometimes, for example when you work together with others, there are meaningless whitespace changes in the diff.

In order to review these diff easier add a key to rerun the current diff without showing whitespace changes.

There is

("\C-c\C-w" . diff-ignore-whitespace-hunk)

which is useful, but incovenient to use when there are many hunks in the diff.

Add a key which does the same, but for all hunks (e.g. diff-toggle-whitespace-changes), so you can easily switch a diff buffer to one which ignores all whitespace changes.

[-- Attachment #2: Type: text/html, Size: 1426 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
  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
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Robert Pluim @ 2022-10-14 15:35 UTC (permalink / raw)
  To: 58516; +Cc: gert

>>>>> On Fri, 14 Oct 2022 11:15:05 +0000, gert via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org> said:

    Gert> Sometimes, for example when you work together with others, there are
    Gert> meaningless whitespace changes in the diff.

    Gert> In order to review these diff easier add a key to rerun the current
    Gert> diff without showing whitespace changes.

    Gert> There is

    Gert> ("\C-c\C-w" . diff-ignore-whitespace-hunk)

    Gert> which is useful, but incovenient to use when there are many hunks in the diff.

    Gert> Add a key which does the same, but for all hunks
    Gert> (e.g. diff-toggle-whitespace-changes), so you can easily switch a diff
    Gert> buffer to one which ignores all whitespace changes.

Something like this, perhaps. I stuck it on a separate key, but we
could put it on "C-u C-c C-w" instead.

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index a9591c9d82..3b8178884a 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -214,6 +214,7 @@ diff-mode-map
   ;; `d' because it duplicates the context :-(  --Stef
   "C-c C-d" #'diff-unified->context
   "C-c C-w" #'diff-ignore-whitespace-hunk
+  "C-c C-W" #'diff-ignore-whitespace-all-hunks
   ;; `l' because it "refreshes" the hunk like C-l refreshes the screen
   "C-c C-l" #'diff-refresh-hunk
   "C-c C-b" #'diff-refine-hunk        ;No reason for `b' :-(
@@ -2275,10 +2276,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 +2301,13 @@ 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."
+  (interactive)
+  (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)





^ permalink raw reply related	[flat|nested] 10+ messages in thread

* bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
  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
  2022-10-15 10:19   ` Lars Ingebrigtsen
  2022-10-15 19:09   ` Juri Linkov
  2 siblings, 1 reply; 10+ messages in thread
From: Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-10-14 16:51 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 58516, gert

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

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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
  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-15 10:19   ` Lars Ingebrigtsen
  2023-02-15 13:11     ` Robert Pluim
  2022-10-15 19:09   ` Juri Linkov
  2 siblings, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2022-10-15 10:19 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 58516, gert

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.

Yes, looks useful, but I'd rather have it on a prefix instead.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
  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-15 10:19   ` Lars Ingebrigtsen
@ 2022-10-15 19:09   ` Juri Linkov
  2022-10-17  8:49     ` Robert Pluim
  2 siblings, 1 reply; 10+ messages in thread
From: Juri Linkov @ 2022-10-15 19:09 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 58516, gert

> +(defun diff-ignore-whitespace-all-hunks ()
> +  "Re-diff all the hunks, ignoring whitespace-differences."
> +  (interactive)
> +  (diff--iterate-hunks (point-max) (lambda (_ _)
> +                                     (diff-refresh-hunk t))
> +                       (point-min)))

A question about performance: would this run the diff command
for every hunk?





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
  2022-10-15 19:09   ` Juri Linkov
@ 2022-10-17  8:49     ` Robert Pluim
  0 siblings, 0 replies; 10+ messages in thread
From: Robert Pluim @ 2022-10-17  8:49 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 58516, gert

>>>>> On Sat, 15 Oct 2022 22:09:35 +0300, Juri Linkov <juri@linkov.net> said:

    >> +(defun diff-ignore-whitespace-all-hunks ()
    >> +  "Re-diff all the hunks, ignoring whitespace-differences."
    >> +  (interactive)
    >> +  (diff--iterate-hunks (point-max) (lambda (_ _)
    >> +                                     (diff-refresh-hunk t))
    >> +                       (point-min)))

    Juri> A question about performance: would this run the diff command
    Juri> for every hunk?

Yes. I donʼt see an easy way to avoid that: we may not have actual
source files available, so we canʼt just run the diff command with
different switches over the whole file.

Robert
-- 





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
  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
  2022-10-17 12:33       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Robert Pluim @ 2022-10-17 12:27 UTC (permalink / raw)
  To: Daniel Martín; +Cc: 58516, gert

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
  2022-10-17 12:27     ` Robert Pluim
@ 2022-10-17 12:33       ` Lars Ingebrigtsen
  2022-10-17 13:01         ` Robert Pluim
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2022-10-17 12:33 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 58516, gert, Daniel Martín

Robert Pluim <rpluim@gmail.com> writes:

> Comments welcome

Looks good to me, but:

> +(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")

That should be "&optional whole-buffer".





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
  2022-10-17 12:33       ` Lars Ingebrigtsen
@ 2022-10-17 13:01         ` Robert Pluim
  0 siblings, 0 replies; 10+ messages in thread
From: Robert Pluim @ 2022-10-17 13:01 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 58516, gert, Daniel Martín

>>>>> On Mon, 17 Oct 2022 14:33:27 +0200, Lars Ingebrigtsen <larsi@gnus.org> said:

    Lars> Robert Pluim <rpluim@gmail.com> writes:
    >> Comments welcome

    Lars> Looks good to me, but:

    >> +(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")

    Lars> That should be "&optional whole-buffer".

The interaction between `interactive' and &optional is one of those
things that my brain always seems to page out, so I believe you :-)

Robert
-- 





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#58516: 28.1; add option/key to rerun  current diff without whitespace changes
  2022-10-15 10:19   ` Lars Ingebrigtsen
@ 2023-02-15 13:11     ` Robert Pluim
  0 siblings, 0 replies; 10+ messages in thread
From: Robert Pluim @ 2023-02-15 13:11 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 58516, gert

tags 58516 fixed
close 58516 30.1
quit

>>>>> On Sat, 15 Oct 2022 12:19:32 +0200, Lars Ingebrigtsen <larsi@gnus.org> said:

    Lars> 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.

    Lars> Yes, looks useful, but I'd rather have it on a prefix instead.

Now pushed to master (belatedly).

Robert
-- 





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-02-15 13:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.