Skip to content
This repository was archived by the owner on Jun 23, 2021. It is now read-only.

Commit 72c21ad

Browse files
authored
Merge pull request #13 from samharad/add-vim-support
added vim inline check support, documentation
2 parents 0180f6e + 25ff2df commit 72c21ad

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ lint381 can now be used for inline style checking within emacs using flycheck. D
9595

9696
![Example lint381 in emacs](media/emacs_example.png)
9797

98+
## vim
99+
100+
lint381 can also be used for inline style checking within vim using Syntastic. Download and follow the directions in [lint381.vim](vim/cpp/lint381.vim) to set it up.
101+
102+
![Example lint381 in vim](media/vim_example.png)
103+
98104
# License
99105

100106
`lint381` is licensed under GPLv3.

media/vim_example.png

130 KB
Loading

vim/c/lint381.vim

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
" lint381.vim --- style check your code according to EECS 381 style guidelines
2+
3+
" This file depends on cpp/lint381.vim -- see cpp/lint381.vim
4+
5+
if exists('g:loaded_syntastic_c_lint381_checker')
6+
finish
7+
endif
8+
let g:loaded_syntastic_c_lint381_checker = 1
9+
10+
call g:SyntasticRegistry.CreateAndRegisterChecker({
11+
\ 'filetype': 'c',
12+
\ 'name': 'lint381',
13+
\ 'redirect': 'cpp/lint381'})

vim/cpp/lint381.vim

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
" lint381.vim --- style check your code according to EECS 381 style guidelines
2+
3+
" This checker filters your code through the lint381 application and displays
4+
" the violations of the EECS 381 style guide right within your vim editor.
5+
" It requires that the lint381 program lives in your path, and that you have
6+
" the Syntastic plugin for vim installed.
7+
8+
" The lint381 program: https://github.com/arxanas/lint381
9+
" See also the EECS 381 style guides:
10+
" http://www.umich.edu/~eecs381/handouts/C_Coding_Standards.pdf
11+
" http://www.umich.edu/~eecs381/handouts/C++_Coding_Standards.pdf
12+
13+
" To use this:
14+
" 1) Ensure that you have Syntastic installed: https://github.com/vim-syntastic/syntastic
15+
" 2) Place this file in ~/.vim/bundle/syntastic/syntax_checkers/cpp
16+
" 3) Place the c/lint381.vim file in ~/.vim/bundle/syntastic/syntax_checkers/c
17+
" 4) Add these lines to your vimrc:
18+
" let g:syntastic_cpp_checkers = ['lint381']
19+
" let g:syntastic_c_checkers = ['lint381']
20+
" Of course, precede 'lint381' with any other linters you may wish to use, e.g.:
21+
" let g:syntastic_cpp_checkers = ['cppcheck', 'lint381']
22+
23+
" Note that if you have multiple checkers enabled, the default behavior of Syntastic
24+
" is to run them in sequence, continuing with the next checker ONLY once the previous
25+
" checker returns no errors.
26+
" To tell Syntastic to always run all checkers, add this to your vimrc:
27+
" let g:syntastic_aggregate_errors = 1
28+
29+
if exists('g:loaded_syntastic_cpp_lint381_checker')
30+
finish
31+
endif
32+
let g:loaded_syntastic_cpp_lint381_checker = 1
33+
34+
if !exists('g:syntastic_cpp_lint381_sort')
35+
let g:syntastic_cpp_lint381_sort = 1
36+
endif
37+
38+
let s:save_cpo = &cpo
39+
set cpo&vim
40+
41+
" Since lint381 only prints the basename of the file being edited,
42+
" if the user edits a file that is not in the current working directory,
43+
" syntastic ends up telling vim that the identified errors are in a file
44+
" in the cwd with the printed name.
45+
" To fix this, we convert the basenames to absolute paths.
46+
function! Basenames_to_absolute_paths(errors) abort
47+
let out = []
48+
for err in a:errors
49+
let str = expand('%:h') . '/' . err
50+
echom str
51+
call add(out, str)
52+
endfor
53+
return out
54+
endfunction
55+
56+
let s:default_args = {
57+
\ 'c': '--lang=c',
58+
\ 'cpp': '--lang=cpp'}
59+
60+
function! SyntaxCheckers_cpp_lint381_IsAvailable() dict
61+
return executable(self.getExec())
62+
endfunction
63+
64+
function! SyntaxCheckers_cpp_lint381_GetLocList() dict
65+
let makeprg = self.makeprgBuild({'args': get(s:default_args, self.getFiletype(), '')})
66+
67+
" See :help errorformat and :help errorformat-multi-line
68+
let errorformat = '%E%f:%l:%c: ' " Matches the file name, line number and column number
69+
let errorformat .= 'error:\ %m' " Matches the error message
70+
let errorformat .= ',%C%p^,%Z' " Matches the ^^^^ that points to the error
71+
72+
" Note that we mark the errors as 'Style' errors; Syntastic can be configured to ignore these.
73+
return SyntasticMake({ 'makeprg': makeprg,
74+
\'errorformat': errorformat,
75+
\'subtype': 'Style',
76+
\'Preprocess': 'Basenames_to_absolute_paths' })
77+
endfunction
78+
79+
call g:SyntasticRegistry.CreateAndRegisterChecker({ 'filetype': 'cpp', 'name': 'lint381' })
80+
81+
let &cpo = s:save_cpo
82+
unlet s:save_cpo

0 commit comments

Comments
 (0)