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#55234: 28.1; replace-string in rectangle regio Date: Thu, 02 Jun 2022 20:19:53 +0300 Organization: LINKOV.NET Message-ID: <86czfrx9s6.fsf@mail.linkov.net> References: <868rrj6r37.fsf@mail.linkov.net> <87bkvcboei.fsf@web.de> <86tu94193i.fsf@mail.linkov.net> <87zgivntno.fsf@web.de> 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="39909"; 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: Paulo Sousa , 55234@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 02 19:33:33 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 1nwohQ-000ACE-82 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 02 Jun 2022 19:33:32 +0200 Original-Received: from localhost ([::1]:42526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwohO-00034Z-Gs for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 02 Jun 2022 13:33:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwogw-00031i-4o for bug-gnu-emacs@gnu.org; Thu, 02 Jun 2022 13:33:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwogv-0004Ai-SB for bug-gnu-emacs@gnu.org; Thu, 02 Jun 2022 13:33:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nwogv-0008GJ-Mv for bug-gnu-emacs@gnu.org; Thu, 02 Jun 2022 13:33:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Jun 2022 17:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55234 X-GNU-PR-Package: emacs Original-Received: via spool by 55234-submit@debbugs.gnu.org id=B55234.165419113331687 (code B ref 55234); Thu, 02 Jun 2022 17:33:01 +0000 Original-Received: (at 55234) by debbugs.gnu.org; 2 Jun 2022 17:32:13 +0000 Original-Received: from localhost ([127.0.0.1]:54555 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nwog9-0008F1-75 for submit@debbugs.gnu.org; Thu, 02 Jun 2022 13:32:13 -0400 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:43131) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nwog7-0008Ea-OU for 55234@debbugs.gnu.org; Thu, 02 Jun 2022 13:32:12 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 42FBD4000A; Thu, 2 Jun 2022 17:32:05 +0000 (UTC) In-Reply-To: <87zgivntno.fsf@web.de> (Michael Heerdegen's message of "Thu, 02 Jun 2022 14:20:43 +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:233561 Archived-At: --=-=-= Content-Type: text/plain >> (mapcar 'car (region-bounds)) > > Sounds reasonable. Then here is the implementation that is more less in line with how other rectangular functions are implemented: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=rectangle--region-beginning.patch diff --git a/lisp/rect.el b/lisp/rect.el index 15d636f074..cb545f473a 100644 --- a/lisp/rect.el +++ b/lisp/rect.el @@ -754,17 +754,42 @@ rectangle-previous-line (rectangle--col-pos col 'point))) +(defun rectangle--region-beginning (orig) + "Like `region-beginning' but supports rectangular regions." + (cond + ((not rectangle-mark-mode) + (funcall orig)) + (t + (caar (region-bounds))))) + +(advice-add 'region-beginning :around #'rectangle--region-beginning) + +(defun rectangle--region-end (orig) + "Like `region-end' but supports rectangular regions." + (cond + ((not rectangle-mark-mode) + (funcall orig)) + (t + (cdar (last (region-bounds)))))) + +(advice-add 'region-end :around #'rectangle--region-end) + (defun rectangle--extract-region (orig &optional delete) (cond ((not rectangle-mark-mode) (funcall orig delete)) ((eq delete 'bounds) - (extract-rectangle-bounds (region-beginning) (region-end))) + (extract-rectangle-bounds + ;; Avoid recursive calls + (let (rectangle-mark-mode) (region-beginning)) + (let (rectangle-mark-mode) (region-end)))) (t (let* ((strs (funcall (if delete #'delete-extract-rectangle #'extract-rectangle) - (region-beginning) (region-end))) + ;; Avoid recursive calls + (let (rectangle-mark-mode) (region-beginning)) + (let (rectangle-mark-mode) (region-end)))) (str (mapconcat #'identity strs "\n"))) (when (eq last-command 'kill-region) ;; Try to prevent kill-region from appending this to some --=-=-=--