mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-07-28 16:34:31 +02: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:
parent
545617f4f4
commit
433d5d8f97
@ -185,7 +185,7 @@ function! s:update_untracked()
|
|||||||
" doesn't happen often in practice, so we let it be.
|
" doesn't happen often in practice, so we let it be.
|
||||||
call s:get_vcs_untracked_async(l:config, l:file)
|
call s:get_vcs_untracked_async(l:config, l:file)
|
||||||
else
|
else
|
||||||
let output = system(l:config.cmd . shellescape(l:file))
|
let output = airline#util#system(l:config.cmd . shellescape(l:file))
|
||||||
if output =~? ('^' . l:config.untracked_mark)
|
if output =~? ('^' . l:config.untracked_mark)
|
||||||
let l:config.untracked[l:file] = get(g:, 'airline#extensions#branch#notexists', g:airline_symbols.notexists)
|
let l:config.untracked[l:file] = get(g:, 'airline#extensions#branch#notexists', g:airline_symbols.notexists)
|
||||||
else
|
else
|
||||||
@ -365,7 +365,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:reset_untracked_cache(shellcmdpost)
|
function! s:reset_untracked_cache(shellcmdpost)
|
||||||
" shellcmdpost - whether function was called as a result of ShellCmdPost hook
|
" shellcmdpost - whether function was called as a result of ShellCmdPost hook
|
||||||
if !s:has_async
|
if !s:has_async && !has('nvim')
|
||||||
if a:shellcmdpost
|
if a:shellcmdpost
|
||||||
" Clear cache only if there was no error or the script uses an
|
" Clear cache only if there was no error or the script uses an
|
||||||
" asynchronous interface. Otherwise, cache clearing would overwrite
|
" asynchronous interface. Otherwise, cache clearing would overwrite
|
||||||
|
@ -77,3 +77,34 @@ else
|
|||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user