diff --git a/autoload/syntastic/makeprg.vim b/autoload/syntastic/makeprg.vim index 571d9222..b3a0f693 100644 --- a/autoload/syntastic/makeprg.vim +++ b/autoload/syntastic/makeprg.vim @@ -3,60 +3,101 @@ if exists("g:loaded_syntastic_makeprg_autoload") endif let g:loaded_syntastic_makeprg_autoload = 1 +"Returns a makeprg of the form +" +"[exe] [args] [filename] [post_args] [tail] +" +"A (made up) example: +" ruby -a -b -c test_file.rb --more --args > /tmp/output +" +"To generate this you would call: +" +" let makeprg = syntastic#makeprg#build({ +" \ 'exe': 'ruby', +" \ 'args': '-a -b -c', +" \ 'post_args': '--more --args', +" \ 'tail': '> /tmp/output', +" \ 'subchecker': 'mri' }) +" +"Note that the current filename is added by default - but can be overridden by +"passing in an 'fname' arg. +" +"All options can be overriden by the user with global variables - even when +"not specified by the checker in syntastic#makeprg#build(). +" +"E.g. They could override the checker exe with +" +" let g:syntastic_ruby_mri_exe="another_ruby_checker_exe.rb" +" +"The general form of the override option is: +" syntastic_[filetype]_[subchecker]_[option-name] +" function! syntastic#makeprg#build(opts) - let opts = copy(a:opts) + let builder = s:MakeprgBuilder.New( + \ get(a:opts, 'exe', ''), + \ get(a:opts, 'args', ''), + \ get(a:opts, 'fname', ''), + \ get(a:opts, 'post_args', ''), + \ get(a:opts, 'tail', ''), + \ get(a:opts, 'subchecker', '') ) - 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) +function! s:MakeprgBuilder.New(exe, args, fname, post_args, tail, subchecker) let newObj = copy(self) let newObj._exe = a:exe let newObj._args = a:args + let newObj._fname = a:fname + let newObj._post_args = a:post_args + let newObj._tail = a:tail let newObj._subchecker = a:subchecker return newObj endfunction function! s:MakeprgBuilder.makeprg() - return join([self.exe(), self.args(), self.fname()]) + return join([self.exe(), self.args(), self.fname(), self.post_args(), self.tail()]) endfunction function! s:MakeprgBuilder.exe() - if self.optExists('exe') - return {self.optName('exe')} - endif - - return self._exe + return self._getOpt('exe') endfunction function! s:MakeprgBuilder.args() - if exists('g:syntastic_' . &ft . '_args') - return g:syntastic_{&ft}_args - endif - - return self._args + return self._getOpt('args') endfunction function! s:MakeprgBuilder.fname() - return shellescape(expand("%")) + if empty(self._fname) + return shellescape(expand("%")) + else + return self._fname + endif endfunction -function! s:MakeprgBuilder.optExists(name) - return exists(self.optName(a:name)) +function! s:MakeprgBuilder.post_args() + return self._getOpt('post_args') endfunction -function! s:MakeprgBuilder.optName(name) +function! s:MakeprgBuilder.tail() + return self._getOpt('tail') +endfunction + +function s:MakeprgBuilder._getOpt(name) + if self._optExists(a:name) + return {self._optName(a:name)} + endif + + return self['_' . a:name] +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 diff --git a/syntax_checkers/dart/dart_analyzer.vim b/syntax_checkers/dart/dart_analyzer.vim index ce51fddc..d78be395 100644 --- a/syntax_checkers/dart/dart_analyzer.vim +++ b/syntax_checkers/dart/dart_analyzer.vim @@ -16,8 +16,8 @@ function! SyntaxCheckers_dart_GetLocList() let args = !empty(g:syntastic_dart_analyzer_conf) ? ' ' . g:syntastic_dart_analyzer_conf : '' let makeprg = syntastic#makeprg#build({ \ 'exe': 'dart_analyzer', + \ 'post_args': args, \ 'subchecker': 'dart_analyser' }) - let makeprg .= ' ' . args let errorformat = '%Efile:%f:%l:%c: %m' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) diff --git a/syntax_checkers/go/gofmt.vim b/syntax_checkers/go/gofmt.vim index 3a823dc9..4b777659 100644 --- a/syntax_checkers/go/gofmt.vim +++ b/syntax_checkers/go/gofmt.vim @@ -16,8 +16,8 @@ function! SyntaxCheckers_go_GetLocList() let makeprg = syntastic#makeprg#build({ \ 'exe': 'gofmt', \ 'args': '-l', + \ 'tail': '1>' . syntastic#util#DevNull(), \ 'subchecker': 'gofmt' }) - let makeprg .= ' 1>/dev/null' let errorformat = '%f:%l:%c: %m,%-G%.%#' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'type': 'e'} }) endfunction diff --git a/syntax_checkers/html/tidy.vim b/syntax_checkers/html/tidy.vim index 960f1029..1e8b2e38 100644 --- a/syntax_checkers/html/tidy.vim +++ b/syntax_checkers/html/tidy.vim @@ -61,8 +61,8 @@ function! SyntaxCheckers_html_GetLocList() let makeprg = syntastic#makeprg#build({ \ 'exe': 'tidy', \ 'args': s:Args(), + \ 'tail': '2>&1', \ 'subchecker': 'tidy' }) - let makeprg .= " 2>&1" let errorformat='%Wline %l column %c - Warning: %m,%Eline %l column %c - Error: %m,%-G%.%#,%-G%.%#' let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) diff --git a/syntax_checkers/java/checkstyle.vim b/syntax_checkers/java/checkstyle.vim index e4bdd6e7..ddca0cec 100644 --- a/syntax_checkers/java/checkstyle.vim +++ b/syntax_checkers/java/checkstyle.vim @@ -17,13 +17,13 @@ endif if !exists("g:syntastic_java_checkstyle_conf_file") let g:syntastic_java_checkstyle_conf_file = 'sun_checks.xml' endif - function! SyntaxCheckers_java_GetLocList() - - let makeprg = 'java -cp ' . g:syntastic_java_checkstyle_classpath . ' com.puppycrawl.tools.checkstyle.Main -c ' - \. g:syntastic_java_checkstyle_conf_file . ' ' - \. expand ( '%:p:h' ) . '/' . expand ( '%:t' ) - \. ' 2>&1 ' + let makeprg = syntastic#makeprg#build({ + \ 'exe': 'java', + \ 'args': '-cp ' . g:syntastic_java_checkstyle_classpath . ' com.puppycrawl.tools.checkstyle.Main -c ' . g:syntastic_java_checkstyle_conf_file, + \ 'fname': expand ( '%:p:h' ) . '/' . expand ( '%:t' ), + \ 'tail': '2>&1', + \ 'subchecker': 'checkstyle' }) " check style format let errorformat = '%f:%l:%c:\ %m,%f:%l:\ %m' diff --git a/syntax_checkers/java/javac.vim b/syntax_checkers/java/javac.vim index b341694d..46da8ce8 100644 --- a/syntax_checkers/java/javac.vim +++ b/syntax_checkers/java/javac.vim @@ -208,9 +208,12 @@ function! SyntaxCheckers_java_GetLocList() let sep = '/' endif - let makeprg = g:syntastic_java_javac_executable . ' '. javac_opts . ' ' - \. fnameescape(expand ( '%:p:h' ) . sep . expand ( '%:t' )) - \. ' 2>&1 ' + let makeprg = syntastic#makeprg#build({ + \ 'exe': g:syntastic_java_javac_executable, + \ 'args': javac_opts, + \ 'fname': fnameescape(expand ( '%:p:h' ) . sep . expand ( '%:t' )), + \ 'tail': '2>&1', + \ 'subchecker': 'javac' }) " unashamedly stolen from *errorformat-javac* (quickfix.txt) and modified to include error types let errorformat = '%E%f:%l:\ error:\ %m,%W%f:%l:\ warning:\ %m,%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#' diff --git a/syntax_checkers/javascript/closurecompiler.vim b/syntax_checkers/javascript/closurecompiler.vim index 422a65fa..3e32846f 100644 --- a/syntax_checkers/javascript/closurecompiler.vim +++ b/syntax_checkers/javascript/closurecompiler.vim @@ -37,7 +37,12 @@ function! SyntaxCheckers_javascript_GetLocList() let file_list = shellescape(expand('%')) endif - let makeprg = 'java -jar ' . g:syntastic_javascript_closure_compiler_path . ' ' . g:syntastic_javascript_closure_compiler_options . ' --js ' . file_list + let makeprg = syntastic#makeprg#build({ + \ 'exe': 'java -jar ' . g:syntastic_javascript_closure_compiler_path, + \ 'args': g:syntastic_javascript_closure_compiler_options . ' --js' , + \ 'fname': file_list, + \ 'subchecker': 'closurecompiler' }) + let errorformat = '%-GOK,%E%f:%l: ERROR - %m,%Z%p^,%W%f:%l: WARNING - %m,%Z%p^' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) endfunction diff --git a/syntax_checkers/javascript/jshint.vim b/syntax_checkers/javascript/jshint.vim index 164b7bd4..600cb351 100644 --- a/syntax_checkers/javascript/jshint.vim +++ b/syntax_checkers/javascript/jshint.vim @@ -13,9 +13,16 @@ if !exists("g:syntastic_javascript_jshint_conf") endif function! SyntaxCheckers_javascript_GetLocList() - " node-jshint uses .jshintrc as config unless --config arg is present - let args = !empty(g:syntastic_javascript_jshint_conf) ? ' --config ' . g:syntastic_javascript_jshint_conf : '' - let makeprg = 'jshint ' . shellescape(expand("%")) . args + let makeprg = syntastic#makeprg#build({ + \ 'exe': 'jshint', + \ 'post_args': s:Args(), + \ 'subchecker': 'jshint' }) + let errorformat = '%ELine %l:%c,%Z\\s%#Reason: %m,%C%.%#,%f: line %l\, col %c\, %m,%-G%.%#' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr('')} }) endfunction + +function s:Args() + " node-jshint uses .jshintrc as config unless --config arg is present + return !empty(g:syntastic_javascript_jshint_conf) ? ' --config ' . g:syntastic_javascript_jshint_conf : '' +endfunction diff --git a/syntax_checkers/json/jsonlint.vim b/syntax_checkers/json/jsonlint.vim index 6e4a4c0a..6b697486 100644 --- a/syntax_checkers/json/jsonlint.vim +++ b/syntax_checkers/json/jsonlint.vim @@ -10,7 +10,10 @@ "============================================================================ function! SyntaxCheckers_json_GetLocList() - let makeprg = 'jsonlint ' . shellescape(expand("%")) . ' --compact' + let makeprg = syntastic#makeprg#build({ + \ 'exe': 'jsonlint', + \ 'post_args': '--compact', + \ 'subchecker': 'jsonlint' }) let errorformat = '%ELine %l:%c,%Z\\s%#Reason: %m,%C%.%#,%f: line %l\, col %c\, %m,%-G%.%#' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr('')} }) endfunction diff --git a/syntax_checkers/less.vim b/syntax_checkers/less.vim index 0aaf0b38..9747cfed 100644 --- a/syntax_checkers/less.vim +++ b/syntax_checkers/less.vim @@ -39,8 +39,8 @@ end function! SyntaxCheckers_less_GetLocList() let makeprg = syntastic#makeprg#build({ \ 'exe': s:check_file, - \ 'args': g:syntastic_less_options }) - let makeprg .= syntastic#util#DevNull() + \ 'args': g:syntastic_less_options, + \ 'tail': syntastic#util#DevNull() }) let errorformat = '%m in %f:%l:%c' return SyntasticMake({ 'makeprg': makeprg, diff --git a/syntax_checkers/lisp.vim b/syntax_checkers/lisp.vim index 6c6c1b30..a7e826ee 100644 --- a/syntax_checkers/lisp.vim +++ b/syntax_checkers/lisp.vim @@ -16,8 +16,10 @@ if !executable("clisp") endif function! SyntaxCheckers_lisp_GetLocList() - let makeprg = syntastic#makeprg#build({ 'exe': 'clisp', 'args': '-c' }) - let makeprg .= ' -o /tmp/clisp-vim-compiled-file' + let makeprg = syntastic#makeprg#build({ + \ 'exe': 'clisp', + \ 'args': '-c' + \ 'tail': '-o /tmp/clisp-vim-compiled-file' }) let efm = '%-G;%.%#,' let efm .= '%W%>WARNING:%.%#line %l : %m,%C %#%m,' let efm .= '%E%>The following functions were %m,%Z %m,' diff --git a/syntax_checkers/python/pylint.vim b/syntax_checkers/python/pylint.vim index 3ede2154..62dc541a 100644 --- a/syntax_checkers/python/pylint.vim +++ b/syntax_checkers/python/pylint.vim @@ -8,10 +8,15 @@ function! SyntaxCheckers_python_GetLocList() let makeprg = syntastic#makeprg#build({ \ 'exe': 'pylint', \ 'args': g:syntastic_python_checker_args. ' -f parseable -r n -i y', + \ 'tail': s:MakeprgTail(), \ 'subchecker': 'pylint' }) - let makeprg .= ' 2>&1 \| sed ''s_: \[\([RCW]\)_: \[W] \[\1_''' . - \ ' \| sed ''s_: \[\([FE]\)_:\ \[E] \[\1_''' let errorformat = '%f:%l: [%t] %m,%Z,%-GNo config %m' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) endfunction + +function! s:MakeprgTail() + return ' 2>&1 \| sed ''s_: \[\([RCW]\)_: \[W] \[\1_''' . + \ ' \| sed ''s_: \[\([FE]\)_:\ \[E] \[\1_''' + +endfunction diff --git a/syntax_checkers/rst.vim b/syntax_checkers/rst.vim index bbf14cc8..0ea723b7 100644 --- a/syntax_checkers/rst.vim +++ b/syntax_checkers/rst.vim @@ -21,9 +21,8 @@ endif function! SyntaxCheckers_rst_GetLocList() let makeprg = syntastic#makeprg#build({ \ 'exe': 'rst2pseudoxml.py', - \ 'args': '--report=2 --exit-status=1' }) - - let makeprg .= syntastic#util#DevNull() + \ 'args': '--report=2 --exit-status=1', + \ 'tail': syntastic#util#DevNull() }) let errorformat = '%f:%l:\ (%tNFO/1)\ %m, \%f:%l:\ (%tARNING/2)\ %m, diff --git a/syntax_checkers/tcl/nagelfar.vim b/syntax_checkers/tcl/nagelfar.vim index 8228309e..3e84708e 100644 --- a/syntax_checkers/tcl/nagelfar.vim +++ b/syntax_checkers/tcl/nagelfar.vim @@ -12,8 +12,10 @@ " "============================================================================ function! SyntaxCheckers_tcl_GetLocList() - let makeprg = "nagelfar -H " . g:syntastic_tcl_nagelfar_conf . " " . shellescape(expand('%')) - + let makeprg = syntastic#makeprg#build({ + \ 'exe': 'nagelfar', + \ 'args': '-H ' . g:syntastic_tcl_nagelfar_conf, + \ 'subchecker': 'nagelfar' }) let errorformat='%I%f: %l: N %m, %f: %l: %t %m, %-GChecking file %f' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) diff --git a/syntax_checkers/tcl/tclsh.vim b/syntax_checkers/tcl/tclsh.vim index 825a470e..69dd4a4e 100644 --- a/syntax_checkers/tcl/tclsh.vim +++ b/syntax_checkers/tcl/tclsh.vim @@ -16,7 +16,7 @@ if !executable("tclsh") endif function! SyntaxCheckers_tclsh_GetLocList() - let makeprg = 'tclsh '.shellescape(expand('%')) + let makeprg = syntastic#makeprg#build({'exe': 'tclsh'}) let errorformat = '%f:%l:%m' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) diff --git a/syntax_checkers/typescript.vim b/syntax_checkers/typescript.vim index 2eafd346..61e86e9f 100644 --- a/syntax_checkers/typescript.vim +++ b/syntax_checkers/typescript.vim @@ -10,8 +10,9 @@ if !executable("tsc") endif function! SyntaxCheckers_typescript_GetLocList() - let makeprg = syntastic#makeprg#build({ 'exe': 'tsc' }) - let makeprg .= ' --out ' . syntastic#util#DevNull() + let makeprg = syntastic#makeprg#build({ + \ 'exe': 'tsc', + \ 'post_args': '--out ' . syntastic#util#DevNull() }) let errorformat = '%f %#(%l\,%c): %m' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) endfunction