-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfoldpythonexception.py
More file actions
executable file
·46 lines (33 loc) · 1.36 KB
/
foldpythonexception.py
File metadata and controls
executable file
·46 lines (33 loc) · 1.36 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
import sublime, sublime_plugin
class FoldPythonExceptCommand(sublime_plugin.TextCommand):
def get_text(self, region):
lines = self.view.lines(region)
start = lines[0].begin()
end = lines[-1].end()
return start, end
def run(self, edit):
try:
for i, region in enumerate( self.view.find_all('except Exception as e',0) ):
start, end = self.get_text(region)
sub_region = self.view.find_all('raise e', end)[i]
sub_start, sub_end = self.get_text(sub_region)
# print (start, sub_end)
fold_region = sublime.Region( end , sub_end)
self.view.fold(fold_region)
except Exception as e: #2
print("hihi")
raise e #2
# '''
class BackgroundFoldPythonExcept(sublime_plugin.EventListener):
def __init__(self):
sublime_plugin.EventListener.__init__(self)
self.last_selected_line = -1
self.status_active = False
def _last_selected_lineno(self, view):
return view.rowcol(view.sel()[0].end())[0]
def on_post_save(self, view):
view.run_command('fold_python_except')
def plugin_loaded():
global pylint_settings
pylint_settings = sublime.load_settings('FoldPythonExcept.sublime-settings')
# '''