1 " Vim compiler file for Python
2 " Compiler: Style checking tool for Python
3 " Maintainer: Oleksandr Tymoshenko <gonzo@univ.kiev.ua>
4 " Last Change: 2009 Apr 19
11 " Drop pylint.vim in ~/.vim/compiler directory. Ensure that your PATH
12 " environment variable includes the path to 'pylint' executable.
14 " Add the following line to the autocmd section of .vimrc
16 " autocmd FileType python compiler pylint
19 " Pylint is called after a buffer with Python code is saved. QuickFix
20 " window is opened to show errors, warnings and hints provided by Pylint.
21 " Code rate calculated by Pylint is displayed at the bottom of the
24 " Above is realized with :Pylint command. To disable calling Pylint every
25 " time a buffer is saved put into .vimrc file
27 " let g:pylint_onwrite = 0
29 " Displaying code rate calculated by Pylint can be avoided by setting
31 " let g:pylint_show_rate = 0
33 " Openning of QuickFix window can be disabled with
35 " let g:pylint_cwindow = 0
37 " Of course, standard :make command can be used as in case of every
42 if exists('current_compiler')
45 let current_compiler = 'pylint'
47 if !exists('g:pylint_onwrite')
48 let g:pylint_onwrite = 1
51 if !exists('g:pylint_show_rate')
52 let g:pylint_show_rate = 1
55 if !exists('g:pylint_cwindow')
56 let g:pylint_cwindow = 1
59 if exists(':Pylint') != 2
60 command Pylint :call Pylint(0)
63 if exists(":CompilerSet") != 2 " older Vim always used :setlocal
64 command -nargs=* CompilerSet setlocal <args>
67 " We should echo filename because pylint truncates .py
68 " If someone know better way - let me know :)
69 CompilerSet makeprg=(echo\ '[%]';\ pylint\ -r\ y\ %)
71 " We could omit end of file-entry, there is only one file
72 " %+I... - include code rating information
73 " %-G... - remove all remaining report lines from quickfix buffer
74 CompilerSet efm=%+P[%f],%t:\ %#%l:%m,%Z,%+IYour\ code%m,%Z,%-G%.%#
79 au BufWritePost * call Pylint(1)
83 function! Pylint(writing)
84 if !a:writing && &modified
89 if has('win32') || has('win16') || has('win95') || has('win64')
95 " If check is executed by buffer write - do not jump to first error
106 call PylintEvaluation()
108 if g:pylint_show_rate
109 echon 'code rate: ' b:pylint_rate ', prev: ' b:pylint_prev_rate
113 function! PylintEvaluation()
114 let l:list = getqflist()
115 let b:pylint_rate = '0.00'
116 let b:pylint_prev_rate = '0.00'
118 if l:item.type == 'I' && l:item.text =~ 'Your code has been rated'
119 let l:re_rate = '\(-\?[0-9]\{1,2\}\.[0-9]\{2\}\)/'
120 let b:pylint_rate = substitute(l:item.text, '.*rated at '.l:re_rate.'.*', '\1', 'g')
121 " Only if there is information about previous run
122 if l:item.text =~ 'previous run: '
123 let b:pylint_prev_rate = substitute(l:item.text, '.*previous run: '.l:re_rate.'.*', '\1', 'g')