Skip to content

Commit

Permalink
Merge branch 'tex_directive_overwrites_settings' of https://github.co…
Browse files Browse the repository at this point in the history
  • Loading branch information
ig0774 committed Mar 13, 2017
2 parents 40218b1 + d59a43c commit 3ffc933
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions latextools_utils/tex_directives.py
Expand Up @@ -25,7 +25,7 @@
re.UNICODE
)

# this is obviously imperfect, but is intended as a heuristic. we
# this is obviously imperfect, but is intended as a heuristic. we
# can tolerate false negatives, but not false positives that match, e.g.,
# Windows paths or parts of Windows paths.
LATEX_COMMAND = re.compile(r'\\[a-zA-Z]+\*?(?:\[[^\]]+\])*\{[^\}]+\}')
Expand Down Expand Up @@ -54,6 +54,7 @@ def parse_tex_directives(view_or_path, multi_values=[], key_maps={},
'''
result = {}

# used to indicate if we opened a file so it can be closed
is_file = False
if isinstance(view_or_path, sublime.View):
lines = view_or_path.substr(
Expand Down Expand Up @@ -123,35 +124,29 @@ def parse_tex_directives(view_or_path, multi_values=[], key_maps={},
lines.close()


# Parse magic comments to retrieve TEX root
# Stops searching for magic comments at first latex command in file
# Returns root file or current file or None (if there is no root file,
# and the current buffer is an unnamed unsaved file)

# Contributed by Sam Finn
def get_tex_root(view):
view_file = view.file_name()
root = view_file

root = None
directives = parse_tex_directives(view, only_for=['root'])
try:
root = directives['root']
except KeyError:
pass
else:
if not is_tex_file(root):
root = view_file

if not os.path.isabs(root) and view_file is not None:
root = None
elif not os.path.isabs(root) and view_file is not None:
file_path, _ = os.path.split(view_file)
root = os.path.normpath(os.path.join(file_path, root))

if root == view_file:
if root is None:
root = get_tex_root_from_settings(view)
if root is not None:
return root
return view_file

return root
if root is not None:
return root
return view_file


def get_tex_root_from_settings(view):
Expand Down

0 comments on commit 3ffc933

Please sign in to comment.