From 9377f6b6cf8263290dbe4ad14b81ade1fc538f2e Mon Sep 17 00:00:00 2001 From: johannst Date: Thu, 10 Nov 2016 22:44:41 +0100 Subject: vimrc added function to kill async job --- vimrc | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/vimrc b/vimrc index bc41df4..b57d314 100644 --- a/vimrc +++ b/vimrc @@ -345,21 +345,21 @@ if s:sandbox_enable function! s:JobExitCB(job, status) "execute 'cbuffer! ' . g:stderr_buffer echom 'AsyncCmdProcessor: Job exited' - let s:async_job_running=0 + let s:gAsyncJobRunning=0 endfunction - let s:async_job_running=0 + let s:gAsyncJobRunning=0 function! s:AsyncCmdProcessor(...) if a:0 == 0 echom 'AsyncCmdProcessor: no cmd specified' return endif - if s:async_job_running == 1 + if s:gAsyncJobRunning == 1 echom 'AsyncCmdProcessor: currently only one job at a time supported' return endif - let s:async_job_running=1 + let s:gAsyncJobRunning=1 let l:current_buffer = bufnr('%') @@ -374,7 +374,7 @@ if s:sandbox_enable endfor echom l:cmd - let s:async_job = job_start(l:cmd, { + let s:gAsyncJob = job_start(l:cmd, { \ 'out_io': 'buffer', \ 'out_buf': s:async_buffer, \ 'out_cb': function('s:StdOutCB'), @@ -387,23 +387,36 @@ if s:sandbox_enable \}) endfunction + " can not be script local because used in statusline function! GetAsyncJobStatus() - if exists('s:async_job') - return job_status(s:async_job) + if exists('s:gAsyncJob') + return job_status(s:gAsyncJob) endif return '*' endfunction + function! s:KillAsyncJob() + if exists('s:gAsyncJob') + let l:dudel = job_stop(s:gAsyncJob) + execute 'sleep 200ms' + if job_status(s:gAsyncJob) !=? 'dead' + echom 'Failed to kill AsyncJob' + endif + endif + endfunction + function! s:CreateLogBuffer(buffer_name) let l:buffer_num = bufnr(a:buffer_name, 1) execute 'b ' . l:buffer_num execute '%d' execute 'setlocal buflisted' execute 'setlocal buftype=nofile' + execute 'setlocal wrap' return l:buffer_num endfunction command! -nargs=* Async call s:AsyncCmdProcessor() nnoremap a :Async + nnoremap ak :call KillAsyncJob() endif "}}} -- cgit v1.2.3