I need to execute a regular expression with case conversion in a entire project. If I run query-replace-regexp
in a single file informing '\([A-Z]+\)'
and '\,(downcase \1)'
, it works as expected. But when I try that with projectile-replace-regexp
I get the following error:
Invalid use of ‘\’ in replacement text
I investigated it a bit and it seems that the elisp expression doesn't work when query-replace-regexp
is not called interactively, because if I run M-:
(replace-regexp "'\\([A-Z_]+'\\)" "'\\,(downcase \\1)")
I also have the error above.
Am I doing something wrong or is this some limitation? If so, is there another way to achieve this?
query-replace-regexp
says "In interactive calls, the replacement text can contain ‘\,’ followed by a Lisp expression. Each replacement evaluates that expression to compute the replacement string. Inside of that expression, ‘\&’ is a string denoting the whole match as a string, ‘\N’ for a partial match, ‘\#&’ and ‘\#N’ for the whole or a partial match converted to a number with ‘string-to-number’, and ‘\#’ itself for the number of replacements done so far (starting with zero)."replace-regexp
says "This function is for interactive use only; in Lisp code usere-search-forward
andreplace-match
instead."query-replace-regexp
behavior then maybe consider filing an enhancement request with its maintainer.replace-regexp
in its name and does not behave like it.