First commit to handle nvim specific async code

This commit is contained in:
Christian Brabandt 2017-08-22 15:29:39 +02:00
parent a01d03a78a
commit 50bfe8dd68
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
2 changed files with 19 additions and 6 deletions

View File

@ -191,8 +191,10 @@ function! s:update_untracked()
" result of the previous call, i.e. the head string is not updated. It " result of the previous call, i.e. the head string is not updated. It
" 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)
elseif has('nvim')
call airline#util#system(l:config, l:file)
else else
let output = airline#util#system(l:config.cmd . shellescape(l:file)) let output = airline#util#system(l:config, 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

View File

@ -94,20 +94,31 @@ if has('nvim')
function! s:system_job_handler(job_id, data, event) dict function! s:system_job_handler(job_id, data, event) dict
if a:event == 'stdout' if a:event == 'stdout'
let self.buf .= join(a:data) 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 endif
endfunction endfunction
function! airline#util#system(cmd) function! airline#util#system(cfg, file)
let l:config = { let l:config = {
\ 'buf': '', \ 'buf': '',
\ 'cfg': a:cfg,
\ 'file': a:file,
\ 'cwd': fnamemodify(a:file, ':p:h'),
\ 'on_stdout': function('s:system_job_handler'), \ 'on_stdout': function('s:system_job_handler'),
\ 'on_exit': function('s:system_job_handler')
\ } \ }
let l:id = jobstart(a:cmd, l:config) let cmd = a:cfg.cmd . shellescape(a:file)
let l:id = jobstart(cmd, l:config)
if l:id < 1 if l:id < 1
return system(a:cmd) return system(cmd)
else
return ''
endif endif
call jobwait([l:id])
return l:config.buf
endfunction endfunction
else else
function! airline#util#system(cmd) function! airline#util#system(cmd)