async: cleanup logic for nvim/vim8/vim7

This commit is contained in:
Christian Brabandt 2019-04-25 15:07:12 +02:00
parent 6b213e1071
commit fdd75df927
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -85,9 +85,12 @@ function! airline#async#vcs_clean(cmd, file, vcs)
if g:airline#init#vim_async
" Vim 8 with async support
noa call airline#async#vim_vcs_clean(a:cmd, a:file, a:vcs)
else
" nvim async or vim without job-feature
elseif has("nvim")
" nvim async
noa call airline#async#nvim_vcs_clean(a:cmd, a:file, a:vcs)
else
" Vim pre 8 using system()
call airline#async#vim7_vcs_clean(a:cmd, a:file, a:vcs)
endif
endfunction
@ -282,6 +285,31 @@ elseif has("nvim")
let s:po_jobs[a:file] = id
endfunction
function! airline#async#nvim_vcs_clean(cmd, file, vcs)
let config = {
\ 'buf': '',
\ 'vcs': a:vcs,
\ 'file': a:file,
\ 'cwd': s:valid_dir(fnamemodify(a:file, ':p:h')),
\ 'on_stdout': function('s:nvim_output_handler'),
\ 'on_stderr': function('s:nvim_output_handler'),
\ 'on_exit': function('s:on_exit_clean')}
if g:airline#init#is_windows && &shell =~ 'cmd'
let cmd = a:cmd
else
let cmd = ['sh', '-c', a:cmd]
endif
if !has_key(s:clean_jobs, a:vcs)
let s:clean_jobs[a:vcs] = {}
endif
if has_key(s:clean_jobs[a:vcs], a:file)
call remove(s:clean_jobs[a:vcs], a:file)
endif
let id = jobstart(cmd, config)
let s:clean_jobs[a:vcs][a:file] = id
endfunction
endif
" Should work in either Vim pre 8 or Nvim
@ -319,36 +347,10 @@ function! airline#async#nvim_vcs_untracked(cfg, file, vcs)
endif
endfunction
function! airline#async#nvim_vcs_clean(cmd, file, vcs)
let config = {
\ 'buf': '',
\ 'vcs': a:vcs,
\ 'file': a:file,
\ 'cwd': s:valid_dir(fnamemodify(a:file, ':p:h'))}
if has("nvim")
call extenc(config, {
\ 'on_stdout': function('s:nvim_output_handler'),
\ 'on_stderr': function('s:nvim_output_handler'),
\ 'on_exit': function('s:on_exit_clean')})
if g:airline#init#is_windows && &shell =~ 'cmd'
let cmd = a:cmd
else
let cmd = ['sh', '-c', a:cmd]
endif
if !has_key(s:clean_jobs, a:vcs)
let s:clean_jobs[a:vcs] = {}
endif
if has_key(s:clean_jobs[a:vcs], a:file)
call remove(s:clean_jobs[a:vcs], a:file)
endif
let id = jobstart(cmd, config)
let s:clean_jobs[a:vcs][a:file] = id
else
" Vim pre 8
let output=system(a:cmd)
if !empty(output)
call s:set_clean_variables(a:file, a:vcs)
endif
function! airline#async#vim7_vcs_clean(cmd, file, vcs)
" Vim pre 8, fallback using system()
let output=system(a:cmd)
if !empty(output)
call s:set_clean_variables(a:file, a:vcs)
endif
endfunction