All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
2 " Python filetype plugin for running flake8
3 " Language: Python (ft=python)
4 " Maintainer: Vincent Driessen <vincent@3rdcloud.com>
5 " Version: Vim 7 (may work with lower Vim versions, but not tested)
6 " URL: http://github.com/nvie/vim-flake8
13 function! flake8#Flake8()
17 function! flake8#Flake8UnplaceMarkers()
18 call s:UnplaceMarkers()
27 function! s:DeclareOption(name, globalPrefix, default) " {{{
28 if !exists('g:'.a:name)
30 execute 'let s:'.a:name.'='.a:default
32 execute 'let s:'.a:name.'=""'
35 execute 'let l:global="g:".a:name'
37 execute 'let s:'.a:name.'="'.a:globalPrefix.'".g:'.a:name
39 execute 'let s:'.a:name.'=""'
44 function! s:SetupConfig() " {{{
48 call s:DeclareOption('flake8_cmd', '', '"flake8"')
50 call s:DeclareOption('flake8_builtins', ' --builtins=', '')
51 call s:DeclareOption('flake8_ignore', ' --ignore=', '')
52 call s:DeclareOption('flake8_max_line_length', ' --max-line-length=', '')
53 call s:DeclareOption('flake8_max_complexity', ' --max-complexity=', '')
55 call s:DeclareOption('flake8_quickfix_location', '', '"belowright"')
56 call s:DeclareOption('flake8_show_quickfix', '', 1)
58 call s:DeclareOption('flake8_show_in_gutter', '', 0)
59 call s:DeclareOption('flake8_show_in_file', '', 0)
60 call s:DeclareOption('flake8_max_markers', '', 500)
62 call s:DeclareOption('flake8_error_marker', '', '"E>"')
63 call s:DeclareOption('flake8_warning_marker', '', '"W>"')
64 call s:DeclareOption('flake8_pyflake_marker', '', '"F>"')
65 call s:DeclareOption('flake8_complexity_marker', '', '"C>"')
66 call s:DeclareOption('flake8_naming_marker', '', '"N>"')
71 if s:flake8_error_marker != ''
72 let s:markerdata['E'] = {
73 \ 'color': 'Flake8_Error',
74 \ 'marker': s:flake8_error_marker,
78 if s:flake8_warning_marker != ''
79 let s:markerdata['W'] = {
80 \ 'color': 'Flake8_Warning',
81 \ 'marker': s:flake8_warning_marker,
85 if s:flake8_pyflake_marker != ''
86 let s:markerdata['F'] = {
87 \ 'color': 'Flake8_PyFlake',
88 \ 'marker': s:flake8_pyflake_marker,
92 if s:flake8_complexity_marker != ''
93 let s:markerdata['C'] = {
94 \ 'color': 'Flake8_Complexity',
95 \ 'marker': s:flake8_complexity_marker,
99 if s:flake8_naming_marker != ''
100 let s:markerdata['N'] = {
101 \ 'color': 'Flake8_Nameing',
102 \ 'marker': s:flake8_naming_marker,
103 \ 'sign': 'Flake8_N',
110 function! s:Flake8() " {{{
114 if !executable(s:flake8_cmd)
115 echoerr "File " . s:flake8_cmd . " not found. Please install it first."
119 " store old grep settings (to restore later)
120 let l:old_gfm=&grepformat
121 let l:old_gp=&grepprg
122 let l:old_shellpipe=&shellpipe
124 " write any changes before continuing
129 set lazyredraw " delay redrawing
130 cclose " close any existing cwindows
132 " set shellpipe to > instead of tee (suppressing output)
135 " perform the grep itself
136 let &grepformat="%f:%l:%c: %m\,%f:%l: %m"
137 let &grepprg=s:flake8_cmd.s:flake8_builtins.s:flake8_ignore.s:flake8_max_line_length.s:flake8_max_complexity
140 echo s:flake8_cmd.s:flake8_builtins.s:flake8_ignore.s:flake8_max_line_length.s:flake8_max_complexity
142 " restore grep settings
143 let &grepformat=l:old_gfm
144 let &grepprg=l:old_gp
145 let &shellpipe=l:old_shellpipe
148 let l:results=getqflist()
149 let l:has_results=results != []
152 if !s:flake8_show_in_gutter == 0 || !s:flake8_show_in_file == 0
153 call s:PlaceMarkers(l:results)
156 if !s:flake8_show_quickfix == 0
158 execute s:flake8_quickfix_location." copen"
160 nnoremap <buffer> <silent> c :cclose<CR>
161 nnoremap <buffer> <silent> q :cclose<CR>
169 if l:has_results == 0
170 echon "Flake8 check OK"
172 echon "Flake8 found issues"
178 function! s:PlaceMarkers(results) " {{{
180 if !s:flake8_show_in_gutter == 0
182 for val in values(s:markerdata)
183 execute "sign define ".val['sign']." text=".val['marker']." texthl=".val['color']
189 if !s:flake8_show_in_file == 0
190 let l:matchstr = '\%('
194 call s:UnplaceMarkers()
200 let l:index = l:index0
201 for result in a:results
202 if l:index >= (s:flake8_max_markers+l:index0)
205 let l:type = strpart(result.text, 0, 1)
206 if has_key(s:markerdata, l:type)
208 if !s:flake8_show_in_file == 0
209 "let s:matchstr .= '\|\%'.result.lnum.'l\%'.result.col.'c'
210 let s:matchids += [matchadd(s:markerdata[l:type]['color'], "\\%".result.lnum."l\\%".result.col."c")]
213 if !s:flake8_show_in_gutter == 0
214 execute ":sign place ".index." name=".s:markerdata[l:type]['sign']
215 \ . " line=".result.lnum." file=".expand("%:p")
216 let s:signids += [l:index]
223 if !s:flake8_show_in_file == 0
224 call matchadd(Error, s:matchstr.'\)')
228 function! s:UnplaceMarkers() " {{{
230 if exists('s:signids')
232 execute ":sign unplace ".i
237 if exists('s:matchids')
247 let &cpo = s:save_cpo