GNU bug report logs - #62505
29.0.60; Switching between query-replace and query-replace-regexp should be easy, like isearch

Previous Next

Package: emacs;

Reported by: Spencer Baugh <sbaugh <at> janestreet.com>

Date: Tue, 28 Mar 2023 15:35:02 UTC

Severity: normal

Found in version 29.0.60

Full log


View this message in rfc822 format

From: Juri Linkov <juri <at> linkov.net>
To: Spencer Baugh <sbaugh <at> janestreet.com>
Cc: 62505 <at> debbugs.gnu.org
Subject: bug#62505: 29.0.60; Switching between query-replace and query-replace-regexp should be easy, like isearch
Date: Sat, 13 Sep 2025 21:37:56 +0300
>> There is such logic in 'query-replace-read-from':
>>
>>               (if regexp-flag
>>                   (read-regexp ...)
>>                 (read-from-minibuffer ...))
>>
>> Changing the value of 'regexp-flag' while the minibuffer is active will require
>> canceling the current minibuffer and restarting 'query-replace' from scratch.
>
> Ah.  Right, troubling.
>
> Hmm...
>
> I guess we could give read-regexp a "non-regexp" or "plain text" mode,
> which can be toggled on and off by the user, and just always call
> read-regexp.  Then read-regexp could return "this string isn't a regex"
> using a text property on the string, just as it returns the text
> property case-fold right now.
>
> Then after we return from read-regexp we could read that text property
> and set regexp-flag based on it.
>
> What do you think?  Too hacky?

Admittedly, it's too hacky: the single purpose of 'read-regexp' is to
read a regexp, so switching to the string mode would defeat its purpose.

>> However, how to implement toggling the regexp mode while using query-replace
>> is clear and is implemented in this patch:
>
> Nice!  I tried it and it works.
>
> Though, one issue is that if you start a query-replace that was meant to
> be a query-replace-regexp, it will probably not have any matches, so it
> will immediately fail.  Though I guess in that case one can just
> immediately do C-M-%.

Yes, I noticed this too.  And indeed it's easy to just do 'C-M-% RET'
that reuses the last search→replace pair in regexp mode.

Also it helps to notice the mistake earlier by looking at the number of
matches at the beginning of the minibuffer while typing a string to replace
that shows "0" for no matches.




This bug report was last modified 6 days ago.

Previous Next


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