From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel =?UTF-8?Q?Mart=C3=ADn?= via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#65380: [PATCH] Add command to copy contents in a diff-mode buffer Date: Sun, 20 Aug 2023 02:59:06 +0200 Message-ID: References: <87wmxrwe6h.fsf@posteo.net> <87ttsvwdv2.fsf@posteo.net> Reply-To: Daniel =?UTF-8?Q?Mart=C3=ADn?= Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35897"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 65380@debbugs.gnu.org To: Philip Kaludercic Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 20 03:00:21 2023 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 1qXWnl-00098L-Hl for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Aug 2023 03:00:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qXWnT-0006k3-DN; Sat, 19 Aug 2023 21:00:03 -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 1qXWnR-0006j4-RB for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 21:00:01 -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 1qXWnR-0005sJ-Ia for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 21:00:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qXWnS-0008RP-HS for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 21:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Daniel =?UTF-8?Q?Mart=C3=ADn?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Aug 2023 01:00: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.169249316532376 (code B ref 65380); Sun, 20 Aug 2023 01:00:02 +0000 Original-Received: (at 65380) by debbugs.gnu.org; 20 Aug 2023 00:59:25 +0000 Original-Received: from localhost ([127.0.0.1]:52514 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXWmq-0008Q7-IR for submit@debbugs.gnu.org; Sat, 19 Aug 2023 20:59:24 -0400 Original-Received: from sonic311-32.consmr.mail.ir2.yahoo.com ([77.238.176.164]:34867) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXWmm-0008Pr-2N for 65380@debbugs.gnu.org; Sat, 19 Aug 2023 20:59:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.es; s=s2048; t=1692493152; bh=70gn0EU5PYqdTnT2pZXZrusJSHG/+5d7R5LiciAETj8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=fETN9WXMJGxjuskvqFQ1hGmxw6dQSRiJl0ZnWCW6r5AqVWNFNmG3jOt4+rcxa2jV0k8Rx0IeVijn/OOR6nukdGxDdwE14TDNIngzlTmxoaRqkhmV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jqEakAvkAKq5c9bJGPnT7EG9S0oNiys 3jCe3Id2H9iQzWq3hocSeK5X.Sh3sZBMfzsQpQjcr9y0kjEh4b4xmchYCjw7i_JK8b77TSFZ54kl blHuZc.m.Rq5OrtQwPzkE2UvX6r2xRZemoGwXmRNKFtOUabbJ0QhPGHhZGEgz40l8VH7.uyq2cga BvcRkPICT1Zy.KFsv72m6VtMoXuwxrM_yDF7kF4fA2e91f39t6hrOJHrN8TRhyR7R7MODPBKA6L8 pnPTVKxeIfwH60dKfV8g2Xgqv.nY84AAX.OkWPabP86WDdo3TwhZRq1QbTYj0UdGjs5lVSkP.O9y 7NrvTbxZygx..u2XId29aiiUNoZldmAx4JG1MBsUr1Y._3kj.fUsdDw5wdELYhGNKEE8aOvnPe_Y PuOryCMm3oOCSRwbXkfH5nlN_3cE0NMRjmoJ6Y5xeh_yuXvNL6Iuyb2IVY6FPHpU.MXFK1zIu30g _K7rNAYL.u7z7PLxnt7zvYWGewfHfbrxkHTP_cx2Mp X-Sonic-MF: X-Sonic-ID: ec789e3f-df73-4a91-af53-324fb41c2258 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ir2.yahoo.com with HTTP; Sun, 20 Aug 2023 00:59:12 +0000 Original-Received: by hermes--production-ir2-5cc57b9c45-v4w2n (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 009cc9cbb3a5a4c96946e16ae78c0988; Sun, 20 Aug 2023 00:59:07 +0000 (UTC) In-Reply-To: <87ttsvwdv2.fsf@posteo.net> (Philip Kaludercic's message of "Sat, 19 Aug 2023 10:00:49 +0000") X-Mailer: WebService/1.1.21732 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo 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:267932 Archived-At: Philip Kaludercic writes: > +(defun diff-kill-ring-save (beg end) > + "Save contents of the region between BEG and END akin to `kill-ring-save'. > +The contents of a region will not include diff indicators at the > +beginning of each line." > + (interactive (list (region-beginning) (region-end))) > + (let ((at-bol (save-excursion (goto-char beg) (bolp))) > + lines) > + (save-restriction > + (narrow-to-region beg end) > + (goto-char (point-min)) > + (while (not (eobp)) > + (let ((line (thing-at-point 'line t))) > + ;; In case the user has selected a region that begins > + ;; mid-line, we should not chomp off the first character. > + (if (and (null lines) (not at-bol)) > + (push line lines) > + (push (substring line 1) lines))) > + (forward-line))) > + (let ((region-extract-function > + (lambda (_) (apply #'concat (nreverse lines))))) > + (kill-ring-save beg end t)))) > As an alternative implementation, to avoid creating lots of intermediate substrings, we could check if we're inside a hunk and, if so, perform a regular expression replace to remove the diff indicators. If the region covers text outside of a hunk, then we could copy the text normally, as if the user pressed M-w.