-
Notifications
You must be signed in to change notification settings - Fork 12
/
Install.py
58 lines (45 loc) · 1.85 KB
/
Install.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
#!/usr/bin/env python
# from __future__ import print_function
import os.path as path
import sublime
userSettings = None
packageName = "Better JavaScript"
def getPackageName():
global packageName
packageDir = path.dirname(path.abspath( __file__ ))
if packageDir[0] != "/":
return
packageName = path.split(packageDir)[1]
# This needs to be run as soon as possible, because if the cwd changes after loading, the results
# may be wrong
getPackageName()
def disable_js_package():
disabled = userSettings.get("ignored_packages", [])
if not "JavaScript" in disabled:
# Find any views currently using the built-in JS syntaxes and set them to use ours
for window in sublime.windows():
for view in window.views():
syntax = path.basename(view.settings().get('syntax'))
if syntax == "JSON.tmLanguage":
view.set_syntax_file(path.join("Packages", packageName, "JSON.tmLanguage"))
if syntax == "JavaScript.tmLanguage":
view.set_syntax_file(path.join("Packages", packageName, "JavaScript.tmLanguage"))
disabled.append("JavaScript")
userSettings.set("ignored_packages", disabled)
sublime.save_settings("Preferences.sublime-settings")
def plugin_loaded():
global userSettings
userSettings = sublime.load_settings("Preferences.sublime-settings")
disable_js_package()
# Since ST < 3 does not provide the plugin_loaded() hook, we need to run manually. However, if we
# run too soon, then the settings loaded will be empty, which can cause problems like all the user
# settings getting erased. This will wait until we believe the user settings have loaded before
# execitomg the disable_js_package method.
def ensureLoaded():
if userSettings.has('ignored_packages'):
disable_js_package()
else:
sublime.set_timeout(ensureLoaded, 1000)
if int(sublime.version()) < 3000:
userSettings = sublime.load_settings("Preferences.sublime-settings")
ensureLoaded()