From 34628404146b8e1d049b63f08d08f47ab6cfde81 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 7 Oct 2017 22:21:45 +0800 Subject: [PATCH] Update job api --- autoload/SpaceVim/api/job.vim | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/autoload/SpaceVim/api/job.vim b/autoload/SpaceVim/api/job.vim index 193f69b07..2bd8cb3bf 100644 --- a/autoload/SpaceVim/api/job.vim +++ b/autoload/SpaceVim/api/job.vim @@ -10,12 +10,11 @@ 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) + au! User SpaceVim_job_stdout nested call call(s:self.opts.on_stdout, s:self.job_argv) + au! User SpaceVim_job_stderr nested call call(s:self.opts.on_stderr, s:self.job_argv) + au! User SpaceVim_job_exit nested call call(s:self.opts.on_exit, s:self.job_argv) augroup ENd endif @@ -119,21 +118,33 @@ function! s:self.start(argv, ...) abort exe 'cd' fnameescape(old_wd) endif let id = -1 - let self.opts = opts + let s:self.opts = opts if v:shell_error if has_key(opts,'on_stderr') - let self.job_argv = [id, output, 'stderr'] - doautocmd User SpaceVim_job_stderr + let s:self.job_argv = [id, output, 'stderr'] + try + doautocmd User SpaceVim_job_stderr + catch + doautocmd User SpaceVim_job_stderr + endtry endif else if has_key(opts,'on_stdout') - let self.job_argv = [id, output, 'stdout'] - doautocmd User SpaceVim_job_stdout + let s:self.job_argv = [id, output, 'stdout'] + try + doautocmd User SpaceVim_job_stdout + catch + doautocmd User SpaceVim_job_stdout + endtry endif endif if has_key(opts,'on_exit') - let self.job_argv = [id, output, 'exit'] + let s:self.job_argv = [id, v:shell_error, 'exit'] + try doautocmd User SpaceVim_job_exit + catch + doautocmd User SpaceVim_job_exit + endtry endif return id endif