wincent/ferret

Multi-word :Ack gives me errors

Closed this issue · 7 comments

I'm trying to switch from my Ack configuration I stole from your dotfiles ages ago to ferret, and I'm running into issues when trying to :Ack for multi-word strings. I've tried :Ack "foo bar", :Ack 'foo bar', :Ack /foo bar/, :Ack \foo bar\, and :Ack foo bar and I always get the same type of error (these errors are for the version with double quotes):

ERR: Error stat()ing: bar"
ERR: Error opening directory bar": No such file or directory

I tried both with and without vim-dispatch and had similar results.

Ah, I just read this from the documentation:

The {pattern} is passed through as-is to the underlying search program, and no escaping is required other than preceding spaces by a single backslash.

So it seems that I am doing this wrong and :Ack foo\ bar works. I suppose this is as designed, but is a little unexpected to me that adding quotes doesn't work since that is what I am accustomed to (both with my previous version of :Ack and with running ag or ack from the command line).

You want :Ack foo\ bar.

The only thing you ever need to escape are spaces in the search pattern.
Not options, or directories etc. Never use quotes.
On Sun, Jul 12, 2015 at 9:52 AM Joe Lencioni notifications@github.com
wrote:

I'm trying to switch from my Ack configuration I stole from your dotfiles
ages ago to ferret, and I'm running into issues when trying to :Ack for
multi-word strings. I've tried :Ack "foo bar", :Ack 'foo bar', :Ack /foo
bar/, :Ack \foo bar, and :Ack foo bar and I always get the same type of
error (these errors are for the version with double quotes):

ERR: Error stat()ing: bar"
ERR: Error opening directory bar": No such file or directory

I tried both with and without vim-dispatch and had similar results.


Reply to this email directly or view it on GitHub
#1.

I suppose this is as designed, but is a little unexpected to me that adding quotes doesn't work since that is what I am accustomed to

Yep, I understand that, but I think this is strictly better. The idea is to make stuff like this easy:

:Ack \blog\((['"]).*?\1\) -i --ignore-dir=src/vendor src dist build

ie. arbitrarily complex Perl-compatible regex syntax — in this case, parens, square brackets, single and double quotes, back references etc — without having to think about shell escaping rules. I think the abstraction used in the editor should isolate you from having to think about the shell. So, with this system there is still one rule to remember (escape spaces in the search pattern), but that's all.

I think I could add to the docs to make this more obvious, or add special casing to detect when people seem to be mis-using quotes. Thoughts?

Yeah, this makes sense to me.

I think I could add to the docs to make this more obvious, or add special casing to detect when people seem to be mis-using quotes. Thoughts?

In my experience, documentation can almost always be improved, but I doubt that will help too much. I think the special casing could help newcomers a lot, so that would get my vote of the two, but both are probably worth doing.

It might also be worth considering changing the command from one that matches a shell command to something either generic (e.g. :FindInFiles) or new (e.g. :Ferret). :Ack even starts out as a bit of a misnomer anyway since ferret prefers ag over ack.

Yeah, the :Ack thing is purely for the benefit of my muscle memory, because back in ancient history (wincent/wincent@61a7e2a, the very first commit in my dotfiles repo), :Ack was a wrapper for ack. I should probably make :Ferret, :Ferrets as synonyms (and :Lack would become... not sure).

mwcz commented

(and :Lack would become... not sure).

:Fack

Ok, I've "fixed" this with some doc updates, and I've opened #10 to track the addition of helpful error messages.