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:Setup() " {{{
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>"')
70 if !exists('s:markerdata')
72 let s:markerdata['E'] = { 'name': 'Flake8_Error' }
73 let s:markerdata['W'] = { 'name': 'Flake8_Warning' }
74 let s:markerdata['F'] = { 'name': 'Flake8_PyFlake' }
75 let s:markerdata['C'] = { 'name': 'Flake8_Complexity' }
76 let s:markerdata['N'] = { 'name': 'Flake8_Nameing' }
78 let s:markerdata['E'].marker = s:flake8_error_marker
79 let s:markerdata['W'].marker = s:flake8_warning_marker
80 let s:markerdata['F'].marker = s:flake8_pyflake_marker
81 let s:markerdata['C'].marker = s:flake8_complexity_marker
82 let s:markerdata['N'].marker = s:flake8_naming_marker
87 function! s:Flake8() " {{{
91 if !executable(s:flake8_cmd)
92 echoerr "File " . s:flake8_cmd . " not found. Please install it first."
96 " store old grep settings (to restore later)
97 let l:old_gfm=&grepformat
99 let l:old_shellpipe=&shellpipe
101 " write any changes before continuing
106 set lazyredraw " delay redrawing
107 cclose " close any existing cwindows
109 " set shellpipe to > instead of tee (suppressing output)
112 " perform the grep itself
113 let &grepformat="%f:%l:%c: %m\,%f:%l: %m"
114 let &grepprg=s:flake8_cmd.s:flake8_builtins.s:flake8_ignore.s:flake8_max_line_length.s:flake8_max_complexity
117 " restore grep settings
118 let &grepformat=l:old_gfm
119 let &grepprg=l:old_gp
120 let &shellpipe=l:old_shellpipe
123 let l:results=getqflist()
124 let l:has_results=results != []
127 if !s:flake8_show_in_gutter == 0 || !s:flake8_show_in_file == 0
128 call s:PlaceMarkers(l:results)
131 if !s:flake8_show_quickfix == 0
133 execute s:flake8_quickfix_location." copen"
135 nnoremap <buffer> <silent> c :cclose<CR>
136 nnoremap <buffer> <silent> q :cclose<CR>
144 if l:has_results == 0
145 echon "Flake8 check OK"
147 echon "Flake8 found issues"
153 function! s:PlaceMarkers(results) " {{{
155 if !s:flake8_show_in_gutter == 0
157 for val in values(s:markerdata)
159 execute "sign define ".val.name." text=".val.marker." texthl=".val.name
165 call s:UnplaceMarkers()
171 let l:index = l:index0
172 for result in a:results
173 if l:index >= (s:flake8_max_markers+l:index0)
176 let l:type = strpart(result.text, 0, 1)
177 if has_key(s:markerdata, l:type) && s:markerdata[l:type].marker != ''
179 if !s:flake8_show_in_file == 0
180 if !has_key(s:markerdata[l:type], 'matchstr')
181 let s:markerdata[l:type].matchstr = '\%('
183 let s:markerdata[l:type].matchstr .= '\|'
185 let s:markerdata[l:type].matchstr .= '\%'.result.lnum.'l\%'.result.col.'c'
188 if !s:flake8_show_in_gutter == 0
189 execute ":sign place ".index." name=".s:markerdata[l:type].name
190 \ . " line=".result.lnum." file=".expand("%:p")
191 let s:signids += [l:index]
198 if !s:flake8_show_in_file == 0
199 for l:val in values(s:markerdata)
200 if l:val.marker != '' && has_key(l:val, 'matchstr')
201 let l:val.matchid = matchadd(l:val.name, l:val.matchstr.'\)')
207 function! s:UnplaceMarkers() " {{{
209 if exists('s:signids')
211 execute ":sign unplace ".i
216 for l:val in values(s:markerdata)
217 if has_key(l:val, 'matchid')
218 call matchdelete(l:val.matchid)
227 let &cpo = s:save_cpo