From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#65380: [PATCH] Add command to copy contents in a diff-mode buffer Date: Tue, 20 Aug 2024 09:44:22 +0300 Organization: LINKOV.NET Message-ID: <86a5h73d89.fsf@mail.linkov.net> References: <87wmxrwe6h.fsf@posteo.net> <83o7j3z4wm.fsf@gnu.org> <87pm3jwboc.fsf@posteo.net> <83lee7z3xs.fsf@gnu.org> <87jztrvxx2.fsf@posteo.net> <83r0nyyhlz.fsf@gnu.org> <86o7j2qgmc.fsf@mail.linkov.net> <83cyzhwpcj.fsf@gnu.org> <87a5ultvuy.fsf@posteo.net> <83a5ulwos6.fsf@gnu.org> <87fs4bgwuj.fsf@posteo.net> <83fs4btiw1.fsf@gnu.org> <871q2n152u.fsf@posteo.net> <87frr1zw6i.fsf@posteo.net> <864j7hzviv.fsf@gnu.org> <87bk1pztsr.fsf@posteo.net> <861q2lzp70.fsf@gnu.org> <87ed6kxq5j.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31462"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: 65380@debbugs.gnu.org, Eli Zaretskii To: Philip Kaludercic Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 20 08:49:40 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 1sgIgV-0007zI-Km for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 20 Aug 2024 08:49:39 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgIgG-0002Ff-RD; Tue, 20 Aug 2024 02:49:26 -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 1sgIgC-0002EQ-PQ for bug-gnu-emacs@gnu.org; Tue, 20 Aug 2024 02:49:21 -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 1sgIgC-00066w-G8 for bug-gnu-emacs@gnu.org; Tue, 20 Aug 2024 02:49:20 -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=dYdZiT+xEMni/TJlAKqRwrA9hNoU46yCo+8Dnx393yI=; b=fdFDmUIlBkVjPp5b5m0bhEVwl8XzpOdrPYT6NXguk4AQQSo8O1gbqZXRGqh+p3uHlt29+bnMxxECL4X43cdFNk3kOrd07sOhMJiSwWvM4t3fKtEgA5ATlOymT0nENGFv1rx3oOKwJ2Z7F6Ell8RkVu9iWW3DPyM3n8/MERfMOv2cdf9rGqqjSpdlc8pmRtEOBiYxeMtRiohhDMEkyU9frHohQqM6myGS1mTNFfAtP0J8SttCHpuxXYtbQntP7UPpnJT0ve41T1qIr383kdxMrawEK/uNzGuKHNVCMhJQ22Rncxl+fxhOUkN+HmVrad//nuErOtd6XxGVfpcVoA35xQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sgIgs-0007zT-5x for bug-gnu-emacs@gnu.org; Tue, 20 Aug 2024 02:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 20 Aug 2024 06:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65380 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65380-submit@debbugs.gnu.org id=B65380.172413660130704 (code B ref 65380); Tue, 20 Aug 2024 06:50:02 +0000 Original-Received: (at 65380) by debbugs.gnu.org; 20 Aug 2024 06:50:01 +0000 Original-Received: from localhost ([127.0.0.1]:59691 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sgIgq-0007zA-NN for submit@debbugs.gnu.org; Tue, 20 Aug 2024 02:50:00 -0400 Original-Received: from relay8-d.mail.gandi.net ([217.70.183.201]:39433) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sgIgp-0007yw-9U for 65380@debbugs.gnu.org; Tue, 20 Aug 2024 02:49:59 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id A334F1BF206; Tue, 20 Aug 2024 06:49:09 +0000 (UTC) In-Reply-To: <87ed6kxq5j.fsf@posteo.net> (Philip Kaludercic's message of "Mon, 19 Aug 2024 19:34:48 +0000") X-GND-Sasl: juri@linkov.net 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:290425 Archived-At: > I'm attaching the newest version of the patch here: Thanks, I tried it out, and it works nicely for the single hunk case. > +*** New command 'diff-kill-ring-save' > +This command copies out the modified contents out of a diff, without > +having to apply it first. If the selected range extends a hunk, the > +commands attempts to look up and copy the text between from the > +referenced file. I'm not sure about usefulness of the last part in multi-hunk case. Does someone really need to copy a huge part of the source file between hunks at the top and bottom? I expected that multi-hunk case would copy only concatenated text of hunks, not the source file. But I have no strong opinion about this. My main use case will be to copy the text of the current hunk. Could you please support this case where typing 'w' would copy the current hunk when the region is not activated. > @@ -630,6 +631,22 @@ diff-end-of-hunk > +(defun diff-beginning-of-hunk-position (&optional try-harder) > + "Call `diff-end-of-hunk' without moving. > +The optional argument TRY-HARDER is passed on to > +`diff-beginning-of-hunk'." > + (save-excursion > + (save-window-excursion > + (diff-beginning-of-hunk try-harder)))) > + > +(defun diff-end-of-hunk-position (&optional style donttrustheader) > + "Call `diff-end-of-hunk' without moving. > +The optional arguments STYLE and DONTTRUSTHEADER are passed on to > +`diff-end-of-hunk'." > + (save-excursion > + (save-window-excursion > + (diff-end-of-hunk style donttrustheader)))) I don't understand why separate functions with 'save-window-excursion' are needed here, since all other uses of 'diff-beginning-of-hunk' just wrap the calls with 'save-excursion'.