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: Sat, 19 Aug 2023 10:00:49 +0000 Message-ID: <87ttsvwdv2.fsf@posteo.net> References: <87wmxrwe6h.fsf@posteo.net> 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="1397"; mail-complaints-to="usenet@ciao.gmane.io" To: 65380@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 19 12:01:20 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 1qXIlk-0000Ck-5k for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Aug 2023 12:01:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qXIlV-0006ah-D9; Sat, 19 Aug 2023 06:01:05 -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 1qXIlS-0006aT-PF for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 06:01:02 -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 1qXIlR-0006g5-Kq for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 06:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qXIlS-0007Mg-Fn for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 06:01: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: Sat, 19 Aug 2023 10:01: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.169243926128297 (code B ref 65380); Sat, 19 Aug 2023 10:01:02 +0000 Original-Received: (at 65380) by debbugs.gnu.org; 19 Aug 2023 10:01:01 +0000 Original-Received: from localhost ([127.0.0.1]:49528 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXIlQ-0007MK-Ro for submit@debbugs.gnu.org; Sat, 19 Aug 2023 06:01:01 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:51963) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXIlO-0007M4-Mu for 65380@debbugs.gnu.org; Sat, 19 Aug 2023 06:00:59 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 06CE0240103 for <65380@debbugs.gnu.org>; Sat, 19 Aug 2023 12:00:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1692439251; bh=7QjQZAnOQ+78ptjwOVuTHpL2ZROSuOTaV6sAZovZ44g=; h=From:To:Subject:Autocrypt:Date:Message-ID:MIME-Version:From; b=D27n95nBcpwp1rXWSyLLhK/Ns3t6kyjnEem3PglmjFs81k0NustT0P4qGo/jR4pvW +2P9TAJPkVgfDpIFcrr63B1gWVhT+1F4VkcMW9dP0ZdobWMb1yS0LXo4lfs/G1uGvb tO/5KPEbUC62w8vDk/Ea/45y3gY7MNN7wDeXwGxyVOJ9kUNyAQTG4DsmWdu3fcUCek IDDkioxzSLnoIyhiX5YXkdJkHA3YkCFgX9qPTeSjP9fhhQu3mUyc9Cj/ylnj67LXHC MHC+gF91HdDwetU0zZ+hUSCElqbIQPZYPbDSFOwrptikM3pKW4/x09Mbez2qVT7Y5T amHeQvyEKDa4A== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RSZ4f4TmPz9rxF for <65380@debbugs.gnu.org>; Sat, 19 Aug 2023 12:00:50 +0200 (CEST) In-Reply-To: <87wmxrwe6h.fsf@posteo.net> (Philip Kaludercic's message of "Sat, 19 Aug 2023 09:53:58 +0000") 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:267842 Archived-At: --=-=-= Content-Type: text/plain Philip Kaludercic writes: > Tags: patch > > > This command solves a long-standing annoyance I have had when working > with diffs. To my knowledge there is no existing way to achieve this > (rectangular selection might be possible, but that behaves differently > when the text is yanked). The binding "w" seems intuitive when > contrasted with "M-w", but might be confused with "W" (widen). Not sure > if that is an issue or not. > > In GNU Emacs 30.0.50 (build 8, x86_64-pc-linux-gnu, GTK+ Version > 3.24.37, cairo version 1.16.0) of 2023-08-18 built on quetzal > Repository revision: 2f74a459d2a82578fd9a92e9e2facdca90dad974 > Repository branch: feature/a-package-for-elpa > System Description: Debian GNU/Linux 12 (bookworm) > > Configured using: > 'configure --with-pgtk --with-native-compilation --with-imagemagick > --with-tree-sitter' It seems I prepared to patch too hastily, and forgot to add a docstring. Here is the updated version, with a docstring: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-command-to-copy-contents-in-a-diff-mode-buffer.patch >From fc39bd54ac93dbebec3b4c16aa1fe995cd421c92 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Sat, 19 Aug 2023 11:47:54 +0200 Subject: [PATCH] Add command to copy contents in a diff-mode buffer * lisp/vc/diff-mode.el (diff-mode-shared-map): Bind 'diff-kill-ring-save'. (diff-mode-map): Ensure the "w" binding does not get prefixed. (diff-kill-ring-save): Add new command * etc/NEWS: Mention 'diff-kill-ring-save'. --- etc/NEWS | 7 +++++++ lisp/vc/diff-mode.el | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index 6588299c532..9ce510e0f81 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -276,6 +276,13 @@ This allows changing which type of whitespace changes are ignored when regenerating hunks with 'diff-ignore-whitespace-hunk'. Defaults to the previously hard-coded "-b". +--- +*** New command 'diff-kill-ring-save'. +This command behaves like 'kill-ring-save', but removes change +indicators ("+", "-") from the beginning of a line. This is useful +when you wish to copy part of the contents of a diff, but not the diff +itself. + ** Ediff --- diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index d776375d681..342d2d8ce90 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -195,6 +195,7 @@ diff-mode-shared-map "RET" #'diff-goto-source "" #'diff-goto-source "W" #'widen + "w" #'diff-kill-ring-save "o" #'diff-goto-source ; other-window "A" #'diff-ediff-patch "r" #'diff-restrict-view @@ -207,7 +208,7 @@ diff-mode-map ;; We want to inherit most bindings from ;; `diff-mode-shared-map', but not all since they may hide ;; useful `M-' global bindings when editing. - (dolist (key '("A" "r" "R" "g" "q" "W" "z")) + (dolist (key '("A" "r" "R" "g" "q" "W" "w" "z")) (keymap-set map key nil)) map) ;; From compilation-minor-mode. @@ -2079,6 +2080,27 @@ diff-goto-source (goto-char (+ (car pos) (cdr src))) (when buffer (next-error-found buffer (current-buffer)))))) +(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)))) (defun diff-current-defun () "Find the name of function at point. -- 2.39.2 --=-=-=--