async: Add comments, better conditions to detect vim/nvim

This commit is contained in:
Christian Brabandt 2017-08-22 23:42:27 +02:00
parent 4c74a95045
commit 2c05a48a26
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -5,6 +5,7 @@ let s:untracked_jobs = {}
let s:mq_jobs = {}
let s:po_jobs = {}
" Generic functions handling on exit event of the various async functions
function! s:untracked_output(dict, buf)
if a:buf =~? ('^'. a:dict.cfg['untracked_mark'])
let a:dict.cfg.untracked[a:dict.file] = get(g:, 'airline#extensions#branch#notexists', g:airline_symbols.notexists)
@ -41,7 +42,8 @@ function! s:po_output(buf, file)
endif
endfunction
if !has("nvim")
if v:version >= 800 && has("job")
" Vim 8.0 with Job feature
function! s:on_stdout(channel, msg) dict abort
let self.buf .= a:msg
@ -130,7 +132,8 @@ if !has("nvim")
let s:untracked_jobs[a:file] = id
endfunction
endif " end !NVim
elseif has("nvim")
" NVim specific functions
function! s:nvim_untracked_job_handler(job_id, data, event) dict
if a:event == 'stdout'
@ -160,35 +163,6 @@ function! s:nvim_po_job_handler(job_id, data, event) dict
endif
endfunction
function! airline#async#nvim_vcs_untracked(cfg, file, vcs)
let config = {
\ 'buf': '',
\ 'vcs': a:vcs,
\ 'cfg': a:cfg,
\ 'file': a:file,
\ 'cwd': fnamemodify(a:file, ':p:h'),
\ 'on_stdout': function('s:nvim_untracked_job_handler'),
\ 'on_exit': function('s:nvim_untracked_job_handler')
\ }
let cmd = a:cfg.cmd . shellescape(a:file)
if !has("nvim")
let id = -1
else
if has_key(s:untracked_jobs, config.file)
" still running
return
endif
let id = jobstart(cmd, config)
let s:untracked_jobs[a:file] = id
endif
" vim without job feature or nvim jobstart failed
if id < 1
let output=system(cmd)
call s:untracked_output(config, output)
call airline#extensions#branch#update_untracked_config(a:file, a:vcs)
endif
endfunction
function! airline#async#nvim_get_mq_async(cmd, file)
let config = {
\ 'buf': '',
@ -230,3 +204,35 @@ function! airline#async#nvim_get_msgfmt_stat(cmd, file)
let id = jobstart(cmd, config)
let s:po_jobs[a:file] = id
endfunction
endif
" Should work in either Vim pre 8 or Nvim
function! airline#async#nvim_vcs_untracked(cfg, file, vcs)
let config = {
\ 'buf': '',
\ 'vcs': a:vcs,
\ 'cfg': a:cfg,
\ 'file': a:file,
\ 'cwd': fnamemodify(a:file, ':p:h'),
\ 'on_stdout': function('s:nvim_untracked_job_handler'),
\ 'on_exit': function('s:nvim_untracked_job_handler')
\ }
let cmd = a:cfg.cmd . shellescape(a:file)
if !has("nvim")
let id = -1
else
if has_key(s:untracked_jobs, config.file)
" still running
return
endif
let id = jobstart(cmd, config)
let s:untracked_jobs[a:file] = id
endif
" vim without job feature or nvim jobstart failed
if id < 1
let output=system(cmd)
call s:untracked_output(config, output)
call airline#extensions#branch#update_untracked_config(a:file, a:vcs)
endif
endfunction