Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gallandarakhneorg committed Aug 16, 2018
2 parents b113c0a + 9aa34a0 commit dea9754
Show file tree
Hide file tree
Showing 297 changed files with 31,117 additions and 2,021 deletions.
136 changes: 136 additions & 0 deletions 01_reload_submodules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#
# This module will reload any existing submodules, such as latextools_utils,
# that may be cached in memory. Note that it must be run before any module
# that uses any imports from any of those modules, hence the name.
#

import sublime

import sys
import traceback

if sys.version_info >= (3,):
from imp import reload

_ST3 = sublime.version() >= '3000'


def _load_module_exports(module):
if 'exports' in module.__dict__:
for name in module.exports:
try:
# lift the export to this modules top level
globals()[name] = module.__dict__[name]
except KeyError:
print(
"Error: {0} not defined in {1}."
.format(name, module.__name__))


MOD_PREFIX = ''

if _ST3:
MOD_PREFIX = 'LaTeXTools.' + MOD_PREFIX

# these modules must be specified in the order they depend on one another
LOAD_ORDER = [
'external.latex_chars',

# reloaded here so that makePDF imports the current version
'parseTeXlog',

'latextools_utils',

'latextools_utils.six',

# no internal dependencies
'latextools_utils.bibformat',
'latextools_utils.settings',
'latextools_utils.utils',
'latextools_utils.tex_directives',
'latextools_utils.system',
'latextools_utils.internal_types',

# depend on previous only
'latextools_utils.distro_utils',
'latextools_utils.is_tex_file',
'latextools_utils.cache',
'latextools_utils.quickpanel',
'latextools_utils.external_command',

# depend on any previous
'latextools_utils.sublime_utils',

# depend on any previous
'latextools_utils.analysis',
'latextools_utils.ana_utils',
'latextools_utils.output_directory',
'latextools_utils.bibcache',

'latextools_plugin',

# ensure latex_fill_all is loaded before the modules that depend on it
'latex_fill_all'
]

if _ST3:
LOAD_ORDER.insert(1, 'latextools_plugin_internal')

# modules which should be scanned for any exports to be hoisted to this
# module's context
EXPORT_MODULES = []
if sublime.version() > '3118':
LOAD_ORDER += [
'st_preview.preview_utils',
'st_preview.preview_threading'
]

EXPORT_MODULES += [
'st_preview.preview_math',
'st_preview.preview_image'
]

LOAD_ORDER += EXPORT_MODULES

for suffix in LOAD_ORDER:
mod = MOD_PREFIX + suffix
try:
if mod in sys.modules and sys.modules[mod] is not None:
reload(sys.modules[mod])
else:
__import__(mod)
except:
traceback.print_exc()

if suffix in EXPORT_MODULES:
_load_module_exports(sys.modules[mod])


def plugin_loaded():
# reload any plugins cached in memory
mods = [m for m in sys.modules if m.startswith('_latextools_')]
for mod in mods:
try:
del sys.modules[mod]
except:
traceback.print_exc()

for module in EXPORT_MODULES:
mod = MOD_PREFIX + module
try:
sys.modules[mod].plugin_loaded()
except AttributeError:
pass


def plugin_unloaded():
for module in EXPORT_MODULES:
mod = MOD_PREFIX + module
try:
sys.modules[mod].plugin_unloaded()
except AttributeError:
pass


if not _ST3:
plugin_loaded()
69 changes: 69 additions & 0 deletions 02_temp_file_cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import json
import os
import sublime
import shutil
import tempfile

if sublime.version() < '3000':
def get_cache_directory():
return os.path.join(
sublime.packages_path(),
'User',
'.lt_cache'
)

strbase = basestring
else:
def get_cache_directory():
return os.path.join(
sublime.cache_path(),
'LaTeXTools'
)

strbase = str


# unfortunately, there is no reliable way to do clean-up on exit in ST
# see https://github.com/SublimeTextIssues/Core/issues/10
# here we cleanup any directories listed in the temporary_output_dirs
# file as having been previously created by the plugin

def plugin_loaded():
temporary_output_dirs = os.path.join(
get_cache_directory(),
'temporary_output_dirs'
)

if os.path.exists(temporary_output_dirs):
with open(temporary_output_dirs, 'r') as f:
data = json.load(f)

tempdir = tempfile.gettempdir()

try:
for directory in data['directories']:
# shutil.rmtree is a rather blunt tool, so here we try to
# ensure we are only deleting legitimate temporary files
if (
directory is None or
not isinstance(directory, strbase) or
not directory.startswith(tempdir)
):
continue

try:
shutil.rmtree(directory)
except OSError:
pass
else:
print(u'Deleted old temp directory ' + directory)
except KeyError:
pass

try:
os.remove(temporary_output_dirs)
except OSError:
pass

if sublime.version() < '3000':
plugin_loaded()
19 changes: 19 additions & 0 deletions 03_reset_phantoms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# On reload, this module will attempt to remove any phantoms associated
# with ViewEventListeners from all active views.
#
import sublime
import sublime_plugin

if sublime.version() > '3118' and sublime_plugin.api_ready:
for w in sublime.windows():
for v in w.views():
if v.score_selector(0, 'text.tex.latex') == 0:
continue
v.erase_phantoms('preview_math')
v.erase_phantoms('preview_image')
v.settings().clear_on_change('preview_math')
v.settings().clear_on_change('preview_image')
s = sublime.load_settings('LaTeXTools.sublime-settings')
s.clear_on_change('preview_math')
s.clear_on_change('preview_image')
23 changes: 23 additions & 0 deletions BibLaTeX.tmLanguage
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>BibLaTeX</string>
<key>fileTypes</key>
<array>
<string>bib</string>
</array>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>text.bibtex</string>
</dict>
</array>
<key>scopeName</key>
<string>text.biblatex</string>
<key>uuid</key>
<string>7920bb3c-1423-11e5-85a9-e16ceb8a2689</string>
</dict>
</plist>
Loading

0 comments on commit dea9754

Please sign in to comment.