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#56418: Add duplicate-dwim [PATCH] Date: Wed, 6 Jul 2022 10:29:29 +0200 Message-ID: <4D430D59-39C0-40DE-862F-FAE7103D1705@acm.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_707EA524-5333-4660-A739-E74A2038E902" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13707"; mail-complaints-to="usenet@ciao.gmane.io" To: 56418@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jul 06 12:09:44 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 1o91yZ-0003KE-Tk for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 06 Jul 2022 12:09:44 +0200 Original-Received: from localhost ([::1]:43850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o91yX-0002wp-CL for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 06 Jul 2022 06:09:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o90Q7-0001Vz-So for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2022 04:30:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58313) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o90Q6-0001L6-PC for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2022 04:30:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o90Q6-0003hO-Kk for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2022 04:30:02 -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: Wed, 06 Jul 2022 08:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 56418 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.165709618614155 (code B ref -1); Wed, 06 Jul 2022 08:30:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Jul 2022 08:29:46 +0000 Original-Received: from localhost ([127.0.0.1]:52210 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o90Pp-0003gE-OF for submit@debbugs.gnu.org; Wed, 06 Jul 2022 04:29:46 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:53658) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o90Pm-0003g4-E8 for submit@debbugs.gnu.org; Wed, 06 Jul 2022 04:29:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o90Pm-0001I2-79 for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2022 04:29:42 -0400 Original-Received: from mail155c50.megamailservers.eu ([91.136.10.165]:54184 helo=mail51c50.megamailservers.eu) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o90Pj-0001IT-9u for bug-gnu-emacs@gnu.org; Wed, 06 Jul 2022 04:29:41 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1657096175; bh=B7exODcssxvmrmqbPMTYIhnTqVJ3tpqedQGiJoSPZCc=; h=From:Subject:Date:To:From; b=XCbq+Vu8K7iPPgJjt+2b60nvD+mq8uG7yUG8oBtW4+NICRZ74pILcNJzCa7ooyP7g GKIUZQlzHmGUlNjeE6vS/ur0rDZ+FWm4d9Kaf+Wn2f/5CsnggVwhIX+pzaXLX24gZV 8FPK/7PJ5MBrq8OvcPyZKG76D3JvuMVllUtGqdZw= 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 mail51c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 2668TUCF021837 for ; Wed, 6 Jul 2022 08:29:34 +0000 X-Mailer: Apple Mail (2.3654.120.0.1.13) X-CTCH-RefID: str=0001.0A782F23.62C547EF.000E, 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 Received-SPF: softfail client-ip=91.136.10.165; envelope-from=mattiase@acm.org; helo=mail51c50.megamailservers.eu X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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" Xref: news.gmane.io gmane.emacs.bugs:236207 Archived-At: --Apple-Mail=_707EA524-5333-4660-A739-E74A2038E902 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii This patch adds duplicate-swim, a command that works like duplicate-line = but works on the region if active. It corresponds exactly to = upcase-dwim, downcase-dwim and capitalize-dwim which have become quite = popular. Rectangular regions are treated specially by duplicating on the = right-hand side. This behaviour turns out to be the most convenient one, = and is also confluent with that of ordinary regions when the rectangle = is only one line tall. --Apple-Mail=_707EA524-5333-4660-A739-E74A2038E902 Content-Disposition: attachment; filename=0001-Add-duplicate-dwim.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Add-duplicate-dwim.patch" Content-Transfer-Encoding: quoted-printable =46rom=20abff5e9e5edcf43c06ca9df2c8c51248f6904b3b=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]=20Add=20duplicate-dwim=0A=0ALike=20duplicate-line=20= but=20duplicates=20the=20region=20instead=20if=20active.=0ARectangular=20= regions=20are=20duplicated=20on=20the=20right-hand=20side.=0AThe=20= region=20remains=20active=20afterwards,=20to=20facilitate=20further=0A= duplication=20or=20other=20operations=20on=20the=20same=20text.=0A=0A*=20= lisp/rect.el=20(rectangle--duplicate-right):=0A*=20lisp/misc.el=20= (duplicate-dwim):=20New.=0A*=20test/lisp/misc-tests.el=20= (misc--duplicate-dwim):=20New=20test.=0A---=0A=20lisp/misc.el=20=20=20=20= =20=20=20=20=20=20=20=20|=2037=20+++++++++++++++++++++++++++++++++++++=0A= =20lisp/rect.el=20=20=20=20=20=20=20=20=20=20=20=20|=2021=20= +++++++++++++++++++++=0A=20test/lisp/misc-tests.el=20|=2038=20= ++++++++++++++++++++++++++++++++++++++=0A=203=20files=20changed,=2096=20= insertions(+)=0A=0Adiff=20--git=20a/lisp/misc.el=20b/lisp/misc.el=0A= index=2028c5d6e07f..a53571f463=20100644=0A---=20a/lisp/misc.el=0A+++=20= b/lisp/misc.el=0A@@=20-79,6=20+79,43=20@@=20duplicate-line=0A=20=20=20=20= =20=20=20(dotimes=20(_=20n)=0A=20=20=20=20=20=20=20=20=20(insert=20line=20= "\n")))))=0A=20=0A+(declare-function=20rectangle--duplicate-right=20= "rect"=20(n))=0A+=0A+;;=20`duplicate-dwim'=20preserves=20an=20active=20= region=20and=20changes=20the=20buffer=0A+;;=20outside=20of=20it:=20= disregard=20the=20region=20when=20immediately=20undoing=20the=0A+;;=20= actions=20of=20this=20command.=0A+(put=20'duplicate-dwim=20= 'undo-inhibit-region=20t)=0A+=0A+;;;###autoload=0A+(defun=20= duplicate-dwim=20(&optional=20n)=0A+=20=20"Duplicate=20the=20current=20= line=20or=20region=20N=20times.=0A+If=20the=20region=20is=20inactive,=20= duplicate=20the=20current=20line=20(like=20`duplicate-line').=0A= +Otherwise,=20duplicate=20the=20region,=20which=20remains=20active=20= afterwards.=0A+If=20the=20region=20is=20rectangular,=20duplicate=20on=20= its=20right-hand=20side.=0A+Interactively,=20N=20is=20the=20prefix=20= numeric=20argument,=20and=20defaults=20to=201."=0A+=20=20(interactive=20= "p")=0A+=20=20(unless=20n=0A+=20=20=20=20(setq=20n=201))=0A+=20=20(cond=0A= +=20=20=20;;=20Duplicate=20rectangle.=0A+=20=20=20((bound-and-true-p=20= rectangle-mark-mode)=0A+=20=20=20=20(rectangle--duplicate-right=20n)=0A+=20= =20=20=20(setq=20deactivate-mark=20nil))=0A+=0A+=20=20=20;;=20Duplicate=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=20(duplicate-line=20n))))=0A+=0A=20;;=20= Variation=20of=20`zap-to-char'.=0A=20=0A=20;;;###autoload=0Adiff=20--git=20= a/lisp/rect.el=20b/lisp/rect.el=0Aindex=20e717d2ac7e..c41a545e85=20= 100644=0A---=20a/lisp/rect.el=0A+++=20b/lisp/rect.el=0A@@=20-931,6=20= +931,27=20@@=20rectangle--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=20rol)=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=20a56feaa049..f84827ab02=20100644=0A---=20= a/test/lisp/misc-tests.el=0A+++=20b/test/lisp/misc-tests.el=0A@@=20-96,5=20= +96,43=20@@=20misc--duplicate-line=0A=20=20=20=20=20(should=20(equal=20= (buffer-string)=20"abc\nabc\n"))=0A=20=20=20=20=20(should=20(equal=20= (point)=202))))=0A=20=0A+(require=20'rect)=0A+=0A+(ert-deftest=20= misc--duplicate-dwim=20()=0A+=20=20;;=20Duplicate=20a=20line.=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-dwim=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)=207)))=0A+=0A+=20=20;;=20Duplicate=20= a=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=20= 7)=0A+=20=20=20=20(transient-mark-mode)=0A+=20=20=20=20(should=20= (use-region-p))=0A+=20=20=20=20(duplicate-dwim)=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=20=20(should=20(region-active-p))=0A+=20= =20=20=20(should=20(equal=20(mark)=202)))=0A+=0A+=20=20;;=20Duplicate=20= a=20rectangular=20region.=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-dwim)=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+=20=20=20=20(should=20(region-active-p))=0A+=20=20=20=20= (should=20rectangle-mark-mode)=0A+=20=20=20=20(should=20(equal=20(mark)=20= 4))))=0A+=0A=20(provide=20'misc-tests)=0A=20;;;=20misc-tests.el=20ends=20= here=0A--=20=0A2.32.0=20(Apple=20Git-132)=0A=0A= --Apple-Mail=_707EA524-5333-4660-A739-E74A2038E902--