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 09:53:58 +0000 Message-ID: <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="14000"; 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 11:55:15 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 1qXIfq-0003VM-Ng for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Aug 2023 11:55:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qXIfh-0005iT-J1; Sat, 19 Aug 2023 05:55: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 1qXIfe-0005iK-W1 for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 05:55:03 -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 1qXIfd-0005TI-6r for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 05:55:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qXIfe-0007Cb-2o for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 05:55: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 09:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65380 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.169243885327619 (code B ref -1); Sat, 19 Aug 2023 09:55:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Aug 2023 09:54:13 +0000 Original-Received: from localhost ([127.0.0.1]:49522 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXIeq-0007BP-Rw for submit@debbugs.gnu.org; Sat, 19 Aug 2023 05:54:13 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:56738) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXIep-0007BD-V4 for submit@debbugs.gnu.org; Sat, 19 Aug 2023 05:54:12 -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 1qXIei-0005Ui-Ua for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 05:54:05 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qXIeg-0005L9-94 for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 05:54:04 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 5BACA240027 for ; Sat, 19 Aug 2023 11:53:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1692438839; bh=ngzJykeBRSkwaym6sBdOFt60WPZiyGgYlVtxF8KAD4U=; h=From:To:Subject:Autocrypt:Date:Message-ID:MIME-Version:From; b=NxERapPzTZqex7V74MbA1WIQCNQ7ZYaLFdsRLVKSiZTBDcjmK79Fyj3DiEF4zWFdG zeWRd3cmpARznRznMi+DHruq0H9bTlxV7XFRGx85FNgrb5Tqsh6uCpWYquHzNjTZZK EnpCPBSCDw+ajSSgeAkl5WaTKmtLBklUb/44LgQrgcDXG9cW7EWnn2GrThkgiwprjX 91vXa3smUuACcCeoJbMQuBKuP5vAvc59nmq+//+UefjyrktlRTRwuY4Fn2Kqu24A0S pGzt7HuBJcueYgEoJ8lTZZWUd5ov9CThc8R1cjoKqRrZKgbOoal94pcaIo9pg0009I p+uY6RJHcYtfw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RSYwk6MRQz9rxD for ; Sat, 19 Aug 2023 11:53:58 +0200 (CEST) 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 Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:267841 Archived-At: --=-=-= Content-Type: text/plain 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' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-command-to-copy-contents-in-a-diff-mode-buffer.patch >From 9d755a12614fb9c1afe4dd88cecfbe16c3c009c4 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 | 22 +++++++++++++++++++++- 2 files changed, 28 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..fce61837069 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,25 @@ diff-goto-source (goto-char (+ (car pos) (cdr src))) (when buffer (next-error-found buffer (current-buffer)))))) +(defun diff-kill-ring-save () + " " + (interactive) + (let ((at-bol (save-excursion + (goto-char (region-beginning)) + (bolp))) + lines) + (save-restriction + (narrow-to-region (region-beginning) (region-end)) + (goto-char (point-min)) + (while (not (eobp)) + (let ((line (thing-at-point 'line t))) + (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))))) + (copy-region-as-kill nil nil t)))) (defun diff-current-defun () "Find the name of function at point. -- 2.39.2 --=-=-=--