From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Newsgroups: gmane.emacs.bugs Subject: bug#46621: Copy line Date: Sat, 18 Jun 2022 11:32:06 +0200 Message-ID: <37626.6154855088$1655544832@news.gmane.org> References: <87tuq99ova.fsf@mail.linkov.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="28887"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) Cc: 46621@debbugs.gnu.org, juri@linkov.net To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 18 11:33:45 2022 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 1o2Ups-0007I4-Mo for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 18 Jun 2022 11:33:45 +0200 Original-Received: from localhost ([::1]:37590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o2Upr-0005Hm-7J for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 18 Jun 2022 05:33:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2UpC-0005Hd-Gx for bug-gnu-emacs@gnu.org; Sat, 18 Jun 2022 05:33:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53621) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o2UpC-00035J-4B for bug-gnu-emacs@gnu.org; Sat, 18 Jun 2022 05:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o2UpC-0004gL-01 for bug-gnu-emacs@gnu.org; Sat, 18 Jun 2022 05:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 18 Jun 2022 09:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46621 X-GNU-PR-Package: emacs Original-Received: via spool by 46621-submit@debbugs.gnu.org id=B46621.165554474117951 (code B ref 46621); Sat, 18 Jun 2022 09:33:01 +0000 Original-Received: (at 46621) by debbugs.gnu.org; 18 Jun 2022 09:32:21 +0000 Original-Received: from localhost ([127.0.0.1]:47518 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o2UoX-0004fT-7F for submit@debbugs.gnu.org; Sat, 18 Jun 2022 05:32:21 -0400 Original-Received: from mailtransmit05.runbox.com ([185.226.149.38]:38156) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o2UoV-0004fD-G0 for 46621@debbugs.gnu.org; Sat, 18 Jun 2022 05:32:20 -0400 Original-Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1o2UoO-007sIn-GB; Sat, 18 Jun 2022 11:32:12 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector1; h=Content-Type:MIME-Version:Message-ID:Date:In-Reply-To:Subject :Cc:To:From; bh=0xzvzunIP0NlhgJzCOpbZplOsugD4d/zHHYTL24UjQk=; b=tn14ehtyGIl8q 4hPExz+B6GKDjIwBb6tZT8ty/oWTfFqeScN3hEb2D4xHzgEQFOlsS+v3D3t4rUAZka3RmMtFpyirj ESyQTLpeLe14Ed8JHs3G/mwd2Tb2A2Cz2KianoutIjMQJPRR6NOC+mH+/tLXU8sPbIdJt2PRRP3RF rgsmgEaerpXDmdJiStoGPxBY+WcnREoWIRh4upIR9/x544gl/tZ5sGEn3lyN+xaTI/75AMCusipFZ KhAzn1+rEMULRqNxTvecA3I3NQFZKQb6xfqFCSuNpot9L+x30oUgsd0bLYnjPjyp6X1Nia2oNut9O WHjTbEKy28AK4QozW5esw==; Original-Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1o2UoO-00057K-10; Sat, 18 Jun 2022 11:32:12 +0200 Original-Received: by submission01.runbox with esmtpsa [Authenticated ID (963757)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1o2UoJ-00058c-Cl; Sat, 18 Jun 2022 11:32:07 +0200 In-Reply-To: <87o7yr42k1.fsf@gnus.org> (message from Lars Ingebrigtsen on Fri, 17 Jun 2022 19:34:06 +0200) 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" Xref: news.gmane.io gmane.emacs.bugs:234740 Archived-At: Lars Ingebrigtsen writes: > I've now added this command to Emacs 29 as `duplicate-line'. Cool! I've had a similar command defined locally since 2015 (which I've found so useful over time that I've given it a short global keybinding). I have some suggestions that I think make the command even more useful: - Making it more DWIM'y by having it duplicate the region instead when it's active (perhaps giving it a more general name like `duplicate-thing`, `duplicate-dwim`, or maybe just `duplicate`). - Having point end up at the duplicated line instead of the original one, since that's the line you usually want to edit (in my experience). - With a prefix argument, comment out the original line/region after duplicating it. This is perhaps a bit too specialized to be useful in general compared to the other two suggestions, though I've found it very useful personally. Happy to help if any of these sound eligible for inclusion. Here's my local definition for reference: (defun duplicate (arg) "Duplicate the current line, or region if active. When called with a prefix argument the current line or region is commented out before it's copied." (interactive "P") (setq arg (or arg 1)) (let ((beg (if (region-active-p) (region-beginning) (line-beginning-position))) (end (if (region-active-p) (region-end) (line-end-position))) (point (point))) (goto-char end) (let ((to-duplicate (buffer-substring beg end))) (when (listp arg) (comment-region beg end) (setq arg 1)) (dotimes (_ arg) (end-of-line) (newline) (insert to-duplicate))) (backward-char (- end point))))