the code:
Code: Select all
# Import packages
import sublime, sublimeplugin, os, os.path, re
# Import namespaces
from os.path import exists
# Code for inserting references
class TexCiteCommand(sublimeplugin.TextCommand):
def run(self, view, args):
print "Starter reference modul"
currentDir=os.getcwd()
dirFiles=os.listdir(currentDir)
bibTex=[] # List of bibTex files
for i in range(len(dirFiles)): # Looping all file entries trough
if dirFiles[i].endswith(".bib"):
bibTex.append(dirFiles[i])
if len(bibTex)>1: # Tjeck if there is more than one bibtex file. This will not matter anything for this function
print "Notice that there exist several .bib tex files. We use them all"
# Reading the bibtext files
for i in range(len(bibTex)):
try:
bibFile=open(bibTex[0])
except IOError:
print "Unable to open the bibtex file.: ", bibTex[0], " The code stops"
return
else:
textBibFil=bibFile.readlines()
bibFile.close()
# Looping all the lines trough.
referencer=[] # Empty list with references
for i in range(len(textBibFil)):
if textBibFil[i][0]=="@": # Here we have a reference
stringStart=textBibFil[i].find("{") # Start char
stringEnd=textBibFil[i].find(",") # End char
referencer.append(textBibFil[i][stringStart+1:stringEnd]) # Appending the pure reference
# Prints the entry
def insertReference(i):
view.runCommand("insertCharacters", [referencer[i]])
# Show select panel
view.window().showSelectPanel(referencer, insertReference, None, 0)