Skip to content

Commit

Permalink
Implement an initial solution for a preview buffer
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
djmoch committed Nov 12, 2016
1 parent 006b0bb commit d281dd1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`

Expand Down
4 changes: 3 additions & 1 deletion doc/makejob.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions plugin/makejob.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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>)
Expand Down

0 comments on commit d281dd1

Please sign in to comment.