I know, Emacs allows calling ELisp while replacing a text with a regex, aka C-M-%, which is bound to query-replace-regexp. I'm trying to make use of that to store an unwieldy regexp as a variable, so instead of writing it out every time, I could just extract it from a variable.
For the sake of simplification, in the testcase here I'm using just a text, so no backslashes are involved:
(setq foo "text")
Text is:
text text
Here's what I tried as the REGEXP in query-replace-regexp:
\,foo\,'foo\,(eval 'foo)\,(eval foo)
None of those work for me. How can I make it work?
C-M-%?query-replace-regexpand asks for a variable to insert.Xoption ofinteractiveto ask for a List expression and evaluate it.query-replace-regexp, it mentions the\,syntax in the replacement text part, but not in the regex part. So AFAICT, you cannot do what you want: you'd have to write your own souped-up version ofquery-replace-regexpas @choroba suggests.