forked from SublimeText/LaTeXTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
texSyntaxListener.py
38 lines (29 loc) · 1.07 KB
/
texSyntaxListener.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
import sublime
import sublime_plugin
try:
from latextools_utils import get_setting
from latextools_utils.is_tex_file import is_tex_file
except ImportError:
from .latextools_utils import get_setting
from .latextools_utils.is_tex_file import is_tex_file
# the new syntax format has been added in build 3084
_HAS_NEW_SYNTAX = sublime.version() >= "3084"
if _HAS_NEW_SYNTAX:
LATEX_SYNTAX = 'Packages/LaTeX/LaTeX.sublime-syntax'
else:
LATEX_SYNTAX = 'Packages/LaTeX/LaTeX.tmLanguage'
class TeXSyntaxListener(sublime_plugin.EventListener):
def on_load(self, view):
self.detect_and_apply_syntax(view)
def on_post_save(self, view):
self.detect_and_apply_syntax(view)
def detect_and_apply_syntax(self, view):
if view.is_scratch() or not view.file_name():
return
if view.score_selector(0, "text.tex"):
return
if not get_setting('latextools_set_syntax', True):
return
file_name = view.file_name()
if is_tex_file(file_name):
view.set_syntax_file(LATEX_SYNTAX)