Skip to content

Commit

Permalink
Initial ST3 fixup: everything now loads
Browse files Browse the repository at this point in the history
  • Loading branch information
msiniscalchi committed Jun 30, 2013
1 parent 21bdf91 commit 7f8b37a
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 82 deletions.
15 changes: 12 additions & 3 deletions DDEExecute.py
@@ -1,3 +1,12 @@
# ST2/ST3 compat
from __future__ import print_function
import sys
if sys.version_info[0] == 2:
# we are on ST2 and Python 2.X
pass
else:
pass

import sublime, sublime_plugin
from ctypes import *

Expand All @@ -6,7 +15,7 @@
class send_ddeCommand(sublime_plugin.TextCommand):
def run(self, edit, service = "", topic = "", command = ""):

print "Got request for DDE!"
print ("Got request for DDE!")

# define win32 api functions
DdeInitialize = windll.user32.DdeInitializeW
Expand Down Expand Up @@ -49,10 +58,10 @@ def py_mycallback(uType, uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2):
#print "start!"
XTYP_EXECUTE = int("4050",16) # transaction type; note -1 for timeout_async
hDdeData = DdeClientTransaction(pData, cbData, hConv, 0, 0, XTYP_EXECUTE, 10000, 0)
print "DDE Execute returned: ", hex(windll.user32.DdeGetLastError(idInst))
print ("DDE Execute returned: ", hex(windll.user32.DdeGetLastError(idInst)))
DdeFreeDataHandle(hDdeData)
else:
print "Could not connect!"
print ("Could not connect!")

#print ret, idInst, hszService, hszTopic, hConv

Expand Down
11 changes: 10 additions & 1 deletion delete_temp_files.py
@@ -1,6 +1,15 @@
# ST2/ST3 compat
from __future__ import print_function
import sys
if sys.version_info[0] == 2:
# we are on ST2 and Python 2.X
import getTeXRoot
else:
import LaTeXTools.getTeXRoot


import sublime, sublime_plugin
import os
import getTeXRoot

class Delete_temp_filesCommand(sublime_plugin.WindowCommand):
def run(self):
Expand Down
18 changes: 16 additions & 2 deletions getTeXRoot.py
@@ -1,5 +1,17 @@
# ST2/ST3 compat
from __future__ import print_function
import sys
if sys.version_info[0] == 2:
# we are on ST2 and Python 2.X
pass
else:
pass


import os.path, re



# Parse magic comments to retrieve TEX root
# Stops searching for magic comments at first non-comment line of file
# Returns root file or current file or None (if there is no root file,
Expand All @@ -11,7 +23,7 @@ def get_tex_root(view):
try:
root = os.path.abspath(view.settings().get('TEXroot'))
if os.path.isfile(root):
print "Main file defined in project settings : " + root
print("Main file defined in project settings : " + root)
return root
except:
pass
Expand All @@ -29,9 +41,11 @@ def get_tex_root(view):
return None
line_regs = view.lines(reg)
lines = map(view.substr, line_regs)
is_file = False

else:
lines = open(texFile, "rU")
is_file = True

for line in lines:
if not line.startswith('%'):
Expand All @@ -52,7 +66,7 @@ def get_tex_root(view):
root = os.path.normpath(root)
break

if isinstance(lines, file):
if is_file: # Not very Pythonic, but works...
lines.close()

return root
31 changes: 20 additions & 11 deletions jumpToPDF.py
@@ -1,5 +1,14 @@
# ST2/ST3 compat
from __future__ import print_function
import sys
if sys.version_info[0] == 2:
# we are on ST2 and Python 2.X
import getTeXRoot
else:
import LaTeXTools.getTeXRoot


import sublime, sublime_plugin, os.path, subprocess, time
import getTeXRoot

# Jump to current line in PDF file
# NOTE: must be called with {"from_keybinding": <boolean>} as arg
Expand All @@ -24,7 +33,7 @@ def run(self, edit, **args):
from_keybinding = args["from_keybinding"]
if from_keybinding:
forward_sync = True
print from_keybinding, keep_focus, forward_sync
print (from_keybinding, keep_focus, forward_sync)

texFile, texExt = os.path.splitext(self.view.file_name())
if texExt.upper() != ".TEX":
Expand All @@ -33,11 +42,11 @@ def run(self, edit, **args):
quotes = "\""
srcfile = texFile + u'.tex'
root = getTeXRoot.get_tex_root(self.view)
print "!TEX root = ", repr(root) # need something better here, but this works.
print ("!TEX root = ", repr(root) ) # need something better here, but this works.
rootName, rootExt = os.path.splitext(root)
pdffile = rootName + u'.pdf'
(line, col) = self.view.rowcol(self.view.sel()[0].end())
print "Jump to: ", line,col
print ("Jump to: ", line,col)
# column is actually ignored up to 0.94
# HACK? It seems we get better results incrementing line
line += 1
Expand All @@ -59,35 +68,35 @@ def run(self, edit, **args):
subprocess.Popen(['sh', skim] + options + [pdffile])
elif plat == 'win32':
# determine if Sumatra is running, launch it if not
print "Windows, Calling Sumatra"
print ("Windows, Calling Sumatra")
# hide console
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
tasks = subprocess.Popen(["tasklist"], stdout=subprocess.PIPE,
startupinfo=startupinfo).communicate()[0]
# Popen returns a byte stream, i.e. a single line. So test simply:
if "SumatraPDF.exe" not in tasks:
print "Sumatra not running, launch it"
print ("Sumatra not running, launch it")
self.view.window().run_command("view_pdf")
time.sleep(0.5) # wait 1/2 seconds so Sumatra comes up
setfocus = 0 if keep_focus else 1
# First send an open command forcing reload, or ForwardSearch won't
# reload if the file is on a network share
command = u'[Open(\"%s\",0,%d,1)]' % (pdffile,setfocus)
print repr(command)
print (repr(command))
self.view.run_command("send_dde",
{ "service": "SUMATRA", "topic": "control", "command": command})
# Now send ForwardSearch command if needed
if forward_sync:
command = "[ForwardSearch(\"%s\",\"%s\",%d,%d,0,%d)]" \
% (pdffile, srcfile, line, col, setfocus)
print command
print (command)
self.view.run_command("send_dde",
{ "service": "SUMATRA", "topic": "control", "command": command})


elif 'linux' in plat: # for some reason, I get 'linux2' from sys.platform
print "Linux!"
print ("Linux!")

# the required scripts are in the 'evince' subdir
ev_path = os.path.join(sublime.packages_path(), 'LaTeXTools', 'evince')
Expand All @@ -112,9 +121,9 @@ def run(self, edit, **args):

evince_running = ("evince " + pdffile in running_apps)
if (not keep_focus) or (not evince_running):
print "(Re)launching evince"
print ("(Re)launching evince")
subprocess.Popen(['sh', ev_sync_exec, py_binary, sb_binary, pdffile], cwd=ev_path)
print "launched evince_sync"
print ("launched evince_sync")
if not evince_running: # Don't wait if we have already shown the PDF
time.sleep(sync_wait)
if forward_sync:
Expand Down
10 changes: 10 additions & 0 deletions latexCommand.py
@@ -1,6 +1,16 @@
# ST2/ST3 compat
from __future__ import print_function
import sys
if sys.version_info[0] == 2:
# we are on ST2 and Python 2.X
pass
else:
pass

import sublime, sublime_plugin
import re


# Insert LaTeX command based on current word
# Position cursor inside braces

Expand Down
12 changes: 11 additions & 1 deletion latexEnvCloser.py
@@ -1,3 +1,13 @@
# ST2/ST3 compat
from __future__ import print_function
import sys
if sys.version_info[0] == 2:
# we are on ST2 and Python 2.X
pass
else:
pass


import sublime, sublime_plugin

# Insert environment closer
Expand Down Expand Up @@ -31,7 +41,7 @@ def run(self, edit, **args):
else:
# note the double escaping of \end
#view.run_command("insertCharacters \"\\\\end" + b[-1] + "\\n\"")
print "now we insert"
print ("now we insert")
# for some reason insert does not work
view.run_command("insert_snippet",
{'contents': "\\\\end" + b[-1] + "\n"})
39 changes: 24 additions & 15 deletions latex_cite_completions.py
@@ -1,7 +1,16 @@
# ST2/ST3 compat
from __future__ import print_function
import sys
if sys.version_info[0] == 2:
# we are on ST2 and Python 2.X
import getTeXRoot
else:
import LaTeXTools.getTeXRoot


import sublime, sublime_plugin
import os, os.path
import re
import getTeXRoot


class UnrecognizedCiteFormatError(Exception): pass
Expand Down Expand Up @@ -31,7 +40,7 @@ def find_bib_files(rootdir, src, bibfiles):
src = src + ".tex"

file_path = os.path.normpath(os.path.join(rootdir,src))
print "Searching file: " + repr(file_path)
print("Searching file: " + repr(file_path))
# See latex_ref_completion.py for why the following is wrong:
#dir_name = os.path.dirname(file_path)

Expand All @@ -40,7 +49,7 @@ def find_bib_files(rootdir, src, bibfiles):
src_file = open(file_path, "r")
except IOError:
sublime.status_message("LaTeXTools WARNING: cannot open included file " + file_path)
print "WARNING! I can't find it! Check your \\include's and \\input's."
print ("WARNING! I can't find it! Check your \\include's and \\input's.")
return

src_content = re.sub("%.*","",src_file.read())
Expand Down Expand Up @@ -172,22 +181,22 @@ def get_cite_completions(view, point, autocompleting=False):
# FIXME: should probably search the buffer instead of giving up
raise NoBibFilesError()

print "TEX root: " + repr(root)
print ("TEX root: " + repr(root))
bib_files = []
find_bib_files(os.path.dirname(root), root, bib_files)
# remove duplicate bib files
bib_files = list(set(bib_files))
print "Bib files found: ",
print repr(bib_files)
print ("Bib files found: ")
print (repr(bib_files))

if not bib_files:
# sublime.error_message("No bib files found!") # here we can!
raise NoBibFilesError()

bib_files = ([x.strip() for x in bib_files])

print "Files:"
print repr(bib_files)
print ("Files:")
print (repr(bib_files))

completions = []
kp = re.compile(r'@[^\{]+\{(.+),')
Expand Down Expand Up @@ -223,13 +232,13 @@ def get_cite_completions(view, point, autocompleting=False):
try:
bibf = open(bibfname)
except IOError:
print "Cannot open bibliography file %s !" % (bibfname,)
print ("Cannot open bibliography file %s !" % (bibfname,))
sublime.status_message("Cannot open bibliography file %s !" % (bibfname,))
continue
else:
bib = bibf.readlines()
bibf.close()
print "%s has %s lines" % (repr(bibfname), len(bib))
print ("%s has %s lines" % (repr(bibfname), len(bib)))

keywords = []
titles = []
Expand Down Expand Up @@ -275,8 +284,8 @@ def get_cite_completions(view, point, autocompleting=False):
if kp_match:
entry["keyword"] = kp_match.group(1).decode('ascii','ignore')
else:
print "Cannot process this @ line: " + line
print "Previous record " + entry
print ("Cannot process this @ line: " + line)
print ("Previous record " + entry)
continue
# Now test for title, author, etc.
# Note: we capture only the first line, but that's OK for our purposes
Expand All @@ -289,7 +298,7 @@ def get_cite_completions(view, point, autocompleting=False):
continue


print "Found %d total bib entries" % (len(keywords),)
print ( "Found %d total bib entries" % (len(keywords),) )

# # Filter out }'s at the end. There should be no commas left
titles = [t.replace('{\\textquoteright}', '').replace('{','').replace('}','') for t in titles]
Expand Down Expand Up @@ -393,7 +402,7 @@ def run(self, edit):
# get view and location of first selection, which we expect to be just the cursor position
view = self.view
point = view.sel()[0].b
print point
print (point)
# Only trigger within LaTeX
# Note using score_selector rather than match_selector
if not view.score_selector(point,
Expand All @@ -419,7 +428,7 @@ def run(self, edit):

# Note we now generate citation on the fly. Less copying of vectors! Win!
def on_done(i):
print "latex_cite_completion called with index %d" % (i,)
print ("latex_cite_completion called with index %d" % (i,) )

# Allow user to cancel
if i<0:
Expand Down

0 comments on commit 7f8b37a

Please sign in to comment.