mirror of
https://github.com/vim-airline/vim-airline.git
synced 2026-02-27 03:52:17 +08:00
Refactor async functions
- create a new async module - refactor async functions from branch.vim and po.vim to async.vim - support nvim async correctly
This commit is contained in:
@@ -86,42 +86,3 @@ 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) dict
|
||||
if a:event == 'stdout'
|
||||
let self.buf .= join(a:data)
|
||||
else " on_exit handler
|
||||
if self.buf =~? ('^' . self.cfg['untracked_mark'])
|
||||
let self.cfg.untracked[self.file] = get(g:, 'airline#extensions#branch#notexists', g:airline_symbols.notexists)
|
||||
else
|
||||
let self.cfg.untracked[self.file] = ''
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#util#system(cfg, file)
|
||||
let l:config = {
|
||||
\ 'buf': '',
|
||||
\ 'cfg': a:cfg,
|
||||
\ 'file': a:file,
|
||||
\ 'cwd': fnamemodify(a:file, ':p:h'),
|
||||
\ 'on_stdout': function('s:system_job_handler'),
|
||||
\ 'on_exit': function('s:system_job_handler')
|
||||
\ }
|
||||
let cmd = a:cfg.cmd . shellescape(a:file)
|
||||
let l:id = jobstart(cmd, l:config)
|
||||
if l:id < 1
|
||||
return system(cmd)
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endfunction
|
||||
else
|
||||
function! airline#util#system(cmd)
|
||||
return system(a:cmd)
|
||||
endfunction
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user