From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Bob Floyd <bobfloyd@comcast.net>, 45617@debbugs.gnu.org
Subject: bug#45617: <query-replace> loses the edit region. Works in 23.3, broke in 26.3
Date: Mon, 04 Jan 2021 19:37:28 +0200 [thread overview]
Message-ID: <87ble4ob6v.fsf@mail.linkov.net> (raw)
In-Reply-To: <83turycc18.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 03 Jan 2021 16:47:47 +0200")
[-- Attachment #1: Type: text/plain, Size: 551 bytes --]
>> 7. Nothing happens because the region in step (1) has been lost.
>> It should ask to replace 4 ‘_xx’s in the region.
>
> I suspect this is due to changes in how selection works in Emacs.
> Those changes were made in Emacs 24; please see the section "Selection
> changes" in the file etc/NEWS.24, where you will also find
> instructions for getting back the old behavior.
I tried to fix this problem by this patch, and indeed it fixed it,
so the region boundaries are preserved even when changed during
the minibuffer reading the strings:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: query-replace-region.patch --]
[-- Type: text/x-diff, Size: 1119 bytes --]
diff --git a/lisp/replace.el b/lisp/replace.el
index 9765b2b5be..c5acf8fca7 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -395,7 +395,10 @@ query-replace
To customize possible responses, change the bindings in `query-replace-map'."
(interactive
- (let ((common
+ (let ((start (if (use-region-p) (region-beginning)))
+ (end (if (use-region-p) (region-end)))
+ (region-noncontiguous-p (if (use-region-p) (region-noncontiguous-p)))
+ (common
(query-replace-read-args
(concat "Query replace"
(if current-prefix-arg
@@ -407,10 +410,7 @@ query-replace
;; These are done separately here
;; so that command-history will record these expressions
;; rather than the values they had this time.
- (if (use-region-p) (region-beginning))
- (if (use-region-p) (region-end))
- (nth 3 common)
- (if (use-region-p) (region-noncontiguous-p)))))
+ start end (nth 3 common) region-noncontiguous-p)))
(perform-replace from-string to-string t nil delimited nil nil start end backward region-noncontiguous-p))
(define-key esc-map "%" 'query-replace)
[-- Attachment #3: Type: text/plain, Size: 831 bytes --]
But then I noticed this comment in 'query-replace':
;; These are done separately here
;; so that command-history will record these expressions
;; rather than the values they had this time.
And indeed this patch broke this feature, so region boundaries
are saved as numbers in command-history for repeat-complex-command
instead of such code:
C-x M-: (query-replace "a" "z" nil (if (use-region-p) (region-beginning)) (if (use-region-p) (region-end)) nil nil)
But anyway this feature was broken by design and never worked:
with a compiled replace.el it saves region boundaries as numbers,
and only when 'query-replace' is manually evaluated with 'eval-defun',
only then region boundaries are saved as code to command-history.
So we could just delete 'fix_command' from callint.c,
and don't worry about such cases.
next prev parent reply other threads:[~2021-01-04 17:37 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-03 1:05 bug#45617: <query-replace> loses the edit region. Works in 23.3, broke in 26.3 Bob Floyd
2021-01-03 14:47 ` Eli Zaretskii
2021-01-03 19:18 ` Bob Floyd
2021-01-04 17:26 ` Eli Zaretskii
2021-01-04 17:37 ` Juri Linkov [this message]
2021-01-04 22:40 ` Bob Floyd
2021-01-05 18:27 ` Juri Linkov
2021-01-05 19:45 ` Bob Floyd
2021-01-06 17:44 ` Juri Linkov
2021-01-06 18:19 ` Eli Zaretskii
2021-01-06 22:10 ` Bob Floyd
2021-01-13 18:53 ` Juri Linkov
2021-01-15 1:22 ` Bob Floyd
2021-01-15 8:54 ` Juri Linkov
2021-01-15 11:23 ` Eli Zaretskii
2021-01-19 17:45 ` Juri Linkov
2021-01-19 18:39 ` Eli Zaretskii
2021-01-15 18:05 ` Bob Floyd
2021-01-19 17:43 ` Juri Linkov
2021-01-20 22:48 ` Bob Floyd
2021-01-20 23:23 ` Bob Floyd
2021-01-21 21:50 ` Juri Linkov
2021-01-22 17:31 ` Bob Floyd
2021-01-23 17:20 ` Juri Linkov
2021-01-23 18:03 ` Bob Floyd
2021-01-23 18:31 ` Juri Linkov
2021-01-24 20:40 ` Bob Floyd
2021-01-25 17:07 ` Juri Linkov
2021-01-25 18:13 ` Bob Floyd
2021-01-25 18:54 ` Juri Linkov
2021-01-25 19:34 ` Bob Floyd
2021-01-25 19:51 ` Juri Linkov
2021-01-26 0:34 ` Bob Floyd
2021-01-27 9:43 ` Juri Linkov
2021-01-28 16:31 ` Bob Floyd
2021-01-28 18:42 ` Juri Linkov
2021-01-28 21:32 ` Bob Floyd
2021-01-29 8:56 ` Juri Linkov
2021-01-15 18:09 ` Bob Floyd
2021-01-07 18:46 ` Juri Linkov
2021-01-07 19:36 ` Eli Zaretskii
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=87ble4ob6v.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=45617@debbugs.gnu.org \
--cc=bobfloyd@comcast.net \
--cc=eliz@gnu.org \
/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).