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)
29 execute 'let s:'.a:name.'='.a:default
31 execute 'let s:'.a:name.'="'.a:globalPrefix.'".g:'.a:name
35 function! s:SetupConfig() " {{{
39 call s:DeclareOption('flake8_cmd', '', '"flake8"')
41 call s:DeclareOption('flake8_builtins', ' --builtins=', '')
42 call s:DeclareOption('flake8_ignore', ' --ignore=', '')
43 call s:DeclareOption('flake8_max_line_length', ' --max-line-length=', '')
44 call s:DeclareOption('flake8_max_complexity', ' --max-complexity=', '')
46 call s:DeclareOption('flake8_quickfix_location', '', '"belowright"')
47 call s:DeclareOption('flake8_show_quickfix', '', 1)
49 call s:DeclareOption('flake8_show_in_gutter', '', 0)
50 call s:DeclareOption('flake8_show_in_file', '', 0)
51 call s:DeclareOption('flake8_max_markers', '', 500)
53 call s:DeclareOption('flake8_error_marker', '', '"E>"')
54 call s:DeclareOption('flake8_warning_marker', '', '"W>"')
55 call s:DeclareOption('flake8_pyflake_marker', '', '"F>"')
56 call s:DeclareOption('flake8_complexity_marker', '', '"C>"')
57 call s:DeclareOption('flake8_naming_marker', '', '"N>"')
62 if s:flake8_error_marker != ''
63 let s:markerdata['E'] = {
64 \ 'color': 'Flake8_Error',
65 \ 'marker': s:flake8_error_marker,
69 if s:flake8_warning_marker != ''
70 let s:markerdata['W'] = {
71 \ 'color': 'Flake8_Warning',
72 \ 'marker': s:flake8_warning_marker,
76 if s:flake8_pyflake_marker != ''
77 let s:markerdata['F'] = {
78 \ 'color': 'Flake8_PyFlake',
79 \ 'marker': s:flake8_pyflake_marker,
83 if s:flake8_complexity_marker != ''
84 let s:markerdata['C'] = {
85 \ 'color': 'Flake8_Complexity',
86 \ 'marker': s:flake8_complexity_marker,
90 if s:flake8_naming_marker != ''
91 let s:markerdata['N'] = {
92 \ 'color': 'Flake8_Nameing',
93 \ 'marker': s:flake8_naming_marker,
101 function! s:Flake8() " {{{
105 if !executable(s:flake8_cmd)
106 echoerr "File " . s:flake8_cmd . " not found. Please install it first."
110 " store old grep settings (to restore later)
111 let l:old_gfm=&grepformat
112 let l:old_gp=&grepprg
113 let l:old_shellpipe=&shellpipe
115 " write any changes before continuing
120 set lazyredraw " delay redrawing
121 cclose " close any existing cwindows
123 " set shellpipe to > instead of tee (suppressing output)
126 " perform the grep itself
127 let &grepformat="%f:%l:%c: %m\,%f:%l: %m"
128 let &grepprg=s:flake8_cmd.s:flake8_builtins.s:flake8_ignore.s:flake8_max_line_length.s:flake8_max_complexity
131 echo s:flake8_cmd.s:flake8_builtins.s:flake8_ignore.s:flake8_max_line_length.s:flake8_max_complexity
133 " restore grep settings
134 let &grepformat=l:old_gfm
135 let &grepprg=l:old_gp
136 let &shellpipe=l:old_shellpipe
139 let l:results=getqflist()
140 let l:has_results=results != []
143 if !s:flake8_show_in_gutter == 0 || !s:flake8_show_in_file == 0
144 call s:PlaceMarkers(l:results)
147 if !s:flake8_show_quickfix == 0
149 execute s:flake8_quickfix_location." copen"
151 nnoremap <buffer> <silent> c :cclose<CR>
152 nnoremap <buffer> <silent> q :cclose<CR>
160 if l:has_results == 0
161 echon "Flake8 check OK"
163 echon "Flake8 found issues"
169 function! s:PlaceMarkers(results) " {{{
171 if !s:flake8_show_in_gutter == 0
173 for val in values(s:markerdata)
174 execute "sign define ".val['sign']." text=".val['marker']." texthl=".val['color']
179 call s:UnplaceMarkers()
185 let l:index = l:index0
186 for result in a:results
187 if l:index >= (s:flake8_max_markers+l:index0)
190 let l:type = strpart(result.text, 0, 1)
191 if has_key(s:markerdata, l:type)
193 if !s:flake8_show_in_file == 0
194 let s:matchids += [matchadd(s:markerdata[l:type]['color'],
195 \ "\\%".result.lnum."l\\%".result.col."c")]
198 if !s:flake8_show_in_gutter == 0
199 execute ":sign place ".index." name=".s:markerdata[l:type]['sign']
200 \ . " line=".result.lnum." file=".expand("%:p")
201 let s:signids += [l:index]
209 function! s:UnplaceMarkers() " {{{
211 if exists('s:signids')
213 execute ":sign unplace ".i
218 if exists('s:matchids')
228 let &cpo = s:save_cpo