Skip to content

Instantly share code, notes, and snippets.

@bitexploder
Created April 17, 2012 17:30
Show Gist options
  • Save bitexploder/2407648 to your computer and use it in GitHub Desktop.
Save bitexploder/2407648 to your computer and use it in GitHub Desktop.
Sublime Text 2 Python Syntax Error Highlighter
import sublime, sublime_plugin, sublime
"""
A quick syntax error highlighter for python. Place in your sublime text
Packages/User directory
"""
class PyHelp(sublime_plugin.EventListener):
def on_modified(self, view):
view.erase_regions("pyhelp_highlight")
def on_post_save(self, view):
fname = view.file_name()
f = open(fname, "r")
code = f.read()
f.close()
try:
compiled = compile(code, '<string>', 'exec')
except SyntaxError as syntax:
print syntax
point = view.text_point(syntax.lineno-1, 0)
highlight_region = view.line(point)
view.add_regions("pyhelp_highlight", [highlight_region],
'keyword',
sublime.DRAW_OUTLINED|sublime.PERSISTENT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment