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

Update job api

This commit is contained in:
wsdjeg 2017-10-07 21:35:09 +08:00
parent c6adab923b
commit 60b50ad743

View File

@ -9,6 +9,16 @@ let s:self.nvim_job = has('nvim')
let s:self.vim_job = !has('nvim') && has('job') && has('patch-8.0.0027')
let s:self.vim_co = SpaceVim#api#import('vim#compatible')
if !s:self.nvim_job && !s:self.vim_job
let s:self.job_argv = ['', '', '']
augroup SpaceVim_job
au!
au! User SpaceVim_job_stdout call call(self.opts.on_stdout, self.job_argv)
au! User SpaceVim_job_stderr call call(self.opts.on_stderr, self.job_argv)
au! User SpaceVim_job_exit call call(self.opts.on_exit, self.job_argv)
augroup ENd
endif
function! s:self.warn(...) abort
if len(a:000) == 0
echohl WarningMsg | echom 'Current version do not support job feature, fallback to sync system()' | echohl None
@ -109,17 +119,21 @@ function! s:self.start(argv, ...) abort
exe 'cd' fnameescape(old_wd)
endif
let id = -1
let self.opts = opts
if v:shell_error
if has_key(opts,'on_stderr')
call call(opts.on_stderr, [id, output, 'stderr'])
let self.job_argv = [id, output, 'stderr']
doautocmd User SpaceVim_job_stderr
endif
else
if has_key(opts,'on_stdout')
call call(opts.on_stdout, [id, output, 'stdout'])
let self.job_argv = [id, output, 'stdout']
doautocmd User SpaceVim_job_stdout
endif
endif
if has_key(opts,'on_exit')
call call(opts.on_exit, [id, v:shell_error, 'exit'])
let self.job_argv = [id, output, 'exit']
doautocmd User SpaceVim_job_exit
endif
return id
endif