From 3eb6118c1661de883b39df17a574702a7149dc8b Mon Sep 17 00:00:00 2001 From: delphinus35 Date: Thu, 9 Aug 2012 16:15:07 +0900 Subject: [PATCH 1/8] perl: specify multiple external libraries --- syntax_checkers/efm_perl.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/syntax_checkers/efm_perl.pl b/syntax_checkers/efm_perl.pl index a193456d..fe6b67d4 100644 --- a/syntax_checkers/efm_perl.pl +++ b/syntax_checkers/efm_perl.pl @@ -92,13 +92,14 @@ my $handle = (defined $opt_f ? \*FILE : \*STDOUT); (my $file = shift) or &usage; # display usage if no filename is supplied my $args = (@ARGV ? ' ' . join ' ', @ARGV : ''); -my @error_lines = `perl @{[defined $opt_I ? "-I$opt_I" : '']} @{[defined $opt_c ? '-c ' : '' ]} @{[defined $opt_w ? '-X ' : '-w ']} "$file$args" 2>&1`; +my $libs = join ' ', map {"-I$_"} split ',', $opt_I; +my @error_lines = `perl $libs @{[defined $opt_c ? '-c ' : '' ]} @{[defined $opt_w ? '-X ' : '-w ']} "$file$args" 2>&1`; my @lines = map { "E:$_" } @error_lines; my @warn_lines; if(defined($opt_w)) { - @warn_lines = `perl @{[defined $opt_I ? $opt_I : '']} @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`; + @warn_lines = `perl $libs @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`; } # Any new errors must be warnings From a26d3aef58a26f2b47ef994f93ce2cf0b2cd06aa Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Tue, 14 Aug 2012 12:57:53 +0100 Subject: [PATCH 2/8] PHP: Work with php-5.3 and php-5.4 The current makeprg doesn't work with php-5.3. display_errors=0 has disabled error outputting and error_log='' disables the error log. With php-5.4 error_log='' is causing errors to be logged to stderr. This patch disables the error_log and enables display_errors. Theoretically errors are displayed on stdout, however php in mountain lion seems to insist on outputting to stderr. As we're now displaying errors rather than logging them to error format has changed to no longer include 'PHP ' and I've removed duplicates. This has been tested with PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) (mountain lion) and PHP 5.4.4 (cli) (built: Jul 2 2012 16:33:50) Fedora 17 --- syntax_checkers/php.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax_checkers/php.vim b/syntax_checkers/php.vim index a2c909d9..5b9b116c 100644 --- a/syntax_checkers/php.vim +++ b/syntax_checkers/php.vim @@ -40,8 +40,8 @@ function! SyntaxCheckers_php_GetLocList() let errors = [] - let makeprg = "php -l -d error_reporting=E_ALL -d display_errors=0 -d error_log='' ".shellescape(expand('%')) - let errorformat='%-GNo syntax errors detected in%.%#,PHP Parse error: %#syntax %trror\, %m in %f on line %l,PHP Fatal %trror: %m in %f on line %l,%-GErrors parsing %.%#,%-G\s%#,Parse error: %#syntax %trror\, %m in %f on line %l,Fatal %trror: %m in %f on line %l,PHP Parse %trror: %m in %f on line %l' + let makeprg = "php -l -d error_reporting=E_ALL -d display_errors=1 -d log_errors=0 ".shellescape(expand('%')) + let errorformat='%-GNo syntax errors detected in%.%#,Parse error: %#syntax %trror\ , %m in %f on line %l,Parse %trror: %m in %f on line %l,Fatal %trror: %m in %f on line %l,%-G\s%#,%-GErrors parsing %.%#' let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) if empty(errors) && !g:syntastic_phpcs_disable && executable("phpcs") From 4c519852b6fcdde597b374712b46344b52ee2648 Mon Sep 17 00:00:00 2001 From: troydm Date: Tue, 14 Aug 2012 19:56:20 +0400 Subject: [PATCH 3/8] java checkstyle syntax checker added, added auto pom classpath detection and classpath editing for javac syntax checker --- syntax_checkers/java.vim | 31 +++--- syntax_checkers/java/checkstyle.vim | 33 ++++++ syntax_checkers/java/javac.vim | 160 ++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+), 18 deletions(-) create mode 100644 syntax_checkers/java/checkstyle.vim create mode 100644 syntax_checkers/java/javac.vim diff --git a/syntax_checkers/java.vim b/syntax_checkers/java.vim index 8d9b247c..6a761c69 100644 --- a/syntax_checkers/java.vim +++ b/syntax_checkers/java.vim @@ -1,28 +1,23 @@ "============================================================================ "File: java.vim -"Description: Syntax checking plugin for syntastic.vim -"Maintainer: Jochen Keil +"Description: Figures out which java syntax checker (if any) to load +" from the java directory. +"Maintainer: Dmitry Geurkov "License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You " Want To Public License, Version 2, as published by Sam Hocevar. " See http://sam.zoy.org/wtfpl/COPYING for more details. " +" Use g:syntastic_java_checker option to specify which java syntax checker +" should be used (see below for a list of supported checkers). +" If g:syntastic_java_checker is not set, just use the first syntax +" checker that we find installed. "============================================================================ -function! SyntaxCheckers_java_GetLocList() +if exists("loaded_java_syntax_checker") + finish +endif +let loaded_java_syntax_checker = 1 - let makeprg = 'javac -Xlint ' - \. expand ( '%:p:h' ) . '/' . expand ( '%:t' ) - \. ' 2>&1 \| ' - \. 'sed -e "s\|' - \. expand ( '%:t' ) - \. '\|' - \. expand ( '%:p:h' ) . '/' . expand ( '%:t' ) - \. '\|"' - - " unashamedly stolen from *errorformat-javac* (quickfix.txt) - let errorformat = '%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#' - - return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) - -endfunction +let s:supported_checkers = ["javac", "checkstyle"] +call SyntasticLoadChecker(s:supported_checkers, 'java') diff --git a/syntax_checkers/java/checkstyle.vim b/syntax_checkers/java/checkstyle.vim new file mode 100644 index 00000000..e4bdd6e7 --- /dev/null +++ b/syntax_checkers/java/checkstyle.vim @@ -0,0 +1,33 @@ +"============================================================================ +"File: checkstyle.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Dmitry Geurkov +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +" Tested with checkstyle 5.5 +"============================================================================ +if !exists("g:syntastic_java_checkstyle_classpath") + let g:syntastic_java_checkstyle_classpath = 'checkstyle-5.5-all.jar' +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 ' + + " check style format + let errorformat = '%f:%l:%c:\ %m,%f:%l:\ %m' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + +endfunction diff --git a/syntax_checkers/java/javac.vim b/syntax_checkers/java/javac.vim new file mode 100644 index 00000000..d65baa7a --- /dev/null +++ b/syntax_checkers/java/javac.vim @@ -0,0 +1,160 @@ +"============================================================================ +"File: javac.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Jochen Keil +" Dmitry Geurkov +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +" Global Options +if !exists("g:syntastic_java_javac_executable") + let g:syntastic_java_javac_executable = 'javac' +endif + +if !exists("g:syntastic_java_javac_options") + let g:syntastic_java_javac_options = '-Xlint' +endif + +if !exists("g:syntastic_java_javac_classpath") + let g:syntastic_java_javac_classpath = '' +endif + +if !exists("g:syntastic_java_javac_delete_output") + let g:syntastic_java_javac_delete_output = 1 +endif + +if !exists("g:syntastic_java_javac_autoload_maven_classpath") + let g:syntastic_java_javac_autoload_maven_classpath = 1 +endif + +" Internal variables, do not ovveride those +if !exists("g:syntastic_java_javac_maven_pom_cwd") + let g:syntastic_java_javac_maven_pom_cwd = '' +endif + +if !exists("g:syntastic_java_javac_maven_pom_ftime") + let g:syntastic_java_javac_maven_pom_ftime = 0 +endif + +if !exists("g:syntastic_java_javac_maven_pom_classpath") + let g:syntastic_java_javac_maven_pom_classpath = '' +endif + +function! s:AddToClasspath(classpath,path) + if a:path == '' + return a:classpath + endif + if a:classpath != '' && a:path != '' + return a:classpath . ":" . a:path + else + return a:path + endif +endfunction + +function! s:SaveClasspath() + let path = '' + let lines = getline(1,line('$')) + for l in lines + if l != '' + let path .= l."\n" + endif + endfor + let g:syntastic_java_javac_classpath = path + let &modified = 0 +endfunction + +function! s:EditClasspath() + let command = 'syntastic javac classpath' + let winnr = bufwinnr('^' . command . '$') + if winnr < 0 + let pathlist = split(g:syntastic_java_javac_classpath,"\n") + execute (len(pathlist)+5) . 'sp ' . fnameescape(command) + au BufWriteCmd call s:SaveClasspath() | bwipeout + setlocal buftype=acwrite bufhidden=wipe nobuflisted noswapfile nowrap number + for p in pathlist | call append(line('$')-1,p) | endfor + else + execute winnr . 'wincmd w' + endif +endfunction +command! SyntasticJavacEditClasspath call s:EditClasspath() + +function! s:GetMavenClasspath() + if filereadable('pom.xml') + if g:syntastic_java_javac_maven_pom_ftime != getftime('pom.xml') || g:syntastic_java_javac_maven_pom_cwd != getcwd() + let mvn_classpath_output = split(system('mvn dependency:build-classpath'),"\n") + let class_path_next = 0 + for line in mvn_classpath_output + if class_path_next == 1 + let mvn_classpath = line + break + endif + if match(line,'Dependencies classpath:') >= 0 + let class_path_next = 1 + endif + endfor + let mvn_classpath = s:AddToClasspath(mvn_classpath,'target/classes') + let g:syntastic_java_javac_maven_pom_cwd = getcwd() + let g:syntastic_java_javac_maven_pom_ftime = getftime('pom.xml') + let g:syntastic_java_javac_maven_pom_classpath = mvn_classpath + endif + return g:syntastic_java_javac_maven_pom_classpath + endif + return '' +endfunction + +function! SyntaxCheckers_java_GetLocList() + + let javac_opts = g:syntastic_java_javac_options + + if g:syntastic_java_javac_delete_output + let output_dir = '/tmp/vim-syntastic' + let javac_opts .= ' -d ' .output_dir + endif + + let javac_classpath = '' + + " add classpathes to javac_classpath + for path in split(g:syntastic_java_javac_classpath,"\n") + if path != '' + let ps = glob(path,0,1) + if type(ps) == type([]) + for p in ps + if p != '' | let javac_classpath = s:AddToClasspath(javac_classpath,p) | endif + endfor + else + let javac_classpath = s:AddToClasspath(javac_classpath,ps) + endif + endif + endfor + + if g:syntastic_java_javac_autoload_maven_classpath + let maven_classpath = s:GetMavenClasspath() + let javac_classpath = s:AddToClasspath(javac_classpath,maven_classpath) + endif + + if javac_classpath != '' + let javac_opts .= ' -cp ' . javac_classpath + endif + + let makeprg = g:syntastic_java_javac_executable . ' '. javac_opts . ' ' + \. expand ( '%:p:h' ) . '/' . expand ( '%:t' ) + \. ' 2>&1 ' + + " 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%.%#' + + if g:syntastic_java_javac_delete_output + call system('mkdir -p ' . output_dir) + endif + let r = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + if g:syntastic_java_javac_delete_output + call system('rm -rf ' . output_dir) + endif + return r + +endfunction From a709b6d505719bc5eacb67e4f30585b486abf0bd Mon Sep 17 00:00:00 2001 From: Mitch Lindgren Date: Mon, 3 Sep 2012 12:24:18 -0700 Subject: [PATCH 4/8] Update README.markdown Added a note on aliases not working for syntax checkers, which tripped me up for a while. --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 84361b15..736f2f7c 100644 --- a/README.markdown +++ b/README.markdown @@ -101,7 +101,7 @@ FAQ __Q. I installed syntastic but it isn't reporting any errors ...__ -A. The most likely reason is that the syntax checker that it requires isn't installed. For example: python requires either `flake8`, `pyflakes` or `pylint` to be installed and in `$PATH`. To see which executable is required, just look in `syntax_checkers/.vim`. +A. The most likely reason is that the syntax checker that it requires isn't installed. For example: python requires either `flake8`, `pyflakes` or `pylint` to be installed and in `$PATH`. To see which executable is required, just look in `syntax_checkers/.vim`. Note that aliases do not work; the actual executable must be available in your `$PATH`. Symbolic links are okay. Another reason it could fail is that the error output for the syntax checker may have changed. In this case, make sure you have the latest version of the syntax checker installed. If it still fails then create an issue - or better yet, create a pull request. From eef0180f8bbbce97006fc30d67330e8e7692ba94 Mon Sep 17 00:00:00 2001 From: Daniel Walker Date: Sun, 8 Apr 2012 15:54:13 -0700 Subject: [PATCH 5/8] Add a syntax checker for the Linux kernel checkpatch.pl utility. I modified the C checker so checkpatch could be given as an alternate checker for C files. --- syntax_checkers/c.vim | 159 ++++--------------------------- syntax_checkers/c/checkpatch.vim | 35 +++++++ syntax_checkers/c/gcc.vim | 158 ++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+), 141 deletions(-) create mode 100644 syntax_checkers/c/checkpatch.vim create mode 100644 syntax_checkers/c/gcc.vim diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index 55b06de8..e202d587 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -1,7 +1,7 @@ "============================================================================ "File: c.vim "Description: Syntax checking plugin for syntastic.vim -"Maintainer: Gregor Uhlenheuer +"Maintainer: Martin Grenfell "License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -9,150 +9,27 @@ " See http://sam.zoy.org/wtfpl/COPYING for more details. " "============================================================================ - -" In order to also check header files add this to your .vimrc: -" (this usually creates a .gch file in your source directory) -" -" let g:syntastic_c_check_header = 1 -" -" To disable the search of included header files after special -" libraries like gtk and glib add this line to your .vimrc: -" -" let g:syntastic_c_no_include_search = 1 -" -" To enable header files being re-checked on every file write add the -" following line to your .vimrc. Otherwise the header files are checked only -" one time on initially loading the file. -" In order to force syntastic to refresh the header includes simply -" unlet b:syntastic_c_includes. Then the header files are being re-checked on -" the next file write. -" -" let g:syntastic_c_auto_refresh_includes = 1 -" -" Alternatively you can set the buffer local variable b:syntastic_c_cflags. -" If this variable is set for the current buffer no search for additional -" libraries is done. I.e. set the variable like this: -" -" let b:syntastic_c_cflags = ' -I/usr/include/libsoup-2.4' -" -" In order to add some custom include directories that should be added to the -" gcc command line you can add those to the global variable -" g:syntastic_c_include_dirs. This list can be used like this: -" -" let g:syntastic_c_include_dirs = [ 'includes', 'headers' ] -" -" Moreover it is possible to add additional compiler options to the syntax -" checking execution via the variable 'g:syntastic_c_compiler_options': -" -" let g:syntastic_c_compiler_options = ' -ansi' -" -" Additionally the setting 'g:syntastic_c_config_file' allows you to define a -" file that contains additional compiler arguments like include directories or -" CFLAGS. The file is expected to contain one option per line. If none is -" given the filename defaults to '.syntastic_c_config': -" -" let g:syntastic_c_config_file = '.config' -" -" Using the global variable 'g:syntastic_c_remove_include_errors' you can -" specify whether errors of files included via the g:syntastic_c_include_dirs' -" setting are removed from the result set: -" -" let g:syntastic_c_remove_include_errors = 1 -" -" Use the variable 'g:syntastic_c_errorformat' to override the default error -" format: -" -" let g:syntastic_c_errorformat = '%f:%l:%c: %trror: %m' - -if exists('loaded_c_syntax_checker') +if exists("loaded_c_syntax_checker") finish endif let loaded_c_syntax_checker = 1 -if !executable('gcc') - finish +if !exists('g:syntastic_c_checker') + let g:syntastic_c_checker = "gcc" endif -let s:save_cpo = &cpo -set cpo&vim - -if !exists('g:syntastic_c_compiler_options') - let g:syntastic_c_compiler_options = '-std=gnu99' +if g:syntastic_c_checker == "gcc" + if executable("gcc") + runtime! syntax_checkers/c/gcc.vim + endif +elseif g:syntastic_c_checker == "checkpatch" + if executable("checkpatch.pl") || executable("./scripts/checkpatch.pl") + runtime! syntax_checkers/c/checkpatch.vim + endif +elseif g:syntastic_c_checker == "checkpatch-kernel-only" + if executable("./scripts/checkpatch.pl") + runtime! syntax_checkers/c/checkpatch.vim + elseif executable("gcc") + runtime! syntax_checkers/c/gcc.vim + endif endif - -if !exists('g:syntastic_c_config_file') - let g:syntastic_c_config_file = '.syntastic_c_config' -endif - -function! SyntaxCheckers_c_GetLocList() - let makeprg = 'gcc -fsyntax-only ' - let errorformat = '%-G%f:%s:,%-G%f:%l: %#error: %#(Each undeclared '. - \ 'identifier is reported only%.%#,%-G%f:%l: %#error: %#for '. - \ 'each function it appears%.%#,%-GIn file included%.%#,'. - \ '%-G %#from %f:%l\,,%f:%l:%c: %trror: %m,%f:%l:%c: '. - \ '%tarning: %m,%f:%l:%c: %m,%f:%l: %trror: %m,'. - \ '%f:%l: %tarning: %m,%f:%l: %m' - - if exists('g:syntastic_c_errorformat') - let errorformat = g:syntastic_c_errorformat - endif - - " add optional user-defined compiler options - let makeprg .= g:syntastic_c_compiler_options - - let makeprg .= ' '.shellescape(expand('%')). - \ ' '.syntastic#c#GetIncludeDirs('c') - - " determine whether to parse header files as well - if expand('%') =~? '.h$' - if exists('g:syntastic_c_check_header') - let makeprg = 'gcc -c '.shellescape(expand('%')). - \ ' '.syntastic#c#GetIncludeDirs('c') - else - return [] - endif - endif - - " check if the user manually set some cflags - if !exists('b:syntastic_c_cflags') - " check whether to search for include files at all - if !exists('g:syntastic_c_no_include_search') || - \ g:syntastic_c_no_include_search != 1 - " refresh the include file search if desired - if exists('g:syntastic_c_auto_refresh_includes') && - \ g:syntastic_c_auto_refresh_includes != 0 - let makeprg .= syntastic#c#SearchHeaders() - else - " search for header includes if not cached already - if !exists('b:syntastic_c_includes') - let b:syntastic_c_includes = syntastic#c#SearchHeaders() - endif - let makeprg .= b:syntastic_c_includes - endif - endif - else - " use the user-defined cflags - let makeprg .= b:syntastic_c_cflags - endif - - " add optional config file parameters - let makeprg .= ' '.syntastic#c#ReadConfig(g:syntastic_c_config_file) - - " process makeprg - let errors = SyntasticMake({ 'makeprg': makeprg, - \ 'errorformat': errorformat }) - - " filter the processed errors if desired - if exists('g:syntastic_c_remove_include_errors') && - \ g:syntastic_c_remove_include_errors != 0 - return filter(errors, - \ 'has_key(v:val, "bufnr") && v:val["bufnr"]=='.bufnr('')) - else - return errors - endif -endfunction - -let &cpo = s:save_cpo -unlet s:save_cpo - -" vim: set et sts=4 sw=4: diff --git a/syntax_checkers/c/checkpatch.vim b/syntax_checkers/c/checkpatch.vim new file mode 100644 index 00000000..8d9f9bac --- /dev/null +++ b/syntax_checkers/c/checkpatch.vim @@ -0,0 +1,35 @@ +"============================================================================ +"File: checkpatch.vim +"Description: Syntax checking plugin for syntastic.vim using checkpatch.pl +"Maintainer: Daniel Walker +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +"============================================================================ +if exists("loaded_checkpatch_syntax_checker") + finish +endif +let loaded_checkpatch_syntax_checker = 1 + +" Bail if the user doesn't have `checkpatch.pl` or ./scripts/checkpatch.pl installed. +if executable("checkpatch.pl") + let g:syntastic_c_checker_checkpatch_location = 'checkpatch.pl' +elseif executable("./scripts/checkpatch.pl") + let g:syntastic_c_checker_checkpatch_location = './scripts/checkpatch.pl' +else + finish +endif + +function! SyntaxCheckers_c_GetLocList() + let makeprg = g:syntastic_c_checker_checkpatch_location + let makeprg .= " --no-summary --no-tree --terse --file ".shellescape(expand('%')) + + let errorformat = '%f:%l: %tARNING: %m,%f:%l: %tRROR: %m' + + let loclist = SyntasticMake({ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'defaults': {'bufnr': bufnr("")} }) + return loclist +endfunction diff --git a/syntax_checkers/c/gcc.vim b/syntax_checkers/c/gcc.vim new file mode 100644 index 00000000..05c9bfce --- /dev/null +++ b/syntax_checkers/c/gcc.vim @@ -0,0 +1,158 @@ +"============================================================================ +"File: c.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Gregor Uhlenheuer +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +" In order to also check header files add this to your .vimrc: +" (this usually creates a .gch file in your source directory) +" +" let g:syntastic_c_check_header = 1 +" +" To disable the search of included header files after special +" libraries like gtk and glib add this line to your .vimrc: +" +" let g:syntastic_c_no_include_search = 1 +" +" To enable header files being re-checked on every file write add the +" following line to your .vimrc. Otherwise the header files are checked only +" one time on initially loading the file. +" In order to force syntastic to refresh the header includes simply +" unlet b:syntastic_c_includes. Then the header files are being re-checked on +" the next file write. +" +" let g:syntastic_c_auto_refresh_includes = 1 +" +" Alternatively you can set the buffer local variable b:syntastic_c_cflags. +" If this variable is set for the current buffer no search for additional +" libraries is done. I.e. set the variable like this: +" +" let b:syntastic_c_cflags = ' -I/usr/include/libsoup-2.4' +" +" In order to add some custom include directories that should be added to the +" gcc command line you can add those to the global variable +" g:syntastic_c_include_dirs. This list can be used like this: +" +" let g:syntastic_c_include_dirs = [ 'includes', 'headers' ] +" +" Moreover it is possible to add additional compiler options to the syntax +" checking execution via the variable 'g:syntastic_c_compiler_options': +" +" let g:syntastic_c_compiler_options = ' -ansi' +" +" Additionally the setting 'g:syntastic_c_config_file' allows you to define a +" file that contains additional compiler arguments like include directories or +" CFLAGS. The file is expected to contain one option per line. If none is +" given the filename defaults to '.syntastic_c_config': +" +" let g:syntastic_c_config_file = '.config' +" +" Using the global variable 'g:syntastic_c_remove_include_errors' you can +" specify whether errors of files included via the g:syntastic_c_include_dirs' +" setting are removed from the result set: +" +" let g:syntastic_c_remove_include_errors = 1 +" +" Use the variable 'g:syntastic_c_errorformat' to override the default error +" format: +" +" let g:syntastic_c_errorformat = '%f:%l:%c: %trror: %m' + +if exists('loaded_gcc_syntax_checker') + finish +endif +let loaded_gcc_syntax_checker = 1 + +if !executable('gcc') + finish +endif + +let s:save_cpo = &cpo +set cpo&vim + +if !exists('g:syntastic_c_compiler_options') + let g:syntastic_c_compiler_options = '-std=gnu99' +endif + +if !exists('g:syntastic_c_config_file') + let g:syntastic_c_config_file = '.syntastic_c_config' +endif + +function! SyntaxCheckers_c_GetLocList() + let makeprg = 'gcc -fsyntax-only ' + let errorformat = '%-G%f:%s:,%-G%f:%l: %#error: %#(Each undeclared '. + \ 'identifier is reported only%.%#,%-G%f:%l: %#error: %#for '. + \ 'each function it appears%.%#,%-GIn file included%.%#,'. + \ '%-G %#from %f:%l\,,%f:%l:%c: %trror: %m,%f:%l:%c: '. + \ '%tarning: %m,%f:%l:%c: %m,%f:%l: %trror: %m,'. + \ '%f:%l: %tarning: %m,%f:%l: %m' + + if exists('g:syntastic_c_errorformat') + let errorformat = g:syntastic_c_errorformat + endif + + " add optional user-defined compiler options + let makeprg .= g:syntastic_c_compiler_options + + let makeprg .= ' '.shellescape(expand('%')). + \ ' '.syntastic#c#GetIncludeDirs('c') + + " determine whether to parse header files as well + if expand('%') =~? '.h$' + if exists('g:syntastic_c_check_header') + let makeprg = 'gcc -c '.shellescape(expand('%')). + \ ' '.syntastic#c#GetIncludeDirs('c') + else + return [] + endif + endif + + " check if the user manually set some cflags + if !exists('b:syntastic_c_cflags') + " check whether to search for include files at all + if !exists('g:syntastic_c_no_include_search') || + \ g:syntastic_c_no_include_search != 1 + " refresh the include file search if desired + if exists('g:syntastic_c_auto_refresh_includes') && + \ g:syntastic_c_auto_refresh_includes != 0 + let makeprg .= syntastic#c#SearchHeaders() + else + " search for header includes if not cached already + if !exists('b:syntastic_c_includes') + let b:syntastic_c_includes = syntastic#c#SearchHeaders() + endif + let makeprg .= b:syntastic_c_includes + endif + endif + else + " use the user-defined cflags + let makeprg .= b:syntastic_c_cflags + endif + + " add optional config file parameters + let makeprg .= ' '.syntastic#c#ReadConfig(g:syntastic_c_config_file) + + " process makeprg + let errors = SyntasticMake({ 'makeprg': makeprg, + \ 'errorformat': errorformat }) + + " filter the processed errors if desired + if exists('g:syntastic_c_remove_include_errors') && + \ g:syntastic_c_remove_include_errors != 0 + return filter(errors, + \ 'has_key(v:val, "bufnr") && v:val["bufnr"]=='.bufnr('')) + else + return errors + endif +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: set et sts=4 sw=4: From e409f1ceb5c578daa51f72a0f0b7c7c77b813567 Mon Sep 17 00:00:00 2001 From: Daniel Walker Date: Sat, 8 Sep 2012 11:28:53 -0700 Subject: [PATCH 6/8] Add a gcc based checker for Objective-C . This checker is just a slightly modified version of the C checker. I did a find/replace to make it use "_objc_" instead of "_c_" . I also modified the errorformat to look more like the cpp errorformat because I discovered that the entries added to the C errorformat no longer seem to match anything. --- syntax_checkers/objc.vim | 160 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 syntax_checkers/objc.vim diff --git a/syntax_checkers/objc.vim b/syntax_checkers/objc.vim new file mode 100644 index 00000000..7e396742 --- /dev/null +++ b/syntax_checkers/objc.vim @@ -0,0 +1,160 @@ +"============================================================================ +"File: objc.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Gregor Uhlenheuer +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +" In order to also check header files add this to your .vimrc: +" (this usually creates a .gch file in your source directory) +" +" let g:syntastic_objc_check_header = 1 +" +" To disable the search of included header files after special +" libraries like gtk and glib add this line to your .vimrc: +" +" let g:syntastic_objc_no_include_search = 1 +" +" To enable header files being re-checked on every file write add the +" following line to your .vimrc. Otherwise the header files are checked only +" one time on initially loading the file. +" In order to force syntastic to refresh the header includes simply +" unlet b:syntastic_objc_includes. Then the header files are being re-checked on +" the next file write. +" +" let g:syntastic_objc_auto_refresh_includes = 1 +" +" Alternatively you can set the buffer local variable b:syntastic_objc_cflags. +" If this variable is set for the current buffer no search for additional +" libraries is done. I.e. set the variable like this: +" +" let b:syntastic_objc_cflags = ' -I/usr/include/libsoup-2.4' +" +" In order to add some custom include directories that should be added to the +" gcc command line you can add those to the global variable +" g:syntastic_objc_include_dirs. This list can be used like this: +" +" let g:syntastic_objc_include_dirs = [ 'includes', 'headers' ] +" +" Moreover it is possible to add additional compiler options to the syntax +" checking execution via the variable 'g:syntastic_objc_compiler_options': +" +" let g:syntastic_objc_compiler_options = ' -ansi' +" +" Additionally the setting 'g:syntastic_objc_config_file' allows you to define a +" file that contains additional compiler arguments like include directories or +" CFLAGS. The file is expected to contain one option per line. If none is +" given the filename defaults to '.syntastic_objc_config': +" +" let g:syntastic_objc_config_file = '.config' +" +" Using the global variable 'g:syntastic_objc_remove_include_errors' you can +" specify whether errors of files included via the g:syntastic_objc_include_dirs' +" setting are removed from the result set: +" +" let g:syntastic_objc_remove_include_errors = 1 +" +" Use the variable 'g:syntastic_objc_errorformat' to override the default error +" format: +" +" let g:syntastic_objc_errorformat = '%f:%l:%c: %trror: %m' + +if exists('loaded_objc_syntax_checker') + finish +endif +let loaded_objc_syntax_checker = 1 + +if !executable('gcc') + finish +endif + +let s:save_cpo = &cpo +set cpo&vim + +if !exists('g:syntastic_objc_compiler_options') + let g:syntastic_objc_compiler_options = '' +endif + +if !exists('g:syntastic_objc_config_file') + let g:syntastic_objc_config_file = '.syntastic_objc_config' +endif + +function! SyntaxCheckers_objc_GetLocList() + let makeprg = 'gcc -fsyntax-only -lobjc' + let errorformat = + \ '%-G%f:%s:,'. + \ '%f:%l:%c: %trror: %m,'. + \ '%f:%l:%c: %tarning: %m,'. + \ '%f:%l:%c: %m,'. + \ '%f:%l: %trror: %m,'. + \ '%f:%l: %tarning: %m,'. + \ '%f:%l: %m' + + if exists('g:syntastic_objc_errorformat') + let errorformat = g:syntastic_objc_errorformat + endif + + " add optional user-defined compiler options + let makeprg .= g:syntastic_objc_compiler_options + + let makeprg .= ' '.shellescape(expand('%')). + \ ' '.syntastic#c#GetIncludeDirs('c') + + " determine whether to parse header files as well + if expand('%') =~? '.h$' + if exists('g:syntastic_objc_check_header') + let makeprg = 'gcc -c '.shellescape(expand('%')). + \ ' '.syntastic#c#GetIncludeDirs('c') + else + return [] + endif + endif + + " check if the user manually set some cflags + if !exists('b:syntastic_objc_cflags') + " check whether to search for include files at all + if !exists('g:syntastic_objc_no_include_search') || + \ g:syntastic_objc_no_include_search != 1 + " refresh the include file search if desired + if exists('g:syntastic_objc_auto_refresh_includes') && + \ g:syntastic_objc_auto_refresh_includes != 0 + let makeprg .= syntastic#c#SearchHeaders() + else + " search for header includes if not cached already + if !exists('b:syntastic_objc_includes') + let b:syntastic_objc_includes = syntastic#c#SearchHeaders() + endif + let makeprg .= b:syntastic_objc_includes + endif + endif + else + " use the user-defined cflags + let makeprg .= b:syntastic_objc_cflags + endif + + " add optional config file parameters + let makeprg .= ' '.syntastic#c#ReadConfig(g:syntastic_objc_config_file) + + " process makeprg + let errors = SyntasticMake({ 'makeprg': makeprg, + \ 'errorformat': errorformat }) + + " filter the processed errors if desired + if exists('g:syntastic_objc_remove_include_errors') && + \ g:syntastic_objc_remove_include_errors != 0 + return filter(errors, + \ 'has_key(v:val, "bufnr") && v:val["bufnr"]=='.bufnr('')) + else + return errors + endif +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: set et sts=4 sw=4: From c0676a74d9d36920ce784ac85c7f4dbe74c00378 Mon Sep 17 00:00:00 2001 From: Yosuke ONOUE Date: Sat, 22 Sep 2012 21:20:57 +0900 Subject: [PATCH 7/8] Fixed compiler options for C++ header check. --- syntax_checkers/cpp.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/syntax_checkers/cpp.vim b/syntax_checkers/cpp.vim index 8aae1fe4..52edfe10 100644 --- a/syntax_checkers/cpp.vim +++ b/syntax_checkers/cpp.vim @@ -108,6 +108,7 @@ function! SyntaxCheckers_cpp_GetLocList() if expand('%') =~? '\%(.h\|.hpp\|.hh\)$' if exists('g:syntastic_cpp_check_header') let makeprg = g:syntastic_cpp_compiler.' -c '.shellescape(expand('%')). + \ ' ' . g:syntastic_cpp_compiler_options. \ ' ' . syntastic#c#GetIncludeDirs('cpp') else return [] From 1bbfbeb3a3004846b311e016e3b108c16735e8b7 Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 23 Sep 2012 22:58:42 +0200 Subject: [PATCH 8/8] add compiler options to C header checking too --- syntax_checkers/c.vim | 5 +++-- syntax_checkers/cpp.vim | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index 55b06de8..6080316d 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -106,8 +106,9 @@ function! SyntaxCheckers_c_GetLocList() " determine whether to parse header files as well if expand('%') =~? '.h$' if exists('g:syntastic_c_check_header') - let makeprg = 'gcc -c '.shellescape(expand('%')). - \ ' '.syntastic#c#GetIncludeDirs('c') + let makeprg = 'gcc -c '.shellescape(expand('%')) . + \ ' ' . g:syntastic_c_compiler_options . + \ ' ' . syntastic#c#GetIncludeDirs('c') else return [] endif diff --git a/syntax_checkers/cpp.vim b/syntax_checkers/cpp.vim index 52edfe10..b5ce6fb1 100644 --- a/syntax_checkers/cpp.vim +++ b/syntax_checkers/cpp.vim @@ -66,7 +66,7 @@ " " Set your compiler executable with e.g. (defaults to g++) " -" let g:syntastic_cpp_compiler = 'clang++' +" let g:syntastic_cpp_compiler = 'clang++' if exists('loaded_cpp_syntax_checker') finish @@ -107,8 +107,8 @@ function! SyntaxCheckers_cpp_GetLocList() if expand('%') =~? '\%(.h\|.hpp\|.hh\)$' if exists('g:syntastic_cpp_check_header') - let makeprg = g:syntastic_cpp_compiler.' -c '.shellescape(expand('%')). - \ ' ' . g:syntastic_cpp_compiler_options. + let makeprg = g:syntastic_cpp_compiler.' -c '.shellescape(expand('%')) . + \ ' ' . g:syntastic_cpp_compiler_options . \ ' ' . syntastic#c#GetIncludeDirs('cpp') else return []