diff --git a/README.mdown b/README.mdown index e89f5dd..dc968b7 100644 --- a/README.mdown +++ b/README.mdown @@ -3,6 +3,8 @@ vim-cpplint `vim-cpplint` is a Vim plugin that runs the currently open file through cpplint.py, a static syntax and style checker for C++ source code. +The code will be checked according to [Google C++ Style Guide ](http://google-styleguide.googlecode.com/svn/trunk/cppguide.html) + Installation ------------ @@ -29,6 +31,20 @@ the `` key if so. For example, to remap it to `` instead, use: autocmd FileType cpp map :call Cpplint() +By default the plugin support following file extensions: +*.cc, *.h, *.cpp, *.cu, *.cuh + +You can change it by setting in .vimrc the variable: + + let g:cpplint_extensions = "cpp,hpp,h,c,cc,cu,cuh" + +The line length, by default it is 80 characters but you can change it by + + let g:cpplint_line_length = + + + + Tips ---- A tip might be to run the cpplint.py check every time you write a C++ file, to @@ -36,3 +52,8 @@ enable this, add the following line to your `.vimrc` file (thanks [Godefroid](http://github.com/gotcha)!): autocmd BufWritePost *.h,*.cpp call Cpplint() + +False positives can be ignored by putting + + // NOLINT at the end of the line or + // NOLINTNEXTLINE in the previous line. diff --git a/ftplugin/cpp_cpplint.vim b/ftplugin/cpp_cpplint.vim index 20d28b6..1a4a854 100644 --- a/ftplugin/cpp_cpplint.vim +++ b/ftplugin/cpp_cpplint.vim @@ -3,11 +3,14 @@ " Language: C++ (ft=cpp) " Maintainer: Thomas Chen " Version: Vim 7 (may work with lower Vim versions, but not tested) -" URL: http://example.com/ " " Code is borrowed from vim-flake8 and slightly modified. " " Only do this when not done yet for this buffer +" +" Running the Google cpplint.py code to validate the style according to: +" http://google-styleguide.googlecode.com/svn/trunk/cppguide.html +" if exists("b:loaded_cpplint_ftplugin") finish endif @@ -15,6 +18,25 @@ let b:loaded_cpplint_ftplugin=1 let s:cpplint_cmd="cpplint.py" +" extensions +let s:cpplint_extensions="cc,h,cpp,cu,cuh" + +if exists("g:cpplint_extensions") + let s:cpplint_extensions=g:cpplint_extensions +endif + +let s:cpplint_cmd_opts = ' --extensions=' . s:cpplint_extensions . ' ' + +" line length +if exists('g:cpplint_line_length') + let s:cpplint_cmd_opts = s:cpplint_cmd_opts . ' --linelength=' . g:cpplint_line_length . ' ' +endif + +" filters +if exists('g:cpplint_filter') + let s:cpplint_cmd_opts = s:cpplint_cmd_opts . ' --filter=' . g:cpplint_filter . ' ' +endif + if !exists("*Cpplint()") function Cpplint() if !executable(s:cpplint_cmd) @@ -36,15 +58,21 @@ if !exists("*Cpplint()") " perform the grep itself let &grepformat="%f:%l: %m" - let &grepprg=s:cpplint_cmd + let &grepprg=s:cpplint_cmd . s:cpplint_cmd_opts . ' ' silent! grep! % + let has_results=1 + for va in getqflist() + if va.text =~ "Total errors found: 0" + let has_results=0 + break + endif + endfor " restore grep settings let &grepformat=l:old_gfm let &grepprg=l:old_gp " open cwindow - let has_results=getqflist() != [] if has_results execute 'belowright copen' setlocal wrap @@ -59,7 +87,7 @@ if !exists("*Cpplint()") " Show OK status hi Green ctermfg=green echohl Green - echon "cpplint.py check OK" + echon "cpplint.py check OK (status: " . has_results . ')' echohl endif endfunction