[TxMt] Dynamic snippets?

Thomas Aylott (subtleGradient) oblivious at subtlegradient.com
Thu Aug 9 11:21:28 UTC 2007


On Aug 9, 2007, at 6:47 AM, Bob Ueland wrote:

> I'm new to TextMate and thinking of using it for teaching purposes.  
> I would like to fill out a form and have TextMate to automatically  
> create the needed file. For instance I have a snippet called csc  
> (short for CreateStandardClass) that looks like this
>
> Class: ${1:ClassName}
> SubClassOf: ${2:Object}
> InstanceVariables: ${3:varName1},${4:varName2}
>
> After I've entered the needed info (Rectangle, width and height) it  
> looks like this
>
> ClassName: Rectangle
> SubClassOf: Object
> InstanceVariables: width,height
>
> After entering height and pressing tab I would like TextMate to  
> generate the Objective-C code below. (It should be possible since  
> all needed data is in the variables $1, $2, $3 and $4)
>
...
> Is there a way to do this?
>
> Thanks Bob

Yes. There are a few ways you could do this.
You could write some sort of ruby script to parse the text you just  
entered and generate the code.
Then bind that command to some sort of keystroke or tab completion.

Or you could write a really complex snippet using multiple instances  
of the same variable.
You can even have some of the instances of the variable use regex  
replacement to change the capitalization and let you insert an  
arbitrary number of objective-c instance variables with the  
corresponding code.

Check the help docs for the syntax. Check out the objective-c bundle  
for examples.

	thomas Aylott — subtleGradient — CrazyEgg — bundleForge

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20070809/93c81054/attachment.html>


More information about the textmate mailing list