Skip to content

Commit

Permalink
Improvements on pull request #16
Browse files Browse the repository at this point in the history
See pull request #16 on GitHub:
  #16
  • Loading branch information
xolox committed Jun 12, 2013
1 parent 1382495 commit a04b3ab
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
15 changes: 11 additions & 4 deletions README.md
Expand Up @@ -48,9 +48,11 @@ Note that on UNIX if the environment variable `$DISPLAY` is empty the plug-in wi

### The `:MakeWithShell` command

This command is a very simple replacement for the [:make] [make] command that does not pop up a console window on Windows. It doesn't come with all of the bells and whistles that Vim's built-in make command does but it should work.
This command is a very simple replacement for the [:make] [] command that does not pop up a console window on Windows. It doesn't come with all of the bells and whistles that Vim's built-in make command does but it should work. It properly triggers the [QuickFixCmdPre] [] and [QuickFixCmdPost] [] events, although it does so using [:silent] [] to avoid printing two "No matching autocommands" messages.

Because Vim's [v:shell_error] [shell_error] variable is read only (which means it cannot be set by a Vim plug-in) the vim-shell plug-in defines its own variable with the exit code of the `make` process executed by `:MakeWithShell`. This variable is called `g:xolox#shell#make_exit_code`. The semantics are exactly the same as for [v:shell_error] [shell_error].
Because Vim's [v:shell_error] [] variable is read only (which means it cannot be set by a Vim plug-in) the vim-shell plug-in defines its own variable with the exit code of the `make` process executed by `:MakeWithShell`. This variable is called `g:xolox#shell#make_exit_code`. The semantics are exactly the same as for [v:shell_error] [].

The `:MakeWithShell` command uses Vim's [quickfix window] []. To make the shell plug-in use the [location-list] [] instead you can use the command `:LMakeWithShell` instead.

### The `xolox#misc#os#exec()` function

Expand Down Expand Up @@ -136,6 +138,8 @@ This software is licensed under the [MIT license] [mit].
© 2013 Peter Odding &lt;<peter@peterodding.com>&gt;.


[:make]: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#:make
[:silent]: http://vimdoc.sourceforge.net/htmldoc/various.html#:silent
[ctags]: http://en.wikipedia.org/wiki/Ctags
[dll]: http://en.wikipedia.org/wiki/Dynamic-link_library
[download-misc]: http://peterodding.com/code/vim/downloads/misc.zip
Expand All @@ -149,16 +153,19 @@ This software is licensed under the [MIT license] [mit].
[gui]: http://vimdoc.sourceforge.net/htmldoc/gui.html#GUI
[gvimfullscreen_win32]: http://www.vim.org/scripts/script.php?script_id=2596
[libcall]: http://vimdoc.sourceforge.net/htmldoc/eval.html#libcall()
[make]: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#:make
[location-list]: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#location-list
[mit]: http://en.wikipedia.org/wiki/MIT_License
[pathogen]: http://www.vim.org/scripts/script.php?script_id=2332
[quickfix window]: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#quickfix
[QuickFixCmdPost]: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#QuickFixCmdPost
[QuickFixCmdPre]: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#QuickFixCmdPre
[screenshots]: http://peterodding.com/code/vim/shell/screenshots/
[sh_opt]: http://vimdoc.sourceforge.net/htmldoc/options.html#%27shell%27
[shcf_opt]: http://vimdoc.sourceforge.net/htmldoc/options.html#%27shellcmdflag%27
[shell_error]: http://vimdoc.sourceforge.net/htmldoc/eval.html#v:shell_error
[stal]: http://vimdoc.sourceforge.net/htmldoc/options.html#%27showtabline%27
[system]: http://vimdoc.sourceforge.net/htmldoc/eval.html#system()
[taskbars]: http://en.wikipedia.org/wiki/Taskbar
[v:shell_error]: http://vimdoc.sourceforge.net/htmldoc/eval.html#v:shell_error
[vim-session]: http://peterodding.com/code/vim/session/
[vim]: http://www.vim.org/
[vim_scripts_entry]: http://www.vim.org/scripts/script.php?script_id=3123
Expand Down
21 changes: 11 additions & 10 deletions autoload/xolox/shell.vim
@@ -1,9 +1,9 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: June 3, 2013
" Last Change: June , 2013
" URL: http://peterodding.com/code/vim/shell/

let g:xolox#shell#version = '0.12.10'
let g:xolox#shell#version = '0.13'

if !exists('s:fullscreen_enabled')
let s:enoimpl = "%s() hasn't been implemented on your platform! %s"
Expand Down Expand Up @@ -146,28 +146,29 @@ function! xolox#shell#execute_with_dll(cmd, async) " {{{1
endif
endfunction

function! xolox#shell#make(bang, args) " {{{1
function! xolox#shell#make(mode, bang, args) " {{{1
" Run :make silent (without a console window).
let command = &makeprg
if a:args =~ '\S'
let command .= ' ' . a:args
endif
call xolox#misc#msg#info("shell.vim %s: Running make command %s ..", g:xolox#shell#version, command)
call xolox#misc#msg#info("shell.vim %s: Running make command: %s", g:xolox#shell#version, command)
if a:bang == '!'
cgetexpr s:make_cmd(command)
execute printf('%sgetexpr s:make_cmd(a:mode, command)', a:mode)
else
cexpr s:make_cmd(command)
execute printf('%sexpr s:make_cmd(a:mode, command)', a:mode)
endif
cwindow
execute a:mode . 'window'
endfunction

function! s:make_cmd(command)
doautocmd QuickFixCmdPre make,lmake
function! s:make_cmd(mode, command)
let event = (a:mode == 'l') ? 'lmake' : 'make'
execute 'silent doautocmd QuickFixCmdPre' event
let command = a:command . ' 2>&1'
let result = xolox#misc#os#exec({'command': command, 'check': 0})
let g:xolox#shell#make_exit_code = result['exit_code']
execute 'silent doautocmd QuickFixCmdPost' event
return join(result['stdout'], "\n")
doautocmd QuickFixCmdPost make,lmake
endfunction

if !exists('g:xolox#shell#make_exit_code')
Expand Down
8 changes: 7 additions & 1 deletion doc/shell.txt
Expand Up @@ -121,14 +121,20 @@ The *:MakeWithShell* command

This command is a very simple replacement for the |:make| command that does not
pop up a console window on Windows. It doesn't come with all of the bells and
whistles that Vim's built-in make command does but it should work.
whistles that Vim's built-in make command does but it should work. It properly
triggers the |QuickFixCmdPre| and |QuickFixCmdPost| events, although it does so
using |:silent| to avoid printing two "No matching autocommands" messages.

Because Vim's |v:shell_error| variable is read only (which means it cannot be
set by a Vim plug-in) the vim-shell plug-in defines its own variable with the
exit code of the 'make' process executed by |:MakeWithShell|. This variable is
called 'g:xolox#shell#make_exit_code'. The semantics are exactly the same as
for |v:shell_error|.

The |:MakeWithShell| command uses Vim's |quickfix| window. To make the shell
plug-in use the |location-list| instead you can use the command
':LMakeWithShell' instead.

-------------------------------------------------------------------------------
The *xolox#misc#os#exec()* function

Expand Down
5 changes: 3 additions & 2 deletions plugin/shell.vim
@@ -1,6 +1,6 @@
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
" Last Change: May 2, 2013
" Last Change: June 12, 2013
" URL: http://peterodding.com/code/vim/shell/

" Support for automatic update using the GLVS plug-in.
Expand Down Expand Up @@ -42,7 +42,8 @@ augroup END
command! -bar -nargs=? -complete=file Open call xolox#shell#open_cmd(<q-args>)
command! -bar Maximize call xolox#shell#maximize()
command! -bar Fullscreen call xolox#shell#fullscreen()
command! -bar -bang -nargs=? MakeWithShell :call xolox#shell#make(<q-bang>, <q-args>)
command! -bar -bang -nargs=? MakeWithShell :call xolox#shell#make('c', <q-bang>, <q-args>)
command! -bar -bang -nargs=? LMakeWithShell :call xolox#shell#make('l', <q-bang>, <q-args>)

" Default key mappings. {{{1

Expand Down

0 comments on commit a04b3ab

Please sign in to comment.