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:
Christian Brabandt
2017-08-22 23:21:19 +02:00
parent 50bfe8dd68
commit 4c74a95045
4 changed files with 279 additions and 203 deletions

View File

@@ -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