From e9403f914d7650ee020f26d41a002ab021d93f38 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Sun, 26 Jan 2020 22:15:55 +0800 Subject: [PATCH] Fix runner and repl (#3305) --- autoload/SpaceVim/plugins/repl.vim | 5 ++++- autoload/SpaceVim/plugins/runner.vim | 25 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/autoload/SpaceVim/plugins/repl.vim b/autoload/SpaceVim/plugins/repl.vim index 1902121b3..6730ee098 100644 --- a/autoload/SpaceVim/plugins/repl.vim +++ b/autoload/SpaceVim/plugins/repl.vim @@ -153,8 +153,11 @@ endfunction " @vimlint(EVL103, 0, a:data) " @vimlint(EVL103, 0, a:event) + + function! s:close() abort - if exists('s:job_id') && s:job_id != 0 + " stop the job if it is running. + if exists('s:job_id') && s:job_id > 0 call s:JOB.stop(s:job_id) let s:job_id = 0 endif diff --git a/autoload/SpaceVim/plugins/runner.vim b/autoload/SpaceVim/plugins/runner.vim index b71392dc9..8d824355a 100644 --- a/autoload/SpaceVim/plugins/runner.vim +++ b/autoload/SpaceVim/plugins/runner.vim @@ -241,9 +241,14 @@ if has('nvim') && exists('*chanclose') else let lines = s:_out_data endif + " if s:SYS.isWindows + " let lines = map(lines, 's:ICONV.iconv(v:val, "cp936", "utf-8")') + " endif if !empty(lines) let lines = map(lines, "substitute(v:val, ' $', '', 'g')") - call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, lines) + if bufexists(s:bufnr) + call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, lines) + endif call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1]) endif let s:lines += len(lines) @@ -266,7 +271,9 @@ if has('nvim') && exists('*chanclose') endif if !empty(lines) let lines = map(lines, "substitute(v:val, ' $', '', 'g')") - call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, lines) + if bufexists(s:bufnr) + call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, lines) + endif call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1]) endif let s:lines += len(lines) @@ -275,7 +282,9 @@ if has('nvim') && exists('*chanclose') endfunction else function! s:on_stdout(job_id, data, event) abort - call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data) + if bufexists(s:bufnr) + call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data) + endif let s:lines += len(a:data) call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1]) call s:update_statusline() @@ -283,7 +292,9 @@ else function! s:on_stderr(job_id, data, event) abort let s:status.has_errors = 1 - call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data) + if bufexists(s:bufnr) + call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data) + endif let s:lines += len(a:data) call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1]) call s:update_statusline() @@ -295,7 +306,9 @@ function! s:on_exit(job_id, data, event) abort let s:status.is_exit = 1 let s:status.exit_code = a:data let done = ['', '[Done] exited with code=' . a:data . ' in ' . s:STRING.trim(reltimestr(s:end_time)) . ' seconds'] - call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, done) + if bufexists(s:bufnr) + call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, done) + endif call s:update_statusline() endfunction @@ -319,7 +332,7 @@ function! SpaceVim#plugins#runner#status() abort endfunction function! SpaceVim#plugins#runner#close() abort - if s:status.is_exit == 0 + if s:status.is_exit == 0 && s:job_id > 0 call s:JOB.stop(s:job_id) endif exe 'bd ' s:bufnr