From: Vincent Driessen Date: Mon, 13 Feb 2012 09:16:06 +0000 (+0100) Subject: Add the plugin files. X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/e338dadd0d83da0e77546451d71ad576aea7b187 Add the plugin files. --- e338dadd0d83da0e77546451d71ad576aea7b187 diff --git a/README.mdown b/README.mdown new file mode 100644 index 0000000..fcfbab2 --- /dev/null +++ b/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 `` 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 `` key for flake8-checking, simply remap it to +another key. It autodetects whether it has been remapped and won't register +the `` key if so. For example, to remap it to `` instead, use: + + autocmd FileType python map :call Flake8() + + +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 `` + and ``) diff --git a/ftplugin/python_flake8.vim b/ftplugin/python_flake8.vim new file mode 100644 index 0000000..bd2c0b9 --- /dev/null +++ b/ftplugin/python_flake8.vim @@ -0,0 +1,74 @@ +" +" Python filetype plugin for running flake8 +" Language: Python (ft=python) +" Maintainer: Vincent Driessen +" 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 c :cclose + nnoremap q :cclose + 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 by default, unless the user +" remapped it already (or a mapping exists already for ) +if !exists("no_plugin_maps") && !exists("no_flake8_maps") + if !hasmapto('Flake8(') + noremap :call Flake8() + noremap! :call Flake8() + endif +endif