TextMate Pt.3: Snippets cont. Transformations

Another feature of TextMate Snippets are Transformations. Transformations are Mirrors (see last TextMate part) with small modifications. One of the most powerful features of TextMate is it’s implementation of the Regular Expression¹ engine which Transformation use to adjust the mirrored text. Here’s an example:

- (id)foo
{
    return foo;
}

- (void)setFoo:(id)aValue
{
    [foo autorelease];
    foo = [aValue retain];
}

is created by this snippet:

- (${1:id})${2:foo}
{
    return $2;
}

- (void)set${2/./\u$0/}:($1)aValue
{
    [$2 autorelease];
    $2 = [aValue retain];
}

Just hit a few tabs and that is what is output, notice the \u which make the next character (in this case “f”) uppercase.

[Via: Macromates]

¹ - If you don’t know anything about Regular Expressions I recommend this Web site for a feeling on what it is: http://www.regular-expressions.info/. But if you want to get a real understand then I recommend Mastering Regular Expressions (book).


 
 

Post a comment to "TextMate Pt.3: Snippets cont. Transformations"