Skip to content

Commit

Permalink
Remove support for vim-dispatch
Browse files Browse the repository at this point in the history
Dispatch is a great hack. It mostly works without problems if you just want
to, well, dispatch any programs.

But it has different adapters that all act a bit different, uses a blacklist
for certain escape sequences and it's not very configurable, which makes it
hard to include in other plugins.

Also because of Vim's textlock, you can't close the quickfix window that
dispatch opens, even if there are no matches at all. Consider this:

    function! s:foo()
      cclose
    endfunction

    autocmd FileType qf call s:foo()

    let &makeprg     = 'grep -Rn qu'.'ux .'
    let &errorformat = '%f:%l:%m'
    Make

This will close the quickfix window, but also jump to the first line of the
buffer and there's no way to avoid this.

If you need real async search without resorting to complicated hacks, use
Neovim instead.
  • Loading branch information
mhinz committed Jan 24, 2016
1 parent 445c195 commit c345137
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 60 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ _Features:_
**findstr**
- quick switching between grep tools
- adding new grep tools or replacing parameters of default ones is easy
- asynchronous search with Neovim or
[vim-dispatch](https://github.com/tpope/vim-dispatch)
- asynchronous search with Neovim
- operator for selecting search queries by motion
- operator action is repeatable if
[vim-repeat](https://github.com/tpope/vim-repeat) is installed
Expand All @@ -43,9 +42,6 @@ Using [vim-plug](https://github.com/junegunn/vim-plug):

Plug 'mhinz/vim-grepper'

" Optional: used for asynchronous searching on Vim
Plug 'tpope/vim-dispatch'

" Optional: used for repeating operator actions via "."
Plug 'tpope/vim-repeat'

Expand Down
54 changes: 10 additions & 44 deletions autoload/grepper.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
" ..ad\\f40+$':-# @=,!;%^&&*()_{}/ /4304\'""?`9$343%$ ^adfadf[ad)[(

let s:options = {
\ 'dispatch': 0,
\ 'quickfix': 1,
\ 'open': 1,
\ 'switch': 1,
Expand Down Expand Up @@ -143,8 +142,7 @@ function! grepper#parse_flags(args) abort
while i < len
let flag = args[i]

if flag =~? '\v^-%(no)?dispatch$' | let flags.dispatch = flag !~? '^-no'
elseif flag =~? '\v^-%(no)?quickfix$' | let flags.quickfix = flag !~? '^-no'
if flag =~? '\v^-%(no)?quickfix$' | let flags.quickfix = flag !~? '^-no'
elseif flag =~? '\v^-%(no)?open$' | let flags.open = flag !~? '^-no'
elseif flag =~? '\v^-%(no)?switch$' | let flags.switch = flag !~? '^-no'
elseif flag =~? '\v^-%(no)?jump$' | let flags.jump = flag !~? '^-no'
Expand Down Expand Up @@ -202,15 +200,6 @@ endfunction

" s:process_flags() {{{1
function! s:process_flags(flags)
" check for vim-dispatch
if has('nvim') || !exists(':FocusDispatch')
let a:flags.dispatch = 0
endif
" vim-dispatch always uses the quickfix window
if a:flags.dispatch
let a:flags.quickfix = 1
endif

if a:flags.cword
let a:flags.query = s:escape_query(a:flags, expand('<cword>'))
endif
Expand Down Expand Up @@ -324,17 +313,6 @@ function! s:run(flags)
\ 'on_exit': function('s:on_exit'),
\ 'errmsg': '' })
return
elseif a:flags.dispatch
" Just a hack since autocmds can't access local variables.
let s:flags = deepcopy(a:flags)
augroup grepper
autocmd FileType qf call s:finish_up(s:flags)
augroup END
try
silent Make
finally
call s:restore_settings()
endtry
else
try
execute 'silent' (a:flags.quickfix ? 'grep!' : 'lgrep!')
Expand All @@ -355,7 +333,7 @@ function! s:store_settings(flags) abort
let s:settings = {}
let prog = s:get_current_tool(a:flags)

if !has('nvim') || !a:flags.dispatch
if !has('nvim')
let s:settings.t_ti = &t_ti
let s:settings.t_te = &t_te
set t_ti= t_te=
Expand Down Expand Up @@ -410,10 +388,6 @@ function! s:finish_up(flags, ...) abort
autocmd!
augroup END

if exists('s:flags')
unlet s:flags
endif

let qf = a:flags.quickfix
let size = len(qf ? getqflist() : getloclist(0))

Expand All @@ -425,9 +399,6 @@ function! s:finish_up(flags, ...) abort
else
if a:flags.jump
execute (qf ? 'cfirst' : 'lfirst')
if a:flags.dispatch
doautocmd BufRead
endif
endif

execute (qf ? 'botright copen' : 'lopen') (size > 10 ? 10 : size)
Expand All @@ -444,19 +415,14 @@ function! s:finish_up(flags, ...) abort
nnoremap <silent><buffer> t <c-w>gFzv
nmap <silent><buffer> T tgT
if a:flags.dispatch
if a:flags.switch
call feedkeys("\<c-w>p", 'n')
endif
else
if !a:flags.open
execute (qf ? 'cclose' : 'lclose')
elseif !a:flags.switch
call feedkeys("\<c-w>p", 'n')
endif
if !has('nvim')
redraw!
endif
if !a:flags.open
execute (qf ? 'cclose' : 'lclose')
elseif !a:flags.switch
call feedkeys("\<c-w>p", 'n')
endif

if !has('nvim')
redraw!
endif

echo printf('Found %d matches.', size)
Expand Down
14 changes: 3 additions & 11 deletions doc/grepper.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ supports most common grep tools, and is easily extendable.

You choose a tool, enter a query, and get your matches into a |quickfix| list.

If you use Neovim or vim-dispatch, the search will be executed asynchronously.
Thus you will be able to continue editing while the grep program is still
running.
If you use Neovim, the search will be executed asynchronously. Thus you will
be able to continue editing while the grep program is still running.

==============================================================================
TOOLS *grepper-tools*
Expand Down Expand Up @@ -78,11 +77,7 @@ Flags:~
-[no]switch Switch to quickfix/location window.

-[no]quickfix Use the quickfix list. If -noquickfix is given, use the
location list instead. When using -dispatch, the quickfix
window will be forced.

-[no]dispatch If vim-dispatch is installed, use |dispatch-:Make| for
executing the query.
location list instead.

-[no]prompt To prompt or not to prompt! Common uses are together with
-cword or -grepprg in a command.
Expand Down Expand Up @@ -180,9 +175,6 @@ switch When the quickfix/location window opens, switch to it.

jump Automatically jump to the first match. Defaults to 0.

dispatch Can be used to start an async search with Vim. It uses
|dispatch-:Make| from vim-dispatch. Defaults to 0.

prompt To prompt or not to prompt! Defaults to 1.

tools These are the tools that you can choose between. The order
Expand Down

5 comments on commit c345137

@mellery451
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch - this hurts. I really like the async search capability, but I'm not ready to switch to nvim yet since homebrew python and nvim doesn't seem to work.

@mhinz
Copy link
Owner Author

@mhinz mhinz commented on c345137 Jan 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a tough call, but I don't like implementing something that only works for mainstream use cases and breaks for everything else. Also I could simplify the code quite a bit now, since I don't have to work around dispatch all the time anymore.

On another note, maybe we'll get a proper job control in Vim, too! See :helpgrep startjob, if you have a very recent version. As of some days ago, we even have functions for (un)marshalling JSON via jsonencode()/jsondecode(), so Bram is apparently serious about implementing some more modern features now. (Maybe because of Neovim?)

@mellery451
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood - well, because of your change, I bit the bullet and installed neovim. There was some python related pain, but I seem to be past that and it works so far. Perhaps this will serve me well going forward. Thanks!

@mellery451
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to keep pestering on this commit. Does the new-ish async functionality in vim offer any decent option here? I realize it's not fun supporting multiple async APIs, but I guess this is the reality for the short-term.

@mhinz
Copy link
Owner Author

@mhinz mhinz commented on c345137 Jun 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was away the last 2 months, but will have a look at the new API. Sounds promising at least. Please see #48 for further developments.

Please sign in to comment.