Hi, everyone. Got a bit of a conundrum and wondered if anyone had a clue about how I might implement something. The quick version is this; can you dynamically generate a tmLanguage file and then assign it to a view? That vis, something that looks like this;
class automaticGrammarsPlugin(sublimePlugin.Plugin):
def onLoad(self, view):
grammar = MakeNewLanguageGrammar(view.fileName())
AssignGrammarToView(view)
Now, that’s what I want to do. Here’s why.
I’m putting together a plugin for hyperlinking between files. If a directory contains
\mydirectory
\foo.txt
\bar.txt
\baz.txt
then there is a special grammar for this folder, highlighting the words “foo”, “bar”, and “baz” in any of these files;
Should make for a very useful little file-based hyperlinking/wiki system. But there’s a crazy sort of dynamism here; each directory needs it’s own language. Go into a different folder and you get an entirely different set of highlighted terms.
So I figure I’m going to have to automatically generate the grammar file (not too hard), then assign this custom grammar to the view (the hard bit.)
Anyone got any ideas?
Also, anyone got any requirements for a wiki-like system? I’ll see if I can bear them in mind, but I can’t promise anything.