From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sean Whitton Newsgroups: gmane.emacs.bugs Subject: bug#73387: 30.0.90; C-x v v in diff-mode doesn't work after C-c C-n Date: Mon, 30 Sep 2024 21:10:04 +0800 Message-ID: <87ikudqocz.fsf@melete.silentflame.com> References: <87zfo28fzu.fsf@zephyr.silentflame.com> <8d0b046e-4b29-4551-b421-e98e212a7b40@yandex.ru> <86msjxefkv.fsf@mail.linkov.net> <87cykt2gkl.fsf@zephyr.silentflame.com> <87jzf01bsk.fsf@zephyr.silentflame.com> <87y13dfgzz.fsf@melete.silentflame.com> <5e956e3b-5891-401a-a898-e339f52ea307@yandex.ru> <87h69ydnvd.fsf@melete.silentflame.com> <878qv9scps.fsf@melete.silentflame.com> <12b28146-5cbc-48cd-b0e2-0c528d4b9b1c@yandex.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23230"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 73387@debbugs.gnu.org, monnier@iro.umontreal.ca, Juri Linkov To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 30 15:10:58 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1svGB0-0005n3-2Y for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 30 Sep 2024 15:10:58 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svGAk-000582-Ve; Mon, 30 Sep 2024 09:10:43 -0400 Original-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 1svGAY-0004wU-MT for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2024 09:10:32 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1svGAX-0008Qn-GW for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2024 09:10:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=6b44OuEqJGpyLthv7UaIDQV9CDLIIt6FhFsqSHmX+04=; b=VezLtY+ZBQEC1IMeWFuhcIKsW3ZAsnZ3gZAkOvW9VuQv7x6apCUIvxVpjglMDN7L/jqtS+2muTmP/z/mCn2lxDREypJkTCHDpeGqvLw7DD0bAN3rsNFJtEDm6N0MA+29MtcL0XIs+SGVsR8Ylus4lC8MIZ2m64PELQ2TzllfVwHb9/5ds7Udf1eq7EAV7qlA4UoKQ8eTOVXg5bIi+7VMwZe4WzyBI0L46Ov7css7hZINnTyCQbkk3IJYaSKpvZDsdC+zQcRTIadDiHNVmg68ePqZLAhK9IiG4yyDu8E0IOHH1P3Bji1Csa82AVNIQQnGNeRAgXJOPwANE5yZsMcjsw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1svGB3-0004Dv-UT for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2024 09:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Sean Whitton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 30 Sep 2024 13:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73387 X-GNU-PR-Package: emacs Original-Received: via spool by 73387-submit@debbugs.gnu.org id=B73387.172770185416228 (code B ref 73387); Mon, 30 Sep 2024 13:11:01 +0000 Original-Received: (at 73387) by debbugs.gnu.org; 30 Sep 2024 13:10:54 +0000 Original-Received: from localhost ([127.0.0.1]:45007 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svGAv-0004Dg-J9 for submit@debbugs.gnu.org; Mon, 30 Sep 2024 09:10:54 -0400 Original-Received: from sendmail.purelymail.com ([34.202.193.197]:60308) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svGAr-0004DY-95 for 73387@debbugs.gnu.org; Mon, 30 Sep 2024 09:10:52 -0400 DKIM-Signature: a=rsa-sha256; b=LdE9VhBqGwx6h10Re021L43ZYGKCJzj4jVU3fPuoMSLar1PLV9WLC7iHmEQPnqVctjJjviQra9IpmxbzywsmZYVGvJpEB9mRtkX7JcWHjcp3yvHmRcahjkG0N6vWJx5vzg9Cfqj+42US6Tasbt5Jpnc+xarSnasJQlKeSCzOlecy8+rJ4Mh4MpG+UwjZKbb9T7qHk14x20KYjMoE1s0JWJWOKPfBveO6GOaOgYeZX6vDUDbghQt0IMUdaXxGh9PPM8HV6qORWNnGEEGz7JJCZ5F4IbArNtOtTvgAsr01cxMJgvntXQk3YicvQEzq2q7o6d5Z/qby8n9irMBl///SLQ==; s=purelymail1; d=spwhitton.name; v=1; bh=Jv94MWqYWdqdULbZiokYkYK+KPYTjETyCMiIeqg1FTs=; h=Received:Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=ppecaTN4bjJADP7ONiEl/25wsorzA0QjK8V9gEVuLySEFzkj0l8VSZQmZGIlyLMUx6fF6/3fV0oNssK6tU1cMR3yS6mIjVA+0oFWVgcEsNbdEciSGC8aImEUzg0P8xPT7MAqQNCyLCqCuzEAbRLVj9qvwJLnzL+bCYdpRfQI+33SM+xPvh9iU/tWOl3GyvklIIFXkeZoAAv9mM2e0R2WFecKmlOw0Vvo0OBnjD0buqCWTLIOG4RX/UTYULFHXFYN4QF6iR3oIrwxGRlhm52n1k0bjsenwLT/vthKrPweJSZxrIwoxRuFb2lqEXmNhbNB5uq71n7jPLK6MGJF1NkMng==; s=purelymail1; d=purelymail.com; v=1; bh=Jv94MWqYWdqdULbZiokYkYK+KPYTjETyCMiIeqg1FTs=; h=Feedback-ID:Received:Received:From:To:Subject:Date; Feedback-ID: 20115:3760:null:purelymail X-Pm-Original-To: 73387@debbugs.gnu.org Original-Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1257781004; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Mon, 30 Sep 2024 13:10:09 +0000 (UTC) Original-Received: by melete.silentflame.com (Postfix, from userid 1000) id 9F4967E1F47; Mon, 30 Sep 2024 14:10:04 +0100 (BST) In-Reply-To: <12b28146-5cbc-48cd-b0e2-0c528d4b9b1c@yandex.ru> (Dmitry Gutov's message of "Mon, 30 Sep 2024 13:11:18 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:292713 Archived-At: --=-=-= Content-Type: text/plain Hello, On Mon 30 Sep 2024 at 01:11pm +03, Dmitry Gutov wrote: > Just these two points: > > - add a command which does the kill-all-but-this-hunk (or hunks in > region if mark active) thing -- it's generally useful. > > - make C-x v v on a narrowed buffer, by default, issue a message saying > "Cannot commit patch when narrowed, consider " Okay, what do you think to the attached? I tested the (apply #'user-error ...) by applying your patch from up-thread, though I think there may be a bug with that patch because after applying it I was not able to use C-x v v to commit. (FTAOD I think the attached is valid independently of your patch.) -- Sean Whitton --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-New-command-diff-delete-other-hunks.patch >From 34f5c95c6d04cd5d07d11214a72516b0c9ff10e4 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 30 Sep 2024 21:08:38 +0800 Subject: [PATCH] New command diff-delete-other-hunks * lisp/vc/diff-mode.el (diff-delete-other-hunks): New command (bug#73387). (diff-mode-map): Bind the new command to C-c RET k. (diff-mode-menu): New entry for the new command. (vc-next-action): Stop, and warn, if the user attempts to commit a patch from a narrowed buffer. * doc/emacs/files.texi (Diff Mode): * etc/NEWS: Document the new command. --- doc/emacs/files.texi | 5 +++++ etc/NEWS | 5 +++++ lisp/vc/diff-mode.el | 35 +++++++++++++++++++++++++++++++++++ lisp/vc/vc.el | 10 ++++++++++ 4 files changed, 55 insertions(+) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index a3a8c854aa6..a32689552b1 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1703,6 +1703,11 @@ Diff Mode Apply all the hunks in the buffer (@code{diff-apply-buffer}). If the diffs were applied successfully, save the changed buffers. +@findex diff-delete-other-hunks +@item C-c @key{RET} k +Delete all hunks other than the current hunk. If the region is active, +then delete all hunks other than those the region overlaps. + @findex diff-refine-hunk @item C-c C-b Highlight the changes of the hunk at point with a finer granularity diff --git a/etc/NEWS b/etc/NEWS index cdc7f47b7a9..a459ec18495 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -369,6 +369,11 @@ This command reverts the hunk at point (i.e., applies the reverse of the hunk), and then removes the hunk from the diffs. This is useful to undo commits when you are in buffers generated by 'C-x v =' and 'C-x v D'. ++++ +*** New command 'diff-delete-other-hunks' bound to C-c RET k. +This command deletes hunks other than the current hunk. +It is useful to prepare a *vc-diff* buffer for committing a single hunk. + ** php-ts-mode --- diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 25c6238765d..ff141e19c50 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -220,6 +220,7 @@ diff-mode-map "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-m k" #'diff-delete-other-hunks "C-c C-e" #'diff-ediff-patch "C-c C-n" #'diff-restrict-view "C-c C-s" #'diff-split-hunk @@ -278,6 +279,8 @@ diff-mode-menu :help "Kill current hunk"] ["Kill current file's hunks" diff-file-kill :help "Kill all current file's hunks"] + ["Delete other hunks" diff-delete-other-hunks + :help "Delete hunks other than the current hunk"] "-----" ["Previous Hunk" diff-hunk-prev :help "Go to the previous count'th hunk"] @@ -814,6 +817,38 @@ diff-hunk-kill (goto-char (car bounds)) (ignore-errors (diff-beginning-of-hunk t))))) +;; This is not `diff-kill-other-hunks' because we might need to make +;; copies of file headers in order to ensure the new kill ring entry +;; would be a patch with the same meaning. That is not implemented +;; because it does not seem like it would be useful to anyone. +(defun diff-delete-other-hunks (&optional beg end) + "Delete hunks other than this one. +Interactively, if the region is active, then delete all hunks that the +region does not overlap. +When called from Lisp, the region to act upon is specified by optional +arguments BEG and END." + (interactive (list (use-region-beginning) (use-region-end))) + (when (buffer-narrowed-p) + (user-error "Command is not safe in a narrowed buffer")) + (let ((inhibit-read-only t)) + (save-excursion + (cond ((xor beg end) + (error "Require exactly zero or two arguments")) + (beg + (goto-char beg) + (setq beg (car (diff-bounds-of-hunk))) + (goto-char end) + (setq end (cadr (diff-bounds-of-hunk)))) + (t + (pcase-setq `(,beg ,end) (diff-bounds-of-hunk)))) + (delete-region end (point-max)) + (goto-char beg) + (diff-beginning-of-file) + (diff-hunk-next) + (delete-region (point) beg) + (diff-beginning-of-file-and-junk) + (delete-region (point-min) (point))))) + (defun diff-beginning-of-file-and-junk () "Go to the beginning of file-related diff-info. This is like `diff-beginning-of-file' except it tries to skip back over leading diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 597a1622f5a..39e5ca424d4 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1302,6 +1302,16 @@ vc-next-action ;; Fileset comes from a diff-mode buffer, see ;; 'diff-vc-deduce-fileset', and the buffer is the patch to apply. ((eq model 'patch) + (when (buffer-narrowed-p) + ;; If we used `diff-restrict-view' then we may not have the file + ;; header and the commit will not succeed (bug#73387). + (apply #'user-error + "Cannot commit patch when narrowed; consider %s %s %s" + (mapcar (lambda (c) + (key-description (where-is-internal c nil t))) + '(widen + diff-delete-other-hunks + vc-next-action)))) (vc-checkin files backend nil nil nil (buffer-string))) ((or (null state) (eq state 'unregistered)) (cond (verbose -- 2.45.2 --=-=-=--