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

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