Skip to content

Commit

Permalink
Add the plugin files.
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Feb 13, 2012
0 parents commit e338dad
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.mdown
@@ -0,0 +1,40 @@
vim-flake8 ![Project status](http://stillmaintained.com/nvie/vim-flake8.png)
==========

Installation
------------
Use [vim-pathogen](https://github.com/tpope/vim-pathogen) if you're not using
it already. Then, simply put the contents of this repository in your
`~/.vim/bundle` directory.

Usage
-----
1. Open a Python file
2. Press `<F7>` to run `flake8` on it

It shows the errors inside a quickfix window, which will allow your to quickly
jump to the error locations by simply pressing [Enter].


Customization
-------------
If you don't want to use the `<F7>` key for flake8-checking, simply remap it to
another key. It autodetects whether it has been remapped and won't register
the `<F7>` key if so. For example, to remap it to `<F3>` instead, use:

autocmd FileType python map <buffer> <F3> :call Flake8()<CR>


Tips
----
A tip might be to run the Flake8 check every time you write a Python file, to
enable this, add the following line to your `.vimrc` file (thanks
[Godefroid](http://github.com/gotcha)!):

autocmd BufWritePost *.py call Flake8()


This plugin goes well together with the following plugin:

- [PyUnit](http://github.com/nvie/vim-pyunit) (unit test helper under `<F8>`
and `<F9>`)
74 changes: 74 additions & 0 deletions ftplugin/python_flake8.vim
@@ -0,0 +1,74 @@
"
" Python filetype plugin for running flake8
" Language: Python (ft=python)
" Maintainer: Vincent Driessen <vincent@datafox.nl>
" Version: Vim 7 (may work with lower Vim versions, but not tested)
" URL: http://github.com/nvie/vim-flake8
"
" Only do this when not done yet for this buffer
if exists("b:loaded_flake8_ftplugin")
finish
endif
let b:loaded_flake8_ftplugin=1

let s:flake8_cmd="flake8"

if !exists("*Flake8()")
function Flake8()
if !executable(s:flake8_cmd)
echoerr "File " . s:flake8_cmd . " not found. Please install it first."
return
endif

set lazyredraw " delay redrawing
cclose " close any existing cwindows

" store old grep settings (to restore later)
let l:old_gfm=&grepformat
let l:old_gp=&grepprg

" write any changes before continuing
if &readonly == 0
update
endif

" perform the grep itself
let &grepformat="%f:%l:%c: %m\,%f:%l: %m"
let &grepprg=s:flake8_cmd
silent! grep! %

" restore grep settings
let &grepformat=l:old_gfm
let &grepprg=l:old_gp

" open cwindow
let has_results=getqflist() != []
if has_results
execute 'belowright copen'
setlocal wrap
nnoremap <buffer> <silent> c :cclose<CR>
nnoremap <buffer> <silent> q :cclose<CR>
endif

set nolazyredraw
redraw!

if has_results == 0
" Show OK status
hi Green ctermfg=green
echohl Green
echon "Flake8 check OK"
echohl
endif
endfunction
endif

" Add mappings, unless the user didn't want this.
" The default mapping is registered under to <F7> by default, unless the user
" remapped it already (or a mapping exists already for <F7>)
if !exists("no_plugin_maps") && !exists("no_flake8_maps")
if !hasmapto('Flake8(')
noremap <buffer> <F7> :call Flake8()<CR>
noremap! <buffer> <F7> :call Flake8()<CR>
endif
endif

0 comments on commit e338dad

Please sign in to comment.