Improve back-slash handling to reduce confusion
xbot opened this issue · 6 comments
Either :Ack App\\\Link
or :Ack App\\\\Link
will find App\Link
.
Why ? Won't it be easier to be understood with :Ack App\\Link
?
You should be confused because it is confusing. There are multiple levels of escaping happening here, I think:
- The shell in which the
ack
/ag
command performs escaping. - The
ack
/ag
performs Perl-Compatible Regular Expression escaping too.
I think the shell in particular makes this tricky to understand, as evidenced by this Stack Exchange post.
@wincent Thanks. Now I understand what happened. The other question is, won't it be more readable for the inputed regular expression if Ferret do the extra escaping ?
That's an interesting idea. If it could be done reliably, that would be great. Having to be aware of the complicated escaping rules definitely makes the current set-up a leaky abstraction.
The only "gotcha" I can think of here is that depending on which mode Ferret is running in (using modern vim "async" primitives, using the vim-dispatch plug-in, or falling back to the legacy code path), the exact method used to launch the underlying tool may vary, so the escaping requirements may be different. We'd want to look into that to be sure that all the cases are correctly handled.
I think I have this working fairly nicely now on the "next" branch. Have tested with async Neovim, async Vim 8, and vanilla (non-async) Vim-8. Haven't bothered to test with vim-dispatch, yet, but I will. If I haven't run into any issues with this in a few days, will merge to master.
Currently, I use ferret with rg to search for patterns. If the pattern is complicated, it is likely that it's not compatible with :Acks
, so I have to escape some characters manually since I'm using the very magic option \v
with :Acks
.
I think it would be better if there is an option with which I can hook a customized function to escape characters when :Acks
is executed, that would be a big boost to efficiency!