fixed syntax checking

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-07-23 02:37:30 +00:00
parent eefc8c6086
commit 1d2f8db085
1 changed files with 11 additions and 16 deletions

View File

@ -1,4 +1,4 @@
import commands, os.path, sets, string
import commands, os.path, sets, string, sys, traceback
import color, completer, default, mode2, method, regex, tab2
from point2 import Point
from lex3 import Grammar, PatternRule, RegionRule, OverridePatternRule
@ -212,21 +212,16 @@ class PythonSetLib(method.Method):
class PythonCheckSyntax(method.Method):
'''Check the syntax of the current python file'''
def _execute(self, w, **vargs):
mod = os.path.splitext(w.buffer.path)[0]
cwd = os.getcwd() + '/'
if mod.startswith(cwd):
mod = mod.replace(cwd, '', 1)
else:
mod = os.path.basename(mod)
mod = mod.replace('/', '.')
cmd = "PYTHONPATH=%s python -c 'import %s'" % (w.mode.pythonlib, mod)
(status, output) = commands.getstatusoutput(cmd)
if status == 0:
w.application.set_error("Syntax OK")
w.application.data_buffer("python-syntax", output, switch_to=False)
else:
output = output + "\ncommand exit status: %d" % (status)
w.application.data_buffer("python-syntax", output, switch_to=True)
syspath = list(sys.path)
sys.path.insert(0, w.mode.pythonlib)
source = w.buffer.make_string()
try:
code = compile(source, w.buffer.path, 'exec')
w.set_error("Syntax OK")
except Exception, e:
output = traceback.format_exc()
w.application.data_buffer("*PythonSyntax*", output, switch_to=True)
sys.path = syspath
class PythonDictCleanup(method.Method):
'''Align assignment blocks and literal dictionaries'''