Skip to content

Commit

Permalink
Complete port to Vim 8. 0.2 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
djmoch committed Nov 4, 2016
1 parent 01346af commit 6325f43
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 74 deletions.
36 changes: 16 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# Vim MakeJob

__NOTE:__ This repository is undergoing conversion from supporting Neovim
to supporting Vim. Please excuse the messiness of the documentation.

There are plenty of [other](http://github.com/scrooloose/syntastic) [build
solutions](http://github.com/neomake/neomake) for
[Vim](http://github.com/vim/vim) and
[Neovim](http://github.com/neovim/neovim), 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
Neovim in just over 100 lines of Vimscript.
There are plenty of [other build
solutions](http://github.com/scrooloose/syntastic) for
[Vim](http://github.com/vim/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.

## Goals
1. Implement a minimal solution for asynchronous `:make` and `:lmake`.
No unnecessary features.
2. Let Neovim be Neovim. Use compiler plugins to configure `makeprg` and
2. Let Vim be Vim. Use compiler plugins to configure `makeprg` and
`errorformat`. Use the Quickfix or Location List window to view
findings.
3. Complete feature parity with `:make` and `:lmake` per the steps
Expand All @@ -23,22 +19,22 @@ Neovim in just over 100 lines of Vimscript.

## Installation
### Pathogen
`cd ~/.config/nvim/bundle`
`git clone https://github.com/djmoch/nvim-makejob.git`
`cd ~/.vim/bundle`
`git clone https://github.com/djmoch/vim-makejob.git`

### Plug.vim
`Plug 'djmoch/nvim-makejob'`
`Plug 'djmoch/vim-makejob'`

Most other plugin managers will resemble one of these two.

## Usage
### The Short Version
Neovim has `:make` and `:lmake`. Replace those calls with `:MakeJob` and
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`.

### The Less Short Version
Users of Syntastic and Neomake may not be aware that Neovim offers many
Users of Syntastic and Neomake may not be aware that Vim offers many
of their features out of the box. Here's a brief rundown.

With no prior configuration, `:make` will run the `make` program with no
Expand All @@ -50,7 +46,7 @@ format of the errors to look for. This gets pretty hairy, and so
we're all better off trying to avoid this in favor of the easy way:
compiler plugins. Using a compiler plugin easy (ex: `:compiler javac`),
they abstract away the work of remembering the `errorformat`, they're
extendable, and many are already included in Neovim. _MakeJob_ uses
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
Expand All @@ -73,11 +69,11 @@ with something like the following:

`autocmd BufWritePost *.py :LmakeJob<CR>`

## Neovim Documentation
## Vim Documentation
Part of the goal of _MakeJob_ is to minimize the size of the plugin by
using features Neovim already offers whenever possible. To that end, if
using features Vim already offers whenever possible. To that end, if
any of what foregoing discussion doesn't make sense, then take a look at
the help documentation in Neovim. Of particular interest will probably
the help documentation in Vim. Of particular interest will probably
be the following:

1. `:h make`
Expand Down
14 changes: 7 additions & 7 deletions doc/makejob.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
*makejob.txt* Minimal, asynchronous make and lmake for Neovim
*makejob.txt* Minimal, asynchronous make and lmake for Vim

Author: Daniel Moch <[email protected]>
License: MIT (see LICENSE file for details)

INTRODUCTION *makejob* *nvim-makejob*
INTRODUCTION *makejob* *vim-makejob*

There are plenty of other build solutions for Vim and Neovim, 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
Neovim in just over 100 lines of Vimscript.
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.

Here are your new make commands.

Expand All @@ -30,4 +30,4 @@ ABOUT *makejob-about*

More details can be found in README.md or by navigating to:

https://github.com/djmoch/nvim-makejob
https://github.com/djmoch/vim-makejob
89 changes: 42 additions & 47 deletions plugin/makejob.vim
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
"
" TITLE: NVIM-MAKEJOB
" TITLE: VIM-MAKEJOB
" AUTHOR: Daniel Moch <[email protected]>
" VERSION: 0.1
" VERSION: 0.2
"
if exists('g:loaded_makejob') || !has('nvim')
if exists('g:loaded_makejob') || version < 800
finish
endif
let g:loaded_makejob = 1

let s:jobinfo = {}

function! s:JobHandler(job_id, data, event_type) abort
if a:event_type == 'stdout' && type(a:data) == type([])
let s:jobinfo[a:job_id]['output'] =
\ s:jobinfo[a:job_id]['output'][:-2] +
\ [s:jobinfo[a:job_id]['output'][-1] . get(a:data,
\ 0, '')] +
\ a:data[1:]
elseif a:event_type == 'exit'
let is_lmake = s:jobinfo[a:job_id]['lmake']
let output = s:jobinfo[a:job_id]['output']
function! s:Function(name)
return substitute(a:name, '^s:', matchstr(expand('<sfile>'),
\'<SNR>\d\+_\zefunction$'),'')
endfunction

" For reasons I don't understand, copying and re-writing
" errorformat fixes a lot of parsing errors
let tempefm = &errorformat
let &errorformat = tempefm
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

if is_lmake
lgetexpr output
else
cgetexpr output
endif
" For reasons I don't understand, copying and re-writing
" errorformat fixes a lot of parsing errors
let tempefm = &errorformat
let &errorformat = tempefm

let initqf = is_lmake ? getloclist(winnr()) : getqflist()
let makeoutput = []
let idx = 0
while idx < len(initqf)
let qfentry = initqf[idx]
if qfentry['valid']
let makeoutput += [qfentry]
endif
let idx += 1
endwhile
if is_lmake
lgetexpr output
else
cgetexpr output
endif

if is_lmake
call setloclist(winnr(), makeoutput, 'r')
else
call setqflist(makeoutput, 'r')
let initqf = is_lmake ? getloclist(winnr()) : getqflist()
let makeoutput = []
let idx = 0
while idx < len(initqf)
let qfentry = initqf[idx]
if qfentry['valid']
let makeoutput += [qfentry]
endif
let idx += 1
endwhile

echo s:jobinfo[a:job_id]['prog']." ended with "
\ .len(makeoutput)." findings"
if is_lmake
call setloclist(winnr(), makeoutput, 'r')
else
call setqflist(makeoutput, 'r')
endif

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

function! s:NumChars(string, char, ...)
Expand Down Expand Up @@ -101,15 +101,10 @@ function! s:MakeJob(lmake, ...)
let joblist += [a:1]
endif
endif
let opts = {
\ 'on_stdout': function('s:JobHandler'),
\ 'on_stderr': function('s:JobHandler'),
\ 'on_exit': function('s:JobHandler')
\ }
let jobid = jobstart(joblist, opts)
let s:jobinfo[jobid] = {'prog': joblist[0], 'output': [''],
\ 'lmake': a:lmake}
echo s:jobinfo[jobid]['prog'].' started'
let opts = { 'close_cb' : s:Function('s:JobHandler') }
let job = job_start(joblist, opts)
let s:jobinfo[split(job_getchannel(job))[1]] = {'prog': joblist[0],'lmake': a:lmake}
echo 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 6325f43

Please sign in to comment.