-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasyncdo.vim
35 lines (30 loc) · 850 Bytes
/
asyncdo.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
" Author: hauleth on r/vim
func! s:populate(file, cmd) abort
unlet! t:job
try
exe 'cgetfile '.a:file
finally
call setqflist([], 'a', {'title': a:cmd})
endtry
endfunc
func! AsyncDo(...) abort
if exists('t:job')
echoerr 'There is currently running job, just wait'
return
endif
call setqflist([], 'r')
let tmp = tempname()
let cmd = join(a:000)
let g:qf_quickfix_titles = []
if has('nvim')
let t:job = jobstart([&sh, &shcf, printf(cmd.&srr, tmp)], {
\ 'on_exit': {id, data, event -> s:populate(tmp, cmd)}
\ })
else
let t:job = job_start([&sh, &shcf, printf(cmd.&srr, tmp)], {
\ 'in_io': 'null','out_io': 'null','err_io': 'null',
\ 'exit_cb': {job, result -> s:populate(tmp, cmd)}
\ })
endif
endfunc
com! -nargs=+ AsyncDo call AsyncDo(<f-args>)