forked from DisposaBoy/GoSublime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsev.py
59 lines (50 loc) · 1.61 KB
/
gsev.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
from gosubl import gs
import gstest
import sublime
import sublime_plugin
DOMAIN = 'GsEV'
class EV(sublime_plugin.EventListener):
def on_post_save(self, view):
sublime.set_timeout(lambda: do_post_save(view), 0)
def on_activated(self, view):
sublime.set_timeout(lambda: do_sync_active_view(view), 0)
class GsOnLeftClick(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
if gs.is_go_source_view(view):
if not gstest.handle_action(view, 'left-click'):
view.run_command('gs_doc', {"mode": "goto"})
elif view.score_selector(gs.sel(view).begin(), "text.9o") > 0:
view.window().run_command("gs9o_open_selection")
class GsOnRightClick(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
if gs.is_go_source_view(view):
if not gstest.handle_action(view, 'right-click'):
view.run_command('gs_doc', {"mode": "hint"})
def do_post_save(view):
if not gs.is_pkg_view(view):
return
for c in gs.setting('on_save', []):
cmd = c.get('cmd', '')
args = c.get('args', {})
msg = 'running on_save command %s' % cmd
tid = gs.begin(DOMAIN, msg, set_status=False)
try:
view.run_command(cmd, args)
except Exception as ex:
gs.notice(DOMAIN, 'Error %s' % ex)
finally:
gs.end(tid)
def do_sync_active_view(view):
fn = view.file_name()
if fn:
gs.set_attr('last_active_fn', fn)
if fn.lower().endswith('.go'):
gs.set_attr('last_active_go_fn', fn)
if gs.is_pkg_view(view):
m = {}
psettings = view.settings().get('GoSublime')
if psettings and gs.is_a(psettings, {}):
m = gs.mirror_settings(psettings)
gs.set_attr('last_active_project_settings', gs.dval(m, {}))