Skip to content

Commit

Permalink
MakeJob v1.2
Browse files Browse the repository at this point in the history
Add a configuration option, g:makejob_hide_preview_window, to do pretty
much what it says. If set to 1, the preview window is hidden during
execution. This option does not affect configured autocmds, which might
open the quickfix or location windows upon job completion if there are
errors.
  • Loading branch information
djmoch committed Apr 2, 2017
1 parent 12a42c4 commit bd891d3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 25 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,19 @@ mapping to my `.vimrc`:

`nnoremap <Leader>g :GrepJob!<Space>`

Finally, if you find the preview windows distracting or otherwise
disruptive to your workflow, you can hide it with the following, global
setting:

`let g:makejob_hide_preview_window = 1`

## Gotchas
1. If `grepprg` is set to `'internal'`, then Vim uses its own builtin grep
command. This still works when you call `:GrepJob`, but not
asynchronously.
2. For simplicity, only one instance of a given executable can run at
once. You can run `make` and `pylint`, but you can't run two
instances of `make`.
instances of `make` simultaneously.

## Vim Documentation
Part of the goal of _MakeJob_ is to minimize the size of the plugin by
Expand Down
59 changes: 39 additions & 20 deletions doc/makejob.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,76 @@
Author: Daniel Moch <[email protected]>
License: MIT (see LICENSE file for details)

INTRODUCTION *makejob* *vim-makejob*
MakeJob *makejob* *vim-makejob*

This is a plugin for folks who think that Vim's quickfix feature is
great, but who don't like how calls to |:make| and |:grep| freeze the
editor. MakeJob implements asynchronous versions of the builtin
commands in just over 150 lines of Vimscript.

1. Commands |makejob-commands|
2. Configuration |makejob-configuration|
3. About |makejob-about|

{only when compiled with the |channel|, |job|, and |quickfix| features}

=============================================================================
1. MakeJob Commands *makejob-commands*

Here are your new quickfix commands.

*makejob-MakeJob*
*makejob-MakeJob* *:MakeJob*
MakeJob[!] [{filename}] Start a makejob on the specified buffer,
populating findings in the quickfix list.
|makeprg| and |errorformat| must be set before
MakeJob is called. {filename}, if specified, is the
name of the file to make, and is appended to the
end of |makeprg|. Ex special characters are
MakeJob is called. {filename}, if specified, is
the name of the file to make, and is appended to
the 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.
|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*
*makejob-LmakeJob* *:LmakeJob*
LmakeJob[!] [{filename}] Same as ":MakeJob", except the location list for
the current window is used instead of the quickfix
list.

*makejob-GrepJob*
GrepJob[!] {filename} Run the grep command specified in |grepprg|
and read into the quickfix list using
|grepformat|. {filename} must be specified,
but can contain wildcards.
*makejob-GrepJob* *:GrepJob*
GrepJob[!] {filename} Run the grep command specified in |grepprg| and
read into the quickfix list using |grepformat|.
{filename} must be specified, but can contain
wildcards.

*makejob-LgrepJob*
*makejob-LgrepJob* *:LgrepJob*
LgrepJob[!] {filename} Same as ":GrepJob", except the location list for
the current window is used instead of the quickfix
list.

*makejob-GrepaddJob*
*makejob-GrepaddJob* *:GrepaddJob*
GrepaddJob[!] {filename} Same as ":GrepJob", but add findings to the
quickfix list without clearing it first.

*makejob-LgrepaddJob*
*makejob-LgrepaddJob* *:LgrepaddJob*
LgrepaddJob[!] {filename} Same as ":GrepaddJob", but add findings to the
location list without clearing it first.

ABOUT *makejob-about*
=============================================================================
2. CONFIGURATION *makejob-configuration*

*g:makejob_hide_preview_window*
number (default 0)
g:makejob_hide_preview_window Hide the preview window during execution.
Default (0) is to show the preview window.
Set to 1 to hide it.

=============================================================================
3. ABOUT *makejob-about*

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

https://github.com/djmoch/vim-makejob

vim:tw=78:ts=8:ft=help:norl:
17 changes: 13 additions & 4 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: 1.2-dev
" VERSION: 1.2
"
if exists('g:loaded_makejob') || &cp
finish
Expand All @@ -14,6 +14,10 @@ let s:save_cpo = &cpo
set cpo&vim
let s:jobinfo = {}

if !exists('g:makejob_hide_preview_window')
let g:makejob_hide_preview_window = 0
endif

function! s:InitAutocmd(lmake, grep, cmd)
let l:returnval = 'doautocmd QuickFixCmd'.a:cmd.' '
if a:grep
Expand Down Expand Up @@ -44,7 +48,7 @@ function! s:JobHandler(channel) abort
let l:qfcmd = l:job['grepadd'] ? 'caddbuffer' : 'cgetbuffer'
endif

if bufwinnr(l:job['outbufnr'])
if bufwinnr(l:job['outbufnr']) && l:job['outbufhidden'] == 0
silent execute bufwinnr(l:job['outbufnr']).'close'
endif
silent execute l:qfcmd.' '.l:job['outbufnr']
Expand Down Expand Up @@ -77,7 +81,11 @@ function! s:CreateMakeJobWindow(prog)
setlocal bufhidden=hide buftype=nofile nobuflisted nolist
setlocal noswapfile nowrap nomodifiable
let l:bufnum = winbufnr(0)
wincmd p
if g:makejob_hide_preview_window
hide
else
wincmd p
end
return l:bufnum
endfunction

Expand Down Expand Up @@ -156,7 +164,8 @@ function! s:MakeJob(grep, lmake, grepadd, bang, ...)
\ 'outbufnr': l:outbufnr,
\ 'srcbufnr': winbufnr(0),
\ 'cfirst': !a:bang, 'grep': a:grep,
\ 'grepadd': a:grepadd }
\ 'grepadd': a:grepadd,
\ 'outbufhidden': g:makejob_hide_preview_window }
echomsg s:jobinfo[split(job_getchannel(l:job))[1]]['prog']
\ .' started'
end
Expand Down

0 comments on commit bd891d3

Please sign in to comment.