11" vim: ts = 4 shiftwidth = 4 expandtab fdm = marker
22" author: tocer tocer.deng@gmail.com
3- " version: 0.6
4- " lastchange: 2008-12-15
3+ " version: 0.6.2
4+ " lastchange: 2008-12-17
55
66
77if ! has (' python' )
2525cmd_check = ' noremap <buffer> %s :py pysyntaxchecker.check()<CR>' % key_check
2626vim .command (cmd_check)
2727if check_when_saving:
28- cmd = ' autocmd BufWritePost *.py py pysyntaxchecker.check()'
28+ filename = " " " vim.eval(" expand (' <afile>:p' )" )" " "
29+ cmd = ' autocmd BufWritePost *.py py pysyntaxchecker.check(%s)' % filename
30+ vim .command (cmd)
31+ cmd = ' autocmd BufLeave *.py py quickfix.close()'
2932 vim .command (cmd)
3033
3134eof
@@ -40,51 +43,12 @@ let g:loaded_pysyntaxchecker=1
4043python << end
4144
4245import vim
46+ import compiler
4347try :
4448 from pyflakes.checker import Checker
4549except: # pyflakes version <= 0.2 .1
4650 from pyflakes import Checker
4751
48- def vimeval (expr ):
49- vim .command (' let g:pcs_variant = eval("%s")' % expr )
50- isint = bool (int (vim .eval (' type(pcs_variant) == type(0)' )))
51- isfunc = bool (int (vim .eval (' type(pcs_variant) == type(function("tr"))' )))
52- isfloat = bool (int (vim .eval (' type(pcs_variant) == type(0.0)' )))
53- value = vim .eval (' pcs_variant' )
54- if isint:
55- value = int (value)
56- elif isfloat:
57- value = float (value)
58- elif isfunc:
59- raise VimError, ' Not supported date type'
60- else : # cound treat correctly
61- pass
62- return value
63-
64- class VimOption (object):
65- setcmd = ' set'
66-
67- def __getattr__ (self , name):
68- _value = vim .eval (' &%s' % name)
69- if isinstance (_value, int):
70- try :
71- vim .eval (' &no%s' % name)
72- value = bool (_value)
73- except VimError:
74- value = int (_value)
75- else :
76- value = str (_value)
77- return value
78-
79- def __setattr__ (self , name, value):
80- if isinstance (value, bool): # is boolean
81- opt = name if value else ' no%s' % name
82- else : # is number or string
83- opt = ' %s=%s' % (name, value)
84- return vim .command (' %s %s' % (self .setcmd, opt ))
85-
86- vimopt = VimOption ()
87-
8852class VimFunction (object):
8953 def __getattr__ (self , name):
9054 self .func_name = name
@@ -119,7 +83,7 @@ class VimQuickFix(object):
11983 if msgs:
12084 keys = [' filename' , ' lnum' , ' text' , ' type' ]
12185 # errors = [dict (zip (keys , msg)) for msg in msgs if None not in msg]
122- errors = [dict (zip (keys , msg)) for msg in msgs]
86+ errors = [dict (zip (keys , msg)) for msg in msgs]
12387 vimfunc.setqflist (errors, ' r' )
12488 self .open ()
12589 else :
@@ -128,12 +92,11 @@ class VimQuickFix(object):
12892quickfix = VimQuickFix ()
12993
13094class PySyntaxChecker (object):
131- def check (self ):
132- source = ' \n' .join (vim .current.buffer [:])
133- filename = vimfunc.expand (r " %:p" )
134- self ._check (source , filename)
135-
136- def _check (self , source , filename):
95+ def check (self , filename= None):
96+ if not filename:
97+ filename = vim .eval (" expand('%:p')" )
98+ source = open (filename, ' r' ).read ()
99+ print >> open (' /tmp/vim.log' , ' a' ), filename, source
137100 msgs = []
138101 try :
139102 tree = compiler .parse (source )
0 commit comments