Skip to content

Commit e4b2a43

Browse files
2 parents b113c0a + 9aa34a0 commit e4b2a43

File tree

298 files changed

+31117
-2204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

298 files changed

+31117
-2204
lines changed

01_reload_submodules.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#
2+
# This module will reload any existing submodules, such as latextools_utils,
3+
# that may be cached in memory. Note that it must be run before any module
4+
# that uses any imports from any of those modules, hence the name.
5+
#
6+
7+
import sublime
8+
9+
import sys
10+
import traceback
11+
12+
if sys.version_info >= (3,):
13+
from imp import reload
14+
15+
_ST3 = sublime.version() >= '3000'
16+
17+
18+
def _load_module_exports(module):
19+
if 'exports' in module.__dict__:
20+
for name in module.exports:
21+
try:
22+
# lift the export to this modules top level
23+
globals()[name] = module.__dict__[name]
24+
except KeyError:
25+
print(
26+
"Error: {0} not defined in {1}."
27+
.format(name, module.__name__))
28+
29+
30+
MOD_PREFIX = ''
31+
32+
if _ST3:
33+
MOD_PREFIX = 'LaTeXTools.' + MOD_PREFIX
34+
35+
# these modules must be specified in the order they depend on one another
36+
LOAD_ORDER = [
37+
'external.latex_chars',
38+
39+
# reloaded here so that makePDF imports the current version
40+
'parseTeXlog',
41+
42+
'latextools_utils',
43+
44+
'latextools_utils.six',
45+
46+
# no internal dependencies
47+
'latextools_utils.bibformat',
48+
'latextools_utils.settings',
49+
'latextools_utils.utils',
50+
'latextools_utils.tex_directives',
51+
'latextools_utils.system',
52+
'latextools_utils.internal_types',
53+
54+
# depend on previous only
55+
'latextools_utils.distro_utils',
56+
'latextools_utils.is_tex_file',
57+
'latextools_utils.cache',
58+
'latextools_utils.quickpanel',
59+
'latextools_utils.external_command',
60+
61+
# depend on any previous
62+
'latextools_utils.sublime_utils',
63+
64+
# depend on any previous
65+
'latextools_utils.analysis',
66+
'latextools_utils.ana_utils',
67+
'latextools_utils.output_directory',
68+
'latextools_utils.bibcache',
69+
70+
'latextools_plugin',
71+
72+
# ensure latex_fill_all is loaded before the modules that depend on it
73+
'latex_fill_all'
74+
]
75+
76+
if _ST3:
77+
LOAD_ORDER.insert(1, 'latextools_plugin_internal')
78+
79+
# modules which should be scanned for any exports to be hoisted to this
80+
# module's context
81+
EXPORT_MODULES = []
82+
if sublime.version() > '3118':
83+
LOAD_ORDER += [
84+
'st_preview.preview_utils',
85+
'st_preview.preview_threading'
86+
]
87+
88+
EXPORT_MODULES += [
89+
'st_preview.preview_math',
90+
'st_preview.preview_image'
91+
]
92+
93+
LOAD_ORDER += EXPORT_MODULES
94+
95+
for suffix in LOAD_ORDER:
96+
mod = MOD_PREFIX + suffix
97+
try:
98+
if mod in sys.modules and sys.modules[mod] is not None:
99+
reload(sys.modules[mod])
100+
else:
101+
__import__(mod)
102+
except:
103+
traceback.print_exc()
104+
105+
if suffix in EXPORT_MODULES:
106+
_load_module_exports(sys.modules[mod])
107+
108+
109+
def plugin_loaded():
110+
# reload any plugins cached in memory
111+
mods = [m for m in sys.modules if m.startswith('_latextools_')]
112+
for mod in mods:
113+
try:
114+
del sys.modules[mod]
115+
except:
116+
traceback.print_exc()
117+
118+
for module in EXPORT_MODULES:
119+
mod = MOD_PREFIX + module
120+
try:
121+
sys.modules[mod].plugin_loaded()
122+
except AttributeError:
123+
pass
124+
125+
126+
def plugin_unloaded():
127+
for module in EXPORT_MODULES:
128+
mod = MOD_PREFIX + module
129+
try:
130+
sys.modules[mod].plugin_unloaded()
131+
except AttributeError:
132+
pass
133+
134+
135+
if not _ST3:
136+
plugin_loaded()

02_temp_file_cleanup.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import json
2+
import os
3+
import sublime
4+
import shutil
5+
import tempfile
6+
7+
if sublime.version() < '3000':
8+
def get_cache_directory():
9+
return os.path.join(
10+
sublime.packages_path(),
11+
'User',
12+
'.lt_cache'
13+
)
14+
15+
strbase = basestring
16+
else:
17+
def get_cache_directory():
18+
return os.path.join(
19+
sublime.cache_path(),
20+
'LaTeXTools'
21+
)
22+
23+
strbase = str
24+
25+
26+
# unfortunately, there is no reliable way to do clean-up on exit in ST
27+
# see https://github.com/SublimeTextIssues/Core/issues/10
28+
# here we cleanup any directories listed in the temporary_output_dirs
29+
# file as having been previously created by the plugin
30+
31+
def plugin_loaded():
32+
temporary_output_dirs = os.path.join(
33+
get_cache_directory(),
34+
'temporary_output_dirs'
35+
)
36+
37+
if os.path.exists(temporary_output_dirs):
38+
with open(temporary_output_dirs, 'r') as f:
39+
data = json.load(f)
40+
41+
tempdir = tempfile.gettempdir()
42+
43+
try:
44+
for directory in data['directories']:
45+
# shutil.rmtree is a rather blunt tool, so here we try to
46+
# ensure we are only deleting legitimate temporary files
47+
if (
48+
directory is None or
49+
not isinstance(directory, strbase) or
50+
not directory.startswith(tempdir)
51+
):
52+
continue
53+
54+
try:
55+
shutil.rmtree(directory)
56+
except OSError:
57+
pass
58+
else:
59+
print(u'Deleted old temp directory ' + directory)
60+
except KeyError:
61+
pass
62+
63+
try:
64+
os.remove(temporary_output_dirs)
65+
except OSError:
66+
pass
67+
68+
if sublime.version() < '3000':
69+
plugin_loaded()

03_reset_phantoms.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# On reload, this module will attempt to remove any phantoms associated
3+
# with ViewEventListeners from all active views.
4+
#
5+
import sublime
6+
import sublime_plugin
7+
8+
if sublime.version() > '3118' and sublime_plugin.api_ready:
9+
for w in sublime.windows():
10+
for v in w.views():
11+
if v.score_selector(0, 'text.tex.latex') == 0:
12+
continue
13+
v.erase_phantoms('preview_math')
14+
v.erase_phantoms('preview_image')
15+
v.settings().clear_on_change('preview_math')
16+
v.settings().clear_on_change('preview_image')
17+
s = sublime.load_settings('LaTeXTools.sublime-settings')
18+
s.clear_on_change('preview_math')
19+
s.clear_on_change('preview_image')

BibLaTeX.tmLanguage

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>BibLaTeX</string>
7+
<key>fileTypes</key>
8+
<array>
9+
<string>bib</string>
10+
</array>
11+
<key>patterns</key>
12+
<array>
13+
<dict>
14+
<key>include</key>
15+
<string>text.bibtex</string>
16+
</dict>
17+
</array>
18+
<key>scopeName</key>
19+
<string>text.biblatex</string>
20+
<key>uuid</key>
21+
<string>7920bb3c-1423-11e5-85a9-e16ceb8a2689</string>
22+
</dict>
23+
</plist>

0 commit comments

Comments
 (0)