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

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