From unknown Sat Jun 21 10:15:23 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#73407 <73407@debbugs.gnu.org> To: bug#73407 <73407@debbugs.gnu.org> Subject: Status: 31.0.50; Add diff-discard-hunk Reply-To: bug#73407 <73407@debbugs.gnu.org> Date: Sat, 21 Jun 2025 17:15:23 +0000 retitle 73407 31.0.50; Add diff-discard-hunk reassign 73407 emacs submitter 73407 Sean Whitton severity 73407 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 21 06:19:37 2024 Received: (at submit) by debbugs.gnu.org; 21 Sep 2024 10:19:37 +0000 Received: from localhost ([127.0.0.1]:37255 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srxDE-0005Tq-Q2 for submit@debbugs.gnu.org; Sat, 21 Sep 2024 06:19:37 -0400 Received: from lists.gnu.org ([209.51.188.17]:39200) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srxDC-0005Tg-IP for submit@debbugs.gnu.org; Sat, 21 Sep 2024 06:19:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srxCs-0007tE-5u for bug-gnu-emacs@gnu.org; Sat, 21 Sep 2024 06:19:14 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srxCp-0003wI-OT for bug-gnu-emacs@gnu.org; Sat, 21 Sep 2024 06:19:13 -0400 DKIM-Signature: a=rsa-sha256; b=XixtdokDImaiT/WusKKOHj91oLsQUQKRKBbYRXQ8H88QFr23V3CyuP414EhLmDTChJqaxHwoFc+qI0EvriRfOAi+xUr6uVoLGqPJQKUzS+btWlPdK/9YkIfu3NbW2wDPNW49RppOmXgzLsjACrJji7wpJxAaQdWsnDl2vk6eowvPcPl448btcaV7yupDKoFMe0T9guAsiEf9XUpgs7Gpo8Y80NGVCTjwBtNgAM/n/rGicrwAxR43w7tszU6C8okzpJw4RipeeDp0IwmqDqa5Ll8UbYjD37EF8EIbIhuXyqaaI2F2lqNxuKlAwMBxgC3pxGe4t6p3EKEJ+uJRsQGEGA==; s=purelymail3; d=spwhitton.name; v=1; bh=EkMtUjZSQeotVEn0UUsaZXD3KyKxSkjTDbE1VN7XnwI=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=jlqWhMZ/asvQzBuqB5cGzEn2spO+lqRDEziAZbCWJLyNs5djRG10XT5TFoWWT/LVFoljYxAgpV3rjuQUHPrLyCPZ76E7FqsKJ2eSzV/2Lbigb6cIU3ZXcZcl+XvEaFyS8UT1TTGQNFzYN0PI3IQXCNRXmWp9DnoUsY+DVj9aL6HCsFDjDGLyCorGdfI9Gn69r9OB++p6JYXmXyjnuXYTRP05tgxsKlt2/5tnvyTnIjhO/DUyqIvbMHxHfBZd2ru1zBFnAmGwjZmhDsrI06vkRO8cKuNJoNmjHXbuBR1IwZFrsoccuE6UT1Wg1IB9Vc2V6i73lIQnwF0QOvmzOopmFg==; s=purelymail3; d=purelymail.com; v=1; bh=EkMtUjZSQeotVEn0UUsaZXD3KyKxSkjTDbE1VN7XnwI=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: bug-gnu-emacs@gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -2089262969 for (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sat, 21 Sep 2024 10:19:07 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 2C762949FDC; Sat, 21 Sep 2024 11:19:06 +0100 (BST) From: Sean Whitton To: bug-gnu-emacs@gnu.org Subject: 31.0.50; Add diff-discard-hunk Date: Sat, 21 Sep 2024 11:19:06 +0100 Message-ID: <87jzf58g2t.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=34.202.193.197; envelope-from=spwhitton@spwhitton.name; helo=sendmail.purelymail.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --=-=-= Content-Type: text/plain X-debbugs-cc: dgutov@yandex.ru, juri@linkov.net These patches add a new command, diff-discard-hunk, inspired by some functionality from Magit. It nicely complements a workflow based around committing with C-x v v from C-x v D. I have been using it every day for a year or so, and I think others will find it useful, too. Posting for comments. Thanks! -- Sean Whitton --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-New-user-option-diff-display-after-apply-hunk.patch >From 8d4911ed2db8a1ace388616bff35857559920f84 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 21 Sep 2024 10:51:23 +0100 Subject: [PATCH 1/2] New user option 'diff-display-after-apply-hunk' * lisp/vc/diff-mode.el (diff-display-after-apply-hunk): New option. (diff-apply-hunk): Use it. * etc/NEWS: Announce the new option. --- etc/NEWS | 6 ++++++ lisp/vc/diff-mode.el | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index 8bd5c7c9515..65e3a484e7a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -304,6 +304,12 @@ according to diffs in the current buffer, but without applying the diffs to the original text. If the selected range extends a hunk, the command attempts to look up and copy the text in-between the hunks. +--- +*** New user option 'diff-display-after-apply-hunk'. +This option can be customized to nil to inhibit how, by default, +'diff-apply-hunk' displays the changed text after applying the hunk. +It can also be let-bound by Lisp code wrapping 'diff-apply-hunk'. + ** php-ts-mode --- diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 4810b9ce01c..8af155c79e0 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -95,6 +95,10 @@ diff-advance-after-apply-hunk "Non-nil means `diff-apply-hunk' will move to the next hunk after applying." :type 'boolean) +(defcustom diff-display-after-apply-hunk t + "Non-nil means `diff-apply-hunk' will display the buffer it just changed." + :type 'boolean) + (defcustom diff-mode-hook nil "Run after setting up the `diff-mode' major mode." :type 'hook @@ -2024,7 +2028,8 @@ diff-apply-hunk (delete-region (car pos) (cdr pos)) (insert (car new))) ;; Display BUF in a window - (set-window-point (display-buffer buf) (+ (car pos) (cdr new))) + (when diff-display-after-apply-hunk + (set-window-point (display-buffer buf) (+ (car pos) (cdr new)))) (diff-hunk-status-msg line-offset (xor switched reverse) nil) (when diff-advance-after-apply-hunk (diff-hunk-next)))))) -- 2.39.5 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-New-command-diff-discard-hunk.patch >From 076a74fd4798bd3908aa0cd4ed07ed85e03559c1 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 21 Sep 2024 11:16:18 +0100 Subject: [PATCH 2/2] New command 'diff-discard-hunk' * lisp/vc/diff-mode.el (diff-discard-hunk): New command. (diff-mode-map): Bind it to C-c C-k. (diff-mode-menu): New entry "Discard hunk". * doc/emacs/files.texi (Diff Mode): * etc/NEWS: Document the new command. --- doc/emacs/files.texi | 11 +++++++++++ etc/NEWS | 5 +++++ lisp/vc/diff-mode.el | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 709cb0910e6..04ecfabc1ee 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1682,6 +1682,17 @@ Diff Mode version. If @code{diff-jump-to-old-file} is non-@code{nil}, apply the hunk to the ``old'' version of the file instead. +@findex diff-discard-hunk +@item C-c C-k +Reverse-apply this hunk to the target file, and then kill it +(@code{diff-discard-hunk}). Unless the buffer visiting the target file +was already modified, save it. + +This command is useful in buffers generated by @w{@kbd{C-x v =}} and +@w{@kbd{C-x v D}} (@pxref{Old Revisions}). You can use this command to +remove hunks you never intend to commit, such as temporary debug prints, +and the like. + @findex diff-apply-buffer @item C-c @key{RET} a Apply all the hunks in the buffer (@code{diff-apply-buffer}). If the diff --git a/etc/NEWS b/etc/NEWS index 65e3a484e7a..8da68eded82 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -310,6 +310,11 @@ This option can be customized to nil to inhibit how, by default, 'diff-apply-hunk' displays the changed text after applying the hunk. It can also be let-bound by Lisp code wrapping 'diff-apply-hunk'. ++++ +*** New command 'diff-discard-hunk' bound to C-c C-k. +This command reverse-applies the hunk at point, and then kills it. +This is useful in buffers generated C-x v = and C-x v D. + ** php-ts-mode --- diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 8af155c79e0..3a6bc62b78a 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -222,6 +222,7 @@ diff-mode-map "C-x 4 A" #'diff-add-change-log-entries-other-window ;; Misc operations. "C-c C-a" #'diff-apply-hunk + "C-c C-k" #'diff-discard-hunk "C-c C-m a" #'diff-apply-buffer "C-c C-e" #'diff-ediff-patch "C-c C-n" #'diff-restrict-view @@ -246,6 +247,8 @@ diff-mode-menu :help "Apply the current hunk to the source file and go to the next"] ["Test applying hunk" diff-test-hunk :help "See whether it's possible to apply the current hunk"] + ["Discard hunk" diff-discard-hunk + :help "Reverse-apply and then kill the current hunk."] ["Apply all hunks" diff-apply-buffer :help "Apply all hunks in the current diff buffer"] ["Apply diff with Ediff" diff-ediff-patch @@ -2055,6 +2058,26 @@ diff-kill-applied-hunks (diff-hunk-kill) (diff-hunk-next))))) +(defun diff-discard-hunk () + "Reverse-apply and then kill the hunk at point. +Unless the buffer was already modified, save the changed buffer. + +This command is useful in buffers generated by \\[vc-diff] and \\[vc-root-diff]. +You can use `diff-hunk-kill' to remove hunks you intend to commit later. +You can use this command to remove hunks you never intend to commit, +such as temporary debug prints, and the like." + (interactive) + (let* ((diff-advance-after-apply-hunk nil) + (diff-display-after-apply-hunk nil) + (buffer (car (diff-find-source-location))) + (to-save (and (not (buffer-modified-p buffer)) + buffer))) + (diff-apply-hunk t) + (diff-hunk-kill) + (when to-save + (with-current-buffer to-save + (save-buffer))))) + (defun diff-apply-buffer () "Apply the diff in the entire diff buffer. When applying all hunks was successful, then save the changed buffers." -- 2.39.5 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 23 18:52:48 2024 Received: (at 73407) by debbugs.gnu.org; 23 Sep 2024 22:52:49 +0000 Received: from localhost ([127.0.0.1]:44903 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ssrvE-0003dQ-Jd for submit@debbugs.gnu.org; Mon, 23 Sep 2024 18:52:48 -0400 Received: from forward500a.mail.yandex.net ([178.154.239.80]:40082) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ssrvC-0003dH-94 for 73407@debbugs.gnu.org; Mon, 23 Sep 2024 18:52:47 -0400 Received: from mail-nwsmtp-smtp-production-main-90.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-90.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:29aa:0:640:d0e8:0]) by forward500a.mail.yandex.net (Yandex) with ESMTPS id 292446116E; Tue, 24 Sep 2024 01:52:21 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-90.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id IqbsUaUOga60-ccOU0M0H; Tue, 24 Sep 2024 01:52:20 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1727131940; bh=rbAcYJEsW3MTUagjtoEdww7s+NCgB13tNjP6yV3a+RI=; h=In-Reply-To:From:Subject:Message-ID:Cc:References:Date:To; b=r+6SJ638KaGaBjL6bGzerAOYAVbHsAkOcM4WpB0zm5k9pjmnqTb3EdyeJ6FVhO7qN JM/egc+W05cXuV0UId+dkZpbMiC8luNqqqGvesBj7PT1Z2I/+6UZZ0xEVv0uopM4Nu K5hpExYbuSOMaM5Lth2rngbB2Mtceckd9iGf+8j4= Authentication-Results: mail-nwsmtp-smtp-production-main-90.myt.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfauth.phl.internal (Postfix) with ESMTP id 16D331200070; Mon, 23 Sep 2024 18:52:17 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Mon, 23 Sep 2024 18:52:18 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddttddgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegughhuthhovheshigrnhguvgigrd hruheqnecuggftrfgrthhtvghrnhepiefhjeeuveetffffvdefteffffekhfeuudejieeh heeiudelgfehgffffeduffdunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepughguhhtohhvodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhi thihqddufeeffeelleehhedvqddvleegjeejjeejiedqughguhhtohhvpeephigrnhguvg igrdhruhesfhgrshhtmhgrihhlrdgtohhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehsphifhhhithhtohhnsehsphifhhhithhtohhnrd hnrghmvgdprhgtphhtthhopeejfeegtdejseguvggssghughhsrdhgnhhurdhorhhgpdhr tghpthhtohepjhhurhhisehlihhnkhhovhdrnhgvth X-ME-Proxy: Feedback-ID: ib1d9465d:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 23 Sep 2024 18:52:16 -0400 (EDT) Message-ID: <98752a7f-d4cd-4397-ad43-0807e29f7803@yandex.ru> Date: Tue, 24 Sep 2024 01:52:13 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk To: Sean Whitton , 73407@debbugs.gnu.org References: <87jzf58g2t.fsf@zephyr.silentflame.com> Content-Language: en-US From: Dmitry Gutov In-Reply-To: <87jzf58g2t.fsf@zephyr.silentflame.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi! On 21/09/2024 13:19, Sean Whitton wrote: > X-debbugs-cc: dgutov@yandex.ru, juri@linkov.net > > These patches add a new command, diff-discard-hunk, inspired by some > functionality from Magit. It nicely complements a workflow based around > committing with C-x v v from C-x v D. I have been using it every day > for a year or so, and I think others will find it useful, too. I'd like to clarify one thing first: for 'C-x v v' to work correctly in a diff buffer (such as one produced by 'C-x v D') you don't have to synchronize any changes in that buffer back to disk before making the commit. In fact, we went to some effort to make this a non-requirement. So when you just want to edit the patch before the commit, you can do so already, for example using 'M-k' (diff-hunk-kill) - or just 'k' if the buffer is read-only. But of course if the idea is to really "discard" some changes, that works. From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 02:54:36 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 06:54:36 +0000 Received: from localhost ([127.0.0.1]:45128 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sszRT-0004m0-P3 for submit@debbugs.gnu.org; Tue, 24 Sep 2024 02:54:35 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:39053) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sszRR-0004lQ-VM for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 02:54:34 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 85CF0FF806; Tue, 24 Sep 2024 06:54:01 +0000 (UTC) From: Juri Linkov To: Sean Whitton Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <87jzf58g2t.fsf@zephyr.silentflame.com> (Sean Whitton's message of "Sat, 21 Sep 2024 11:19:06 +0100") Organization: LINKOV.NET References: <87jzf58g2t.fsf@zephyr.silentflame.com> Date: Tue, 24 Sep 2024 09:36:27 +0300 Message-ID: <865xqleexg.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org, dgutov@yandex.ru X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > These patches add a new command, diff-discard-hunk, inspired by some > functionality from Magit. It nicely complements a workflow based around > committing with C-x v v from C-x v D. I have been using it every day > for a year or so, and I think others will find it useful, too. > > Posting for comments. Thanks! It was hard to understand how it's related to C-x v v. But then I realized it saves time to do what currently is done with: 'C-c C-r' (diff-reverse-direction) 'C-c C-a' (diff-apply-hunk) 'k' (diff-hunk-kill). > +(defcustom diff-display-after-apply-hunk t > + "Non-nil means `diff-apply-hunk' will display the buffer it just changed." > + :type 'boolean) > + > @@ -2024,7 +2028,8 @@ diff-apply-hunk > - (set-window-point (display-buffer buf) (+ (car pos) (cdr new))) > + (when diff-display-after-apply-hunk > + (set-window-point (display-buffer buf) (+ (car pos) (cdr new)))) Probably this change is not needed if 'diff-discard-hunk' could avoid using 'diff-apply-hunk', and instead rely on the algorithm from 'diff-apply-buffer'. Also optional region arguments 'beg' and 'end' could be added to 'diff-apply-buffer'. From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 03:53:45 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 07:53:45 +0000 Received: from localhost ([127.0.0.1]:45196 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st0Mi-00085R-Kw for submit@debbugs.gnu.org; Tue, 24 Sep 2024 03:53:44 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:58920) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st0Mf-000855-TL for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 03:53:43 -0400 DKIM-Signature: a=rsa-sha256; b=jqwyJUTPbLHyUsfdZ5+QrUGmRbeKjhD+mVjwC45AV4YD+eXBMHxI5AsEbfyXvRAL9FRihKDov0A/BUR9JJ8FMI+vtE5Qz0abYZmaME0XCUomEjOGkRUEfGpshRhZ49S7sQOTrxFJTsMPYc3UyMSdH5aKdDsaXwkcXEHtKFrRuY6xqP/t0+bSJR/sXeoPQqUKYXG+A6W3ZNZ27a0+OcB0pCV9EacoE4t6nbMdXIQuHORSx91JGk8Dl2+mPxLSvhlDoMqDlf1tQQO8Dw7Uj0fL61+9pgzt1j9QH+nzzQy1OyEpVsj6ry5HiEypUBgNItOVqz7YWNga9jpaJ9kR44QUxw==; s=purelymail1; d=spwhitton.name; v=1; bh=vfO9fQM1/jEGmDZdqTsS7i/arZ//+vGNb4O1YtTwEQk=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=HQY8myZRLtNqmlZPk/TQL2I1TFBcn0s07HBlLNcL/AaELw9VkePEBKSGISSYVIsAHjfZMzZKfwXsdWBuVQFRyY4ec62hF9rkbXQG/WAlwSHwBkEagd6Bln1GSXAPZMZqSrB1E51z79V67SscSfZBBdjhIuaREhLAaVnrhY/YRBTc+0qNeh+tn5a5LR0TuG56R4ButgHczPPbNabDeaA16evI1WobfzbY8hMtsOoqB/Z+N/a+ijGHJRQdH5ikXv2pzcZFiMpyh6asxI/Kqy1Iko3t2Bt0DCVBF0zaaCzJNJ2gi4n/4Zive0iyeaTGM1BxaDCB6cWrEZxIDKOkM7RhWQ==; s=purelymail1; d=purelymail.com; v=1; bh=vfO9fQM1/jEGmDZdqTsS7i/arZ//+vGNb4O1YtTwEQk=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73407@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 280452794; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 24 Sep 2024 07:53:11 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 0820894194D; Tue, 24 Sep 2024 08:53:10 +0100 (BST) From: Sean Whitton To: Dmitry Gutov Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <98752a7f-d4cd-4397-ad43-0807e29f7803@yandex.ru> (Dmitry Gutov's message of "Tue, 24 Sep 2024 01:52:13 +0300") References: <87jzf58g2t.fsf@zephyr.silentflame.com> <98752a7f-d4cd-4397-ad43-0807e29f7803@yandex.ru> Date: Tue, 24 Sep 2024 08:53:10 +0100 Message-ID: <877cb1o5cp.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org, juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, On Tue 24 Sep 2024 at 01:52am +03, Dmitry Gutov wrote: > Hi! > > On 21/09/2024 13:19, Sean Whitton wrote: >> X-debbugs-cc: dgutov@yandex.ru, juri@linkov.net >> These patches add a new command, diff-discard-hunk, inspired by some >> functionality from Magit. It nicely complements a workflow based around >> committing with C-x v v from C-x v D. I have been using it every day >> for a year or so, and I think others will find it useful, too. > > I'd like to clarify one thing first: for 'C-x v v' to work correctly in a diff > buffer (such as one produced by 'C-x v D') you don't have to synchronize any > changes in that buffer back to disk before making the commit. In fact, we went > to some effort to make this a non-requirement. Right. I believe I was responsible for some of that effort! > So when you just want to edit the patch before the commit, you can do so > already, for example using 'M-k' (diff-hunk-kill) - or just 'k' if the buffer > is read-only. > > But of course if the idea is to really "discard" some changes, that works. Yeah, this is about really discarding the changes. It's like using C-x v D as a kind of review view. You use it for committing what you want to keep and getting rid of temporary changes you made just for development purposes, such as additional debug prints. When I used Magit I used its magit-discard for this a lot (the docstring for that function talks about conflicts but it's also useful without those). One question I have is whether this should offer a y/n prompt to confirm discarding the change. Do you have an opinion on that? -- Sean Whitton From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 04:08:23 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 08:08:24 +0000 Received: from localhost ([127.0.0.1]:45202 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st0at-0000SO-8F for submit@debbugs.gnu.org; Tue, 24 Sep 2024 04:08:23 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:33268) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st0aq-0000S7-CS for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 04:08:21 -0400 DKIM-Signature: a=rsa-sha256; b=trZljWKh7lKxywC7rOwMWPUtrlM9M87hko9HjSD9w5+5G39pMdNmpgInnnBeaNIyDoEC4uTb9muygW9YbSwW3WHxpNijb47LTkNh0ptvCpGJ8Zdn8MoRd1eVE2cXwY7E1/WFbLT7TCyYKxxD/HEOABSkYCDEgNGfqLGL1gtL5QgW8MbCIsAvTrvyMz84Q65tWYtK2NElDg72d3xpBvr9EEPCVvNSoUvTuniP9alr3E3jUN8f9sk0QmfygSJKjjHX8bAkVEb0D5wV9/g02dD8Hb3+LN6FtC/xtx5A7kuNLjw/eLQ4W38fcGSVeNxOKKmlPt93mk3HK1Git2fRfQrWbA==; s=purelymail1; d=spwhitton.name; v=1; bh=53XpKhNEbhSEKQceae+A7uHsCgneU3UIbvwyr1WtA74=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=l9cpTlsROfQfy1eSFYhcHt6230TMofRD+z7KJIQ0+ctioMdM+9JJe4BeRiGpPmNfaaUMpqJ6U1U3XqY4aQ0yKTfdzy6dKeAEuuTk4ijPZSAWLF9yiss4DBuhukVY3QuGra5IWE4BQc/CU9iXW7WJzXa9omuophtDOMLf4gH+nx7NqKjOtVTKl28AL1o4gn0mwSdxukjYQYCrPJH+N8k0RUmk+5vVYwjsvIvkRjeqMRk/gumdjwcZeB7UZAFBk08jz0OkAnaLQCUkl4yMtcWOEkqYowWCM5OoxSWWyDYePcUruKXt/hlcW+vgNcBoL819hCcyuAU0uzaZ6xUwawbzLg==; s=purelymail1; d=purelymail.com; v=1; bh=53XpKhNEbhSEKQceae+A7uHsCgneU3UIbvwyr1WtA74=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73407@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1365795042; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 24 Sep 2024 08:07:48 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 7CAA594194D; Tue, 24 Sep 2024 09:07:47 +0100 (BST) From: Sean Whitton To: Juri Linkov Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <865xqleexg.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 24 Sep 2024 09:36:27 +0300") References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> Date: Tue, 24 Sep 2024 09:07:47 +0100 Message-ID: <8734lpo4oc.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org, dgutov@yandex.ru X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, On Tue 24 Sep 2024 at 09:36am +03, Juri Linkov wrote: >> These patches add a new command, diff-discard-hunk, inspired by some >> functionality from Magit. It nicely complements a workflow based around >> committing with C-x v v from C-x v D. I have been using it every day >> for a year or so, and I think others will find it useful, too. >> >> Posting for comments. Thanks! > > It was hard to understand how it's related to C-x v v. > But then I realized it saves time to do what currently is done with: > 'C-c C-r' (diff-reverse-direction) > 'C-c C-a' (diff-apply-hunk) > 'k' (diff-hunk-kill). Yeah, exactly. >> +(defcustom diff-display-after-apply-hunk t >> + "Non-nil means `diff-apply-hunk' will display the buffer it just changed." >> + :type 'boolean) >> + >> @@ -2024,7 +2028,8 @@ diff-apply-hunk >> - (set-window-point (display-buffer buf) (+ (car pos) (cdr new))) >> + (when diff-display-after-apply-hunk >> + (set-window-point (display-buffer buf) (+ (car pos) (cdr new)))) > > Probably this change is not needed if 'diff-discard-hunk' > could avoid using 'diff-apply-hunk', and instead rely > on the algorithm from 'diff-apply-buffer'. Also optional > region arguments 'beg' and 'end' could be added to > 'diff-apply-buffer'. I'll look into that, thanks. -- Sean Whitton From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 04:41:08 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 08:41:08 +0000 Received: from localhost ([127.0.0.1]:45252 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st16a-0002Ko-4G for submit@debbugs.gnu.org; Tue, 24 Sep 2024 04:41:08 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:57022) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st16W-0002K9-Fw for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 04:41:06 -0400 DKIM-Signature: a=rsa-sha256; b=VvzpMyq375GDybq2oeb/3yZyGSSAZqEeAiuTltaZIPLOPMoBN5lsfBqfFR+1yks2zOaT0LKsw8KSOGUu9ndlw4c0H5yZukln3pX6OsZmpZjS2W/0n/w9AzjrNbjeSAquHg5X1cx+j74+Uxfw7xJKf6h3gbzrP0gSFp1UaC7pgfHjaYuin9LKtlVVQRQxXkhyho8a2l/5kXu292sXOYUp1/gtdqlG5sO7HdfDsw1qe9c4PS2X4zZzrvyPrQSESSj7YNKe+/kGFZG8slJrHo4yAjuZyuQ95xvGIHk8X8+QP0DKaRUjiGcWJp8oeiUpeptMnBOQaxhXMJUS45aAaTOXZw==; s=purelymail1; d=spwhitton.name; v=1; bh=P7WT7q5uebArbw2ujwDMutyZMqo8rvnQcaIpPo3zNc4=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=l1753x4c5EXn5hPRcuZcGkLatep7A7LmraM2lRBNlow3zJ2gJfkO3QRxPYk8a92G9NiurmVxUjyRVkN1tDM3s3A+Ccx1VKU4oOwWo+agfDIWCbshmXt3tw/FBeAc+XokYHo5rxQcjnLMa6yc8E2WBAmXJSSykxCTympMsxW0hrwL4ALPTNjyrvPC/9j8ivWhl66jmzDTqn2JAVcxep5YSqCN6cbDiFvYythITM6CAl/jyNYKSwRJBJ90ypYtacVzb1XD/k0mdkZTIDeMe1l70ZPxfRYN2OHqSpnVBT9nxIIIcNuEr3V6zEENtI125vQl8v4VyyOYdgt2rL6IrSnnaA==; s=purelymail1; d=purelymail.com; v=1; bh=P7WT7q5uebArbw2ujwDMutyZMqo8rvnQcaIpPo3zNc4=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73407@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1350465131; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 24 Sep 2024 08:40:31 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 9E4CF94194D; Tue, 24 Sep 2024 09:40:30 +0100 (BST) From: Sean Whitton To: Juri Linkov , dgutov@yandex.ru Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <865xqleexg.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 24 Sep 2024 09:36:27 +0300") References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> Date: Tue, 24 Sep 2024 09:40:30 +0100 Message-ID: <87y13hmold.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Hello, Thank you both for looking. Here is a revised patch based on Juri's ideas about implementation, and also adding a y/n confirmation, since this operation is destructive. Let me know what you think! -- Sean Whitton --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v2-0001-New-command-diff-discard-hunk.patch >From 2eccebb6159e6c384e1cb7a543f259d2146d8b81 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Tue, 24 Sep 2024 09:38:43 +0100 Subject: [PATCH v2] New command diff-discard-hunk * lisp/vc/diff-mode.el (diff-discard-hunk): New command (bug#73407). (diff-apply-buffer): New optional BEG and END arguments. Return nil if buffers were saved, or the number of failed applications. (diff-mode-map): Bind diff-discard-hunk to C-c C-k. (diff-mode-menu): New entry "Discard hunk". * doc/emacs/files.texi (Diff Mode): * etc/NEWS: Document the new command. --- doc/emacs/files.texi | 11 +++++++++++ etc/NEWS | 5 +++++ lisp/vc/diff-mode.el | 40 +++++++++++++++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 709cb0910e6..04ecfabc1ee 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1682,6 +1682,17 @@ Diff Mode version. If @code{diff-jump-to-old-file} is non-@code{nil}, apply the hunk to the ``old'' version of the file instead. +@findex diff-discard-hunk +@item C-c C-k +Reverse-apply this hunk to the target file, and then kill it +(@code{diff-discard-hunk}). Unless the buffer visiting the target file +was already modified, save it. + +This command is useful in buffers generated by @w{@kbd{C-x v =}} and +@w{@kbd{C-x v D}} (@pxref{Old Revisions}). You can use this command to +remove hunks you never intend to commit, such as temporary debug prints, +and the like. + @findex diff-apply-buffer @item C-c @key{RET} a Apply all the hunks in the buffer (@code{diff-apply-buffer}). If the diff --git a/etc/NEWS b/etc/NEWS index c1a0524c8ba..3edd827d15c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -341,6 +341,11 @@ according to diffs in the current buffer, but without applying the diffs to the original text. If the selected range extends a hunk, the command attempts to look up and copy the text in-between the hunks. ++++ +*** New command 'diff-discard-hunk' bound to C-c C-k. +This command reverse-applies the hunk at point, and then kills it. +This is useful in buffers generated C-x v = and C-x v D. + ** php-ts-mode --- diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 4810b9ce01c..a48ba8e717a 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -218,6 +218,7 @@ diff-mode-map "C-x 4 A" #'diff-add-change-log-entries-other-window ;; Misc operations. "C-c C-a" #'diff-apply-hunk + "C-c C-k" #'diff-discard-hunk "C-c C-m a" #'diff-apply-buffer "C-c C-e" #'diff-ediff-patch "C-c C-n" #'diff-restrict-view @@ -242,6 +243,8 @@ diff-mode-menu :help "Apply the current hunk to the source file and go to the next"] ["Test applying hunk" diff-test-hunk :help "See whether it's possible to apply the current hunk"] + ["Discard hunk" diff-discard-hunk + :help "Reverse-apply and then kill the current hunk."] ["Apply all hunks" diff-apply-buffer :help "Apply all hunks in the current diff buffer"] ["Apply diff with Ediff" diff-ediff-patch @@ -2050,15 +2053,39 @@ diff-kill-applied-hunks (diff-hunk-kill) (diff-hunk-next))))) -(defun diff-apply-buffer () +(defun diff-discard-hunk () + "Reverse-apply and then kill the hunk at point. Save changed buffer. + +This command is useful in buffers generated by \\[vc-diff] and \\[vc-root-diff]. +You can use `diff-hunk-kill' to remove hunks you intend to commit later. +You can use this command to remove hunks you never intend to commit, +such as temporary debug prints, and the like." + (interactive) + (when (yes-or-no-p "Discard this hunk?") + (cl-destructuring-bind (beg end) (diff-bounds-of-hunk) + (diff-reverse-direction beg end) + (condition-case ret + (diff-apply-buffer beg end) + ;; Reversing the hunk is an implementation detail, so ensure the + ;; user never sees it. + (error (diff-reverse-direction beg end) + (signal (car ret) (cdr ret))) + (:success (if ret + (diff-reverse-direction beg end) + (diff-hunk-kill))))))) + +(defun diff-apply-buffer (&optional beg end) "Apply the diff in the entire diff buffer. -When applying all hunks was successful, then save the changed buffers." +When applying all hunks was successful, then save the changed buffers. +When called from Lisp with optional arguments, restrict the application +to hunks lying between BEG and END. Returns nil if buffers were saved, +or the number of failed applications." (interactive) (let ((buffer-edits nil) (failures 0) (diff-refine nil)) (save-excursion - (goto-char (point-min)) + (goto-char (or beg (point-min))) (diff-beginning-of-hunk t) (while (pcase-let ((`(,buf ,line-offset ,pos ,_src ,dst ,switched) (diff-find-source-location nil nil))) @@ -2068,6 +2095,7 @@ diff-apply-buffer (t (setq failures (1+ failures)))) (and (not (eq (prog1 (point) (ignore-errors (diff-hunk-next))) (point))) + (or (not end) (< (point) end)) (looking-at-p diff-hunk-header-re))))) (cond ((zerop failures) (dolist (buf-edits (reverse buffer-edits)) @@ -2080,9 +2108,11 @@ diff-apply-buffer (delete-region (car pos) (cdr pos)) (insert (car dst)))) (save-buffer))) - (message "Saved %d buffers" (length buffer-edits))) + (message "Saved %d buffers" (length buffer-edits)) + nil) (t - (message "%d hunks failed; no buffers changed" failures))))) + (message "%d hunks failed; no buffers changed" failures) + failures)))) (defalias 'diff-mouse-goto-source #'diff-goto-source) -- 2.39.5 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 04:43:22 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 08:43:22 +0000 Received: from localhost ([127.0.0.1]:45258 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st18j-0002Oa-Sy for submit@debbugs.gnu.org; Tue, 24 Sep 2024 04:43:22 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:57528) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st18i-0002OL-1Q for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 04:43:20 -0400 DKIM-Signature: a=rsa-sha256; b=C4OnseD1hmvHBojQ9hkxN2H/yfa1uY8IlJXakZpuQVx2yvvECtPfRZgYtBNSFyfq9UlMH2v/XUJ68XSi3QEaqpJC840S7bUsYExw1pkEjNSzH9VYmHKR6M8N2vpSPnxKnTsixOwIUahMfFV3bOF4trZMvaXk9kJ4DscOcC0PvcvZvgAQ57bSOZMfUa4fezZig0q8ClkRme1t2XTYwacNcGBOW+JAzraNRq50TpzUjfiIuSBOLxc0M56ZE1lEzn5X5YsSZLdyGPPY9GrU3571Lw9j3Inf/K0jzUkiekb61YHGMMQXNW6sif3aGm6t5accwpTcowCTHiFZbf+JAkhHLA==; s=purelymail1; d=spwhitton.name; v=1; bh=ctUEIRH9TGPYqqwxzy5GJMJwROIYjjlVxyPXs6QFTjw=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=gCEDZ3jI+l0b3twvHqe8zATnLDnGwfUyrj5WatpB6KL7x4QqRD5/UBCSjmkzq3WcC+6SxvxdWR/RXLGGcdZJ7/wA3OPbblNEhX9l6CgAdHAO54QW5aynz/dWVw03/tca8xk7u8BqlksEONuVHFsQyh8AR59h9I0enBeBVDAdlFDmTVbb+Vm2EIXXBYuF6g1jHCljdlL0Use2ABhhsq2j3meaET7j5wcToZVhy1eltXH/Ghk9CM3dtKPfHKKRVIUXW/ZAKH/XQcJ0X4hzpBhGjSF4LSifVn0uvsHldaDIDevUv/6dFWESFaQU/IXIGovxxpMRDLkh6bvNFf80i+D9bg==; s=purelymail1; d=purelymail.com; v=1; bh=ctUEIRH9TGPYqqwxzy5GJMJwROIYjjlVxyPXs6QFTjw=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73407@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 494278201; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 24 Sep 2024 08:42:50 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 4218394194D; Tue, 24 Sep 2024 09:42:49 +0100 (BST) From: Sean Whitton To: Juri Linkov , dgutov@yandex.ru Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <87y13hmold.fsf@zephyr.silentflame.com> (Sean Whitton's message of "Tue, 24 Sep 2024 09:40:30 +0100") References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> Date: Tue, 24 Sep 2024 09:42:49 +0100 Message-ID: <87setpmohi.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Hello, On Tue 24 Sep 2024 at 09:40am +01, Sean Whitton wrote: > Hello, > > Thank you both for looking. Here is a revised patch based on Juri's > ideas about implementation, and also adding a y/n confirmation, since > this operation is destructive. > > Let me know what you think! I missed updating something in the info; here is v3. -- Sean Whitton --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v3-0001-New-command-diff-discard-hunk.patch >From a384ea810d388dfb685a3694e851457bb5e668dd Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Tue, 24 Sep 2024 09:38:43 +0100 Subject: [PATCH v3] New command diff-discard-hunk * lisp/vc/diff-mode.el (diff-discard-hunk): New command (bug#73407). (diff-apply-buffer): New optional BEG and END arguments. Return nil if buffers were saved, or the number of failed applications. (diff-mode-map): Bind diff-discard-hunk to C-c C-k. (diff-mode-menu): New entry "Discard hunk". * doc/emacs/files.texi (Diff Mode): * etc/NEWS: Document the new command. --- doc/emacs/files.texi | 10 ++++++++++ etc/NEWS | 5 +++++ lisp/vc/diff-mode.el | 40 +++++++++++++++++++++++++++++++++++----- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 709cb0910e6..78d90a914aa 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1682,6 +1682,16 @@ Diff Mode version. If @code{diff-jump-to-old-file} is non-@code{nil}, apply the hunk to the ``old'' version of the file instead. +@findex diff-discard-hunk +@item C-c C-k +Reverse-apply this hunk to the target file, and then kill it +(@code{diff-discard-hunk}). Save the buffer visiting the target file. + +This command is useful in buffers generated by @w{@kbd{C-x v =}} and +@w{@kbd{C-x v D}} (@pxref{Old Revisions}). You can use this command to +remove hunks you never intend to commit, such as temporary debug prints, +and the like. + @findex diff-apply-buffer @item C-c @key{RET} a Apply all the hunks in the buffer (@code{diff-apply-buffer}). If the diff --git a/etc/NEWS b/etc/NEWS index c1a0524c8ba..3edd827d15c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -341,6 +341,11 @@ according to diffs in the current buffer, but without applying the diffs to the original text. If the selected range extends a hunk, the command attempts to look up and copy the text in-between the hunks. ++++ +*** New command 'diff-discard-hunk' bound to C-c C-k. +This command reverse-applies the hunk at point, and then kills it. +This is useful in buffers generated C-x v = and C-x v D. + ** php-ts-mode --- diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 4810b9ce01c..a48ba8e717a 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -218,6 +218,7 @@ diff-mode-map "C-x 4 A" #'diff-add-change-log-entries-other-window ;; Misc operations. "C-c C-a" #'diff-apply-hunk + "C-c C-k" #'diff-discard-hunk "C-c C-m a" #'diff-apply-buffer "C-c C-e" #'diff-ediff-patch "C-c C-n" #'diff-restrict-view @@ -242,6 +243,8 @@ diff-mode-menu :help "Apply the current hunk to the source file and go to the next"] ["Test applying hunk" diff-test-hunk :help "See whether it's possible to apply the current hunk"] + ["Discard hunk" diff-discard-hunk + :help "Reverse-apply and then kill the current hunk."] ["Apply all hunks" diff-apply-buffer :help "Apply all hunks in the current diff buffer"] ["Apply diff with Ediff" diff-ediff-patch @@ -2050,15 +2053,39 @@ diff-kill-applied-hunks (diff-hunk-kill) (diff-hunk-next))))) -(defun diff-apply-buffer () +(defun diff-discard-hunk () + "Reverse-apply and then kill the hunk at point. Save changed buffer. + +This command is useful in buffers generated by \\[vc-diff] and \\[vc-root-diff]. +You can use `diff-hunk-kill' to remove hunks you intend to commit later. +You can use this command to remove hunks you never intend to commit, +such as temporary debug prints, and the like." + (interactive) + (when (yes-or-no-p "Discard this hunk?") + (cl-destructuring-bind (beg end) (diff-bounds-of-hunk) + (diff-reverse-direction beg end) + (condition-case ret + (diff-apply-buffer beg end) + ;; Reversing the hunk is an implementation detail, so ensure the + ;; user never sees it. + (error (diff-reverse-direction beg end) + (signal (car ret) (cdr ret))) + (:success (if ret + (diff-reverse-direction beg end) + (diff-hunk-kill))))))) + +(defun diff-apply-buffer (&optional beg end) "Apply the diff in the entire diff buffer. -When applying all hunks was successful, then save the changed buffers." +When applying all hunks was successful, then save the changed buffers. +When called from Lisp with optional arguments, restrict the application +to hunks lying between BEG and END. Returns nil if buffers were saved, +or the number of failed applications." (interactive) (let ((buffer-edits nil) (failures 0) (diff-refine nil)) (save-excursion - (goto-char (point-min)) + (goto-char (or beg (point-min))) (diff-beginning-of-hunk t) (while (pcase-let ((`(,buf ,line-offset ,pos ,_src ,dst ,switched) (diff-find-source-location nil nil))) @@ -2068,6 +2095,7 @@ diff-apply-buffer (t (setq failures (1+ failures)))) (and (not (eq (prog1 (point) (ignore-errors (diff-hunk-next))) (point))) + (or (not end) (< (point) end)) (looking-at-p diff-hunk-header-re))))) (cond ((zerop failures) (dolist (buf-edits (reverse buffer-edits)) @@ -2080,9 +2108,11 @@ diff-apply-buffer (delete-region (car pos) (cdr pos)) (insert (car dst)))) (save-buffer))) - (message "Saved %d buffers" (length buffer-edits))) + (message "Saved %d buffers" (length buffer-edits)) + nil) (t - (message "%d hunks failed; no buffers changed" failures))))) + (message "%d hunks failed; no buffers changed" failures) + failures)))) (defalias 'diff-mouse-goto-source #'diff-goto-source) -- 2.39.5 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 08:21:31 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 12:21:31 +0000 Received: from localhost ([127.0.0.1]:45474 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st4Xr-0005yr-Cy for submit@debbugs.gnu.org; Tue, 24 Sep 2024 08:21:31 -0400 Received: from forward501d.mail.yandex.net ([178.154.239.209]:49386) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st4Xn-0005yM-2t for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 08:21:29 -0400 Received: from mail-nwsmtp-smtp-production-main-42.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-42.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:4749:0:640:7137:0]) by forward501d.mail.yandex.net (Yandex) with ESMTPS id 7E130611CF; Tue, 24 Sep 2024 15:20:59 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-42.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id uKSYo905QeA0-CZicXR5i; Tue, 24 Sep 2024 15:20:58 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1727180458; bh=p1Wxk5VjX3ErdpU5GHAmhSptb+Rzgn/te9zMOxGqL9Q=; h=In-Reply-To:From:Subject:Message-ID:Cc:References:Date:To; b=VYqOgR1BKqWGEzj47i1Ls7GZQpwpGlI/QszN3DRvqbANdLKSSzSVAXdNztgexIOEj R3SbgwA5A8z8tz06Y2yCJn9zkBgnd2APJQr8S73GTMXs9fqiplEaz5vz7eE7MqeJ02 qHCHW6LzNzwiZXaTxOTjgQrbVqkPZ2OqnPVcpCaE= Authentication-Results: mail-nwsmtp-smtp-production-main-42.klg.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id 6A4F7120006A; Tue, 24 Sep 2024 08:20:56 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 24 Sep 2024 08:20:56 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtvddghedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegughhuthhovheshigrnhguvgigrd hruheqnecuggftrfgrthhtvghrnhepiefhjeeuveetffffvdefteffffekhfeuudejieeh heeiudelgfehgffffeduffdunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepughguhhtohhvodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhi thihqddufeeffeelleehhedvqddvleegjeejjeejiedqughguhhtohhvpeephigrnhguvg igrdhruhesfhgrshhtmhgrihhlrdgtohhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehjuhhriheslhhinhhkohhvrdhnvghtpdhrtghpth htohepshhpfihhihhtthhonhesshhpfihhihhtthhonhdrnhgrmhgvpdhrtghpthhtohep jeefgedtjeesuggvsggsuhhgshdrghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: ib1d9465d:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 24 Sep 2024 08:20:54 -0400 (EDT) Message-ID: <3e096c4a-05af-408e-8b79-6b5e0b36f742@yandex.ru> Date: Tue, 24 Sep 2024 15:20:52 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk To: Juri Linkov , Sean Whitton References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> Content-Language: en-US From: Dmitry Gutov In-Reply-To: <865xqleexg.fsf@mail.linkov.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 24/09/2024 09:36, Juri Linkov wrote: > 'C-c C-r' (diff-reverse-direction) > 'C-c C-a' (diff-apply-hunk) Also known as 'C-u C-c C-a'. From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 08:22:20 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 12:22:20 +0000 Received: from localhost ([127.0.0.1]:45479 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st4Yd-00060Z-Mm for submit@debbugs.gnu.org; Tue, 24 Sep 2024 08:22:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39028) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st4Yb-00060J-11 for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 08:22:17 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1st4Y5-0003CS-Lm; Tue, 24 Sep 2024 08:21:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=E/gbTGIlv3dxz3H/cbbh24bfBzvPl2XT7MjI9QruTzU=; b=fQDUl7ktWvEY mIBwLTNMelNAXRazwGOHpuLTPS0eZKWQl5ldEBHDrVf0IwmjiktUEp39NqGszuenBMcMin2u1UOG/ tv0wE9DU+bi+DwLEjzZmFV4xOSPFppmzcSQWNc1gU8RT8adZZkzskQxKKYgecW+5lf1e9CbYhfvYE tt7/NrS2tJbIlfrUstQxXMnvO5I+zpcH231WvGZ+PCkRad0t1dKHkGHDTaZmsW6yJV0STYAF2RmQo rHtkhJN7suq3sn972ZKopYNG29+1qmdu+4CYuQPIHaHru8IoYa/rbVkVtLvNsL8nzMXbu+j/yZnpO 4a5f5MoWJqRqH6atr84hig==; Date: Tue, 24 Sep 2024 15:21:42 +0300 Message-Id: <86ikuldyy1.fsf@gnu.org> From: Eli Zaretskii To: Sean Whitton In-Reply-To: <87y13hmold.fsf@zephyr.silentflame.com> (message from Sean Whitton on Tue, 24 Sep 2024 09:40:30 +0100) Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 73407 Cc: dgutov@yandex.ru, 73407@debbugs.gnu.org, juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: 73407@debbugs.gnu.org > From: Sean Whitton > Date: Tue, 24 Sep 2024 09:40:30 +0100 > > +@findex diff-discard-hunk > +@item C-c C-k > +Reverse-apply this hunk to the target file, and then kill it > +(@code{diff-discard-hunk}). Unless the buffer visiting the target file > +was already modified, save it. We should come up with a better name for this command. diff-discard-hunk tells me the command will discard the hunk, but says nothing about applying it, let alone reverse-applying it. How about diff-revert-hunk, or maybe diff-revert-and-discard? > +This command is useful in buffers generated by @w{@kbd{C-x v =}} and > +@w{@kbd{C-x v D}} (@pxref{Old Revisions}). You can use this command to > +remove hunks you never intend to commit, such as temporary debug prints, > +and the like. This text could also use some clarification: "remove hunks you never intended to commit" only hints on what it actually does. A better description would be something like "undo some of the changes you made that you didn't intend". I wouldn't mention "commit" at all, since AFAIU this command is not specific to VC and doesn't require a VCS. > - (message "%d hunks failed; no buffers changed" failures))))) > + (message "%d hunks failed; no buffers changed" failures) > + failures)))) This comes from existing text, but still: what does the above say when there's only 1 failure? does it say "1 hunks failed"? If so, can we improve the handling of singular/plural here? Thanks. From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 08:23:30 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 12:23:30 +0000 Received: from localhost ([127.0.0.1]:45483 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st4Zm-00062z-B8 for submit@debbugs.gnu.org; Tue, 24 Sep 2024 08:23:30 -0400 Received: from forward501d.mail.yandex.net ([178.154.239.209]:41734) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st4Zl-00062s-1c for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 08:23:29 -0400 Received: from mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:51a0:0:640:3bf:0]) by forward501d.mail.yandex.net (Yandex) with ESMTPS id 1204660D04; Tue, 24 Sep 2024 15:23:04 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id 1NS0iaRlEqM0-dDCVvhmi; Tue, 24 Sep 2024 15:23:03 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1727180583; bh=XesRNI7Cxy8XTFz7X6dgvjtp/iXfLh4Cs5ScelYr7BQ=; h=In-Reply-To:From:Subject:Message-ID:Cc:References:Date:To; b=D5dJcb+YhCeXCMzJC/80IhtufaaOUZMIFEDFyLF8bZYxD0j49quhTCGZnL4NPBlMY Rr0fWzwcMa+y7LooD61+OlxCTnSwrHRnbAgp+TvTsDZPabALeZVb0lNYT0nb4ZwX+j UMz+tDEx2Y/0E+0fIvdk7ks2F4+Z0k4UEmsRhHWI= Authentication-Results: mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfauth.phl.internal (Postfix) with ESMTP id 211BB1200043; Tue, 24 Sep 2024 08:23:01 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Tue, 24 Sep 2024 08:23:01 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtvddghedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegughhuthhovheshigrnhguvgigrd hruheqnecuggftrfgrthhtvghrnhepiefhjeeuveetffffvdefteffffekhfeuudejieeh heeiudelgfehgffffeduffdunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepughguhhtohhvodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhi thihqddufeeffeelleehhedvqddvleegjeejjeejiedqughguhhtohhvpeephigrnhguvg igrdhruhesfhgrshhtmhgrihhlrdgtohhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehsphifhhhithhtohhnsehsphifhhhithhtohhnrd hnrghmvgdprhgtphhtthhopehjuhhriheslhhinhhkohhvrdhnvghtpdhrtghpthhtohep jeefgedtjeesuggvsggsuhhgshdrghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: ib1d9465d:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 24 Sep 2024 08:22:59 -0400 (EDT) Message-ID: <99cb69af-c955-4623-95f9-4e37aea5607a@yandex.ru> Date: Tue, 24 Sep 2024 15:22:56 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk To: Sean Whitton , Juri Linkov References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> <87setpmohi.fsf@zephyr.silentflame.com> Content-Language: en-US From: Dmitry Gutov In-Reply-To: <87setpmohi.fsf@zephyr.silentflame.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 24/09/2024 11:42, Sean Whitton wrote: > +*** New command 'diff-discard-hunk' bound to C-c C-k. I'm a little concerned about the binding. We have 'diff-hunk-kill' on M-k (and also 'k'), and this new addition is actually more destructive. I'm expecting users will trip over the difference and call one of them when they wanted to call the other. From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 08:25:15 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 12:25:15 +0000 Received: from localhost ([127.0.0.1]:45487 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st4bS-00066d-QU for submit@debbugs.gnu.org; Tue, 24 Sep 2024 08:25:15 -0400 Received: from forward502d.mail.yandex.net ([178.154.239.210]:56760) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st4bQ-00066P-0u for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 08:25:13 -0400 Received: from mail-nwsmtp-smtp-production-main-45.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-45.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:70a1:0:640:6c31:0]) by forward502d.mail.yandex.net (Yandex) with ESMTPS id 35EC26128E; Tue, 24 Sep 2024 15:24:04 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-45.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id 1OS0cdg4Q8c0-KUIXTsXs; Tue, 24 Sep 2024 15:24:03 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1727180643; bh=h+8cOKyVZY835kEo/1IFPA0Vgz64cT5QeroUn61MfhA=; h=In-Reply-To:From:Subject:Message-ID:Cc:References:Date:To; b=LExDvl7YO+TSiAD0VOLuWskmJsXGGm6StnLCGZ2ySxtQc6QdZoQvBnd5Kaqee+csG MDh6jcxgaA+al09MX1Fwu8PENa6R6Bj8us5fR7Ccyov058onezeO+N8kexnGSD9/zP /+EhNUUQF1t4jUZ4uwmyC3pye7lvSO3kLsMeD4b4= Authentication-Results: mail-nwsmtp-smtp-production-main-45.klg.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfauth.phl.internal (Postfix) with ESMTP id 5F4C51200043; Tue, 24 Sep 2024 08:24:01 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Tue, 24 Sep 2024 08:24:01 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtvddgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegughhuthhovheshigrnhguvgigrd hruheqnecuggftrfgrthhtvghrnhepiefhjeeuveetffffvdefteffffekhfeuudejieeh heeiudelgfehgffffeduffdunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepughguhhtohhvodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhi thihqddufeeffeelleehhedvqddvleegjeejjeejiedqughguhhtohhvpeephigrnhguvg igrdhruhesfhgrshhtmhgrihhlrdgtohhmpdhnsggprhgtphhtthhopeegpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopegvlhhiiiesghhnuhdrohhrghdprhgtphhtthhope hsphifhhhithhtohhnsehsphifhhhithhtohhnrdhnrghmvgdprhgtphhtthhopeejfeeg tdejseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepjhhurhhisehlihhnkh hovhdrnhgvth X-ME-Proxy: Feedback-ID: ib1d9465d:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 24 Sep 2024 08:23:59 -0400 (EDT) Message-ID: Date: Tue, 24 Sep 2024 15:23:57 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk To: Eli Zaretskii , Sean Whitton References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> <86ikuldyy1.fsf@gnu.org> Content-Language: en-US From: Dmitry Gutov In-Reply-To: <86ikuldyy1.fsf@gnu.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org, juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 24/09/2024 15:21, Eli Zaretskii wrote: > We should come up with a better name for this command. > diff-discard-hunk tells me the command will discard the hunk, but says > nothing about applying it, let alone reverse-applying it. How about > diff-revert-hunk, or maybe diff-revert-and-discard? diff-revert-and-kill, maybe. From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 08:27:52 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 12:27:52 +0000 Received: from localhost ([127.0.0.1]:45513 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st4dz-0006K8-LN for submit@debbugs.gnu.org; Tue, 24 Sep 2024 08:27:51 -0400 Received: from forward502a.mail.yandex.net ([178.154.239.82]:35570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st4dx-0006Jy-JS for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 08:27:50 -0400 Received: from mail-nwsmtp-smtp-production-main-24.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-24.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:9a26:0:640:21cf:0]) by forward502a.mail.yandex.net (Yandex) with ESMTPS id 8F1A261B33; Tue, 24 Sep 2024 15:27:23 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-24.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id LRSMgraOcuQ0-kJyFbVEp; Tue, 24 Sep 2024 15:27:22 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1727180843; bh=EN0F7Of0gJKf9gJyDspVW3tO01hlqZEjk+VAMb6H37E=; h=In-Reply-To:From:Subject:Message-ID:Cc:References:Date:To; b=tKYR8qGwmbyNp73kqYMqSb2SLp+KqkNWOSP/mdZe78/ylPgfEAmOzaq1/8uPwvOfy 97TI7hKYuQvjFfMdbBpJjcEZDLpoogE2YM8jJgNjQZ6Wywffdse8Cr+ET60anTR8Av swa46oCFJg2Ffs178/BDevfbc55FB3OK8jgrGzYs= Authentication-Results: mail-nwsmtp-smtp-production-main-24.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfauth.phl.internal (Postfix) with ESMTP id DE51E120006B; Tue, 24 Sep 2024 08:27:20 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Tue, 24 Sep 2024 08:27:20 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtvddgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegughhuthhovheshigrnhguvgigrd hruheqnecuggftrfgrthhtvghrnhepiefhjeeuveetffffvdefteffffekhfeuudejieeh heeiudelgfehgffffeduffdunecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpe hmrghilhhfrhhomhepughguhhtohhvodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhi thihqddufeeffeelleehhedvqddvleegjeejjeejiedqughguhhtohhvpeephigrnhguvg igrdhruhesfhgrshhtmhgrihhlrdgtohhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehsphifhhhithhtohhnsehsphifhhhithhtohhnrd hnrghmvgdprhgtphhtthhopeejfeegtdejseguvggssghughhsrdhgnhhurdhorhhgpdhr tghpthhtohepjhhurhhisehlihhnkhhovhdrnhgvth X-ME-Proxy: Feedback-ID: ib1d9465d:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 24 Sep 2024 08:27:19 -0400 (EDT) Message-ID: <96efe4b3-edf4-4ae1-9c54-fc3dd5abc3f8@yandex.ru> Date: Tue, 24 Sep 2024 15:27:16 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk To: Sean Whitton References: <87jzf58g2t.fsf@zephyr.silentflame.com> <98752a7f-d4cd-4397-ad43-0807e29f7803@yandex.ru> <877cb1o5cp.fsf@zephyr.silentflame.com> Content-Language: en-US From: Dmitry Gutov In-Reply-To: <877cb1o5cp.fsf@zephyr.silentflame.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org, juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 24/09/2024 10:53, Sean Whitton wrote: >> I'd like to clarify one thing first: for 'C-x v v' to work correctly in a diff >> buffer (such as one produced by 'C-x v D') you don't have to synchronize any >> changes in that buffer back to disk before making the commit. In fact, we went >> to some effort to make this a non-requirement. > > Right. I believe I was responsible for some of that effort! Oh, right. Sorry. >> So when you just want to edit the patch before the commit, you can do so >> already, for example using 'M-k' (diff-hunk-kill) - or just 'k' if the buffer >> is read-only. >> >> But of course if the idea is to really "discard" some changes, that works. > > Yeah, this is about really discarding the changes. > > It's like using C-x v D as a kind of review view. You use it for > committing what you want to keep and getting rid of temporary changes > you made just for development purposes, such as additional debug prints. > > When I used Magit I used its magit-discard for this a lot (the docstring > for that function talks about conflicts but it's also useful without those). > > One question I have is whether this should offer a y/n prompt to confirm > discarding the change. Do you have an opinion on that? I guess we should? 'diff-hl-revert-hunk' also prompts, but it has a user option to disable that. From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 10:33:41 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 14:33:42 +0000 Received: from localhost ([127.0.0.1]:46580 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st6bl-00056i-Jj for submit@debbugs.gnu.org; Tue, 24 Sep 2024 10:33:41 -0400 Received: from relayout01.e.movistar.es ([86.109.101.201]:40225 helo=relayout01-redir.e.movistar.es) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st6bj-00056U-Cj for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 10:33:40 -0400 Received: from sky (132.red-81-39-22.dynamicip.rima-tde.net [81.39.22.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: 981711563@telefonica.net) by relayout01.e.movistar.es (Postfix) with ESMTPSA id 4XCj5H2XLWzfbtK; Tue, 24 Sep 2024 16:33:06 +0200 (CEST) From: =?utf-8?Q?=C3=93scar_Fuentes?= To: Dmitry Gutov Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: (Dmitry Gutov's message of "Tue, 24 Sep 2024 15:23:57 +0300") References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> <86ikuldyy1.fsf@gnu.org> Date: Tue, 24 Sep 2024 16:33:06 +0200 Message-ID: <8734lpxgt9.fsf@telefonica.net> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-TnetOut-Country: IP: 81.39.22.132 | Country: ES X-TnetOut-Information: AntiSPAM and AntiVIRUS on relayout01 X-TnetOut-MsgID: 4XCj5H2XLWzfbtK.A9D51 X-TnetOut-SpamCheck: no es spam, clean X-TnetOut-From: ofv@wanadoo.es X-TnetOut-Watermark: 1727793189.168@E77p1ZBnkLziyMXz9xWkSQ X-Spam-Status: No X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 73407 Cc: Eli Zaretskii , juri@linkov.net, 73407@debbugs.gnu.org, Sean Whitton X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Dmitry Gutov writes: > On 24/09/2024 15:21, Eli Zaretskii wrote: > >> We should come up with a better name for this command. >> diff-discard-hunk tells me the command will discard the hunk, but says >> nothing about applying it, let alone reverse-applying it. How about >> diff-revert-hunk, or maybe diff-revert-and-discard? > > diff-revert-and-kill, maybe. If this command works on hunks, please say it on the name: diff-revert-and-kill-hunk It makes the intent clear and greatly helps discoverability when using certain tools that navigate the command names. From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 11:44:24 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 15:44:24 +0000 Received: from localhost ([127.0.0.1]:50214 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st7iB-0001jA-5j for submit@debbugs.gnu.org; Tue, 24 Sep 2024 11:44:24 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:60282) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st7i8-0001if-Lg for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 11:44:21 -0400 DKIM-Signature: a=rsa-sha256; b=U8J5/pu7sXd3P6y3eXkrs8vk7p/0RHawKMaSjpEWYzl0x24k5+tCMHX++qYXg8GbJ/jIKu7G/ZPVRdiVXw8MSKLhkkSWxFfd1vglfgkJ9DDNSr/7haS8fXa2FKzGqUZxsNJcANqhStZKHhgHOwk/Lxr4NpXThO96qL0rPFdCDTBgxCo4Ul3BOG3CUJwHie5kDXEp3De58xaN+0S7GvBAzaWhQxToh7fg6WGQWswDgYD1lbuEC389nTglwZFhwVarzbgby0PYJRvNdzvz2fURDxLo2aNmQi4piPxKMtUCfFGsedCgvfM2JXhJ3oySP0JRnjbzJIcNNYGH+PufNwbpUw==; s=purelymail1; d=spwhitton.name; v=1; bh=EG24NayJkKTjMqlRCBEGo+dY4PGwN8GldoaXF4roSoE=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=otdyaiCC2q5i/E7zuxQxwWs0pzCwmkz8Q9dBvFsS+i3Unuox83M8ndkOw4sRX6L7YA9EaEXy8IB7kqu9MQLIekkBZAWerBRxBc8+mJ1AcE3kTbjuX9Oe0sOVHwg7uidtWZ9sZKWvganzBTltEyNp2mc/K43X/FktnMX5TKQVfcjjd+tFoyFxBCZpppiPOJb5ptbYr/PV5uITL2ZBVSrvXKRzBwyWR+laYWMhmJVqCdHlDVwN0VOoP1YX4l8t+KyxdsE8bUs5tpU4s6BpW26GvQicQ7Kc8kqDiEnFxbgD6Vmt+8qX4cjESXRBEoME/jHMbf4/SwoE1/gBbCj0ta6Pzw==; s=purelymail1; d=purelymail.com; v=1; bh=EG24NayJkKTjMqlRCBEGo+dY4PGwN8GldoaXF4roSoE=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73407@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1743115294; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 24 Sep 2024 15:43:48 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 1F03D949F28; Tue, 24 Sep 2024 16:43:48 +0100 (BST) From: Sean Whitton To: Eli Zaretskii , dgutov@yandex.ru Subject: [PATCH v4] bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <86ikuldyy1.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 24 Sep 2024 15:21:42 +0300") References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> <86ikuldyy1.fsf@gnu.org> Date: Tue, 24 Sep 2024 16:43:48 +0100 Message-ID: <87r0992h1n.fsf_-_@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org, juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Hello, On Tue 24 Sep 2024 at 03:21pm +03, Eli Zaretskii wrote: > We should come up with a better name for this command. > diff-discard-hunk tells me the command will discard the hunk, but says > nothing about applying it, let alone reverse-applying it. How about > diff-revert-hunk, or maybe diff-revert-and-discard? Oh, nice. I was just following Magit, but including "revert" is better, indeed. I think I prefer diff-revert-and-kill-hunk. >> +This command is useful in buffers generated by @w{@kbd{C-x v =}} and >> +@w{@kbd{C-x v D}} (@pxref{Old Revisions}). You can use this command to >> +remove hunks you never intend to commit, such as temporary debug prints, >> +and the like. > > This text could also use some clarification: "remove hunks you never > intended to commit" only hints on what it actually does. A better > description would be something like "undo some of the changes you made > that you didn't intend". I wouldn't mention "commit" at all, since > AFAIU this command is not specific to VC and doesn't require a VCS. Yes, this is the diff-mode manual, so that makes sense. I've made a similar change in the docstring but kept a reference to committing, there. >> - (message "%d hunks failed; no buffers changed" failures))))) >> + (message "%d hunks failed; no buffers changed" failures) >> + failures)))) > > This comes from existing text, but still: what does the above say when > there's only 1 failure? does it say "1 hunks failed"? If so, can we > improve the handling of singular/plural here? I've installed a fix for that. On Tue 24 Sep 2024 at 03:22pm +03, Dmitry Gutov wrote: > I'm a little concerned about the binding. > > We have 'diff-hunk-kill' on M-k (and also 'k'), and this new addition is > actually more destructive. I'm expecting users will trip over the difference > and call one of them when they wanted to call the other. Yeah, and thinking about it more, it also doesn't really match what C-c C-k does elsewhere in Emacs. I've made it C-c M-r in the attached v4. -- Sean Whitton --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v4-0001-New-command-diff-revert-and-kill-hunk.patch >From fc5e3a5be18f9b1532490c4c6b81b90b83c0acf6 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Tue, 24 Sep 2024 09:38:43 +0100 Subject: [PATCH v4] New command diff-revert-and-kill-hunk * lisp/vc/diff-mode.el (diff-revert-and-kill-hunk): New command (bug#73407). (diff-apply-buffer): New optional BEG and END arguments. Return nil if buffers were saved, or the number of failed applications. (diff-mode-map): Bind diff-revert-and-kill-hunk to C-c M-r. (diff-mode-menu): New entry "Revert and kill hunk". * doc/emacs/files.texi (Diff Mode): * etc/NEWS: Document the new command. --- doc/emacs/files.texi | 11 +++++++++++ etc/NEWS | 5 +++++ lisp/vc/diff-mode.el | 41 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 709cb0910e6..434fb30484a 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1682,6 +1682,17 @@ Diff Mode version. If @code{diff-jump-to-old-file} is non-@code{nil}, apply the hunk to the ``old'' version of the file instead. +@findex diff-revert-and-kill-hunk +@item C-c M-r +Reverse-apply this hunk to the target file, and then kill it +(@code{diff-revert-and-kill-hunk}). Save the buffer visiting the target +file. + +This command is useful in buffers generated by @w{@kbd{C-x v =}} and +@w{@kbd{C-x v D}} (@pxref{Old Revisions}). These buffers present you +with a view of the changes you've made, and then you can use this +command to drop changes you didn't intend, or no longer want. + @findex diff-apply-buffer @item C-c @key{RET} a Apply all the hunks in the buffer (@code{diff-apply-buffer}). If the diff --git a/etc/NEWS b/etc/NEWS index c1a0524c8ba..7b85b9cbc04 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -341,6 +341,11 @@ according to diffs in the current buffer, but without applying the diffs to the original text. If the selected range extends a hunk, the command attempts to look up and copy the text in-between the hunks. ++++ +*** New command 'diff-revert-and-kill-hunk' bound to C-c M-r. +This command reverse-applies the hunk at point, and then kills it. +This is useful in buffers generated by C-x v = and C-x v D. + ** php-ts-mode --- diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index be3d94db011..9e39e58e69b 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -218,6 +218,7 @@ diff-mode-map "C-x 4 A" #'diff-add-change-log-entries-other-window ;; Misc operations. "C-c C-a" #'diff-apply-hunk + "C-c M-r" #'diff-revert-and-kill-hunk "C-c C-m a" #'diff-apply-buffer "C-c C-e" #'diff-ediff-patch "C-c C-n" #'diff-restrict-view @@ -242,6 +243,8 @@ diff-mode-menu :help "Apply the current hunk to the source file and go to the next"] ["Test applying hunk" diff-test-hunk :help "See whether it's possible to apply the current hunk"] + ["Revert and kill hunk" diff-revert-and-kill-hunk + :help "Reverse-apply and then kill the current hunk."] ["Apply all hunks" diff-apply-buffer :help "Apply all hunks in the current diff buffer"] ["Apply diff with Ediff" diff-ediff-patch @@ -2050,15 +2053,40 @@ diff-kill-applied-hunks (diff-hunk-kill) (diff-hunk-next))))) -(defun diff-apply-buffer () +(defun diff-revert-and-kill-hunk () + "Reverse-apply and then kill the hunk at point. Save changed buffer. + +This command is useful in buffers generated by \\[vc-diff] and \\[vc-root-diff], +especially when preparing to commit the patch with \\[vc-next-action]. +You can use \\\\[diff-hunk-kill] to temporarily remove changes that you intend to +include in a separate commit or commits, and you can use this command +to permanently drop changes you didn't intend, or no longer want." + (interactive) + (when (yes-or-no-p "Really reverse-apply and kill this hunk?") + (cl-destructuring-bind (beg end) (diff-bounds-of-hunk) + (diff-reverse-direction beg end) + (condition-case ret + (diff-apply-buffer beg end) + ;; Reversing the hunk is an implementation detail, so ensure the + ;; user never sees it. + (error (diff-reverse-direction beg end) + (signal (car ret) (cdr ret))) + (:success (if ret + (diff-reverse-direction beg end) + (diff-hunk-kill))))))) + +(defun diff-apply-buffer (&optional beg end) "Apply the diff in the entire diff buffer. -When applying all hunks was successful, then save the changed buffers." +When applying all hunks was successful, then save the changed buffers. +When called from Lisp with optional arguments, restrict the application +to hunks lying between BEG and END. Returns nil if buffers were saved, +or the number of failed applications." (interactive) (let ((buffer-edits nil) (failures 0) (diff-refine nil)) (save-excursion - (goto-char (point-min)) + (goto-char (or beg (point-min))) (diff-beginning-of-hunk t) (while (pcase-let ((`(,buf ,line-offset ,pos ,_src ,dst ,switched) (diff-find-source-location nil nil))) @@ -2068,6 +2096,7 @@ diff-apply-buffer (t (setq failures (1+ failures)))) (and (not (eq (prog1 (point) (ignore-errors (diff-hunk-next))) (point))) + (or (not end) (< (point) end)) (looking-at-p diff-hunk-header-re))))) (cond ((zerop failures) (dolist (buf-edits (reverse buffer-edits)) @@ -2080,10 +2109,12 @@ diff-apply-buffer (delete-region (car pos) (cdr pos)) (insert (car dst)))) (save-buffer))) - (message "Saved %d buffers" (length buffer-edits))) + (message "Saved %d buffers" (length buffer-edits)) + nil) (t (message "%d %s failed; no buffers changed" - failures (if (> failures 1) "hunks" "hunk")))))) + failures (if (> failures 1) "hunks" "hunk")) + failures)))) (defalias 'diff-mouse-goto-source #'diff-goto-source) -- 2.39.5 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 11:49:00 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 15:49:00 +0000 Received: from localhost ([127.0.0.1]:50572 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st7md-00026A-K5 for submit@debbugs.gnu.org; Tue, 24 Sep 2024 11:48:59 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:33158) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st7mb-00025g-LO for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 11:48:58 -0400 DKIM-Signature: a=rsa-sha256; b=OskxDdZN/pnKjiQjuO9+2mRgaNzImFQH3N2h9k7snBMcApSyc6vC2Xdlf0pOM7RSD9+lLVY626yDIUjBv8KcdKaX+opXZuUPeACwi7yEjegbECCn3ycsx+OLQqBdVbM8F226oys7Ss7ffe0Fc9DOMkXh3eIi0HybxSbzaNHyMXpXD216WahApJu0KW7JeJP6lachENYgDjl+a4eWHfg5hCnnA66f6vzI8ziPhNLqbUOey69rjFIHPPe3xEuvgKNlaPILYLZyGDfwt2PECOB/0nR/hkwo+w2TxsgSDUhe94leknx3h5ROlaGxKTqd7HM+aAN7QFCIBNpb1DDY20DsJA==; s=purelymail1; d=spwhitton.name; v=1; bh=713WOXy1Y2nUD3erREerKgXJwwbVJXs10nKFbcY/utk=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=NyjoOxWDYjaGwB9zJXdKsNC7LvDW3I8z9MlNMCExTXVsGeTT22L+V4tHe7ABsx0txSp3WfnbMD10x0L/3AhJO4luOCyBFibOenEq2wCItsW81artFjLkLYfNqqb1oW0VQEDg/L6Wrmef/9h2bZvgWJNfow4jj2iXAQpa7nVxqb3FRkPlZnytXbOGzOnKJMWmmAdJITgfppV4atX1MSgHKlol4kZ7FCkCztV6I8a694hidB/WeZG4LFfe51NzQz2AfeJ51UcEPYeelXok9df7NAAFl6imuh4rQ1IOo6U5bxFfBRuXAW89p+K5G2ZUvVpCaveC9xtu5ojhUHIcWJ9bPw==; s=purelymail1; d=purelymail.com; v=1; bh=713WOXy1Y2nUD3erREerKgXJwwbVJXs10nKFbcY/utk=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73407@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -1921376546; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 24 Sep 2024 15:48:26 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id BE303949F28; Tue, 24 Sep 2024 16:48:25 +0100 (BST) From: Sean Whitton To: Dmitry Gutov Subject: Re: bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <96efe4b3-edf4-4ae1-9c54-fc3dd5abc3f8@yandex.ru> (Dmitry Gutov's message of "Tue, 24 Sep 2024 15:27:16 +0300") References: <87jzf58g2t.fsf@zephyr.silentflame.com> <98752a7f-d4cd-4397-ad43-0807e29f7803@yandex.ru> <877cb1o5cp.fsf@zephyr.silentflame.com> <96efe4b3-edf4-4ae1-9c54-fc3dd5abc3f8@yandex.ru> Date: Tue, 24 Sep 2024 16:48:25 +0100 Message-ID: <87ldzh2gty.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: 73407@debbugs.gnu.org, juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, On Tue 24 Sep 2024 at 03:27pm +03, Dmitry Gutov wrote: > Oh, right. Sorry. Not at all! > 'diff-hl-revert-hunk' also prompts, but it has a user option to > disable that. Hmm. I've added prompting. Let's try using it for a while and see if we feel like such a user option is needed for this one too. -- Sean Whitton From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 13:00:36 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 17:00:37 +0000 Received: from localhost ([127.0.0.1]:56167 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st8tw-0007p3-JV for submit@debbugs.gnu.org; Tue, 24 Sep 2024 13:00:36 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:46275) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st8tu-0007i7-Rs for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 13:00:35 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 0D39D1BF204; Tue, 24 Sep 2024 16:59:59 +0000 (UTC) From: Juri Linkov To: Sean Whitton Subject: Re: [PATCH v4] bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <87r0992h1n.fsf_-_@zephyr.silentflame.com> (Sean Whitton's message of "Tue, 24 Sep 2024 16:43:48 +0100") Organization: LINKOV.NET References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> <86ikuldyy1.fsf@gnu.org> <87r0992h1n.fsf_-_@zephyr.silentflame.com> Date: Tue, 24 Sep 2024 19:59:04 +0300 Message-ID: <867cb1dm3r.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 73407 Cc: Eli Zaretskii , 73407@debbugs.gnu.org, dgutov@yandex.ru X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) >>> - (message "%d hunks failed; no buffers changed" failures))))) >>> + (message "%d hunks failed; no buffers changed" failures) >>> + failures)))) >> >> This comes from existing text, but still: what does the above say when >> there's only 1 failure? does it say "1 hunks failed"? If so, can we >> improve the handling of singular/plural here? > > I've installed a fix for that. Another variant would be to use 'ngettext'. >> I'm a little concerned about the binding. >> >> We have 'diff-hunk-kill' on M-k (and also 'k'), and this new addition is >> actually more destructive. I'm expecting users will trip over the difference >> and call one of them when they wanted to call the other. > > Yeah, and thinking about it more, it also doesn't really match what C-c > C-k does elsewhere in Emacs. I've made it C-c M-r in the attached v4. There is the existing 'C-c C-m' submap that could be used with e.g. 'C-c RET C-k'. > + (diff-reverse-direction beg end) > + (condition-case ret > + (diff-apply-buffer beg end) > + ;; Reversing the hunk is an implementation detail, so ensure the > + ;; user never sees it. > + (error (diff-reverse-direction beg end) > + (signal (car ret) (cdr ret))) > + (:success (if ret > + (diff-reverse-direction beg end) Instead of reversing the direction back and forth, it would be simpler to add another optional argument to 'diff-apply-buffer' to delegate it to the REVERSE argument of 'diff-find-source-location'. From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 13:56:43 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 17:56:43 +0000 Received: from localhost ([127.0.0.1]:60360 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st9mE-0003g1-Pi for submit@debbugs.gnu.org; Tue, 24 Sep 2024 13:56:43 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:51910) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1st9mC-0003fj-IG for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 13:56:41 -0400 DKIM-Signature: a=rsa-sha256; b=SCx7uojEtfpo2i8cB8rzgoSL3lLUOvnj+7K+VRm2cNdDB+BMvJZ1tP2JYMo3WuEDeH0SnISeeznnb4HO2AgVo8+PVpP/7DgeLgCgEIYkbMJHPq6L7gRqik2kYi2KhNIfT9OAHEhzma9NI/n9QrGcFkyz838tj2DEubC05s/e09GWvgt3s0x6vdN/+jHtn2x7h681S3YOX6j36AA223GKwEIqCpwskMtF/Ol6oMFoJddsAJDxpAlA4pxvCmx53jD20LVA1dhambx65Sr2RpOqIcDXuYKYj4AkgF/6pKGoOlZasrwV6FEvN5c4dUeKJqzJEECzKcw7OjewPZeNCdipkQ==; s=purelymail1; d=spwhitton.name; v=1; bh=DF9xhWS+Thj2TiQy8maecdQ2qpiH8MVfhJtrV6Zcdy4=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=eLyPSPnDEFquf9ld5PAZgjQxO7tMqrJOZfPXHeloQzuJjfBja8HIYX0YNyvtfxE+RSsBy4plPZeeKqdgpGf08yB0B0VLJgymL5LG1LxKTUoOirV8PQ/JJw6FDJ2cfjZgqKkPLX49o0MnsF2/rt4enCv8ro/dqNtubVojS2QorxvLtx5HaUCIwvGXxA9ZrVsW5hfgnrnKq7rd4SAEJELP8AsFkFwecr7FNuZKXN1sAHc23TQLTGUsCwNj1BogwGqf5t1ztUWgjSZe0vwsQKOcZ5A3VbULV9y4Nv73mXZzEW6qdqB+A2+wfPQx2oo6akho6eeDLNeB401dw11pvPauiA==; s=purelymail1; d=purelymail.com; v=1; bh=DF9xhWS+Thj2TiQy8maecdQ2qpiH8MVfhJtrV6Zcdy4=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73407@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -950218522; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 24 Sep 2024 17:56:08 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 048D6949F28; Tue, 24 Sep 2024 18:56:08 +0100 (BST) From: Sean Whitton To: Juri Linkov Subject: Re: [PATCH v4] bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <867cb1dm3r.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 24 Sep 2024 19:59:04 +0300") References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> <86ikuldyy1.fsf@gnu.org> <87r0992h1n.fsf_-_@zephyr.silentflame.com> <867cb1dm3r.fsf@mail.linkov.net> Date: Tue, 24 Sep 2024 18:56:07 +0100 Message-ID: <87wmj10wco.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: Eli Zaretskii , 73407@debbugs.gnu.org, dgutov@yandex.ru X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, On Tue 24 Sep 2024 at 07:59pm +03, Juri Linkov wrote: >>>> - (message "%d hunks failed; no buffers changed" failures))))) >>>> + (message "%d hunks failed; no buffers changed" failures) >>>> + failures)))) >>> >>> This comes from existing text, but still: what does the above say when >>> there's only 1 failure? does it say "1 hunks failed"? If so, can we >>> improve the handling of singular/plural here? >> >> I've installed a fix for that. > > Another variant would be to use 'ngettext'. TIL! >>> I'm a little concerned about the binding. >>> >>> We have 'diff-hunk-kill' on M-k (and also 'k'), and this new addition is >>> actually more destructive. I'm expecting users will trip over the difference >>> and call one of them when they wanted to call the other. >> >> Yeah, and thinking about it more, it also doesn't really match what C-c >> C-k does elsewhere in Emacs. I've made it C-c M-r in the attached v4. > > There is the existing 'C-c C-m' submap that could be used with e.g. > 'C-c RET C-k'. I considered that, but I think I'd prefer that it's shorter sequence if possible, because you might want to use it several times. By contrast, C-c C-m a is a command you probably just want once at a time. >> + (diff-reverse-direction beg end) >> + (condition-case ret >> + (diff-apply-buffer beg end) >> + ;; Reversing the hunk is an implementation detail, so ensure the >> + ;; user never sees it. >> + (error (diff-reverse-direction beg end) >> + (signal (car ret) (cdr ret))) >> + (:success (if ret >> + (diff-reverse-direction beg end) > > Instead of reversing the direction back and forth, > it would be simpler to add another optional argument > to 'diff-apply-buffer' to delegate it to the > REVERSE argument of 'diff-find-source-location'. Thanks, I'll try that. -- Sean Whitton From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 24 15:10:14 2024 Received: (at 73407) by debbugs.gnu.org; 24 Sep 2024 19:10:14 +0000 Received: from localhost ([127.0.0.1]:37321 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stAvN-0000f0-2N for submit@debbugs.gnu.org; Tue, 24 Sep 2024 15:10:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55870) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stAoM-0000BO-Cc for 73407@debbugs.gnu.org; Tue, 24 Sep 2024 15:02:59 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1st9ww-0006E7-1w; Tue, 24 Sep 2024 14:07:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=ytG316PFERXuQ6MNlIjj5z2UsH4hOp6vgdObPQcE64I=; b=QRlt25JwWH0B d8k7P7QOnzMEg0u6o/1ZYUU13hNCTiTP7EqkSy1Q4vDQGV0Mybr78Cf39l/wzb/ccGS5QxCWACltt rzWA9OGlbVIHfr2oDtJiP2nRQ91lzHowwhwxY2fKDrCwUgTPnq4qHWsznaWzm3CWblnt+ul+yHcrP ECDx5O9eHhJIlAC2DdC37hNvytDqfh772dAx0kt9+k3Nbmr7mEASvPB43QGCyLPP0zpVWk9TLyoHd uZu+yuQix/2Z/hQ7uTydRMql8zOI+3JpW0qH0WWpwjIADk8xtLUvUVKR7YQcaAXAHWuB9goF1fqQR Bi3sb+cc9wJXqV+Hfe3wtw==; Date: Tue, 24 Sep 2024 21:07:42 +0300 Message-Id: <86o74dc4cx.fsf@gnu.org> From: Eli Zaretskii To: Juri Linkov In-Reply-To: <867cb1dm3r.fsf@mail.linkov.net> (message from Juri Linkov on Tue, 24 Sep 2024 19:59:04 +0300) Subject: Re: [PATCH v4] bug#73407: 31.0.50; Add diff-discard-hunk References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> <86ikuldyy1.fsf@gnu.org> <87r0992h1n.fsf_-_@zephyr.silentflame.com> <867cb1dm3r.fsf@mail.linkov.net> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 73407 Cc: dgutov@yandex.ru, 73407@debbugs.gnu.org, spwhitton@spwhitton.name X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Juri Linkov > Cc: Eli Zaretskii , dgutov@yandex.ru, 73407@debbugs.gnu.org > Date: Tue, 24 Sep 2024 19:59:04 +0300 > > >>> - (message "%d hunks failed; no buffers changed" failures))))) > >>> + (message "%d hunks failed; no buffers changed" failures) > >>> + failures)))) > >> > >> This comes from existing text, but still: what does the above say when > >> there's only 1 failure? does it say "1 hunks failed"? If so, can we > >> improve the handling of singular/plural here? > > > > I've installed a fix for that. > > Another variant would be to use 'ngettext'. That's what I had in mind... From debbugs-submit-bounces@debbugs.gnu.org Wed Sep 25 02:37:19 2024 Received: (at 73407) by debbugs.gnu.org; 25 Sep 2024 06:37:19 +0000 Received: from localhost ([127.0.0.1]:42822 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stLeJ-0006t9-8v for submit@debbugs.gnu.org; Wed, 25 Sep 2024 02:37:19 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:49378) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stLeH-0006st-9y for 73407@debbugs.gnu.org; Wed, 25 Sep 2024 02:37:18 -0400 DKIM-Signature: a=rsa-sha256; b=mTwnkcVEFIDyAh+7X6GqDTD+Q2l1rQWcVyCLa+kihlUZyMSiB5tDzoXXEIvXByyi3E2oOGa9s4RQVACY+31PM3xqamF9uGVifxqJg38jtXzUeFnjJoknpG/yI3RZq1SrWEJxs8wgc+psHod8ksseBHENwogHaxxKHAD/ruJtMLTqh6F6+68TBUceMZaHTPoYCt2Hahs04aSdL8nZ8mz5mAT1rRZ47kguM8jAEBq6KZid7BHD1ZOjWqfgnA3F+IaGzy2yZIN8MFGcGOUQGWuAbKo9VnYR+42dNpm7Lgn5URZwqa8z6KhGAUNCQZ8gRuy4WWvaqkXWwWxU3IA1mgGW8w==; s=purelymail1; d=spwhitton.name; v=1; bh=kRrMASG1b6LNamKu30W2t03K6GjXINY7KCFqxwGx6uI=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=YbS4sGnJhvpag2ytFrzdm34VTjBRo5GPkg+qf5WuW2Hz8N1jcPcB9f4tH9uv5nYEfJhDUKDb2COW+36w4ChDgGFBVnwn2O8yVFeK4WOtDj78318PW7Nibz4VHdypNJf7AtRYOcGkGO5fKDZfXS4ldwxd3vl/JdeGMw25V4IB41JiueAmA3SCXLiT/8BsYwjqkZcYgWV+UgDEfrLhz8v7ZMJG1cxWXLzLqC6yioHxLcCZCETd+lw2vuTEQ7/Ap8PTgHPf9GboJ7ewD2/2FG462fOg1+wSy9rrPAhnj+pXApIeIkMkZPE6FISFmzws113yfoOf06qFVPY++oRnJ2pqAw==; s=purelymail1; d=purelymail.com; v=1; bh=kRrMASG1b6LNamKu30W2t03K6GjXINY7KCFqxwGx6uI=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73407@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -1740573694; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 25 Sep 2024 06:36:43 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 02079949F2A; Wed, 25 Sep 2024 07:36:42 +0100 (BST) From: Sean Whitton To: Eli Zaretskii Subject: Re: [PATCH v4] bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <86o74dc4cx.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 24 Sep 2024 21:07:42 +0300") References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> <86ikuldyy1.fsf@gnu.org> <87r0992h1n.fsf_-_@zephyr.silentflame.com> <867cb1dm3r.fsf@mail.linkov.net> <86o74dc4cx.fsf@gnu.org> Date: Wed, 25 Sep 2024 07:36:42 +0100 Message-ID: <87cyks1bph.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: dgutov@yandex.ru, 73407@debbugs.gnu.org, Juri Linkov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, On Tue 24 Sep 2024 at 09:07pm +03, Eli Zaretskii wrote: >> From: Juri Linkov >> Cc: Eli Zaretskii , dgutov@yandex.ru, 73407@debbugs.gnu.org >> Date: Tue, 24 Sep 2024 19:59:04 +0300 >> >> >>> - (message "%d hunks failed; no buffers changed" failures))))) >> >>> + (message "%d hunks failed; no buffers changed" failures) >> >>> + failures)))) >> >> >> >> This comes from existing text, but still: what does the above say when >> >> there's only 1 failure? does it say "1 hunks failed"? If so, can we >> >> improve the handling of singular/plural here? >> > >> > I've installed a fix for that. >> >> Another variant would be to use 'ngettext'. > > That's what I had in mind... Do you mean like this? diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index be3d94db011..9677fbb9175 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2083,7 +2083,7 @@ diff-apply-buffer (message "Saved %d buffers" (length buffer-edits))) (t (message "%d %s failed; no buffers changed" - failures (if (> failures 1) "hunks" "hunk")))))) + failures (ngettext "hunk" "hunks" failures)))))) (defalias 'diff-mouse-goto-source #'diff-goto-source) -- Sean Whitton From debbugs-submit-bounces@debbugs.gnu.org Wed Sep 25 08:17:55 2024 Received: (at 73407) by debbugs.gnu.org; 25 Sep 2024 12:17:55 +0000 Received: from localhost ([127.0.0.1]:58213 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stQxu-0004tC-IW for submit@debbugs.gnu.org; Wed, 25 Sep 2024 08:17:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51530) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stQxr-0004sl-TR for 73407@debbugs.gnu.org; Wed, 25 Sep 2024 08:17:53 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1stQxG-0003If-IK; Wed, 25 Sep 2024 08:17:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=W3DDHPys97cut5H4MHC8p7FO6i/XvvPOqcC9J79CGLs=; b=fZa5BFadILiL yn1j3CvIwgeOU5y+3nCVtjhdwxwKbYeZUxGn4Gq63dDvZa8os/2oglmJCZYRB2fXk+BMinh0yVRWI uPZQ0nSjMpqivsWVO0xhtIFRXGDNxeAvzR1uLV9n3a7DO9tutzNNmN0Lr9iarszcgi60LiiTJRIX1 ZlUogQXk3HnXcewH8tgqpgzw8rJ3UxUi7k4K7YvdENSwOCR3UQcPR2TKlHUpBGnfjMt2DMbUU+vWI WoIVeeQkzEfVkbM54V0MNWGBpz3F00hgAd3tQGuXOCOemOVRuT23w3c44OrvotkvYdJ7fAbPNalKD pFJ2Sz/uhlUJIFHH54RSfA==; Date: Wed, 25 Sep 2024 15:17:08 +0300 Message-Id: <867cb0c4hn.fsf@gnu.org> From: Eli Zaretskii To: Sean Whitton In-Reply-To: <87cyks1bph.fsf@zephyr.silentflame.com> (message from Sean Whitton on Wed, 25 Sep 2024 07:36:42 +0100) Subject: Re: [PATCH v4] bug#73407: 31.0.50; Add diff-discard-hunk References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> <86ikuldyy1.fsf@gnu.org> <87r0992h1n.fsf_-_@zephyr.silentflame.com> <867cb1dm3r.fsf@mail.linkov.net> <86o74dc4cx.fsf@gnu.org> <87cyks1bph.fsf@zephyr.silentflame.com> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 73407 Cc: dgutov@yandex.ru, 73407@debbugs.gnu.org, juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Sean Whitton > Cc: Juri Linkov , dgutov@yandex.ru, 73407@debbugs.gnu.org > Date: Wed, 25 Sep 2024 07:36:42 +0100 > > >> Another variant would be to use 'ngettext'. > > > > That's what I had in mind... > > Do you mean like this? Yes. But it is considered a better style not to break the message into separate words, so the below would be even better: (message (ngettext "%d hunk failed; no buffers changed" "%d hunks failed; no buffers changed" failures)) From debbugs-submit-bounces@debbugs.gnu.org Wed Sep 25 15:34:32 2024 Received: (at 73407) by debbugs.gnu.org; 25 Sep 2024 19:34:33 +0000 Received: from localhost ([127.0.0.1]:49821 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stXmS-0003Mk-Mp for submit@debbugs.gnu.org; Wed, 25 Sep 2024 15:34:32 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:37010) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stXmQ-0003ML-Fz for 73407@debbugs.gnu.org; Wed, 25 Sep 2024 15:34:31 -0400 DKIM-Signature: a=rsa-sha256; b=l7qPO1T5l/VErYlKXtAnZlNhnFpWyM95s2fXsFvnIQs8VCltetp7m7RtN3tCyLlOl3P0SxOttxYQ0m3WiuMKNKGp4L7KP7R9m9qZpOK0vWmY+5WziyCx3NuD8XXY2lY6eCfjT4Jq3JHup57WA0Ap/IcmeWBfAY1C/wKoc/a6VSjUmV/ZPA7x87WAV+MQJapYaZdzuMXdAjnM+XsWLNvZnVDkrQNLlrVIFv7Sx/oESRCXTKD0v8e3vWPVzEum+u1wYm/DUvlXEXsagJD04Rzji1ESlKKMuaXE5RJ9ybO0IjSgyOtDWyVZ9zYdz+Ct/QYMpRMG7BiAmIK72fOuxmXXrQ==; s=purelymail1; d=spwhitton.name; v=1; bh=Auyut9mJV0oS9UXFLHonhXcNZimJuCsICwuFyQZ4WD8=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=mc+BaPRo3GG/X2Ai951EcbMdfNXy++0D+mhrfCOEgUyylBGIAIknpY8KExrAK5moVr2rZbTenLesVy7zqJE3j3EJ6aNej6t9aRoX/mCJbsHqzhlxC+3n+vsQ5WuKc/zLRjxQM+fYTOD+bW88AKyueuLcvUQjXbTPEvNK0Fmsi1VgZymnuHRmfyUiE2REGiB2d6jr+S9yXF66vSFoW+X0MQw7lw75GdiW/VGSu0r2zYNCn/edNKjTEMCB2jNs2o86bxzoAjxnfVbWQWIHqkmkT8CZ4iynhHnqa5FU8vL25fcjVqi4ILXpwg/AOKlPl9Y2OTDNVZPbEmhcD959i21I6w==; s=purelymail1; d=purelymail.com; v=1; bh=Auyut9mJV0oS9UXFLHonhXcNZimJuCsICwuFyQZ4WD8=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73407@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1739191297; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 25 Sep 2024 19:33:57 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 3E4A694086D; Wed, 25 Sep 2024 20:33:56 +0100 (BST) From: Sean Whitton To: Eli Zaretskii Subject: Re: [PATCH v4] bug#73407: 31.0.50; Add diff-discard-hunk In-Reply-To: <867cb0c4hn.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 25 Sep 2024 15:17:08 +0300") References: <87jzf58g2t.fsf@zephyr.silentflame.com> <865xqleexg.fsf@mail.linkov.net> <87y13hmold.fsf@zephyr.silentflame.com> <86ikuldyy1.fsf@gnu.org> <87r0992h1n.fsf_-_@zephyr.silentflame.com> <867cb1dm3r.fsf@mail.linkov.net> <86o74dc4cx.fsf@gnu.org> <87cyks1bph.fsf@zephyr.silentflame.com> <867cb0c4hn.fsf@gnu.org> Date: Wed, 25 Sep 2024 20:33:56 +0100 Message-ID: <87cykrzfx7.fsf@zephyr.silentflame.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407 Cc: dgutov@yandex.ru, 73407@debbugs.gnu.org, juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, On Wed 25 Sep 2024 at 03:17pm +03, Eli Zaretskii wrote: > Yes. But it is considered a better style not to break the message > into separate words, so the below would be even better: > > (message (ngettext "%d hunk failed; no buffers changed" > "%d hunks failed; no buffers changed" > failures)) Thanks -- installed. -- Sean Whitton From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 26 06:53:09 2024 Received: (at 73407-done) by debbugs.gnu.org; 26 Sep 2024 10:53:09 +0000 Received: from localhost ([127.0.0.1]:56000 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stm7R-0005pQ-IA for submit@debbugs.gnu.org; Thu, 26 Sep 2024 06:53:09 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:42212) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stm7O-0005op-EE for 73407-done@debbugs.gnu.org; Thu, 26 Sep 2024 06:53:07 -0400 DKIM-Signature: a=rsa-sha256; b=a0yVILIOAXDLWI3ufHUTAX0OilEZQqiBnhEG7UvhZKOl+E+Bxagj6qSXguhY8v4UiNAaA0X+uckXAap5TbpQAbR1HciMYIHo67sAEwj+QzKhK33mg3ciq0ARtrddt0ytWZzSitId054K/xJN96Wo3BfU8zWeSD9YfzS9adOKlWQCCir+1NXdXl/h1mhWTxOhQ1/EgYWfh3Rsj5FLcRVnsk5AP7fI5rw7LrbEuMktCx7napq0l5MuYwTYfxZY3w9s/94Ik4iVZQKwdLYQ20XqPIzI8qjgUGvlWeQMaBsprSt3cBwEMqFJFVFUo+eZRzXnlR78D+wdxUx8n9lBxRcErQ==; s=purelymail1; d=spwhitton.name; v=1; bh=9QgcEOJLvsjoz0LZvUF1u7gbu5SO7UxpFnIyHnlTY2c=; h=Received:Received:Date:From:To:Subject; DKIM-Signature: a=rsa-sha256; b=om4ydy08uJeNxtXDiy3UfsZWdoV1rzJ7lJqIaHWQNjGDgxhndG6N7pW2k4NnRyS2DAexb7Wdc2f3m1Jc1VFTAcN1Qz9yvQB3pRZMhaG478AAeTsvdZMCBFoW+x6V/L+MS2kBLX6h2/ir9NRUq+ennNKt2HflIUvbzDBhexM9nIHzxIFH3lkRu5U7eh6CXoHVFM1Ign3er3SYiw2P3iZabwfJczbhuXBPbj5Wq67iz2FTWAWBMlZ6Jt/Pa6LOO0x3bZ6oUAU3Ou6eI63DKooI+DuQ9R7Wb7ET00U9DRWocNqi+IObG10FtoIgXaSLTYDP60iiWOo8Be+11pqA9NPJjw==; s=purelymail1; d=purelymail.com; v=1; bh=9QgcEOJLvsjoz0LZvUF1u7gbu5SO7UxpFnIyHnlTY2c=; h=Feedback-ID:Received:Received:Date:From:To:Subject; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73407-done@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1433636758 for <73407-done@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Thu, 26 Sep 2024 10:52:31 +0000 (UTC) Received: by zephyr.silentflame.com (Postfix, from userid 1000) id 9C383940500; Thu, 26 Sep 2024 11:52:30 +0100 (BST) Date: Thu, 26 Sep 2024 11:52:30 +0100 From: Sean Whitton To: 73407-done@debbugs.gnu.org Subject: Re: bug#73407: 31.0.50; Add diff-revert-and-kill-hunk Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 73407-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hello, I believe all outstanding issues are resolved, so I've installed this, and am closing the bug. Thank you for the input, which improved my work, as ever. -- Sean Whitton From unknown Sat Jun 21 10:15:23 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 24 Oct 2024 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator