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: Fri, 03 Jun 2022 21:09:31 +0300 Organization: LINKOV.NET Message-ID: <86wndxwqgk.fsf@mail.linkov.net> References: <868rrj6r37.fsf@mail.linkov.net> <87bkvcboei.fsf@web.de> <86tu94193i.fsf@mail.linkov.net> <87zgivntno.fsf@web.de> <86czfrx9s6.fsf@mail.linkov.net> <86wndynq93.fsf@mail.linkov.net> 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="36159"; 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 Fri Jun 03 20:32:17 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 1nxC5p-0009C9-9Q for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 03 Jun 2022 20:32:17 +0200 Original-Received: from localhost ([::1]:41910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nxC5n-0003Ty-OX for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 03 Jun 2022 14:32:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nxC5a-0003Tp-3n for bug-gnu-emacs@gnu.org; Fri, 03 Jun 2022 14:32:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34878) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nxC5Z-0007Gb-R1 for bug-gnu-emacs@gnu.org; Fri, 03 Jun 2022 14:32:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nxC5Z-0007aR-Lj for bug-gnu-emacs@gnu.org; Fri, 03 Jun 2022 14:32: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: Fri, 03 Jun 2022 18:32: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.165428109027679 (code B ref 55234); Fri, 03 Jun 2022 18:32:01 +0000 Original-Received: (at 55234) by debbugs.gnu.org; 3 Jun 2022 18:31:30 +0000 Original-Received: from localhost ([127.0.0.1]:57008 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nxC53-0007C3-LJ for submit@debbugs.gnu.org; Fri, 03 Jun 2022 14:31:29 -0400 Original-Received: from relay8-d.mail.gandi.net ([217.70.183.201]:50169) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nxC50-00073o-9b for 55234@debbugs.gnu.org; Fri, 03 Jun 2022 14:31:28 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id C34451BF209; Fri, 3 Jun 2022 18:31:18 +0000 (UTC) In-Reply-To: <86wndynq93.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 03 Jun 2022 10:46:32 +0300") 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:233620 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: >> >> diff --git a/lisp/rect.el b/lisp/rect.el >> +(advice-add 'region-beginning :around #'rectangle--region-beginning) > > This causes a strange compilation error: > Symbol's function definition is void: easy-menu-define This patch avoids such problem: --=-=-= 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..334c6f59fd 100644 --- a/lisp/rect.el +++ b/lisp/rect.el @@ -656,6 +656,8 @@ rectangle-mark-mode :lighter nil (rectangle--reset-crutches) (when rectangle-mark-mode + (advice-add 'region-beginning :around #'rectangle--region-beginning) + (advice-add 'region-end :around #'rectangle--region-end) (add-hook 'deactivate-mark-hook (lambda () (rectangle-mark-mode -1))) (unless (region-active-p) @@ -754,17 +756,38 @@ 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))))) + +(defun rectangle--region-end (orig) + "Like `region-end' but supports rectangular regions." + (cond + ((not rectangle-mark-mode) + (funcall orig)) + (t + (cdar (last (region-bounds)))))) + (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 --=-=-=--