projectile icon indicating copy to clipboard operation
projectile copied to clipboard

projectile-replace-regexp handling of backslash

Open novakboskov opened this issue 3 years ago • 2 comments

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:

  1. replace occurrences of \a in the first file where it occurs and then stop replacing when it needs to continue to the next file, or
  2. just fail to replace \a anywhere and print Replaced 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, \a seems to match a, resulting in \a -> \\b.
  • Third, M-x projectile-replace-regexp \a RET \b results in Invalid use of ‘\’ in replacement text error.

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

novakboskov avatar Mar 28 '22 23:03 novakboskov

Seems like this now works properly in Emacs 28.1.

novakboskov avatar Apr 11 '22 04:04 novakboskov

So, a problem that solved itself? My favourite kind! 😆

bbatsov avatar Oct 30 '22 05:10 bbatsov