]> git.madduck.net Git - etc/vim.git/blob - ftplugin/python_flake8.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

710abf7d97acf3d29a3a1ad750aeaf5c66a3248c
[etc/vim.git] / ftplugin / python_flake8.vim
1 "
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
7 "
8 " Only do this when not done yet for this buffer
9 if exists("b:loaded_flake8_ftplugin")
10     finish
11 endif
12 let b:loaded_flake8_ftplugin=1
13
14 if !exists("*Flake8()")
15     function Flake8()
16         if exists("g:flake8_cmd")
17             let s:flake8_cmd=g:flake8_cmd
18         else
19             let s:flake8_cmd="flake8"
20         endif
21
22         if !executable(s:flake8_cmd)
23             echoerr "File " . s:flake8_cmd . " not found. Please install it first."
24             return
25         endif
26
27         set lazyredraw   " delay redrawing
28         cclose           " close any existing cwindows
29
30         " store old grep settings (to restore later)
31         let l:old_gfm=&grepformat
32         let l:old_gp=&grepprg
33
34         " write any changes before continuing
35         if &readonly == 0
36             update
37         endif
38
39         " read config
40         if exists("g:flake8_builtins")
41             let s:flake8_builtins_opt=" --builtins=".g:flake8_builtins
42         else
43             let s:flake8_builtins_opt=""
44         endif
45
46         if exists("g:flake8_ignore")
47             let s:flake8_ignores=" --ignore=".g:flake8_ignore
48         else
49             let s:flake8_ignores=""
50         endif
51
52         if exists("g:flake8_max_line_length")
53             let s:flake8_max_line_length=" --max-line-length=".g:flake8_max_line_length
54         else
55             let s:flake8_max_line_length=""
56         endif
57
58         if exists("g:flake8_max_complexity")
59             let s:flake8_max_complexity=" --max-complexity=".g:flake8_max_complexity
60         else
61             let s:flake8_max_complexity=""
62         endif
63
64         " perform the grep itself
65         let &grepformat="%f:%l:%c: %m\,%f:%l: %m"
66         let &grepprg=s:flake8_cmd.s:flake8_builtins_opt.s:flake8_ignores.s:flake8_max_line_length.s:flake8_max_complexity
67         silent! grep! %
68
69         " restore grep settings
70         let &grepformat=l:old_gfm
71         let &grepprg=l:old_gp
72
73         " open cwindow
74         let has_results=getqflist() != []
75         if has_results
76             execute 'belowright copen'
77             setlocal wrap
78             nnoremap <buffer> <silent> c :cclose<CR>
79             nnoremap <buffer> <silent> q :cclose<CR>
80         endif
81
82         set nolazyredraw
83         redraw!
84
85         if has_results == 0
86             " Show OK status
87             hi Green ctermfg=green
88             echohl Green
89             echon "Flake8 check OK"
90             echohl
91         endif
92     endfunction
93 endif
94
95 " Add mappings, unless the user didn't want this.
96 " The default mapping is registered under to <F7> by default, unless the user
97 " remapped it already (or a mapping exists already for <F7>)
98 if !exists("no_plugin_maps") && !exists("no_flake8_maps")
99     if !hasmapto('Flake8(')
100         noremap <buffer> <F7> :call Flake8()<CR>
101     endif
102 endif