1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-15 08:09:11 +08:00

Fallback to sync system()

This commit is contained in:
wsdjeg 2017-04-22 14:03:37 +08:00
parent 91a1b6027f
commit 607882765f
2 changed files with 33 additions and 1 deletions

View File

@ -7,9 +7,12 @@ let s:self = {}
let s:self.jobs = {}
let s:self.nvim_job = has('nvim')
let s:self.vim_job = !has('nvim') && has('job') && has('patch-8.0.0027')
if !s:self.nvim_job && !s:self.vim_job
let s:self.vim_co = SpaceVim#api#import('vim#compatible')
endif
function! s:self.warn(...) abort
if len(a:000) == 0
echohl WarningMsg | echom 'Current version do not support job feature!' | echohl None
echohl WarningMsg | echom 'Current version do not support job feature, fallback to sync system()' | echohl None
elseif len(a:000) == 1 && type(a:1) == type('')
echohl WarningMsg | echom a:1| echohl None
else
@ -89,6 +92,23 @@ function! s:self.start(argv, ...) abort
return id
else
call self.warn()
if len(a:000) > 0
let opts = a:1
else
let opts = {}
endif
let output = self.vim_co.systemlist(a:argv)
let id = len(self.jobs) + 1
if v:shell_error
if has_key(opts,'on_stderr')
call call(opts.on_stderr, [id, output, 'on_stderr'])
endif
else
if has_key(opts,'on_stdout')
call call(opts.on_stderr, [id, output, 'on_stdout'])
endif
endif
return id
endif
endfunction

View File

@ -29,6 +29,9 @@ if has('nvim')
function! s:system(cmd, ...) abort
return a:0 == 0 ? system(a:cmd) : system(a:cmd, a:1)
endfunction
function! s:systemlist(cmd, ...) abort
return a:0 == 0 ? systemlist(a:cmd) : systemlist(a:cmd, a:1)
endfunction
else
function! s:system(cmd, ...) abort
if type(a:cmd) == 3
@ -39,6 +42,15 @@ else
return a:0 == 0 ? system(a:cmd) : system(a:cmd, a:1)
endif
endfunction
function! s:systemlist(cmd, ...) abort
if type(a:cmd) == 3
let cmd = map(a:cmd, 'shellescape(v:val)')
let cmd = join(cmd, ' ')
return a:0 == 0 ? systemlist(cmd) : systemlist(cmd, a:1)
else
return a:0 == 0 ? systemlist(a:cmd) : systemlist(a:cmd, a:1)
endif
endfunction
endif
" vim:set et sw=2 cc=80: