Created
April 17, 2012 17:30
-
-
Save bitexploder/2407648 to your computer and use it in GitHub Desktop.
Sublime Text 2 Python Syntax Error Highlighter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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