fixup for async feature

This commit is contained in:
Christian Brabandt 2016-10-09 15:47:23 +02:00
parent 81ccd3bdf6
commit 4f8a16c31e
2 changed files with 14 additions and 14 deletions

View File

@ -76,7 +76,7 @@ function! s:get_git_untracked(file)
endif endif
if !has_key(s:untracked_git, a:file) if !has_key(s:untracked_git, a:file)
if s:has_async if s:has_async
call s:DoAsync(s:git_cmd, a:file) call s:get_vcs_untracked_async(s:git_cmd, a:file)
else else
let output = system(s:git_cmd. shellescape(a:file)) let output = system(s:git_cmd. shellescape(a:file))
if output[0:1] is# '??' && output[3:-2] is? a:file if output[0:1] is# '??' && output[3:-2] is? a:file
@ -88,13 +88,13 @@ function! s:get_git_untracked(file)
endfunction endfunction
function! s:get_hg_untracked(file) function! s:get_hg_untracked(file)
if !s:has_lawrencium || empty(a:file) || !executable('hg') if empty(a:file) || !executable('hg')
return return
endif endif
" delete cache when unlet b:airline head? " delete cache when unlet b:airline head?
if !has_key(s:untracked_hg, a:file) if !has_key(s:untracked_hg, a:file)
if s:has_async if s:has_async
call s:DoAsync(s:hg_cmd, a:file) call s:get_vcs_untracked_async(s:hg_cmd, a:file)
else else
let untracked = (system(s:hg_cmd. shellescape(a:file))[0] is# '?' ? let untracked = (system(s:hg_cmd. shellescape(a:file))[0] is# '?' ?
\ get(g:, 'airline#extensions#branch#notexists', g:airline_symbols.notexists) : '') \ get(g:, 'airline#extensions#branch#notexists', g:airline_symbols.notexists) : '')
@ -126,9 +126,10 @@ if s:has_async
else else
let s:untracked_{self.cmd}[self.file] = '' let s:untracked_{self.cmd}[self.file] = ''
endif endif
call remove(s:jobs, self.file)
endfunction endfunction
function! s:DoAsync(cmd, file) function! s:get_vcs_untracked_async(cmd, file)
if g:airline#util#is_windows && &shell =~ 'cmd' if g:airline#util#is_windows && &shell =~ 'cmd'
let cmd = a:cmd. shellescape(a:file) let cmd = a:cmd. shellescape(a:file)
else else
@ -140,8 +141,7 @@ if s:has_async
if has_key(s:jobs, a:file) if has_key(s:jobs, a:file)
if job_status(get(s:jobs, a:file)) == 'run' if job_status(get(s:jobs, a:file)) == 'run'
return return
else elseif has_key(s:jobs, a:file)
call job_stop(get(s:jobs, a:file))
call remove(s:jobs, a:file) call remove(s:jobs, a:file)
endif endif
endif endif
@ -251,12 +251,12 @@ function! s:check_in_path()
endfunction endfunction
function! s:reset_untracked_cache(shellcmdpost) function! s:reset_untracked_cache(shellcmdpost)
" shellcmdpost - whether function was called as a result of ShellCmdPost hook
if !s:has_async if !s:has_async
if a:shellcmdpost if a:shellcmdpost
" function called after executing a shell command, " Clear cache only if there was no error or the script uses an
" only clear cache, if there was no error, else the " asynchronous interface. Otherwise, cache clearing would overwrite
" system() command from get_git_untracked() would " v:shell_error with a system() call inside get_*_untracked.
" overwrite the v:shell_error status
if v:shell_error if v:shell_error
return return
endif endif

View File

@ -27,10 +27,11 @@ if s:has_async
else else
let b:airline_po_stats = '' let b:airline_po_stats = ''
endif endif
call remove(s:jobs, self.file)
call s:shorten() call s:shorten()
endfunction endfunction
function! s:DoAsyncPO(cmd, file) function! s:get_msgfmt_stat_async(cmd, file)
if g:airline#util#is_windows || !executable('msgfmt') if g:airline#util#is_windows || !executable('msgfmt')
" no msgfmt on windows? " no msgfmt on windows?
return return
@ -42,8 +43,7 @@ if s:has_async
if has_key(s:jobs, a:file) if has_key(s:jobs, a:file)
if job_status(get(s:jobs, a:file)) == 'run' if job_status(get(s:jobs, a:file)) == 'run'
return return
else elseif has_key(s:jobs, a:file)
call job_stop(get(s:jobs, a:file))
call remove(s:jobs, a:file) call remove(s:jobs, a:file)
endif endif
endif endif
@ -69,7 +69,7 @@ function! airline#extensions#po#stats()
let cmd = 'msgfmt --statistics -o /dev/null -- ' let cmd = 'msgfmt --statistics -o /dev/null -- '
if s:has_async if s:has_async
call s:DoAsyncPO(cmd, expand('%:p')) call s:get_msgfmt_stat_async(cmd, expand('%:p'))
else else
let airline_po_stats = system(cmd. shellescape(expand('%:p'))) let airline_po_stats = system(cmd. shellescape(expand('%:p')))
if v:shell_error if v:shell_error