diff --git a/autoload/syntastic/makeprg.vim b/autoload/syntastic/makeprg.vim new file mode 100644 index 00000000..571d9222 --- /dev/null +++ b/autoload/syntastic/makeprg.vim @@ -0,0 +1,65 @@ +if exists("g:loaded_syntastic_makeprg_autoload") + finish +endif +let g:loaded_syntastic_makeprg_autoload = 1 + +function! syntastic#makeprg#build(opts) + let opts = copy(a:opts) + + if !has_key(opts, 'args') + let opts['args'] = '' + endif + + if !has_key(opts, 'subchecker') + let opts['subchecker'] = '' + endif + + let builder = s:MakeprgBuilder.New(opts['exe'], opts['args'], opts['subchecker']) + return builder.makeprg() +endfunction + +let s:MakeprgBuilder = {} + +function! s:MakeprgBuilder.New(exe, args, subchecker) + let newObj = copy(self) + let newObj._exe = a:exe + let newObj._args = a:args + let newObj._subchecker = a:subchecker + return newObj +endfunction + +function! s:MakeprgBuilder.makeprg() + return join([self.exe(), self.args(), self.fname()]) +endfunction + +function! s:MakeprgBuilder.exe() + if self.optExists('exe') + return {self.optName('exe')} + endif + + return self._exe +endfunction + +function! s:MakeprgBuilder.args() + if exists('g:syntastic_' . &ft . '_args') + return g:syntastic_{&ft}_args + endif + + return self._args +endfunction + +function! s:MakeprgBuilder.fname() + return shellescape(expand("%")) +endfunction + +function! s:MakeprgBuilder.optExists(name) + return exists(self.optName(a:name)) +endfunction + +function! s:MakeprgBuilder.optName(name) + let setting = "g:syntastic_" . &ft + if !empty(self._subchecker) + let setting .= '_' . self._subchecker + endif + return setting . '_' . a:name +endfunction diff --git a/syntax_checkers/coffee.vim b/syntax_checkers/coffee.vim index a5f011e6..100e62c0 100644 --- a/syntax_checkers/coffee.vim +++ b/syntax_checkers/coffee.vim @@ -21,7 +21,9 @@ endif function! SyntaxCheckers_coffee_GetLocList() - let makeprg = 'coffee -c -l -o /tmp '.shellescape(expand('%')) + let makeprg = syntastic#makeprg#build({ + \ 'exe': 'coffee', + \ 'args': '-c -l -o /tmp' }) let errorformat = 'Syntax%trror: In %f\, %m on line %l,%EError: In %f\, Parse error on line %l: %m,%EError: In %f\, %m on line %l,%W%f(%l): lint warning: %m,%-Z%p^,%W%f(%l): warning: %m,%-Z%p^,%E%f(%l): SyntaxError: %m,%-Z%p^,%-G%.%#' let coffee_results = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) diff --git a/syntax_checkers/python/flake8.vim b/syntax_checkers/python/flake8.vim index cd32cff2..5dbd4a5c 100644 --- a/syntax_checkers/python/flake8.vim +++ b/syntax_checkers/python/flake8.vim @@ -22,7 +22,10 @@ function! SyntaxCheckers_python_GetHighlightRegex(i) endfunction function! SyntaxCheckers_python_GetLocList() - let makeprg = 'flake8 '.g:syntastic_python_checker_args.' '.shellescape(expand('%')) + let makeprg = syntastic#makeprg#build({ + \ 'exe': 'flake8', + \ 'args': g:syntastic_python_checker_args, + \ 'subchecker': 'flake8' }) let errorformat = '%E%f:%l: could not compile,%-Z%p^,%E%f:%l:%c: %m,%W%f:%l: %m,%-G%.%#' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) endfunction