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 d281dd16ad196f8e7dd58a94f42e870955f6560b
parent 006b0bba81f6d8a36724f57d9ec540afdfe8ae66
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Fri, 11 Nov 2016 20:16:49 -0500

Implement an initial solution for a preview buffer

The buffer is used to show the output of the make command while it is
running. This will be useful for longer running jobs, and approximates
the behavior of :make without stealing focus from the active buffer.

Desirable improvements include:
1. A handler to receive stdout/stderr messages and write them to the
   preview buffer, setting and un-setting the modifiable boolean as
   necessary.
2. Local buffer flags for the preview buffer (e.g., noswapfile)

Diffstat:
MREADME.md | 15++++++++++-----
Mdoc/makejob.txt | 4+++-
Mplugin/makejob.vim | 15++++++++-------
3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/README.md b/README.md @@ -30,8 +30,14 @@ Most other plugin managers will resemble one of these two. ## Usage ### The Short Version Vim has `:make` and `:lmake`. Replace those calls with `:MakeJob` and -`:LmakeJob`. Call it a day. If `:MakeJob` reports findings, use `:copen` -to view them, and likewise `:lopen` for `:LmakeJob`. +`:LmakeJob`. A buffer will open showing the command output, which will +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 +(in the case of MakeJob), and likewise `:lopen` to open the LocationList +for `:LmakeJob`. ### The Less Short Version Users of Syntastic may not be aware that Vim offers many of the same @@ -49,9 +55,8 @@ they abstract away the work of remembering the `errorformat`, they're extendable, and many are already included in Vim. _MakeJob_ uses compilers. -Also, it's possible to use `autocmd` to set the compiler of your choice - automatically. Just for the sake of completeness, an example of that - trick would like like this: +It's also possible to use `autocmd` to set the compiler of your choice + automatically. An example of that trick would like like this: `autocmd! FileType python compiler pylint` diff --git a/doc/makejob.txt b/doc/makejob.txt @@ -8,7 +8,7 @@ INTRODUCTION *makejob* *vim-makejob* There are plenty of other build solutions for Vim and Vim, many of them offering feature sets that overlap with those the editor already offers. With minimalism as a goal, MakeJob implements asynchronous |:make| and -|:lmake| for Vim in just over 100 lines of Vimscript. +|:lmake| for Vim in under 100 lines of Vimscript. Here are your new make commands. @@ -22,6 +22,8 @@ MakeJob [{bufname}] Start a makejob on the specified buffer, the special character % (see |_%|). |autowrite|, |QuickFixCmdPre|, and |QuickFixCmdPost| all work as expected. + While the job runs, output will be directed + to a preview buffer below the active buffer. *makejob-LmakeJob* LmakeJob [{bufname}] Same as ":MakeJob", except the location list for diff --git a/plugin/makejob.vim b/plugin/makejob.vim @@ -18,10 +18,8 @@ endfunction function! s:JobHandler(channel) abort let is_lmake = s:jobinfo[split(a:channel)[1]]['lmake'] - let output = [] - while ch_status(a:channel, {'part': 'out'}) == 'buffered' - let output += [ch_read(a:channel)] - endwhile + let output = getbufline('MakeJob', 1, '$') + silent bdelete! MakeJob " For reasons I don't understand, copying and re-writing " errorformat fixes a lot of parsing errors @@ -51,7 +49,7 @@ function! s:JobHandler(channel) abort silent doautocmd QuickFixCmdPost make endif - echo s:jobinfo[split(a:channel)[1]]['prog']." ended with " + echomsg s:jobinfo[split(a:channel)[1]]['prog']." ended with " \ .makeoutput." findings" endfunction @@ -64,7 +62,8 @@ function! s:MakeJob(lmake, ...) let make = make.' '.a:1 endif endif - let opts = { 'close_cb' : s:Function('s:JobHandler') } + let opts = { 'close_cb' : s:Function('s:JobHandler'), + \ 'out_io': 'buffer', 'out_name': 'MakeJob' } if a:lmake silent doautocmd QuickFixCmdPre lmake @@ -76,9 +75,11 @@ function! s:MakeJob(lmake, ...) silent write endif + silent belowright pedit MakeJob + let job = job_start(make, opts) let s:jobinfo[split(job_getchannel(job))[1]] = {'prog': split(make)[0],'lmake': a:lmake} - echo s:jobinfo[split(job_getchannel(job))[1]]['prog'].' started' + echomsg s:jobinfo[split(job_getchannel(job))[1]]['prog'].' started' endfunction command! -nargs=? MakeJob call s:MakeJob(0,<f-args>)