PK V4=&|m m Hyperlinking.package-menu
PK V4=Q) Hypergrammar.pyimport os
class GrammarGenerator:
"""generates a grammar for a view"""
def __init__(self, folderPath):
self.folderPath = os.path.abspath(folderPath)
self.head = """
uuid
F15EC19A-970E-4a82-B3AD-C6F8B6DF9F09
patterns
"""
self.foot = """
name
Custom grammar for ${wikiname}
scopeName
string
fileTypes
.wiki
"""
self.template = """
match\\b${name}\\b
namemarkup.italic
"""
def syntaxFile(self):
return os.path.join(self.folderPath, "syntax-highlighting.tmLanguage")
def run(self):
if os.path.exists(self.folderPath) == False:
print "Folder '%s' does not exist" % self.folderPath
return None
wikiName = os.path.split(self.folderPath)[1]
content = self.head
files = [f for f in os.listdir(self.folderPath) if f.endswith(".wiki")]
names = [os.path.splitext(n)[0] for n in files]
for name in names:
content = content + self.template.replace("${name}", name)
content = content + self.foot.replace("${wikiname}", wikiName)
syntaxFile = self.syntaxFile()
f = open(syntaxFile, 'w')
f.write(content)
f.close()
return syntaxFile
if __name__ == "__main__":
gen = GrammarGenerator("C:\\usr\\projects\\fiction-modus-operandi")
syntaxFile = gen.run()
print syntaxFilePK V4=\ Default.sublime-keymap
PK V4=;i Hyperlinking.py#HYPERLINKING
#
# A Plugin for Sublime Text, By Steve Cooper
#
# see README.txt for usage instructions.
import sublime, sublimeplugin, re, os, Hypergrammar
class NavigateBase(sublimeplugin.TextCommand):
def ensureFile(self, fileName):
if os.path.exists(fileName) == False:
print "creating %s" % fileName
f = open(fileName, 'w')
f.write("")
f.close()
def run(self, view, args):
print "base class!"
class NavigateToWikiIndexPageCommand(NavigateBase):
"""This command creates a new view containing all the files
which can be visited from the currently-visible wiki file
"""
def run(self, view, args):
dirName = os.path.dirname(view.fileName())
indexFileName = os.path.join(dirName, "IndexPage.wiki")
self.ensureFile(indexFileName)
allFiles = os.listdir(dirName)
wikiFiles = [ "[%s]" % f[:-5] for f in allFiles if os.path.isfile(f) and f.lower().endswith(".wiki")]
wikiFiles.sort()
bufferContent = "FILES IN " + dirName + "\r\n\r\n" + "\r\n".join( wikiFiles )
newView = view.window().openFile(indexFileName)
# openFile() is asynchronous, so it returns None. Therefore we can't insertfil
#newView.insert(0, bufferContent)
def isEnabled(self, view, args):
return view.fileName()
class NavigateToWikiPageCommand(NavigateBase):
"""This command takes the user to a wiki page under the cursor.
Eg, if the cursor is in NewPa|geToNavigateTo, and the user executes
the command, NewPageToNavigateTo.wiki in the same folder will be opened
"""
# OLD FORM
# matches, eg, ExampleWikiFile, MissingFile
#wikiWordPattern = r"^([A-Z][a-z0-9]+){2,}"
# NEW FORM
# matches any word
wikiWordPattern = r"^\w+\b"
# what extension do wiki pages have?
wikiFileExtension = "wiki"
def run(self, view, args):
# get the wikiname under the cursor.
for s in view.sel():
# try to find a phrase in square brackets
name = self.phraseInSquareBrackets(view, s)
if name == None:
# nothing in square brackets -- try a word
name = self.wordUnderCursor(view, s)
if name == None:
# total failure!
sublime.statusMessage("No suitable hyperlink found. Try square brackets around the text.")
return
candidateFileName = os.path.split(view.fileName())[0] + "\\" + name + "." + self.wikiFileExtension
print candidateFileName
if (os.access(candidateFileName, os.R_OK)):
sublime.statusMessage("Opening page: %s" % candidateFileName)
view.window().openFile(candidateFileName)
else:
if sublime.questionBox("Do you want to create %s" % candidateFileName):
self.ensureFile(candidateFileName)
sublime.statusMessage("No page at %s: starting new file" % candidateFileName)
view.window().openFile(candidateFileName)
def phraseInSquareBrackets(self, view, s):
start = self.findStartSquareBracket(view, s)
end = self.findEndSquareBracket(view, s)
if end > 0:
return view.substr(sublime.Region(start, end))
def wordUnderCursor(self, view, s):
wb = self.findWordBoundary(view, s)
# see if what follows the word boundary is a wikiword
word = self.getWordAtPoint(view, wb)
return word
def findEndSquareBracket(self, view, s):
pos = s.begin()
while True:
if (pos == view.size()): return 0 # no end sq
charAfterPoint = view.substr(sublime.Region(pos, pos+1))
if charAfterPoint == "]":
return pos
if charAfterPoint == "[":
return 0
pos = pos + 1
def findStartSquareBracket(self, view, s):
pos = s.begin()
while True:
if (pos == 0): return 0
#search for open square bracket before cursor
charBeforePoint = view.substr(sublime.Region(pos-1, pos))
if charBeforePoint == "[":
return pos
if charBeforePoint == "]":
return 0
pos = pos - 1
def findWordBoundary(self, view, s):
pos = s.begin()
wbRx = re.compile(r"[^\w]\w")
while True:
if (pos == 0): return 0
#search for not-word, word around cursor
twoCharsAroundPoint= view.substr(sublime.Region(pos-1, pos+1))
match = wbRx.match(twoCharsAroundPoint)
if match:
return pos
pos = pos - 1
def getWordAtPoint(self, view, p):
wikiWordRx = re.compile(self.wikiWordPattern)
stringToSearch = view.substr(sublime.Region(p, p+128))
match = wikiWordRx.match(stringToSearch)
if (match):
return match.group(0)
return None
# class RefreshSyntaxHighlightingCommand(sublimeplugin.TextCommand):
# def run(self, view, args):
# print view.syntaxName(view.sel()[0].begin())
# print view.fileName()
# folder = os.path.split(view.fileName())[0]
# if os.path.exists(folder) == False:
# print "no folder"
# return
# grammarGenerator = Hypergrammar.GrammarGenerator(folder)
# syntaxFile = grammarGenerator.run()
# view.options().set('syntax', syntaxFile)
# print "set syntax file to %s" % syntaxFile
PK V4=p
README.txtBringing hyperlinking to text file navigation...
This plugin provides a simple hyperlinking facility, which allows you to create very lightweight, text-file-based wikis.
# Getting Started
Here's how you use it; create a folder and add at least one file with a ".wiki" extension. say;
\world_of_fruit
\fruit.wiki
Now edit fruit.wiki:
The apple is a fine fruit. So is the orange.
Put your cursor somewhere inside the word 'apple', like this;
The ap|ple is a fine fruit. So is the orange.
Hit ctrl+alt+n (navigate). You'll be prompted to see if you want to create a new file, apple.wiki. If you say yes, apple.wiki is created and you can start editing it straight away. Easy!
# Longer Links
If you want to create a file with a longer name, you can enclose it in square brackets;
Have you ever wondered about the [nutritional values of kiwis]?
Then you can use the same navigation keypress (ctrl+alt+n) to visit 'nutritional values of kiwis.wiki'
PK V4=&|m m Hyperlinking.package-menuPK V4=Q) Hypergrammar.pyPK V4=\ { Default.sublime-keymapPK V4=;i E Hyperlinking.pyPK V4=p
README.txtPK = *"