From a709b6d505719bc5eacb67e4f30585b486abf0bd Mon Sep 17 00:00:00 2001 From: Mitch Lindgren Date: Mon, 3 Sep 2012 12:24:18 -0700 Subject: [PATCH 1/2] 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 2/2] 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: