From 58e65d99a4b1086312e009439dceef6012150f50 Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 18 Dec 2011 18:09:27 +0100 Subject: [PATCH 1/5] C: remove duplicates in include directories --- syntax_checkers/c.vim | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index d8ff3f2d..016b3db9 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -61,15 +61,24 @@ set cpo&vim let s:default_includes = [ '.', '..', 'include', 'includes', \ '../include', '../includes' ] +function! s:Unique(list) + let l = [] + for elem in a:list + if index(l, elem) == -1 + let l = add(l, elem) + endif + endfor + return l +endfunction + function! s:GetIncludeDirs() let include_dirs = s:default_includes if exists('g:syntastic_c_include_dirs') - " TODO: check for duplicates call extend(include_dirs, g:syntastic_c_include_dirs) endif - return join(map(copy(include_dirs), '"-I" . v:val'), ' ') + return join(map(s:Unique(include_dirs), '"-I" . v:val'), ' ') endfunction function! SyntaxCheckers_c_GetLocList() From 309652c840910f77d504b0fad3e0ca406e1bfc9a Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 18 Dec 2011 18:24:28 +0100 Subject: [PATCH 2/5] C: modify the default include directories --- syntax_checkers/c.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index 016b3db9..f84702d0 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -58,8 +58,8 @@ endif let s:save_cpo = &cpo set cpo&vim -let s:default_includes = [ '.', '..', 'include', 'includes', - \ '../include', '../includes' ] +" default include directories +let s:default_includes = [ '.', '..' ] function! s:Unique(list) let l = [] From 5accceb04ac07b00a9911e556fa989604906bcec Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 18 Dec 2011 18:25:07 +0100 Subject: [PATCH 3/5] C: add some explanatory comments --- syntax_checkers/c.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index f84702d0..422d351e 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -61,6 +61,7 @@ set cpo&vim " default include directories let s:default_includes = [ '.', '..' ] +" uniquify the input list function! s:Unique(list) let l = [] for elem in a:list @@ -71,6 +72,8 @@ function! s:Unique(list) return l endfunction +" get the gcc include directory argument depending on the default +" includes and the optional user-defined 'g:syntastic_c_include_dirs' function! s:GetIncludeDirs() let include_dirs = s:default_includes @@ -89,6 +92,7 @@ function! SyntaxCheckers_c_GetLocList() \ 'each function it appears%.%#,%-GIn file included%.%#,'. \ '%-G %#from %f:%l\,,%f:%l:%c: %m,%f:%l: %trror: %m,%f:%l: %m' + " determine whether to parse header files as well if expand('%') =~? '.h$' if exists('g:syntastic_c_check_header') let makeprg = 'gcc -c '.shellescape(expand('%')). @@ -98,6 +102,7 @@ function! SyntaxCheckers_c_GetLocList() endif endif + " add optional user-defined compiler options if exists('g:syntastic_c_compiler_options') let makeprg .= g:syntastic_c_compiler_options endif From 18073102b39b754abe41abaa8a91089b8f7a4384 Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 18 Dec 2011 18:59:24 +0100 Subject: [PATCH 4/5] C: option to remove errors from included files (#70) --- syntax_checkers/c.vim | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index 422d351e..fe74512f 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -40,11 +40,17 @@ " 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' +" +" 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 if exists('loaded_c_syntax_checker') finish @@ -107,13 +113,17 @@ function! SyntaxCheckers_c_GetLocList() let makeprg .= g:syntastic_c_compiler_options 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 @@ -121,10 +131,22 @@ function! SyntaxCheckers_c_GetLocList() endif endif else + " use the user-defined cflags let makeprg .= b:syntastic_c_cflags endif - return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + " 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 From 138e48c2758895a0e55f362485e9cb0d178c92d8 Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 18 Dec 2011 19:05:40 +0100 Subject: [PATCH 5/5] C: readd default include dirs --- syntax_checkers/c.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index fe74512f..8bd486b6 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -65,7 +65,8 @@ let s:save_cpo = &cpo set cpo&vim " default include directories -let s:default_includes = [ '.', '..' ] +let s:default_includes = [ '.', '..', 'include', 'includes', + \ '../include', '../includes' ] " uniquify the input list function! s:Unique(list)