From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#65380: [PATCH] Add command to copy contents in a diff-mode buffer Date: Sun, 20 Aug 2023 07:52:29 +0000 Message-ID: <87msymup4y.fsf@posteo.net> References: <87wmxrwe6h.fsf@posteo.net> <87ttsvwdv2.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27920"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65380@debbugs.gnu.org To: Daniel =?UTF-8?Q?Mart=C3=ADn?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 13 13:51:36 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 1qgOP9-00071L-Or for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 13 Sep 2023 13:51:35 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgOOi-0004iH-6R; Wed, 13 Sep 2023 07:51:08 -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 1qgOOZ-0004SJ-1P for bug-gnu-emacs@gnu.org; Wed, 13 Sep 2023 07:51:00 -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 1qgOOX-0004NC-3s for bug-gnu-emacs@gnu.org; Wed, 13 Sep 2023 07:50:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qgOOc-0005fy-9S for bug-gnu-emacs@gnu.org; Wed, 13 Sep 2023 07:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 Sep 2023 11:51: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.169460580721741 (code B ref 65380); Wed, 13 Sep 2023 11:51:02 +0000 Original-Received: (at 65380) by debbugs.gnu.org; 13 Sep 2023 11:50:07 +0000 Original-Received: from localhost ([127.0.0.1]:60982 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qgONi-0005eb-Kp for submit@debbugs.gnu.org; Wed, 13 Sep 2023 07:50:06 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:60679) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qgONf-0005dv-6Q for 65380@debbugs.gnu.org; Wed, 13 Sep 2023 07:50:05 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 3749B240103 for <65380@debbugs.gnu.org>; Wed, 13 Sep 2023 13:49:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1694605792; bh=KyNoeTdtmDBSs6MPhohWbjZk/B6UYtY8N0U/LKyR5vU=; h=From:To:Cc:Subject:Date:Message-ID:Autocrypt:MIME-Version: Content-Transfer-Encoding:From; b=QRChSWYFh4TOEPGVyeNOmkEB4qI7UesGiP638vRlPikFFsJEB7C2JMuGSy3zZ3vKM QEWhZK95u/wCOF9g/31QZLhIHMZBnY9on5TPUgf4fEhSr3bT5Oh/96d3++4fCNchUh H1zxtzpNFKemG8M74yO4XnjfJ5Fm8lGux5MVWOyuxDXATLdT5Cnedp9JqMMq2j/yro x6J+rHXYJ4NWGpB29urgE6+TIFY7Wdm3WyRF9m3B5O3ovLUGbZ+G0+58bnbq/nEBOB E4wnzjAMJeL1ZoaScDapDO+LRhbgEXjuZ6piFxaxU6Tc89CDMklxx4DuehrtqYOF+P b+ZlNly+qZMXg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RlzJv5zt0z6tvt; Wed, 13 Sep 2023 13:49:51 +0200 (CEST) In-Reply-To: ("Daniel =?UTF-8?Q?Mart=C3=ADn?="'s message of "Sun, 20 Aug 2023 02:59:06 +0200") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM 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:270263 Archived-At: Daniel Mart=C3=ADn writes: > Philip Kaludercic writes: > >> +(defun diff-kill-ring-save (beg end) >> + "Save contents of the region between BEG and END akin to `kill-ring-s= ave'. >> +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. What text would we want to copy outside of a hunk? Something like a patch commit message?