-
Notifications
You must be signed in to change notification settings - Fork 22
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
Option to not open first found file automatically #21
Comments
Makes sense. Had to move to another plugin just because of this option. |
Recently I switched to CtrlSF. It gives me more options and Edit Mode (which is more user-friendly in most of the cases). |
Wow, CtrlSF is pretty impressive. I'm going to close this for now as it's not a pain point that I feel. If anybody wants to fix it, I think these are the options:
I'd be open to pull requests. |
I don't remember the code well, but I guess you set |
There is a little bit of fragility here because the user can override the handler behavior with `g:FerretQFHandler` (for example, my use of `wincmd p` here assumes you've switched focus with `copen` rather than `cwindow`, but short of removing that functionality I am not sure how one would avoid this). As it is, the `wincmd` can do the wrong thing, so this feature is decidedly fragile. eg: - run a search, and leaving focus in the quickfix listing - let g:FerretDispatch=0 - let g:FerretAutojump=0 - our wincmd here rotates us out of the quickfix window Related #21
Thanks for quick response! |
@kriansa: yeah, I think we can merge something like that (will need to redo it it no longer applies cleanly). Lots of edge cases to deal with, but it will have to be something like this: diff --git a/autoload/ferret/private/shared.vim b/autoload/ferret/private/shared.vim
index 14ad5a1..ff1d929 100644
--- a/autoload/ferret/private/shared.vim
+++ b/autoload/ferret/private/shared.vim
@@ -1,19 +1,43 @@
" Copyright 2015-present Greg Hurrell. All rights reserved.
" Licensed under the terms of the BSD 2-clause license.
+" Convenience function to get/sanitize the current g:FerretAutojump setting.
+function! s:autojump()
+ let l:autojump=get(g:, 'FerretAutojump', 1)
+ if l:autojump != 0 && l:autojump != 1 && l:autojump != 2
+ let l:autojump=0
+ endif
+ return l:autojump
+endfunction
+
function! ferret#private#shared#finalize_search(output, ack)
let l:original_errorformat=&errorformat
+ let l:autojump=s:autojump()
+ if a:ack
+ let l:prefix='c' " Will use cexpr, cgetexpr.
+ let l:handler=get(g:, 'FerretQFHandler', 'botright copen')
+ let l:post='qf'
+ else
+ let l:prefix='l' " Will use lexpr, lgetexpr.
+ let l:handler=get(g:, 'FerretLLHandler', 'lopen')
+ let l:post='location'
+ endif
try
let &errorformat=g:FerretFormat
- if a:ack
- call s:swallow('cexpr a:1', a:output)
- execute get(g:, 'FerretQFHandler', 'botright cwindow')
- call ferret#private#post('qf')
+ if l:autojump == 2 " Show listing and jump to first result.
+ call s:swallow(l:prefix . 'expr a:1', a:output)
else
- call s:swallow('lexpr a:1', a:output)
- execute get(g:, 'FerretLLHandler', 'lwindow')
- call ferret#private#post('location')
+ call s:swallow(l:prefix . 'getexpr a:1', a:output)
endif
+ let l:before=winnr()
+ execute l:handler
+ if l:autojump != 1 " Show listing, but don't jump anywhere.
+ let l:after=winnr()
+ if l:before != l:after
+ execute l:before . 'wincmd w'
+ end
+ endif
+ call ferret#private#post(l:post)
finally
let &errorformat=l:original_errorformat
endtry |
This is a fairly invasive change, so I'll keep my finger poised above the revert button. For more context, see: #21 Notable changes since I last explored this: - Using `winnr()` to avoid blindly relying on `wincmd p`. - Switched to `:copen` (from `:cwindow`) to get consistent focusing behavior. - Slight change of `post()` callback ordering so that we can decide whether or not to open the listing at all; this allows us to avoid showing an empty listing with `:copen`.
Ok, so I pushed something to the "next" branch. Will let it bake there for a while before merging to master. |
Thank you for your quick response! |
As asked in #13, I'm filling a new issue for this topic.
Maybe it would be better to have on option to not open the file when searching (and maybe it could be the default), as the user may be only looking for the existence of some search term on the project, and don't intend to lose focus from the current code (yeah, it's possible to go back to where it was by pressing
<c-o>
, but sometimes it's inconvenient to use it everytime when using ferret).The text was updated successfully, but these errors were encountered: