Use neovim's async job's instead of system

This commit makes branch.vim use neovim's async jobs instead of a system()
function. This way we avoid the v:shell_error overwrite bug and allow live
updates of the untracked status.
This commit is contained in:
Grzegorz Milka
2016-10-30 12:55:11 +01:00
parent 545617f4f4
commit 433d5d8f97
2 changed files with 33 additions and 2 deletions

View File

@@ -77,3 +77,34 @@ else
return 0
endfunction
endif
" Define a wrapper over system() that uses nvim's async job control if
" available. This way we avoid overwriting v:shell_error, which might
" potentially disrupt other plugins.
if has('nvim')
function! s:system_job_handler(job_id, data, event)
if a:event == 'stdout'
let self.buf .= join(a:data)
endif
endfunction
function! airline#util#system(cmd)
let l:config = {
\ 'buf': '',
\ 'on_stdout': function('s:system_job_handler'),
\ }
let l:id = jobstart(a:cmd, l:config)
if l:id < 1
return system(a:cmd)
endif
let l:ret_code = jobwait([l:id])
if l:ret_code != [0]
return system(a:cmd)
endif
return l:config.buf
endfunction
else
function! airline#util#system(cmd)
return system(a:cmd)
endfunction
endif