Subject: bug#77973: 30.1; `which-key' breaks `string-rectangle' after popup shown

From: Alcor <[email-masked]>
Date: Wed, 23 Apr 2025 17:33:59 +0200

Eli Zaretskii <[email-masked]> writes:

> My bother with commit 3a8222e is that it uses move-to-column, which
> might behave in surprising ways when there are 'display' properties,
> TABs, composed characters, and other display features around.
>
> Did someone try the new code in those cases?  If not, I'd like you or
> someone else to try that first, because I'd like to avoid introducing
> regressions into Emacs 30.2.

I tested a cherry-picked 3a8222e with composite emojis and tabs and
haven't observed any differences vs. plain 30.1 (see attachment). Not
sure about "other display features" though. And 3a8222e isn't a recent
change either - it's about ~9 months old, so I'd assume it has been
incubating long enough for problems to be noticable (?).

As an alternative, the following more trivial patch can be applied onto
the emacs-30 branch. It merely binds `rectangle-mark-mode' to nil during
the `region-bounds' call to protect against infinite recursion (as done
elsewhere in rect.el):

--- lisp/rect.el
+++ #<buffer rect.el.gz>
@@ -766,7 +766,7 @@
    ((not rectangle-mark-mode)
     (funcall orig))
    (t
-    (apply #'min (mapcar #'car (region-bounds))))))
+    (apply #'min (mapcar #'car (let (rectangle-mark-mode) (region-bounds)))))))
 
 (defun rectangle--region-end (orig)
   "Like `region-end' but supports rectangular regions."
@@ -774,7 +774,7 @@
    ((not rectangle-mark-mode)
     (funcall orig))
    (t
-    (apply #'max (mapcar #'cdr (region-bounds))))))
+    (apply #'max (mapcar #'cdr (let (rectangle-mark-mode) (region-bounds)))))))
 
 (defun rectangle--extract-region (orig &optional delete)
   (cond