Skip to content

Commit

Permalink
vim-makejob 1.0
Browse files Browse the repository at this point in the history
Configure job output "preview" buffer per the notes in the previous
commit
  • Loading branch information
djmoch committed Nov 12, 2016
1 parent d281dd1 commit 80fe1f4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ just over 100 lines of Vimscript.
outlined in `:help make`. `autowrite`, `QuickFixCmdPre` and
`QuickFixCmdPost` work as expected.

## Requirements
Vim 8 minimum compiled with `+job` and `+channel`.

## Installation
### Pathogen
`cd ~/.vim/bundle`
Expand Down
2 changes: 1 addition & 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 under 100 lines of Vimscript.
|:lmake| for Vim in just over 100 lines of Vimscript.

Here are your new make commands.

Expand Down
44 changes: 34 additions & 10 deletions plugin/makejob.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"
" TITLE: VIM-MAKEJOB
" AUTHOR: Daniel Moch <[email protected]>
" VERSION: 0.3
" VERSION: 1.0
"
if exists('g:loaded_makejob') || version < 800 || !has('job') ||
\ !has('channel')
Expand All @@ -17,22 +17,27 @@ function! s:Function(name)
endfunction

function! s:JobHandler(channel) abort
let is_lmake = s:jobinfo[split(a:channel)[1]]['lmake']
let output = getbufline('MakeJob', 1, '$')
silent bdelete! MakeJob
let job = remove(s:jobinfo, split(a:channel)[1])
let is_lmake = job['lmake']
let output = getbufline(job['outbufnr'], 1, '$')
silent execute job['outbufnr'].'bdelete!'

" For reasons I don't understand, copying and re-writing
" errorformat fixes a lot of parsing errors
let tempefm = &errorformat
let &errorformat = tempefm

execute bufwinnr(job['srcbufnr']).'wincmd w'

if is_lmake
lgetexpr output
else
cgetexpr output
endif

let initqf = is_lmake ? getloclist(winnr()) : getqflist()
wincmd p

let initqf = is_lmake ? getloclist(bufwinnr(job['srcbufnr'])) : getqflist()
let makeoutput = 0
let idx = 0
while idx < len(initqf)
Expand All @@ -49,12 +54,28 @@ function! s:JobHandler(channel) abort
silent doautocmd QuickFixCmdPost make
endif

echomsg s:jobinfo[split(a:channel)[1]]['prog']." ended with "
\ .makeoutput." findings"
echomsg job['prog']." ended with ".makeoutput." findings"
endfunction

function! s:CreateMakeJobWindow(prog)
silent execute 'belowright 10split '.a:prog
setlocal bufhidden=wipe buftype=nofile nobuflisted nolist
setlocal noswapfile nowrap nomodifiable
let bufnum = winbufnr(0)
wincmd p
return bufnum
endfunction

function! s:MakeJob(lmake, ...)
let make = &makeprg
let prog = split(make)[0]
execute 'let openbufnr = bufnr("^'.prog.'$")'
if openbufnr != -1
echohl WarningMsg
echo prog.' already running'
echohl None
return
endif
if a:0
if a:1 == '%'
let make = make.' '.bufname(a:1)
Expand All @@ -63,7 +84,8 @@ function! s:MakeJob(lmake, ...)
endif
endif
let opts = { 'close_cb' : s:Function('s:JobHandler'),
\ 'out_io': 'buffer', 'out_name': 'MakeJob' }
\ 'out_io': 'buffer', 'out_name': prog,
\ 'out_modifiable': 0 }

if a:lmake
silent doautocmd QuickFixCmdPre lmake
Expand All @@ -75,10 +97,12 @@ function! s:MakeJob(lmake, ...)
silent write
endif

silent belowright pedit MakeJob
let outbufnr = s:CreateMakeJobWindow(prog)

let job = job_start(make, opts)
let s:jobinfo[split(job_getchannel(job))[1]] = {'prog': split(make)[0],'lmake': a:lmake}
let s:jobinfo[split(job_getchannel(job))[1]] =
\ { 'prog': prog,'lmake': a:lmake,
\ 'outbufnr': outbufnr, 'srcbufnr': winbufnr(0) }
echomsg s:jobinfo[split(job_getchannel(job))[1]]['prog'].' started'
endfunction

Expand Down

0 comments on commit 80fe1f4

Please sign in to comment.