Closed paulhybryant closed 9 years ago
Fantastic! I was hoping to add this functionality in the future. Not sure if there's an open issue for it or not.
One question I had when thinking about this was: how does this work for modified buffers? How should it work? What would most users expect?
I didn't see an issue open for this feature.
That is a great question. Did some experiment just now. The current behavior seems to be that if a buffer is modified, both Ag / AgBuffer will cause the buffer to be saved, and the modified content will be available in the search result.
As a user, my initial expectation is that the modified buffer will be left in modified state, and the modified contents won't be available in the search result.
However, knowing that saving the buffer is a side effect of running Ag, this behavior seems reasonable to me (I am saving very frequently anyways). Not sure what others would think though.
I think not searching the motified buffer is fine (though confusing, so we can document it).
Since when are open buffers saved after running this plugin? Or does this pull introduce that?
This pull does not introduce the behavior of saving buffers. It is already there before the pull.
On Fri, Jan 2, 2015 at 7:38 PM, Josh Hoff notifications@github.com wrote:
I think not searching the motified buffer is fine (though confusing, so we can document it).
Since when are open buffers saved after running this plugin? Or does this pull introduce that?
— Reply to this email directly or view it on GitHub https://github.com/rking/ag.vim/pull/80#issuecomment-68581775.
With Regards,
Yu Huang
Software Engineer, Google Inc.
Oh strange. Sorry I hadn't seen your earlier comment when I asked the question. I'm not sure that saving buffers when searching is expected behavior. It should either be reverted or documented.
Agree. Documenting the behavior might not be related to this pull though. Any comments on this pull so that we can merge it? Thanks :)!
Just a couple more things.
I found out that this plugin doesn't save files before running, unless you enable the 'autowrite' option. That's why it's saving files for you, but not for me.
One more problem I noticed with this plugin though, is that if you have a directory open (:edit $PWD
), which is something I do a lot because I use vim-vinegar, then the folder will show up in the buffer list, and be searched through by :AgBuffer
. This might give you more results than expected. Do you think it should ignore folders?
Finally, could you make a documentation commit that describes this command? It'd be nice to have a disclaimer about searching through files rather than exact buffers; something like this?:
Note: this will not find your changes in modified buffers (it really only searches the files that match your open buffers). You can save buffers automatically when searching with the 'autowrite' option.
Thanks for the findings about 'autowrite'.
I think we should definitely ignore folders. If searching the folder is desired, the users should use :Ag [pattern] [folder] to search under this folder. I have made changes to ignore the buffer if that is a folder and also updated the documentation.
I found one more issue. If you open a file, then run :AgBuffer something
, then you can't jump to the matches (because the output doesn't match what we've set 'errorformat' to). This is because the output is different when searching through one file; from ag's --help:
-H --[no]heading Print file names (Enabled unless searching a single file)
Luckily, ag provides a --vimgrep
option, which gives us the format we want by default. I'll make another commit for that though, because it's a quick documentation/default change.
Thanks for the pull!
Add commands AgBuffer and LAgBuffer to search pattern in all open buffers