Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

projectile-replace stomps regular expressions #576

Closed
seanfisk opened this issue Dec 13, 2014 · 6 comments · Fixed by #977
Closed

projectile-replace stomps regular expressions #576

seanfisk opened this issue Dec 13, 2014 · 6 comments · Fixed by #977

Comments

@seanfisk
Copy link
Contributor

I'll start with a question, because I'm a little unclear: Is projectile-replace supposed to support regular expressions?

This issue mostly has to do with improvements introduced in #269 by @shosti. projectile-replace uses tags-query-replace, which uses Emacs regular expressions. However, projectile-files-with-string stomps entered regexp under certain conditions.

I'm working on Mac OS X ((projectile-unixy-system-p)t). I have ag, ack, git grep, and grep (henceforth "grep tools") installed. Under these conditions, ag is selected, and then passed the --literal flag, removing meaning from my regexp query. That's what led me to the problem, but that's not the only issue.

Summary:

  • Each of the grep tools has their own interpretation of regular expressions, and
  • None of these match how Emacs (i.e., tags-query-replace) interprets them [AFAIK]. Furthermore,
  • All of the grep tools can handle literal matches more or less the same, but
  • tags-query-replace doesn't support literal matches.

It might be possible to somewhat accurately use the grep tools to speed up literal matches, providing a literal version of tags-query-replace could be created. However, I don't see a clear way that the file list could be narrowed for a regular expression replace without finding a tool that exactly emulates Emacs' regular expressions.

Though filtering files through a faster tool is a significant benefit, it comes at the cost of accuracy. This might not seem to be a big deal, but it's very unexpected when matches you think should be replaced aren't being replaced. In this case, I think accuracy trumps speed.

I'm willing to implement a solution if there is agreement on the desired behavior. Projectile rocks and I love using it! Thanks!

@shosti
Copy link
Contributor

shosti commented Dec 13, 2014

To me, what would make the most sense would be to have two functions, projectile-replace and projectile-replace-regexp. It's unfortunate that tags-query-replace doesn't have a literal matching option, but I think it could be worked around either with some hacking or by escaping special characters in the search string. projectile-replace-regexp would have to use a straight tags-query-replace I think, since the problem of translating Emacs regexps to grep regexps seems much too hard.

@seanfisk
Copy link
Contributor Author

@shosti Agree completely.

The code for tags-query-replace looks somewhat simple to convert to non-regexp at first glance. query-replace-read-args takes a Boolean regexp-flag which could be passed as nil, and re-search-forward could be changed to search-forward.

@Catalectic
Copy link

:+1 for fixing that issue, is there any consensus/interest on supporting regexps across all grep tools for projectile-replace?

@seanfisk
Copy link
Contributor Author

@Catalectic It's probably possible but I'm not sure it's practical. The problem is that almost all regexp tools have their own subtle differences.

Possibly check out https://github.com/joddie/pcre2el.

@d12frosted
Copy link

Any updates in this issue? Or maybe any alternatives? :) Better to have not very sufficient method for projectile-replace-regexp than not having it at all.

@seanfisk
Copy link
Contributor Author

@d12frosted I don't think anybody has really worked on it. Seeing this again, though, it does bother me that I still can't reliably replace by regexp. I may try to throw together a PR soon. I'll keep this thread updated.

bbatsov added a commit that referenced this issue Mar 12, 2016
[Fix #576] Implement `projectile-replace-regexp'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants