« Nice new editing features | Home

Snippets!

By Dan | May 10, 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

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

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!

Topics: development |

One Response to “Snippets!”

  1. Regex Replacer : Nuclear-Powered Nutcracker Says:
    May 10th, 2008 at 10:53 am

    [...] needed this library to get Textmate snippets working in Redcar, and therefore it uses a slightly different syntax to gsub (”$1″ instead of [...]

Comments