New option for SyntasticMake(): env.

Setting environment variables by prefixing commands with 'VARIABLE=value'
doesn't work under csh.  Solution: let Vim set the environment variables.
This commit is contained in:
LCD 47 2014-07-07 19:04:22 +03:00
parent c325f6c815
commit 4c5ff42723
16 changed files with 85 additions and 53 deletions

View File

@ -19,7 +19,7 @@ if has('reltime')
lockvar! g:syntastic_start
endif
let g:syntastic_version = '3.4.0-92'
let g:syntastic_version = '3.4.0-93'
lockvar g:syntastic_version
" Sanity checks {{{1
@ -408,7 +408,9 @@ endfunction " }}}2
" 'preprocess' - a function to be applied to the error file before parsing errors
" 'postprocess' - a list of functions to be applied to the error list
" 'cwd' - change directory to the given path before running the checker
" 'env' - environment variables to set before running the checker
" 'returns' - a list of valid exit codes for the checker
" @vimlint(EVL102, 1, l:env_save)
function! SyntasticMake(options) " {{{2
call syntastic#log#debug(g:SyntasticDebugTrace, 'SyntasticMake: called with options:', a:options)
@ -432,11 +434,31 @@ function! SyntasticMake(options) " {{{2
execute 'lcd ' . fnameescape(a:options['cwd'])
endif
" set environment variables {{{3
let env_save = {}
if has_key(a:options, 'env') && len(a:options['env'])
for key in keys(a:options['env'])
if key =~? '\m^[a-z_]\+$'
exec 'let env_save[' . string(key) . '] = $' . key
exec 'let $' . key . ' = ' . string(a:options['env'][key])
endif
endfor
endif
let $LC_MESSAGES = 'C'
let $LC_ALL = ''
" }}}3
let err_lines = split(system(a:options['makeprg']), "\n", 1)
" restore environment variables {{{3
let $LC_ALL = old_lc_all
let $LC_MESSAGES = old_lc_messages
if len(env_save)
for key in keys(env_save)
exec 'let $' . key . ' = ' . string(env_save[key])
endfor
endif
" }}}3
call syntastic#log#debug(g:SyntasticDebugLoclist, 'checker output:', err_lines)
@ -497,6 +519,7 @@ function! SyntasticMake(options) " {{{2
return errors
endfunction " }}}2
" @vimlint(EVL102, 0, l:env_save)
"return a string representing the state of buffer according to
"g:syntastic_stl_format

View File

@ -22,24 +22,14 @@ function! SyntaxCheckers_eruby_ruby_IsAvailable() dict
if !exists('g:syntastic_eruby_ruby_exec') && exists('g:syntastic_ruby_exec')
let g:syntastic_eruby_ruby_exec = g:syntastic_ruby_exec
endif
let s:exe = self.getExec()
if executable(s:exe)
let s:exe = syntastic#util#shescape(s:exe)
if !syntastic#util#isRunningWindows()
let s:exe = 'RUBYOPT= ' . s:exe
endif
return 1
endif
return 0
return executable(self.getExec())
endfunction
function! SyntaxCheckers_eruby_ruby_GetLocList() dict
let fname = "'" . escape(expand('%'), "\\'") . "'"
" TODO: encodings became useful in ruby 1.9 :)
if syntastic#util#versionIsAtLeast(syntastic#util#getVersion(s:exe . ' --version'), [1, 9])
if syntastic#util#versionIsAtLeast(syntastic#util#getVersion(self.getExecEscaped(). ' --version'), [1, 9])
let enc = &fileencoding != '' ? &fileencoding : &encoding
let encoding_spec = ', :encoding => "' . (enc ==? 'utf-8' ? 'UTF-8' : 'BINARY') . '"'
else
@ -48,11 +38,11 @@ function! SyntaxCheckers_eruby_ruby_GetLocList() dict
"gsub fixes issue #7, rails has it's own eruby syntax
let makeprg =
\ s:exe . ' -rerb -e ' .
\ self.getExecEscaped() . ' -rerb -e ' .
\ syntastic#util#shescape('puts ERB.new(File.read(' .
\ fname . encoding_spec .
\ ').gsub(''<%='',''<%''), nil, ''-'').src') .
\ ' | ' . s:exe . ' -c'
\ ' | ' . self.getExecEscaped() . ' -c'
let errorformat =
\ '%-GSyntax OK,'.
@ -61,9 +51,12 @@ function! SyntaxCheckers_eruby_ruby_GetLocList() dict
\ '%Z%p^,'.
\ '%-C%.%#'
let env = syntastic#util#isRunningWindows() ? {} : { 'RUBYOPT': '' }
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'env': env,
\ 'defaults': { 'bufnr': bufnr(""), 'vcol': 1 } })
endfunction

View File

@ -186,9 +186,7 @@ function! s:Args()
endfunction
function! SyntaxCheckers_html_tidy_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'args_after': s:Args(),
\ 'tail': '2>&1' })
let makeprg = self.makeprgBuild({ 'args_after': s:Args() })
let errorformat =
\ '%Wline %l column %v - Warning: %m,' .

View File

@ -399,8 +399,7 @@ function! SyntaxCheckers_java_javac_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'args': javac_opts,
\ 'fname': syntastic#util#shescape(fname),
\ 'tail': '2>&1' })
\ 'fname': syntastic#util#shescape(fname) })
" unashamedly stolen from *errorformat-javac* (quickfix.txt) and modified to include error types
let errorformat =

View File

@ -19,8 +19,7 @@ function! SyntaxCheckers_python_flake8_GetHighlightRegex(item)
endfunction
function! SyntaxCheckers_python_flake8_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'TERM=dumb') })
let makeprg = self.makeprgBuild({})
let errorformat =
\ '%E%f:%l: could not compile,%-Z%p^,' .
@ -28,9 +27,12 @@ function! SyntaxCheckers_python_flake8_GetLocList() dict
\ '%A%f:%l: %t%n %m,' .
\ '%-G%.%#'
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat })
\ 'errorformat': errorformat,
\ 'env': env })
for e in loclist
" E*** and W*** are pep8 errors

View File

@ -19,9 +19,7 @@ let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_python_frosted_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'TERM=dumb'),
\ 'args_after': '-vb' })
let makeprg = self.makeprgBuild({ 'args_after': '-vb' })
let errorformat =
\ '%f:%l:%c:%m,' .
@ -29,9 +27,12 @@ function! SyntaxCheckers_python_frosted_GetLocList() dict
\ '%-Z%p^,' .
\ '%-G%.%#'
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'env': env,
\ 'returns': [0, 1] })
for e in loclist

View File

@ -19,8 +19,7 @@ function! SyntaxCheckers_python_pep257_GetLocList() dict
\ self.getExecEscaped() . ' --version'), [0, 3])
endif
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'TERM=dumb') })
let makeprg = self.makeprgBuild({})
if s:pep257_new
let errorformat =
@ -33,9 +32,12 @@ function! SyntaxCheckers_python_pep257_GetLocList() dict
\ '%+C %m'
endif
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'env': env,
\ 'subtype': 'Style',
\ 'preprocess': 'killEmpty',
\ 'postprocess': ['compressWhitespace'] })

View File

@ -21,14 +21,16 @@ let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_python_pep8_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'TERM=dumb') })
let makeprg = self.makeprgBuild({})
let errorformat = '%f:%l:%c: %m'
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'env': env,
\ 'subtype': 'Style' })
for e in loclist

View File

@ -14,14 +14,16 @@ let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_python_py3kwarn_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'TERM=dumb') })
let makeprg = self.makeprgBuild({})
let errorformat = '%W%f:%l:%c: %m'
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat })
\ 'errorformat': errorformat,
\ 'env': env })
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({

View File

@ -40,8 +40,7 @@ function! SyntaxCheckers_python_pyflakes_GetHighlightRegex(i)
endfunction
function! SyntaxCheckers_python_pyflakes_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'TERM=dumb') })
let makeprg = self.makeprgBuild({})
let errorformat =
\ '%E%f:%l: could not compile,'.
@ -50,9 +49,12 @@ function! SyntaxCheckers_python_pyflakes_GetLocList() dict
\ '%E%f:%l: %m,'.
\ '%-G%.%#'
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'env': env,
\ 'defaults': {'text': "Syntax error"} })
for e in loclist

View File

@ -23,18 +23,19 @@ function! SyntaxCheckers_python_pylama_GetHighlightRegex(item)
endfunction
function! SyntaxCheckers_python_pylama_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'TERM=dumb'),
\ 'args_after': '-f pep8' })
let makeprg = self.makeprgBuild({ 'args_after': '-f pep8' })
" TODO: "WARNING:pylama:..." messages are probably a logging bug
let errorformat =
\ '%-GWARNING:pylama:%.%#,' .
\ '%A%f:%l:%c: %m'
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat })
\ 'errorformat': errorformat,
\ 'env': env })
" adjust for weirdness in each checker
for e in loclist

View File

@ -23,7 +23,6 @@ endfunction
function! SyntaxCheckers_python_pylint_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'TERM=dumb'),
\ 'args_after': (s:pylint_new ? '-f text --msg-template="{path}:{line}:{column}:{C}: [{symbol}] {msg}" -r n' : '-f parseable -r n -i y') })
let errorformat =
@ -33,9 +32,12 @@ function! SyntaxCheckers_python_pylint_GetLocList() dict
\ '%-Z%p^%.%#,' .
\ '%-G%.%#'
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'env': env,
\ 'returns': range(32) })
for e in loclist

View File

@ -26,15 +26,16 @@ function! SyntaxCheckers_python_python_IsAvailable() dict
endfunction
function! SyntaxCheckers_python_python_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'TERM=dumb'),
\ 'exe': [self.getExec(), s:compiler] })
let makeprg = self.makeprgBuild({ 'exe': [self.getExec(), s:compiler] })
let errorformat = '%E%f:%l:%c: %m'
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'env': env,
\ 'returns': [0] })
endfunction

View File

@ -20,7 +20,6 @@ set cpo&vim
function! SyntaxCheckers_ruby_jruby_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'RUBYOPT='),
\ 'args': (syntastic#util#isRunningWindows() ? '-T1' : ''),
\ 'args_after': '-W1 -c' })
@ -33,9 +32,12 @@ function! SyntaxCheckers_ruby_jruby_GetLocList() dict
\ '%W%f:%l: %m,'.
\ '%-C%.%#'
let env = syntastic#util#isRunningWindows() ? {} : { 'RUBYOPT': '' }
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat })
\ 'errorformat': errorformat,
\ 'env': env })
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({

View File

@ -18,9 +18,7 @@ let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_ruby_macruby_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': 'RUBYOPT=',
\ 'args_after': '-W1 -c' })
let makeprg = self.makeprgBuild({ 'args_after': '-W1 -c' })
let errorformat =
\ '%-GSyntax OK,'.
@ -31,9 +29,12 @@ function! SyntaxCheckers_ruby_macruby_GetLocList() dict
\ '%W%f:%l: %m,'.
\ '%-C%.%#'
let env = { 'RUBYOPT': '' }
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat })
\ 'errorformat': errorformat,
\ 'env': env })
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({

View File

@ -35,9 +35,7 @@ function! SyntaxCheckers_ruby_mri_GetHighlightRegex(i)
endfunction
function! SyntaxCheckers_ruby_mri_GetLocList() dict
let makeprg = self.makeprgBuild({
\ 'exe_before': (syntastic#util#isRunningWindows() ? '' : 'RUBYOPT='),
\ 'args_after': '-w -T1 -c' })
let makeprg = self.makeprgBuild({ 'args_after': '-w -T1 -c' })
"this is a hack to filter out a repeated useless warning in rspec files
"containing lines like
@ -62,9 +60,12 @@ function! SyntaxCheckers_ruby_mri_GetLocList() dict
\ '%W%f:%l: %m,'.
\ '%-C%.%#'
let env = syntastic#util#isRunningWindows() ? {} : { 'RUBYOPT': '' }
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat })
\ 'errorformat': errorformat,
\ 'env': env })
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({