Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Additional options #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand All @@ -29,10 +31,29 @@ the `<F7>` key if so. For example, to remap it to `<F3>` instead, use:
autocmd FileType cpp map <buffer> <F3> :call Cpplint()<CR>


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 = <line length>




Tips
----
A tip might be to run the cpplint.py check every time you write a C++ file, to
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.
36 changes: 32 additions & 4 deletions ftplugin/cpp_cpplint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,40 @@
" Language: C++ (ft=cpp)
" Maintainer: Thomas Chen <[email protected]>
" 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
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)
Expand All @@ -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
Expand All @@ -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
Expand Down