Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e338dad
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |