From eb8f243a2933f58c51bcabd338550bc7c44a071d Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 7 Aug 2011 14:22:32 +0200 Subject: [PATCH 1/4] add possibility to add custom include directories --- syntax_checkers/c.vim | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index f6e2e07a..5c1aa7cc 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -81,8 +81,22 @@ function! s:Init() unlet! s:RegHandler endfunction +let s:default_includes = [ '.', '..', 'include', 'includes' ] + +function! s:GetIncludeDirs() + let include_dirs = s:default_includes + + if exists('g:syntastic_c_include_dirs') + call extend(include_dirs, g:syntastic_c_include_dirs) + endif + + return join(map(copy(include_dirs), '"-I" . v:val'), ' ') +endfunction + function! SyntaxCheckers_c_GetLocList() - let makeprg = 'gcc -fsyntax-only '.shellescape(expand('%')).' -I. -I..' + let makeprg = 'gcc -fsyntax-only '.shellescape(expand('%')). + \ ' '.s:GetIncludeDirs() + echom makeprg 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%.%#,'. @@ -90,7 +104,8 @@ function! SyntaxCheckers_c_GetLocList() if expand('%') =~? '.h$' if exists('g:syntastic_c_check_header') - let makeprg = 'gcc -c '.shellescape(expand('%')).' -I. -I..' + let makeprg = 'gcc -c '.shellescape(expand('%')). + \ ' '.s:GetIncludeDirs() else return [] endif From f50116f31c4fa1956e92311deccbd53b270711a0 Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 7 Aug 2011 14:25:42 +0200 Subject: [PATCH 2/4] c syntax checker: add doc --- syntax_checkers/c.vim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index 5c1aa7cc..99c082a8 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -34,6 +34,13 @@ " 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' ] + if exists('loaded_c_syntax_checker') finish From c13ff43d4e3411542ee918f5ecfe8bd2a7c556c0 Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 7 Aug 2011 14:37:34 +0200 Subject: [PATCH 3/4] remove debug print --- syntax_checkers/c.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index 99c082a8..1092e01c 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -94,6 +94,7 @@ 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 @@ -103,7 +104,6 @@ endfunction function! SyntaxCheckers_c_GetLocList() let makeprg = 'gcc -fsyntax-only '.shellescape(expand('%')). \ ' '.s:GetIncludeDirs() - echom makeprg 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%.%#,'. From bb834f38e5ebc524c281305a6f0a8d0636d6dff5 Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 7 Aug 2011 14:38:55 +0200 Subject: [PATCH 4/4] extend default includes --- 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 1092e01c..06e3c081 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -88,7 +88,8 @@ function! s:Init() unlet! s:RegHandler endfunction -let s:default_includes = [ '.', '..', 'include', 'includes' ] +let s:default_includes = [ '.', '..', 'include', 'includes', + \ '../include', '../includes' ] function! s:GetIncludeDirs() let include_dirs = s:default_includes