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;

Code: Select all
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

Code: Select all
  \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;

Why not read foo, bar or baz?

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.
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg

Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

### Re: crazy-dynamic highlighting for hyperlinking

should you want to try it out, there's a first version available at http://www.sublimetextwiki.com/sublime- ... me-package

Hyperlinking Sublime Package, by Steve Cooper

This provides a simple hyperlinking facility.

You use it like this; create a folder and add at least one file with a ".wiki" extension. Open a file up, and insert hyperlinks like this;

visit the [Other File]

Place your cursor inside the "[Other File]" text and hit ctrl-alt-n (navigate). You'll be prompted to create the file, then it'll be opened up. You can use this to create a rudimentary wiki.
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg

Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

### Re: crazy-dynamic highlighting for hyperlinking

Hi, Nick.

> Why do you need the dynamic highlighting? If you are using square brackets etc and the links are fairly distinct a static hard coded pattern would be ok yeah? Or are the square brackets a workaround for the moment? [...] A markup converted to html not cutting it for you huh?

My intended audience are very non-technical. I'm putting together some tools for authors, who I think could benefit from some of the great goo available in text editors that isn't available from Word. For example, authors need version control as much as developers, but they don't really know about it; Sublime Text with Automatic Backups seems like a great starter in this area.

What comes next is richer manuscripts; if I have this paragraph;

"What the hell?" said Jake, as the ninja's sword swished past his ear.

Then I want the user to be able to create a suplementary file, Jake.wiki, by putting the cursor inside the string "Jake" and pressing a key. That means that the manuscript gets linked in to all the author's other notes, which is a big win. Thing is, I'm trying to keep the markup so light that authors don't realise they're using markup. If my instructions read 'there is a special code for...,' then I've failed.

The square brackets are more of an advanced feature, for longer phrases;

What amazing adventures await [Flash Gordon]? Find out next week!

Although, if I'm really slick, I'll be able to detect the presence of a "Flash Gordon.wiki" file, and allow the user to navigate to it without using the square brackets.

So yeah, the square brackets are a pragmatic choice so that I can get something working ASAP.

> Are you going to have facility for linking between different directories?

Already there if you use square brackets;

Code: Select all
why not travel to [..\my_other_wiki\other page]

Otherwise, I don't know yet how I'm going to do this.
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg

Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

### Re: crazy-dynamic highlighting for hyperlinking

> Check out a piece of software called "The Brain"

I've seen the brain -- it's really pretty, and I like it in principle, but always find myself gravitating back towards text. Hence this little project.

> The idea sounds like it would be really handy. Useful for navigating between files as well if you make the engine generic. eg opening css/ js files linked to from within a html file.

Now that's a very nice idea. I could possibly pair regexen to opening-functions; eg

Code: Select all
    "import ([a-z])" => OpenPythonImportFile("$1");"href="(.*)" => OpenHtmlFile("$1");"[A-Z][a-z]{,2}" => OpenWikiWord("\$1");

I'll have a think...
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg

Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

### Re: crazy-dynamic highlighting for hyperlinking

Steve - assigning a syntax definition to a buffer on the fly is fairly straight forward, you just need something along the lines of:

Code: Select all
view.options.set('syntax', u'Packages/Foo/Foo.tmLanguage')
jps

Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

### Re: crazy-dynamic highlighting for hyperlinking

jps wrote:Steve - assigning a syntax definition to a buffer on the fly is fairly straight forward

Great, jon. That may be all I need.
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg

Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

### Who is online

Users browsing this forum: Yahoo [Bot] and 12 guests