Skip to content

Instantly share code, notes, and snippets.

@cosimo
Created February 12, 2014 10:51
Show Gist options
  • Save cosimo/8953333 to your computer and use it in GitHub Desktop.
Save cosimo/8953333 to your computer and use it in GitHub Desktop.
Pylint Vim compiler plugin that works...
" Vim compiler file for Python
" Compiler: Style checking tool for Python
" Maintainer: Oleksandr Tymoshenko <gonzo@univ.kiev.ua>
" Last Change: 2014 Feb 12 (Cosimo)
" - Removed the pylint rate parsing and display
" - Fixed errorformat for current Pylint versions
" Version: 0.6-dev
" Contributors:
" Artur Wroblewski
" Menno
"
" Installation:
" Drop pylint.vim in ~/.vim/compiler directory. Ensure that your PATH
" environment variable includes the path to 'pylint' executable.
"
" Add the following line to the autocmd section of .vimrc
"
" autocmd FileType python compiler pylint
"
" Usage:
" Pylint is called after a buffer with Python code is saved. QuickFix
" window is opened to show errors, warnings and hints provided by Pylint.
" Code rate calculated by Pylint is displayed at the bottom of the
" window.
"
" Above is realized with :Pylint command. To disable calling Pylint every
" time a buffer is saved put into .vimrc file
"
" let g:pylint_onwrite = 0
"
" Opening of QuickFix window can be disabled with
"
" let g:pylint_cwindow = 0
"
" Of course, standard :make command can be used as in case of every
" other compiler.
"
if exists('current_compiler')
finish
endif
let current_compiler = 'pylint'
if !exists('g:pylint_onwrite')
let g:pylint_onwrite = 1
endif
if !exists('g:pylint_show_rate')
let g:pylint_show_rate = 1
endif
if !exists('g:pylint_cwindow')
let g:pylint_cwindow = 1
endif
if exists(':Pylint') != 2
command Pylint :call Pylint(0)
endif
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
command -nargs=* CompilerSet setlocal <args>
endif
" We should echo filename because pylint truncates .py
" If someone know better way - let me know :)
"
" Yes, there is the --output-format=parseable to have filename:line
" prefix for every line, but we lose the column number I think.
" Doesn't seem to be worth it.
"
CompilerSet makeprg=(echo\ '[%]'\ ;\ pylint\ -i\ y\ -r\ n\ %)
" We could omit end of file-entry, there is only one file
" %+I... - include code rating information
" %-G... - remove all remaining report lines from quickfix buffer
CompilerSet efm=%+P[%f],%t%n:%l\\,%c:%m
if g:pylint_onwrite
augroup python
au!
au BufWritePost * call Pylint(1)
augroup end
endif
function! Pylint(writing)
if !a:writing && &modified
" Save before running
write
endif
if has('win32') || has('win16') || has('win95') || has('win64')
setlocal sp=>%s
else
setlocal sp=>%s\ 2>&1
endif
" If check is executed by buffer write - do not jump to first error
if !a:writing
silent make
else
silent make!
endif
if g:pylint_cwindow
cwindow
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment