From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#46621: Copy line Date: Mon, 20 Jun 2022 11:26:18 +0200 Message-ID: <181B4CC3-B934-45AE-A7E8-9AF2B70C302E@acm.org> 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> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_FD6963D3-E822-4B76-82F1-C13517A0EE3B" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34706"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 46621@debbugs.gnu.org, Simen =?UTF-8?Q?Heggest=C3=B8yl?= , Juri Linkov To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 20 11:27:13 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 1o3Dge-0008p1-Er for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 20 Jun 2022 11:27:12 +0200 Original-Received: from localhost ([::1]:54586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3Dgc-0004uz-To for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 20 Jun 2022 05:27:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:32950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3DgU-0004uj-2v for bug-gnu-emacs@gnu.org; Mon, 20 Jun 2022 05:27:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60464) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o3DgT-00070t-R5 for bug-gnu-emacs@gnu.org; Mon, 20 Jun 2022 05:27:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o3DgT-0004Jy-Ly for bug-gnu-emacs@gnu.org; Mon, 20 Jun 2022 05:27:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 20 Jun 2022 09:27: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.165571719016566 (code B ref 46621); Mon, 20 Jun 2022 09:27:01 +0000 Original-Received: (at 46621) by debbugs.gnu.org; 20 Jun 2022 09:26:30 +0000 Original-Received: from localhost ([127.0.0.1]:54361 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o3Dfy-0004J8-Gr for submit@debbugs.gnu.org; Mon, 20 Jun 2022 05:26:30 -0400 Original-Received: from mail1437c50.megamailservers.eu ([91.136.14.37]:46026 helo=mail263c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o3Dfv-0004Iq-Tk for 46621@debbugs.gnu.org; Mon, 20 Jun 2022 05:26:28 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1655717181; bh=RbLBSMyaoxvrY693hQZpj1YecXwPHcdgy9ETBwS0JSo=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=dVFcUTp3CwNsmyuhKYv2lteAtWKJtCHNQTULbZt2/Kyy3WKUSwYcBI2sSYWsfxauo /F/blSG+JbHQIcCvTFZ4fAXltXpgWkKk73Vuck8kHrBQQHhNRLW8WgrQWJeiEmFFFL 3PHrvUOEGANjOnxr8fOeBI+byt/B3kkHHO8Fb0kA= Feedback-ID: mattiase@acm.or Original-Received: from smtpclient.apple (c188-150-171-71.bredband.tele2.se [188.150.171.71]) (authenticated bits=0) by mail263c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 25K9QIms095627; Mon, 20 Jun 2022 09:26:20 +0000 In-Reply-To: <871qvkvft6.fsf@gnus.org> X-Mailer: Apple Mail (2.3654.120.0.1.13) X-CTCH-RefID: str=0001.0A782F15.62B03D3D.0031, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-Origin-Country: SE 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:234854 Archived-At: --Apple-Mail=_FD6963D3-E822-4B76-82F1-C13517A0EE3B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 19 juni 2022 kl. 17.22 skrev Lars Ingebrigtsen : > No, it's consistent -- it always creates a new line. Either behaviour can be seen as consistent. I suppose it's a matter of = what behaviour we find more convenient. It's expected to be a rare case and I have no strong opinion about it. > It's edgy compared to what it's supposed to be doing -- duplicating > lines. Well, now it does more. Do you mean that you prefer it wouldn't, or that = we change the name? I have no strong opinion about the name but it would be a shame to make = the command less useful. Here is an updated patch that fixes a bug in the original code (would = crash when called without an argument) and adds tests. --Apple-Mail=_FD6963D3-E822-4B76-82F1-C13517A0EE3B Content-Disposition: attachment; filename=0001-Make-duplicate-line-work-on-regions-bug-46621.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Make-duplicate-line-work-on-regions-bug-46621.patch" Content-Transfer-Encoding: quoted-printable =46rom=208f210a9ee0f61c22a2b1996b1b61c7242e2372dc=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Mon,=2020=20Jun=202022=2011:16:26=20+0200=0A= Subject:=20[PATCH]=20Make=20duplicate-line=20work=20on=20regions=20= (bug#46621)=0A=0AWith=20an=20active=20region,=20duplicate=20that=20= region=20instead=20of=20the=20current=0Aline.=20=20Rectangular=20regions=20= are=20duplicated=20on=20the=20right-hand=20side.=0A=0A*=20lisp/rect.el=20= (rectangle--duplicate-right):=20New.=0A*=20lisp/misc.el=20= (duplicate-line):=20Work=20on=20regions.=20=20Allow=20calls=20without=0A= an=20argument.=0A*=20test/lisp/misc-tests.el=20(misc--duplicate-line):=20= New=20test.=0A---=0A=20lisp/misc.el=20=20=20=20=20=20=20=20=20=20=20=20|=20= 48=20+++++++++++++++++++++++++++++++++++------=0A=20lisp/rect.el=20=20=20= =20=20=20=20=20=20=20=20=20|=2021=20++++++++++++++++++=0A=20= test/lisp/misc-tests.el=20|=2035=20++++++++++++++++++++++++++++++=0A=203=20= files=20changed,=2097=20insertions(+),=207=20deletions(-)=0A=0Adiff=20= --git=20a/lisp/misc.el=20b/lisp/misc.el=0Aindex=203fb30e5372..906d6c2012=20= 100644=0A---=20a/lisp/misc.el=0A+++=20b/lisp/misc.el=0A@@=20-63,19=20= +63,53=20@@=20copy-from-above-command=0A=20=09=09=09=09=20(+=20n=20= (point)))))))=0A=20=20=20=20=20(insert=20string)))=0A=20=0A= +(declare-function=20rectangle--duplicate-right=20"rect"=20(n))=0A+=0A= +;;=20`duplicate-line'=20preserves=20an=20active=20region=20and=20= changes=20the=20buffer=0A+;;=20outside=20of=20it:=20disregard=20the=20= region=20when=20immediately=20undoing=20the=0A+;;=20actions=20of=20this=20= command.=0A+(put=20'duplicate-line=20'undo-inhibit-region=20t)=0A+=0A=20= ;;;###autoload=0A=20(defun=20duplicate-line=20(&optional=20n)=0A=20=20=20= "Duplicate=20the=20current=20line=20N=20times.=0A+If=20the=20region=20is=20= inactive,=20duplicate=20the=20current=20line.=0A+Otherwise,=20duplicate=20= the=20region's=20contents.=20=20The=20region=20remains=0A+active=20= afterwards.=0A+If=20the=20region=20is=20rectangular,=20duplicate=20on=20= its=20right-hand=20side.=0A=20Interactively,=20N=20is=20the=20prefix=20= numeric=20argument,=20and=20defaults=20to=201.=0A=20Also=20see=20the=20= `copy-from-above-command'=20command."=0A=20=20=20(interactive=20"p")=0A-=20= =20(let=20((line=20(buffer-substring=20(line-beginning-position)=20= (line-end-position))))=0A-=20=20=20=20(save-excursion=0A-=20=20=20=20=20=20= (forward-line=201)=0A-=20=20=20=20=20=20(unless=20(bolp)=0A-=20=20=20=20=20= =20=20=20(insert=20"\n"))=0A-=20=20=20=20=20=20(dotimes=20(_=20n)=0A-=20=20= =20=20=20=20=20=20(insert=20line=20"\n")))))=0A+=20=20(unless=20n=0A+=20=20= =20=20(setq=20n=201))=0A+=20=20(cond=0A+=20=20=20;;=20Duplicate=20= rectangle.=0A+=20=20=20((bound-and-true-p=20rectangle-mark-mode)=0A+=20=20= =20=20(require=20'rect)=0A+=20=20=20=20(rectangle--duplicate-right=20n)=0A= +=20=20=20=20(setq=20deactivate-mark=20nil))=0A+=0A+=20=20=20;;=20= Duplicate=20(contiguous)=20region.=0A+=20=20=20((use-region-p)=0A+=20=20=20= =20(let*=20((beg=20(region-beginning))=0A+=20=20=20=20=20=20=20=20=20=20=20= (end=20(region-end))=0A+=20=20=20=20=20=20=20=20=20=20=20(text=20= (buffer-substring=20beg=20end)))=0A+=20=20=20=20=20=20(save-excursion=0A= +=20=20=20=20=20=20=20=20(goto-char=20end)=0A+=20=20=20=20=20=20=20=20= (dotimes=20(_=20n)=0A+=20=20=20=20=20=20=20=20=20=20(insert=20text))))=0A= +=20=20=20=20(setq=20deactivate-mark=20nil))=0A+=0A+=20=20=20;;=20= Duplicate=20line.=0A+=20=20=20(t=0A+=20=20=20=20(let=20((line=20= (buffer-substring=20(line-beginning-position)=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20(line-end-position))))=0A+=20=20=20=20=20=20(save-excursion=0A+=20=20=20= =20=20=20=20=20(forward-line=201)=0A+=20=20=20=20=20=20=20=20(unless=20= (bolp)=0A+=20=20=20=20=20=20=20=20=20=20(insert=20"\n"))=0A+=20=20=20=20=20= =20=20=20(dotimes=20(_=20n)=0A+=20=20=20=20=20=20=20=20=20=20(insert=20= line=20"\n")))))))=0A=20=0A=20;;=20Variation=20of=20`zap-to-char'.=0A=20=0A= diff=20--git=20a/lisp/rect.el=20b/lisp/rect.el=0Aindex=20= e717d2ac7e..c41a545e85=20100644=0A---=20a/lisp/rect.el=0A+++=20= b/lisp/rect.el=0A@@=20-931,6=20+931,27=20@@=20= rectangle--unhighlight-for-redisplay=0A=20=20=20=20=20(mapc=20= #'delete-overlay=20(nthcdr=205=20rol))=0A=20=20=20=20=20(setcar=20(cdr=20= rol)=20nil)))=0A=20=0A+(defun=20rectangle--duplicate-right=20(n)=0A+=20=20= "Duplicate=20the=20rectangular=20region=20N=20times=20on=20the=20= right-hand=20side."=0A+=20=20(let=20((cols=20(rectangle--pos-cols=20= (point)=20(mark))))=0A+=20=20=20=20(apply-on-rectangle=0A+=20=20=20=20=20= (lambda=20(startcol=20endcol)=0A+=20=20=20=20=20=20=20(let=20((lines=20= (list=20nil)))=0A+=20=20=20=20=20=20=20=20=20(extract-rectangle-line=20= startcol=20endcol=20lines)=0A+=20=20=20=20=20=20=20=20=20(move-to-column=20= endcol=20t)=0A+=20=20=20=20=20=20=20=20=20(dotimes=20(_=20n)=0A+=20=20=20= =20=20=20=20=20=20=20=20(insert=20(cadr=20lines)))))=0A+=20=20=20=20=20= (region-beginning)=20(region-end))=0A+=20=20=20=20;;=20Recompute=20the=20= rectangle=20state;=20no=20crutches=20should=20be=20needed=20now.=0A+=20=20= =20=20(let=20((p=20(point))=0A+=20=20=20=20=20=20=20=20=20=20(m=20= (mark)))=0A+=20=20=20=20=20=20(rectangle--reset-crutches)=0A+=20=20=20=20= =20=20(goto-char=20m)=0A+=20=20=20=20=20=20(move-to-column=20(cdr=20= cols)=20t)=0A+=20=20=20=20=20=20(set-mark=20(point))=0A+=20=20=20=20=20=20= (goto-char=20p)=0A+=20=20=20=20=20=20(move-to-column=20(car=20cols)=20= t))))=0A+=0A=20(provide=20'rect)=0A=20=0A=20;;;=20rect.el=20ends=20here=0A= diff=20--git=20a/test/lisp/misc-tests.el=20b/test/lisp/misc-tests.el=0A= index=20236223ef49..2036488f13=20100644=0A---=20= a/test/lisp/misc-tests.el=0A+++=20b/test/lisp/misc-tests.el=0A@@=20-80,5=20= +80,40=20@@=20misc-test-backward-to-word=0A=20=20=20=20=20= (backward-to-word=203)=0A=20=20=20=20=20(should=20(equal=20(point)=20= 1))))=0A=20=0A+(ert-deftest=20misc--duplicate-line=20()=0A+=20=20;;=20= Duplicate=20a=20line=20(twice).=0A+=20=20(with-temp-buffer=0A+=20=20=20=20= (insert=20"abc\ndefg\nh\n")=0A+=20=20=20=20(goto-char=207)=0A+=20=20=20=20= (duplicate-line=202)=0A+=20=20=20=20(should=20(equal=20(buffer-string)=20= "abc\ndefg\ndefg\ndefg\nh\n"))=0A+=20=20=20=20(should=20(equal=20(point)=20= 7)))=0A+=20=20;;=20Duplicate=20a=20non-terminated=20line.=0A+=20=20= (with-temp-buffer=0A+=20=20=20=20(insert=20"abc")=0A+=20=20=20=20= (goto-char=202)=0A+=20=20=20=20(duplicate-line)=0A+=20=20=20=20(should=20= (equal=20(buffer-string)=20"abc\nabc\n"))=0A+=20=20=20=20(should=20= (equal=20(point)=202)))=0A+=20=20;;=20Duplicate=20a=20region.=0A+=20=20= (with-temp-buffer=0A+=20=20=20=20(insert=20"abc\ndef\n")=0A+=20=20=20=20= (set-mark=202)=0A+=20=20=20=20(goto-char=207)=0A+=20=20=20=20(should=20= (use-region-p))=0A+=20=20=20=20(duplicate-line)=0A+=20=20=20=20(should=20= (equal=20(buffer-string)=20"abc\ndebc\ndef\n"))=0A+=20=20=20=20(should=20= (equal=20(point)=207)))=0A+=20=20;;=20Duplicate=20a=20rectangular=20= region.=0A+=20=20(with-temp-buffer=0A+=20=20=20=20(insert=20= "x\n>a\n>bcde\n>fg\nyz\n")=0A+=20=20=20=20(goto-char=204)=0A+=20=20=20=20= (rectangle-mark-mode)=0A+=20=20=20=20(goto-char=2015)=0A+=20=20=20=20= (rectangle-forward-char=201)=0A+=20=20=20=20(duplicate-line)=0A+=20=20=20= =20(should=20(equal=20(buffer-string)=20"x\n>a=20=20a=20=20= \n>bcdbcde\n>fg=20fg=20\nyz\n"))=0A+=20=20=20=20(should=20(equal=20= (point)=2024))))=0A+=0A=20(provide=20'misc-tests)=0A=20;;;=20= misc-tests.el=20ends=20here=0A--=20=0A2.32.0=20(Apple=20Git-132)=0A=0A= --Apple-Mail=_FD6963D3-E822-4B76-82F1-C13517A0EE3B--