-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplier
More file actions
127 lines (110 loc) · 3.38 KB
/
complier
File metadata and controls
127 lines (110 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
" Vim compiler file for Python
" Compiler: Style checking tool for Python
" Maintainer: Oleksandr Tymoshenko <gonzo@univ.kiev.ua>
" Last Change: 2009 Apr 19
" Version: 0.5
" 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
"
" Displaying code rate calculated by Pylint can be avoided by setting
"
" let g:pylint_show_rate = 0
"
" Openning 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 :)
CompilerSet makeprg=(echo\ '[%]';\ pylint\ -r\ y\ %)
" 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:\ %#%l:%m,%Z,%+IYour\ code%m,%Z,%-G%.%#
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
call PylintEvaluation()
if g:pylint_show_rate
echon 'code rate: ' b:pylint_rate ', prev: ' b:pylint_prev_rate
endif
endfunction
function! PylintEvaluation()
let l:list = getqflist()
let b:pylint_rate = '0.00'
let b:pylint_prev_rate = '0.00'
for l:item in l:list
if l:item.type == 'I' && l:item.text =~ 'Your code has been rated'
let l:re_rate = '\(-\?[0-9]\{1,2\}\.[0-9]\{2\}\)/'
let b:pylint_rate = substitute(l:item.text, '.*rated at '.l:re_rate.'.*', '\1', 'g')
" Only if there is information about previous run
if l:item.text =~ 'previous run: '
let b:pylint_prev_rate = substitute(l:item.text, '.*previous run: '.l:re_rate.'.*', '\1', 'g')
endif
endif
endfor
endfunction