-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
GoSublime.py
134 lines (115 loc) · 3.19 KB
/
GoSublime.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import os
import sublime
import sublime_plugin
import sys
import traceback
st2 = (sys.version_info[0] == 2)
dist_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, dist_dir)
ANN = ''
VERSION = ''
MARGO_EXE = ''
fn = os.path.join(dist_dir, 'gosubl', 'about.py')
execErr = ''
try:
with open(fn) as f:
code = compile(f.read(), fn, 'exec')
exec(code)
except Exception:
execErr = "Error: failed to exec about.py: Exception: %s" % traceback.format_exc()
print("GoSublime: %s" % execErr)
def loadable_mods():
from . import _before
from . import _after
from .gosubl import gs
from .gosubl import sh
from .gosubl import margo
from .gosubl import mg9
return [
('_before', _before),
('gs', gs),
('sh', sh),
('margo', margo),
('mg9', mg9),
('_after', _after),
]
def plugin_loaded():
from threading import Thread
Thread(target=_plugin_loaded_async).start()
def _plugin_loaded_async():
from .gosubl import about
from .gosubl import sh
from .gosubl import ev
from .gosubl import gs
if VERSION != about.VERSION:
gs.show_output('GoSublime-main', '\n'.join([
'GoSublime has been updated.',
'New version: `%s`, current version: `%s`' % (VERSION, about.VERSION),
'Please restart Sublime Text to complete the update.',
execErr,
]))
return
if gs.attr('about.version'):
gs.show_output('GoSublime-main', '\n'.join([
'GoSublime appears to have been updated.',
'New ANNOUNCE: `%s`, current ANNOUNCE: `%s`' % (ANN, about.ANN),
'You may need to restart Sublime Text.',
]))
return
gs.set_attr('about.version', VERSION)
gs.set_attr('about.ann', ANN)
for mod_name, mod in loadable_mods():
print('GoSublime %s: %s.init()' % (VERSION, mod_name))
try:
mod.gs_init({
'version': VERSION,
'ann': ANN,
'margo_exe': MARGO_EXE,
})
except AttributeError:
pass
except TypeError:
# old versions didn't take an arg
mod.gs_init()
ev.init.post_add = lambda e, f: f()
ev.init()
def cb():
aso = gs.aso()
old_version = aso.get('version', '')
old_ann = aso.get('ann', '')
if about.VERSION > old_version or about.ANN > old_ann:
aso.set('version', about.VERSION)
aso.set('ann', about.ANN)
gs.save_aso()
gs.focus(gs.dist_path('CHANGELOG.md'))
sublime.set_timeout(cb, 0)
def plugin_unloaded():
for mod_name, mod in loadable_mods():
try:
fini = mod.gs_fini
except AttributeError:
continue
print('GoSublime %s: %s.fini()' % (VERSION, mod_name))
fini({
})
class GosublimeDoesntSupportSublimeText2(sublime_plugin.TextCommand):
def run(self, edit):
msg = '\n'.join([
'Sublime Text 2 is no longer supported by GoSublime'+
'',
'See https://github.com/DisposaBoy/GoSublime/blob/master/SUPPORT.md#sublime-text',
'',
'If you have a *good* reason to not upgrade to Sublime Text 3,',
'discuss it here https://github.com/DisposaBoy/GoSublime/issues/689',
'',
])
self.view.set_scratch(True)
self.view.set_syntax_file(gs.tm_path('9o'))
self.view.set_name('GoSublime no longer supports Sublime Text 2')
self.view.insert(edit, 0, msg)
self.view.set_read_only(True)
if st2:
def cb():
view = sublime.active_window().new_file()
view.run_command('gosublime_doesnt_support_sublime_text2')
sublime.set_timeout(cb, 1000)