mirror of
https://github.com/vim-airline/vim-airline.git
synced 2026-02-26 03:27:12 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user