GNU bug report logs - #55234
28.1; replace-string in rectangle regio

Previous Next

Package: emacs;

Reported by: Paulo Sousa <de.sousa.paulus <at> gmail.com>

Date: Mon, 2 May 2022 23:34:02 UTC

Severity: normal

Found in version 28.1

Fixed in version 29.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Juri Linkov <juri <at> linkov.net>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: Paulo Sousa <de.sousa.paulus <at> gmail.com>, 55234 <at> debbugs.gnu.org
Subject: bug#55234: 28.1; replace-string in rectangle regio
Date: Fri, 03 Jun 2022 21:09:31 +0300
[Message part 1 (text/plain, inline)]
>>>>   (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:

[rectangle--region-beginning.patch (text/x-diff, inline)]
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

This bug report was last modified 3 years and 41 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.