/
cross.py
71 lines (65 loc) · 1.8 KB
/
cross.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
OPTIONS
"show_cross": true
show cross.
"show_multiple_cross":true
show multiple cross
"""
import math
import sublime
import sublime_plugin
settings_cross = sublime.load_settings('Cross.sublime-settings')
class CrossCommand(sublime_plugin.TextCommand):
def run(self, edit):
show_cross = int(bool(settings_cross.get('show_cross')))
settings_cross.set('show_cross',not show_cross)
def unload_handler():
for window in sublime.windows():
for view in window.views():
view.erase_regions('CrossListener')
class CrossListener(sublime_plugin.EventListener):
def __init__(self):
print ('sublime-cross init')
def update_cross(self, view):
settings_index = view.settings()
viewport = view.viewport_extent()
if viewport[1]<30:
settings_index.set('rulers','')
return
show_multiple_cross = int(bool(settings_cross.get('show_multiple_cross')))
cross_width = settings_cross.get('cross_width')
show_cross = settings_cross.get('show_cross')
if cross_width:
cross_width = int(cross_width)
else:
cross_width = 1
if show_cross:
show_cross = int(bool(show_cross))
else:
show_cross = True
if not show_cross:
settings_index.set('rulers',[])
return
rulers = []
gap = 0.5/view.em_width()
start = -math.ceil(cross_width)*gap
for sel in reversed(view.sel()):
end_sel = sel.end()
pos_xy = view.text_to_layout(end_sel)
pos_x = pos_xy[0]
pos = int(pos_x/view.em_width())
rulers.append(pos)
for i in range(0,cross_width*2):
rulers.append(pos+start)
start+=gap
if not show_multiple_cross:
break
settings_index.set('rulers',rulers)
def on_load(self, view):
self.update_cross(view)
def on_activated(self, view):
self.update_cross(view)
def on_modified(self, view):
self.update_cross(view)
def on_selection_modified(self, view):
self.update_cross(view)