Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toLowerCase or capitalize functions for Sublime Text 2 Snippets

Is it possible to define some sort of capitalize() or toLowerCase() function when creating Sublime Text 2 Snippets?

For example:

<snippet>
<content><![CDATA[
<?php
class ${1} extends Datamapper
{
    var \$has_one = array();
    var \$has_many = array();
    var \$table = '${1}s';
    //constructor and other stuff next...
}
?>
]]></content>
<tabTrigger>dmm</tabTrigger>
</snippet>

This particular snippet helps me create Datamapper ORM models on the fly. When I type dmm the Snippet is fired and my cursor is placed in two areas at the same time; the class's name & the assignment to $table. The first cursor requires capitalization whereas the second cursor should not. Can I force the Snippet's case? Something like {1.toLowerCase}

Simple example, but I can think of other times when I could use this.

like image 736
Jordan Arseno Avatar asked Jun 13 '12 21:06

Jordan Arseno


1 Answers

You can use substitution and the Perl format string syntax

I have tested this code:

<snippet>
<content><![CDATA[
<?php
class ${1} extends Datamapper
{
    var \$has_one = array();
    var \$has_many = array();
    var \$table = '${1/(.+)/\L\1/g}s';
    //constructor and other stuff next...
}
?>
]]></content>
<tabTrigger>dmm</tabTrigger>
</snippet>

Regards, Armando

like image 87
aanton Avatar answered Oct 05 '22 11:10

aanton