vim-makejob

Minimal, asynchronous quickfix commands for Vim 8.0
git clone git://git.danielmoch.com/vim-makejob.git
Log | Files | Refs | README | LICENSE

commit e70bc581f04e7b75851c0915ae7f3d281f830192
parent bd891d3c3ede61626db4af0110f1ebb0ffd023c0
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sun, 30 Apr 2017 08:01:28 -0400

Add MakeJobStop

Command is used to cancel a running job.

Without an argument, the command will cancel a running MakeJob in one of
two ways:
    1. If the current buffer spawned a MakeJob, that job will be
       stopped.
    2. If the current buffer is displaying MakeJob output, that job will
       stopped.

MakeJobStop also accepts as an argument the name of the MakeJob to stop
(e.g., ":MakeJobStop make"). Command completion can be used to make
finding the name easier.

Additionally do the following refactorings:
1. Add MakeJobStop to help file
2. Update README for MakeJobStop
3. Roll version on script
4. Rename CreateMakeJobWindow to CreateMakeJobBuffer
5. Use <sid> in command definitions according to best practices

Diffstat:
MREADME.md | 5+++--
Mdoc/makejob.txt | 15+++++++++++++++
Mplugin/makejob.vim | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
3 files changed, 74 insertions(+), 18 deletions(-)

diff --git a/README.md b/README.md @@ -36,15 +36,16 @@ be parsed into the Quickfix or LocationList window when the job completes. Bask in your newfound freedom to do as you please in Vim while _MakeJob_ runs. -If _MakeJob_ reports findings, use `:copen` to view the QuickFix window +If _MakeJob_ reports findings, use `:copen` to view the Quickfix window (in the case of `:MakeJob`), and likewise `:lopen` to open the LocationList -for `:LmakeJob`. +for `:LmakeJob`. There's also `:MakeJobStop` to stop a running MakeJob. Speaking of `:LmakeJob`, all of the LocationList complements to the Quickfix commands are there with _MakeJob_, bringing the full list of commands to: - `:MakeJob` +- `:MakeJobStop` - `:LmakeJob` - `:GrepJob` - `:LgrepJob` diff --git a/doc/makejob.txt b/doc/makejob.txt @@ -59,6 +59,21 @@ GrepaddJob[!] {filename} Same as ":GrepJob", but add findings to the LgrepaddJob[!] {filename} Same as ":GrepaddJob", but add findings to the location list without clearing it first. + *makejob-MakeJobStop* *:MakeJobStop* +MakeJobStop [{MakeJob}] Use this command to cancel a running MakeJob. + + Without an argument, the command will cancel a + running MakeJob in one of two ways: + 1. If the current buffer spawned a MakeJob, + that job will be stopped. + 2. If the current buffer is displaying MakeJob + output, that job will stopped. + + MakeJobStop also accepts as an argument the name + of the MakeJob to stop (e.g., ":MakeJobStop + make"). Command completion can be used to make + finding the name easier. + ============================================================================= 2. CONFIGURATION *makejob-configuration* diff --git a/plugin/makejob.vim b/plugin/makejob.vim @@ -1,7 +1,7 @@ " " TITLE: VIM-MAKEJOB " AUTHOR: Daniel Moch <daniel@danielmoch.com> -" VERSION: 1.2 +" VERSION: 1.3-dev " if exists('g:loaded_makejob') || &cp finish @@ -28,6 +28,31 @@ function! s:InitAutocmd(lmake, grep, cmd) return l:returnval endfunction +function! s:JobStop(...) abort + if a:0 + if bufexists(a:1) + execute bufwinnr(a:1).'wincmd w' + if exists('b:makejob') + if !job_stop(b:makejob) + echoerr 'Failed to stop current MakeJob' + end + else + echoerr 'Provided buffer is not a MakeJob' + end + wincmd p + else + echoerr 'Provided MakeJob does not exist' + endif + elseif exists('b:makejob') + let l:job = s:jobinfo[split(job_getchannel(b:makejob))[1]] + if !job_stop(b:makejob) + echoerr 'Failed to stop '.l:job['prog'] + endif + else + echoerr 'Not in a MakeJob buffer, and none specified' + endif +endfunction + function! s:JobHandler(channel) abort let l:job = remove(s:jobinfo, split(a:channel)[1]) @@ -76,9 +101,9 @@ function! s:JobHandler(channel) abort echomsg l:job['prog']." ended with ".l:makeoutput." findings" endfunction -function! s:CreateMakeJobWindow(prog) +function! s:CreateMakeJobBuffer(prog) silent execute 'belowright 10split '.a:prog - setlocal bufhidden=hide buftype=nofile nobuflisted nolist + setlocal bufhidden=hide buftype=nofile buflisted nolist setlocal noswapfile nowrap nomodifiable let l:bufnum = winbufnr(0) if g:makejob_hide_preview_window @@ -103,7 +128,7 @@ function! s:Expand(input) return join(l:expanded_input) endfunction -function! s:MakeJob(grep, lmake, grepadd, bang, ...) +function! s:MakeJob(grep, lmake, grepadd, bang, ...) abort let l:make = a:grep ? s:Expand(&grepprg) : s:Expand(&makeprg) let l:prog = split(l:make)[0] let l:internal_grep = l:make ==# 'internal' ? 1 : 0 @@ -148,7 +173,7 @@ function! s:MakeJob(grep, lmake, grepadd, bang, ...) silent execute s:InitAutocmd(a:lmake, a:grep, 'Pre') - if &autowrite && !a:grep + if &autowrite && !empty(bufname('%')) && !a:grep silent write endif @@ -156,32 +181,47 @@ function! s:MakeJob(grep, lmake, grepadd, bang, ...) execute l:make return else - let l:outbufnr = s:CreateMakeJobWindow(prog) + let l:outbufnr = s:CreateMakeJobBuffer(prog) - let l:job = job_start(l:make, l:opts) - let s:jobinfo[split(job_getchannel(l:job))[1]] = + let l:makejob = job_start(l:make, l:opts) + let b:makejob = l:makejob + let s:jobinfo[split(job_getchannel(b:makejob))[1]] = \ { 'prog': l:prog,'lmake': a:lmake, \ 'outbufnr': l:outbufnr, \ 'srcbufnr': winbufnr(0), \ 'cfirst': !a:bang, 'grep': a:grep, - \ 'grepadd': a:grepadd, + \ 'grepadd': a:grepadd, 'job': b:makejob, \ 'outbufhidden': g:makejob_hide_preview_window } - echomsg s:jobinfo[split(job_getchannel(l:job))[1]]['prog'] + echomsg s:jobinfo[split(job_getchannel(b:makejob))[1]]['prog'] \ .' started' + + execute bufwinnr(l:outbufnr).'wincmd w' + let b:makejob = l:makejob + wincmd p end endfunction +function! s:MakeJobCompletion(arglead, cmdline, cursorpos) + let l:return = [] + for l:key in keys(s:jobinfo) + let l:return += [s:jobinfo[l:key]['prog']] + endfor + return l:return +endfunction + command! -bang -nargs=* -complete=file MakeJob - \ call s:MakeJob(0,0,0,<bang>0,<q-args>) + \ call <sid>MakeJob(0,0,0,<bang>0,<q-args>) command! -bang -nargs=* -complete=file LmakeJob - \ call s:MakeJob(0,1,0,<bang>0,<q-args>) + \ call <sid>MakeJob(0,1,0,<bang>0,<q-args>) command! -bang -nargs=+ -complete=file GrepJob - \ call s:MakeJob(1,0,0,<bang>0,<q-args>) + \ call <sid>MakeJob(1,0,0,<bang>0,<q-args>) command! -bang -nargs=+ -complete=file LgrepJob - \ call s:MakeJob(1,1,0,<bang>0,<q-args>) + \ call <sid>MakeJob(1,1,0,<bang>0,<q-args>) command! -bang -nargs=+ -complete=file GrepaddJob - \ call s:MakeJob(1,0,1,<bang>0,<q-args>) + \ call <sid>MakeJob(1,0,1,<bang>0,<q-args>) command! -bang -nargs=+ -complete=file LgrepaddJob - \ call s:MakeJob(1,1,1,<bang>0,<q-args>) + \ call <sid>MakeJob(1,1,1,<bang>0,<q-args>) +command! -nargs=? -complete=customlist,<sid>MakeJobCompletion + \ MakeJobStop call <sid>JobStop(<f-args>) let &cpo = s:save_cpo unlet s:save_cpo