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

:AgBuffer fix for legacy --column users #89

Merged
merged 1 commit into from
Feb 14, 2015

Conversation

ches
Copy link

@ches ches commented Feb 6, 2015

Prior to the --vimgrep option being added, it was very hard to get Ag to output file names consistently if only one file was searched rather than multiple files or a directory.

TL;DR on that, it meant that if you ran an :AgBuffer search when you had only opened one buffer in your Vim session, quickfix navigation would be broken for the results (no file names in the output).

The changed incantation of ag in this commit is the best behavior I was able to get out of earlier Ag versions, after a long saga. It has one minor drawback: it results in empty newlines between results for different files, where a heading might otherwise be. This is a small cosmetic problem that probably isn't worth special-case code to parse out—Vim's quickfix parses it just fine and skips over these blank lines on :cnext without any glitch or extra keystrokes. This seems a worthwhile exchange for the outright bug of the single-buffer case.

References d42171e

Prior to the `--vimgrep` option being added, it was very hard to get Ag
to output file names consistently if only one file was searched rather
than multiple files or a directory [1].

This meant that if you ran an `:AgBuffer` search when you had only
opened one buffer in your Vim session, quickfix navigation would be
broken for your results.

The changed incantation of `ag` in this commit is the best behavior I
was able to get out of earlier Ag versions, after a long saga. It has
one minor drawback: it results in empty newlines between results for
different files, where a heading might otherwise be. This is a small
cosmetic problem--Vim's quickfix parses it just fine and skips over
these on `:cnext` without any glitch or extra keystrokes. This seems a
worthwhile exchange for the outright bug of the single-buffer case.

References d42171e

[1]: ggreer/the_silver_searcher#361
@losingkeys
Copy link
Collaborator

The new g:ag_prg command works for me with ag 0.29.0. However that version of ag says that --nogroup implies --nobreak --noheading. If that's the case, wouldn't we only need --nogroup? Maybe that's a recent change to ag. Also, if --nobreak is in there, shouldn't it not give us that extra newline?

Thanks again for your work on this, especially the doc update.

@ches
Copy link
Author

ches commented Feb 7, 2015

Yeah, on current ag versions, the --vimgrep option is definitely the way to go, it's finally exactly what these plugins need.

The main point of this change is fixing the fact that ag --column alone is totally broken with :AgBuffer if you only have one buffer open, you can see that with current ag by changing g:ag_prg to that. So anyone still on older ag is going to run into this by default.

As for the specifics of the arguments, I'd have to confirm for certain after installing an older ag since I've now upgraded, but as you can tell from the issue I linked, I spent a lot of time trying combinations before --vimgrep existed. A lot of combinations did not (and still do not on current ag) produce results you'd expect from the names and docs. What I can remember at the moment without trying an old version is simply that ag --column --nogroup --noheading was the best result I was ever able to get 😄 And it's 95% perfect for ag.vim usage.

ches pushed a commit to ches/ag.vim that referenced this pull request Feb 7, 2015
@losingkeys
Copy link
Collaborator

Ohh, I was testing it wrong (changing some logic in the plugin instead of changing g:ag_prg).

I guess I'm still confused as to why --nobreak doesn't prevent the extra newline, and why we would need --noheading if we have --nogroup (the help output suggests the first implies the second).

@ches
Copy link
Author

ches commented Feb 13, 2015

I guess I'm still confused as to why --nobreak doesn't prevent the extra newline, and why we would need --noheading if we have --nogroup (the help output suggests the first implies the second).

Sorry if I sound impatient, but what I've tried to make clear is that ag's handling of its options is at times nonintuitive and at others downright zany. It's changed at times from version to version but there are still a lot of cases where it doesn't make sense and possibly contradicts documentation.

You can take my word for it that this set of options, however senseless it may seem, was the best result I could get before --vimgrep existed; or you could test a bunch of combinations on an old version yourself; or you could read the issue I first linked in the PR including the most recent comment where I've saved you some time of trying all that; or you could just close this as wontfix, it won't hurt my feelings 😄

But if you happen to get a report from any user of an older ag version that they can't open results from :AgBuffer, recall this issue and send them a link 😄

@losingkeys
Copy link
Collaborator

Just double checking some of your research 😄. Thanks again for the pull!

losingkeys added a commit that referenced this pull request Feb 14, 2015
:AgBuffer fix for legacy --column users
@losingkeys losingkeys merged commit f05f313 into rking:master Feb 14, 2015
@ches ches deleted the single-agbuffer-fix branch February 20, 2015 11:53
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 this pull request may close these issues.

2 participants