Skip to content

Commit

Permalink
Better way to find the main file if there is a project file
Browse files Browse the repository at this point in the history
  • Loading branch information
jrast committed Sep 7, 2012
1 parent 123dc08 commit 5c5a6cb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
12 changes: 11 additions & 1 deletion getTeXRoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@

# Contributed by Sam Finn

def get_tex_root(texFile):
def get_tex_root(view):
root = os.path.abspath(view.settings().get('TEXroot'))
try:
if os.path.isfile(root):
print "Main file defined in project settings : " + root
return root
except:
pass


texFile = view.file_name()
for line in open(texFile, "rU").readlines():
if not line.startswith('%'):
root = texFile
Expand Down
4 changes: 1 addition & 3 deletions jumpToPDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def run(self, edit, **args):
return
quotes = "\""
srcfile = texFile + u'.tex'
root = self.view.settings().get('TEXroot')
if not root:
root = getTeXRoot.get_tex_root(self.view.file_name())
root = getTeXRoot.get_tex_root(self.view)
print "!TEX root = ", root
rootName, rootExt = os.path.splitext(root)
pdffile = rootName + u'.pdf'
Expand Down
8 changes: 1 addition & 7 deletions latex_cite_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,7 @@ def on_query_completions(self, view, prefix, locations):
completions = ["TEST"]

#### GET COMPLETIONS HERE #####
# first search sublime-project file settings for TEXroot
root = view.settings().get('TEXroot')

if not root:
# Find tex root and search all tex source referenced
# TEX root is the current file itself if no TEX root is specified
root = getTeXRoot.get_tex_root(view.file_name())
root = getTeXRoot(view)

print "TEX root: " + root
bib_files = []
Expand Down
8 changes: 1 addition & 7 deletions latex_ref_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,7 @@ def on_query_completions(self, view, prefix, locations):
# stop matching at FIRST } after \label{
view.find_all(r'\\label\{([^\{\}]+)\}', 0, '\\1', completions)

# first search sublime-project file settings for TEXroot
root = view.settings().get('TEXroot')

if not root:
# Find tex root and search all tex source referenced
# TEX root is the current file itself if no TEX root is specified
root = getTeXRoot.get_tex_root(view.file_name())
root = getTeXRoot(view)

print "TEX root: " + root
find_labels_in_files(os.path.dirname(root), root, completions)
Expand Down
6 changes: 3 additions & 3 deletions makePDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ def run(self, cmd="", file_regex="", path=""):
self.proc = None

view = self.window.active_view()
self.file_name = view.settings().get('TEXroot')
if not self.file_name:
self.file_name = getTeXRoot.get_tex_root(view.file_name())

self.file_name = getTeXRoot.get_tex_root(view)

# self.file_name = view.file_name()
self.tex_base, self.tex_ext = os.path.splitext(self.file_name)
# On OSX, change to file directory, or latexmk will spew stuff into root!
Expand Down
5 changes: 2 additions & 3 deletions viewPDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ def run(self):
sublime.error_message("%s is not a TeX source file: cannot view." % (os.path.basename(view.fileName()),))
return
quotes = ""# \"" MUST CHECK WHETHER WE NEED QUOTES ON WINDOWS!!!
root = view.settings().get('TEXroot')
if not root:
root = getTeXRoot.get_tex_root(view.file_name())
root = getTeXRoot.get_tex_root(view)

rootFile, rootExt = os.path.splitext(root)
pdfFile = quotes + rootFile + '.pdf' + quotes
s = platform.system()
Expand Down

0 comments on commit 5c5a6cb

Please sign in to comment.