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 20f85b21f7c829eb304af84e7c655aa3eb319cef
parent eb87bb0e4ce7e148c371c7d35102eedeec242871
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sat, 19 Nov 2016 11:35:33 -0500

Miscellaneous improvements

1. Preview buffer is wiped instead of deleted
2. Automatically jump to first error unless bang operator used
3. If the preview buffer is hidden mid-process, it is NOT wiped
4. Ex special characters are properly expanded

Diffstat:
MREADME.md | 26++++++++++++++------------
Mdoc/makejob.txt | 17+++++++++--------
Mplugin/makejob.vim | 25+++++++++++++------------
3 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/README.md b/README.md @@ -15,7 +15,7 @@ just over 100 lines of Vimscript. findings. 3. Complete feature parity with `:make` and `:lmake` per the steps outlined in `:help make`. `autowrite`, `QuickFixCmdPre` and - `QuickFixCmdPost` work as expected. + `QuickFixCmdPost`, and `!` work as expected. ## Requirements Vim 8 minimum compiled with `+job` and `+channel`. @@ -58,24 +58,26 @@ they abstract away the work of remembering the `errorformat`, they're extendable, and many are already included in Vim. _MakeJob_ uses compilers. -It's also possible to use `autocmd` to set the compiler of your choice - automatically. An example of that trick would like like this: +It's also possible to use the`after/ftplugin` folder to automatically +configure compilers on a per-file-type basis. An example of that trick +would be to add the following to `~/.vim/after/ftplugin/python.vim`: -`autocmd! FileType python compiler pylint` +`compiler pylint` -Add that line to your `.vimrc` and you're good to go for Python files -(assuming you have a pylint compiler which hey, if you need one I've -[got you covered](http://github.com/djmoch/vim-compiler)). +Add that and you're good to go for Python files (assuming you have a +pylint compiler which hey, if you need one I've [got you +covered](http://github.com/djmoch/vim-compiler)). Additionally, if you'd like _MakeJob_ to run a linter automatically when -you write a file, then something like the following will to the trick. +you write a file, then something like the following in your `.vimrc` +will to the trick. -`autocmd BufWritePost * :LmakeJob<CR>` +`autocmd! BufWritePost * :LmakeJob! %<CR>` -For more granular control, you can set this trigger on a file-type basis -with something like the following: +For more granular control, you can set this trigger on a per-file-type +basis with something like the following: -`autocmd BufWritePost *.py :LmakeJob<CR>` +`autocmd! BufWritePost *.py :LmakeJob! %<CR>` ## Vim Documentation Part of the goal of _MakeJob_ is to minimize the size of the plugin by diff --git a/doc/makejob.txt b/doc/makejob.txt @@ -13,20 +13,21 @@ With minimalism as a goal, MakeJob implements asynchronous |:make| and Here are your new make commands. *makejob-MakeJob* -MakeJob [{bufname}] Start a makejob on the specified buffer, +MakeJob[!] [{bufname}] Start a makejob on the specified buffer, populating findings in the quickfix list. |makeprg| and |errorformat| must be set before MakeJob is called. {bufname}, if specified, is the name of the file to make, and is appended to the - end of |makeprg|. MakeJob currently only expands - 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. + end of |makeprg|. Ex special characters are + expanded (see |cmdline-special|). |autowrite|, + |QuickFixCmdPre|, and |QuickFixCmdPost| all + work as expected. While the job runs, output + will be directed to a preview buffer below + the active buffer. If [!] is not given, the + first error is jumped to. *makejob-LmakeJob* -LmakeJob [{bufname}] Same as ":MakeJob", except the location list for +LmakeJob[!] [{bufname}] Same as ":MakeJob", except the location list for the current window is used instead of the quickfix list. 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.0 +" VERSION: 1.1-dev " if exists('g:loaded_makejob') || version < 800 || !has('job') || \ !has('channel') @@ -20,7 +20,7 @@ function! s:JobHandler(channel) abort 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!' + silent execute job['outbufnr'].'bwipe!' " For reasons I don't understand, copying and re-writing " errorformat fixes a lot of parsing errors @@ -54,19 +54,23 @@ function! s:JobHandler(channel) abort silent doautocmd QuickFixCmdPost make endif + if job['cfirst'] + cfirst + end + 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 bufhidden=hide buftype=nofile nobuflisted nolist setlocal noswapfile nowrap nomodifiable let bufnum = winbufnr(0) wincmd p return bufnum endfunction -function! s:MakeJob(lmake, ...) +function! s:MakeJob(lmake, bang, ...) let make = &makeprg let prog = split(make)[0] execute 'let openbufnr = bufnr("^'.prog.'$")' @@ -77,11 +81,7 @@ function! s:MakeJob(lmake, ...) return endif if a:0 - if a:1 == '%' - let make = make.' '.bufname(a:1) - else - let make = make.' '.a:1 - endif + let make = make.' '.expand(a:1) endif let opts = { 'close_cb' : s:Function('s:JobHandler'), \ 'out_io': 'buffer', @@ -106,9 +106,10 @@ function! s:MakeJob(lmake, ...) let job = job_start(make, opts) let s:jobinfo[split(job_getchannel(job))[1]] = \ { 'prog': prog,'lmake': a:lmake, - \ 'outbufnr': outbufnr, 'srcbufnr': winbufnr(0) } + \ 'outbufnr': outbufnr, 'srcbufnr': winbufnr(0), + \ 'cfirst': !a:bang } echomsg s:jobinfo[split(job_getchannel(job))[1]]['prog'].' started' endfunction -command! -nargs=? MakeJob call s:MakeJob(0,<f-args>) -command! -nargs=? LmakeJob call s:MakeJob(1,<f-args>) +command! -bang -nargs=? -complete=file MakeJob call s:MakeJob(0,<bang>0,<f-args>) +command! -bang -nargs=? -complete=file LmakeJob call s:MakeJob(1,<bang>0,<f-args>)