From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#46621: Copy line Date: Wed, 06 Jul 2022 20:34:19 +0300 Organization: LINKOV.NET Message-ID: <86k08qtxws.fsf@mail.linkov.net> References: <87tuq99ova.fsf@mail.linkov.net> <07496A25-CD5D-46E6-8F1C-7BD29143F3C8@acm.org> <87o7yoyj38.fsf@gnus.org> <449B2624-107D-4083-AE74-989F39C93936@acm.org> <871qvkvft6.fsf@gnus.org> <181B4CC3-B934-45AE-A7E8-9AF2B70C302E@acm.org> <87bkum1eyc.fsf@gnus.org> <861qvikk4l.fsf@mail.linkov.net> <87zgi5uyr1.fsf@gnus.org> <86o7yl9oc4.fsf@mail.linkov.net> <878rppuo9j.fsf@gnus.org> <87wnd8r4v2.fsf@codeisgreat.org> <87y1xnzuog.fsf@gnus.org> <87a6a3ree0.fsf@codeisgreat.org> <87wnd7ycl1.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39574"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: 46621@debbugs.gnu.org, Andreas Schwab , Pankaj Jangid To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jul 06 19:44:16 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 1o994R-000A8y-Ky for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 06 Jul 2022 19:44:15 +0200 Original-Received: from localhost ([::1]:57232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o994Q-000652-AO for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 06 Jul 2022 13:44:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o994E-00063t-Og for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2022 13:44:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:32915) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o994E-0005P9-EJ for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2022 13:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o994E-0007Zf-Cj for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2022 13:44:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 06 Jul 2022 17:44:02 +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.165712938329017 (code B ref 46621); Wed, 06 Jul 2022 17:44:02 +0000 Original-Received: (at 46621) by debbugs.gnu.org; 6 Jul 2022 17:43:03 +0000 Original-Received: from localhost ([127.0.0.1]:55041 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o993H-0007Xx-Hz for submit@debbugs.gnu.org; Wed, 06 Jul 2022 13:43:03 -0400 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:48071) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o993G-0007XO-7c for 46621@debbugs.gnu.org; Wed, 06 Jul 2022 13:43:02 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id DD753200003; Wed, 6 Jul 2022 17:42:53 +0000 (UTC) In-Reply-To: <87wnd7ycl1.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 23 Jun 2022 11:05:14 +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:236280 Archived-At: >> duplicate-line should keep point at the same column. > > Ah, yes, that might be nice... Here is the patch that does this. So if you have foo 1 bar and need to get foo 1 bar foo 2 bar foo 3 bar foo 4 bar foo 5 bar it requires typing the minimal number of keys - move point to the column with 1, and type: C-u 2 3 4 5 ``` diff --git a/lisp/misc.el b/lisp/misc.el index 28c5d6e07f..57cf8c59ed 100644 --- a/lisp/misc.el +++ b/lisp/misc.el @@ -71,13 +71,15 @@ duplicate-line (interactive "p") (unless n (setq n 1)) - (let ((line (buffer-substring (line-beginning-position) (line-end-position)))) + (let ((line (buffer-substring (line-beginning-position) (line-end-position))) + (column (current-column))) + (forward-line 1) + (unless (bolp) + (insert "\n")) (save-excursion - (forward-line 1) - (unless (bolp) - (insert "\n")) (dotimes (_ n) - (insert line "\n"))))) + (insert line "\n"))) + (move-to-column column))) ;; Variation of `zap-to-char'. ```