]> 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:

18d0bf3fecdd9bcd114c979b123556030a819a35
[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         let l:old_shellpipe=&shellpipe
34
35         " write any changes before continuing
36         if &readonly == 0
37             update
38         endif
39
40         " read config
41         if exists("g:flake8_builtins")
42             let s:flake8_builtins_opt=" --builtins=".g:flake8_builtins
43         else
44             let s:flake8_builtins_opt=""
45         endif
46
47         if exists("g:flake8_ignore")
48             let s:flake8_ignores=" --ignore=".g:flake8_ignore
49         else
50             let s:flake8_ignores=""
51         endif
52
53         if exists("g:flake8_max_line_length")
54             let s:flake8_max_line_length=" --max-line-length=".g:flake8_max_line_length
55         else
56             let s:flake8_max_line_length=""
57         endif
58
59         if exists("g:flake8_max_complexity")
60             let s:flake8_max_complexity=" --max-complexity=".g:flake8_max_complexity
61         else
62             let s:flake8_max_complexity=""
63         endif
64
65         if exists("g:flake8_quickfix_location")
66             let s:flake8_quickfix_location=g:flake8_quickfix_location
67         else
68             let s:flake8_quickfix_location="belowright"
69         endif
70
71         if exists("g:flake8_hide_quickfix")
72             let s:flake8_hide_quickfix=g:flake8_hide_quickfix
73         else
74             let s:flake8_hide_quickfix=0
75         endif
76
77         " set shellpipe to > instead of tee (suppressing output)
78         set shellpipe=>
79
80         " perform the grep itself
81         let &grepformat="%f:%l:%c: %m\,%f:%l: %m"
82         let &grepprg=s:flake8_cmd.s:flake8_builtins_opt.s:flake8_ignores.s:flake8_max_line_length.s:flake8_max_complexity
83         silent! grep! "%"
84
85         " restore grep settings
86         let &grepformat=l:old_gfm
87         let &grepprg=l:old_gp
88         let &shellpipe=l:old_shellpipe
89
90         " open cwindow
91         let has_results=getqflist() != []
92         if has_results
93             if s:flake8_hide_quickfix == 0
94                 execute s:flake8_quickfix_location." copen"
95                 setlocal wrap
96                 nnoremap <buffer> <silent> c :cclose<CR>
97                 nnoremap <buffer> <silent> q :cclose<CR>
98             endif
99         endif
100
101         set nolazyredraw
102         redraw!
103
104         if has_results == 0
105             " Show OK status
106             hi Green ctermfg=green
107             echohl Green
108             echon "Flake8 check OK"
109             echohl
110         endif
111     endfunction
112 endif
113
114 " Add mappings, unless the user didn't want this.
115 " The default mapping is registered under to <F7> by default, unless the user
116 " remapped it already (or a mapping exists already for <F7>)
117 if !exists("no_plugin_maps") && !exists("no_flake8_maps")
118     if !hasmapto('Flake8(')
119         noremap <buffer> <F7> :call Flake8()<CR>
120     endif
121 endif