]> git.madduck.net Git - etc/vim.git/commitdiff

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:

Add the plugin files.
authorVincent Driessen <vincent@3rdcloud.com>
Mon, 13 Feb 2012 09:16:06 +0000 (10:16 +0100)
committerVincent Driessen <vincent@3rdcloud.com>
Mon, 13 Feb 2012 09:16:06 +0000 (10:16 +0100)
README.mdown [new file with mode: 0644]
ftplugin/python_flake8.vim [new file with mode: 0644]

diff --git a/README.mdown b/README.mdown
new file mode 100644 (file)
index 0000000..fcfbab2
--- /dev/null
@@ -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>`)
diff --git a/ftplugin/python_flake8.vim b/ftplugin/python_flake8.vim
new file mode 100644 (file)
index 0000000..bd2c0b9
--- /dev/null
@@ -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