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

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