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()
18 function! flake8#Flake8UnplaceMarkers()
19 call s:UnplaceMarkers()
29 let s:displayed_warnings = 0
31 if !s:displayed_warnings
32 let l:show_website_url = 0
34 let l:msg = "has been depreciated in favour of flake8 config files"
35 for setting_name in ['g:flake8_ignore', 'g:flake8_builtins', 'g:flake8_max_line_length', 'g:flake8_max_complexity']
36 if exists(setting_name)
37 echohl WarningMsg | echom setting_name l:msg | echohl None
38 let l:show_website_url = 1
43 let l:url = "http://flake8.readthedocs.org/en/latest/config.html"
44 echohl WarningMsg | echom l:url | echohl None
46 let s:displayed_warnings = 1
52 function! s:DeclareOption(name, globalPrefix, default) " {{{
53 if !exists('g:'.a:name)
55 execute 'let s:'.a:name.'='.a:default
57 execute 'let s:'.a:name.'=""'
60 execute 'let l:global="g:".a:name'
62 execute 'let s:'.a:name.'="'.a:globalPrefix.'".g:'.a:name
64 execute 'let s:'.a:name.'=""'
69 function! s:Setup() " {{{
73 call s:DeclareOption('flake8_cmd', '', '"flake8"')
75 call s:DeclareOption('flake8_quickfix_location', '', '"belowright"')
76 call s:DeclareOption('flake8_quickfix_height', '', 5)
77 call s:DeclareOption('flake8_show_quickfix', '', 1)
79 call s:DeclareOption('flake8_show_in_gutter', '', 0)
80 call s:DeclareOption('flake8_show_in_file', '', 0)
81 call s:DeclareOption('flake8_max_markers', '', 500)
83 call s:DeclareOption('flake8_error_marker', '', '"E>"')
84 call s:DeclareOption('flake8_warning_marker', '', '"W>"')
85 call s:DeclareOption('flake8_pyflake_marker', '', '"F>"')
86 call s:DeclareOption('flake8_complexity_marker', '', '"C>"')
87 call s:DeclareOption('flake8_naming_marker', '', '"N>"')
91 if !exists('s:markerdata')
93 let s:markerdata['E'] = {'name': 'Flake8_Error'}
94 let s:markerdata['W'] = {'name': 'Flake8_Warning'}
95 let s:markerdata['F'] = {'name': 'Flake8_PyFlake'}
96 let s:markerdata['C'] = {'name': 'Flake8_Complexity'}
97 let s:markerdata['N'] = {'name': 'Flake8_Nameing'}
99 let s:markerdata['E'].marker = s:flake8_error_marker
100 let s:markerdata['W'].marker = s:flake8_warning_marker
101 let s:markerdata['F'].marker = s:flake8_pyflake_marker
102 let s:markerdata['C'].marker = s:flake8_complexity_marker
103 let s:markerdata['N'].marker = s:flake8_naming_marker
108 function! s:Flake8() " {{{
112 if !executable(s:flake8_cmd)
113 echoerr "File " . s:flake8_cmd . " not found. Please install it first."
118 call s:UnplaceMarkers()
122 " store old grep settings (to restore later)
123 let l:old_gfm=&grepformat
124 let l:old_gp=&grepprg
125 let l:old_shellpipe=&shellpipe
127 " write any changes before continuing
132 set lazyredraw " delay redrawing
133 cclose " close any existing cwindows
135 " set shellpipe to > instead of tee (suppressing output)
138 " perform the grep itself
139 let &grepformat="%f:%l:%c: %m\,%f:%l: %m"
140 let &grepprg=s:flake8_cmd
143 " restore grep settings
144 let &grepformat=l:old_gfm
145 let &grepprg=l:old_gp
146 let &shellpipe=l:old_shellpipe
149 let l:results=getqflist()
150 let l:has_results=results != []
153 if !s:flake8_show_in_gutter == 0 || !s:flake8_show_in_file == 0
154 call s:PlaceMarkers(l:results)
157 if !s:flake8_show_quickfix == 0
159 execute s:flake8_quickfix_location." copen".s:flake8_quickfix_height
161 nnoremap <buffer> <silent> c :cclose<CR>
162 nnoremap <buffer> <silent> q :cclose<CR>
170 if l:has_results == 0
171 echon "Flake8 check OK"
173 echon "Flake8 found issues"
179 function! s:PlaceMarkers(results) " {{{
181 if !s:flake8_show_in_gutter == 0
183 for val in values(s:markerdata)
185 execute "sign define ".val.name." text=".val.marker." texthl=".val.name
192 let l:index = l:index0
193 for result in a:results
194 if l:index >= (s:flake8_max_markers+l:index0)
197 let l:type = strpart(result.text, 0, 1)
198 if has_key(s:markerdata, l:type) && s:markerdata[l:type].marker != ''
200 if !s:flake8_show_in_file == 0
201 if !has_key(s:markerdata[l:type], 'matchstr')
202 let s:markerdata[l:type].matchstr = '\%('
204 let s:markerdata[l:type].matchstr .= '\|'
206 let s:markerdata[l:type].matchstr .= '\%'.result.lnum.'l\%'.result.col.'c'
209 if !s:flake8_show_in_gutter == 0
210 execute ":sign place ".index." name=".s:markerdata[l:type].name
211 \ . " line=".result.lnum." file=".expand("%:p")
212 let s:signids += [l:index]
219 if !s:flake8_show_in_file == 0
220 for l:val in values(s:markerdata)
221 if l:val.marker != '' && has_key(l:val, 'matchstr')
222 let l:val.matchid = matchadd(l:val.name, l:val.matchstr.'\)')
228 function! s:UnplaceMarkers() " {{{
230 if exists('s:signids')
232 execute ":sign unplace ".i
237 for l:val in values(s:markerdata)
238 if has_key(l:val, 'matchid')
239 call matchdelete(l:val.matchid)
248 let &cpo = s:save_cpo