Snippets!
10 May 2008

Awesome:

The basics are not too complicated. Slap a couple of Gtk::TextMarks around each tab stop to keep track of where they are, and monitor keystrokes to update mirrors and transformations.

The part that really flummoxed me was what to do when tab stops are right next to each other. Because they go to zero width all the time (you have to delete text inside a mirror before you can add new text) I was ending up with overlapping tab stops. For example:

<1>mirror one text</1><2>mirror two text</2>

would go to

REXML could not parse this XML/HTML: 
<div class="highlight"><pre>
&lt;1&g&lt;2&gt;t;mirror one text&lt;/2&gt;&lt;/1&gt;
</pre></div>

Which is very wrong. If mirror 1 overlaps mirror 2 then you are never going to see text in mirror 2.

This kept me going for a good few days. I kept writing baroque solutions, and then discarding them thinking: there has got to be a simple way of doing this. And there was!

The solution was to give the textmarks an ordering and enforce that ordering after every text insertion. The final code is to fix this is about 40 lines, and crucially only required changing one part of the snippet inserter.

There are still things to fix. I fudged the Bundle support paths for now. That will all have to be revisited when I do Textmate commands anyway. And no doubt there will be more bastard edge cases to fix. But all the snippets I’ve tested so far work!

blog comments powered by Disqus