projectile
projectile copied to clipboard
projectile-replace-regexp handling of backslash
Expected behavior
Users may expect projectile-replace-regexp to handle regexp the same way as replace-regexp does (and as described in Emacs docs).
I'm referring to this part: "To include a ‘\’ in the text to replace with, you must enter ‘\’."
Actual behavior
M-x projectile-replace-regexp \\a RET \\b will either do:
- replace occurrences of
\ain the first file where it occurs and then stop replacing when it needs to continue to the next file, or - just fail to replace
\aanywhere and printReplaced 0 occurrences.
What happens seems to depend on what file is opened in the current buffer.
Why don't you just do M-x projectile-replace-regexp \a RET \\b?
- First, it behaves the same way as in 1. above.
- Second, even for the matches in the first file,
\aseems to matcha, resulting in\a -> \\b. - Third,
M-x projectile-replace-regexp \a RET \bresults inInvalid use of ‘\’ in replacement texterror.
Steps to reproduce the problem
mkdir test_project
cd test_project
touch .projectile a.txt b.txt
echo "\a" > a.txt
echo "\a" > b.txt
M-x projectile-replace-regexp \\a RET \\b
Environment & Version information
Projectile version information
Projectile 2.6.0-snapshot
Emacs version
Emacs 27.2
Operating system
Ubuntu 18.04
Seems like this now works properly in Emacs 28.1.
So, a problem that solved itself? My favourite kind! 😆