unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: Paulo Sousa <de.sousa.paulus@gmail.com>, 55234@debbugs.gnu.org
Subject: bug#55234: 28.1; replace-string in rectangle regio
Date: Fri, 03 Jun 2022 21:09:31 +0300	[thread overview]
Message-ID: <86wndxwqgk.fsf@mail.linkov.net> (raw)
In-Reply-To: <86wndynq93.fsf@mail.linkov.net> (Juri Linkov's message of "Fri,  03 Jun 2022 10:46:32 +0300")

[-- Attachment #1: Type: text/plain, Size: 443 bytes --]

>>>>   (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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: rectangle--region-beginning.patch --]
[-- Type: text/x-diff, Size: 1939 bytes --]

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

  reply	other threads:[~2022-06-03 18:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-02 22:36 bug#55234: 28.1; replace-string in rectangle regio Paulo Sousa
2022-05-03  6:57 ` Juri Linkov
2022-06-01 11:42   ` Michael Heerdegen
2022-06-01 19:23     ` Juri Linkov
2022-06-02 12:20       ` Michael Heerdegen
2022-06-02 17:19         ` Juri Linkov
2022-06-03  7:46           ` Juri Linkov
2022-06-03 18:09             ` Juri Linkov [this message]
2022-06-04 13:20               ` Michael Heerdegen
2022-06-06  7:43                 ` Juri Linkov
2022-06-09 11:12                   ` Michael Heerdegen
2022-06-09 17:05                     ` Juri Linkov
2022-06-02 17:23         ` Juri Linkov
2022-06-03  9:37           ` Michael Heerdegen
2022-06-08 17:10 ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86wndxwqgk.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=55234@debbugs.gnu.org \
    --cc=de.sousa.paulus@gmail.com \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).