From 85c347c14f8b356007f76567190ce72380291a52 Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 11 Mar 2012 19:33:10 +0100 Subject: [PATCH 1/4] fix custom c++ compiler options --- syntax_checkers/cpp.vim | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/syntax_checkers/cpp.vim b/syntax_checkers/cpp.vim index 5fc6111e..473590c0 100644 --- a/syntax_checkers/cpp.vim +++ b/syntax_checkers/cpp.vim @@ -65,10 +65,16 @@ let s:save_cpo = &cpo set cpo&vim function! SyntaxCheckers_cpp_GetLocList() - let makeprg = 'g++ -fsyntax-only '.shellescape(expand('%')). - \ ' ' . syntastic#c#GetIncludeDirs(1) + let makeprg = 'g++ -fsyntax-only ' let errorformat = '%-G%f:%s:,%f:%l:%c: %m,%f:%l: %m' + if exists('g:syntastic_cpp_compiler_options') + let makeprg .= g:syntastic_cpp_compiler_options + endif + + let makeprg .= ' ' . shellescape(expand('%')) . + \ ' ' . syntastic#c#GetIncludeDirs(1) + if expand('%') =~? '\%(.h\|.hpp\|.hh\)$' if exists('g:syntastic_cpp_check_header') let makeprg = 'g++ -c '.shellescape(expand('%')). @@ -78,10 +84,6 @@ function! SyntaxCheckers_cpp_GetLocList() endif endif - if exists('g:syntastic_cpp_compiler_options') - let makeprg .= g:syntastic_cpp_compiler_options - endif - if !exists('b:syntastic_cpp_cflags') if !exists('g:syntastic_cpp_no_include_search') || \ g:syntastic_cpp_no_include_search != 1 From c11c97da8be0c158ac9cb85bd9ed336c1cf5f0a1 Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 11 Mar 2012 19:35:52 +0100 Subject: [PATCH 2/4] fix compiler options for C as well --- syntax_checkers/c.vim | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index 740ad746..9b645f41 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -65,13 +65,20 @@ let s:save_cpo = &cpo set cpo&vim function! SyntaxCheckers_c_GetLocList() - let makeprg = 'gcc -fsyntax-only -std=gnu99 '.shellescape(expand('%')). - \ ' '.syntastic#c#GetIncludeDirs(0) + let makeprg = 'gcc -fsyntax-only -std=gnu99 ' 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: %m,%f:%l: %trror: %m,%f:%l: %m' + " add optional user-defined compiler options + if exists('g:syntastic_c_compiler_options') + let makeprg .= g:syntastic_c_compiler_options + endif + + let makeprg .= ' '.shellescape(expand('%')). + \ ' '.syntastic#c#GetIncludeDirs(0) + " determine whether to parse header files as well if expand('%') =~? '.h$' if exists('g:syntastic_c_check_header') @@ -82,11 +89,6 @@ 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 - " check if the user manually set some cflags if !exists('b:syntastic_c_cflags') " check whether to search for include files at all From 6ce5880b81d1feee712c3b18050448f313e1544f Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 11 Mar 2012 19:40:53 +0100 Subject: [PATCH 3/4] set default C compiler options --- syntax_checkers/c.vim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index 9b645f41..d32c5460 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -64,17 +64,19 @@ 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 + function! SyntaxCheckers_c_GetLocList() - let makeprg = 'gcc -fsyntax-only -std=gnu99 ' + 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: %m,%f:%l: %trror: %m,%f:%l: %m' " add optional user-defined compiler options - if exists('g:syntastic_c_compiler_options') - let makeprg .= g:syntastic_c_compiler_options - endif + let makeprg .= g:syntastic_c_compiler_options let makeprg .= ' '.shellescape(expand('%')). \ ' '.syntastic#c#GetIncludeDirs(0) From adedb47ad70e9dba5eebaf2225f5a22df90ac4dc Mon Sep 17 00:00:00 2001 From: kongo2002 Date: Sun, 11 Mar 2012 19:55:01 +0100 Subject: [PATCH 4/4] refactoring of GetIncludeDirs() for C/C++ --- autoload/syntastic/c.vim | 12 +++--------- syntax_checkers/c.vim | 4 ++-- syntax_checkers/cpp.vim | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/autoload/syntastic/c.vim b/autoload/syntastic/c.vim index 8699a172..73623b15 100644 --- a/autoload/syntastic/c.vim +++ b/autoload/syntastic/c.vim @@ -55,17 +55,11 @@ endfunction " get the gcc include directory argument depending on the default " includes and the optional user-defined 'g:syntastic_c_include_dirs' -function! syntastic#c#GetIncludeDirs(cpp) +function! syntastic#c#GetIncludeDirs(filetype) let include_dirs = copy(s:default_includes) - if a:cpp == 1 - if exists('g:syntastic_cpp_include_dirs') - call extend(include_dirs, g:syntastic_cpp_include_dirs) - endif - else - if exists('g:syntastic_c_include_dirs') - call extend(include_dirs, g:syntastic_c_include_dirs) - endif + if exists('g:syntastic_'.a:filetype.'_include_dirs') + call extend(include_dirs, g:syntastic_{a:filetype}_include_dirs) endif return join(map(s:Unique(include_dirs), '"-I" . v:val'), ' ') diff --git a/syntax_checkers/c.vim b/syntax_checkers/c.vim index d32c5460..c20b68d0 100644 --- a/syntax_checkers/c.vim +++ b/syntax_checkers/c.vim @@ -79,13 +79,13 @@ function! SyntaxCheckers_c_GetLocList() let makeprg .= g:syntastic_c_compiler_options let makeprg .= ' '.shellescape(expand('%')). - \ ' '.syntastic#c#GetIncludeDirs(0) + \ ' '.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(0) + \ ' '.syntastic#c#GetIncludeDirs('c') else return [] endif diff --git a/syntax_checkers/cpp.vim b/syntax_checkers/cpp.vim index 473590c0..7fe2e0ec 100644 --- a/syntax_checkers/cpp.vim +++ b/syntax_checkers/cpp.vim @@ -73,12 +73,12 @@ function! SyntaxCheckers_cpp_GetLocList() endif let makeprg .= ' ' . shellescape(expand('%')) . - \ ' ' . syntastic#c#GetIncludeDirs(1) + \ ' ' . syntastic#c#GetIncludeDirs('cpp') if expand('%') =~? '\%(.h\|.hpp\|.hh\)$' if exists('g:syntastic_cpp_check_header') let makeprg = 'g++ -c '.shellescape(expand('%')). - \ ' ' . syntastic#c#GetIncludeDirs(1) + \ ' ' . syntastic#c#GetIncludeDirs('cpp') else return [] endif