[TxMt] Nested Transformations in Snippets

Ed Singleton singletoned at gmail.com
Tue Apr 3 15:05:59 UTC 2007


Is there a way to do nested transformations in snippets?

I want to do something like:

class FooFields:
[...]
foo_form = [...]

where the Foo is easily changed.  Fields should be converted to form
and the whole thing should be converted from CamelCase to
under_scored.

I can do the underscored convertion, but I can't work out how to do
another search and replace as well.

I though this might work:

class ${1:FooFields}:
[...]
${2:${${1/Fields/Form/}/([a-z0-9])?([A-Z])/(?1:$1_)(?2:\l$2)/g}} = [...]

Where the first regex is input to the second regex.  But it doesn't
work.   Instead it doesn't seem to recognise the regex as a regex at
all and outputs:

class FooFields:
[...]
{1/Fields/Form//([a-z0-9])?([A-Z])/(?1:FooFields_)(?2:\l{1/Fields/Form/)/g}}
= [...]

Whilst writing this I have realised that I can just do:

class ${1:Foo}Fields:
[...]
${2:${1/([a-z0-9])?([A-Z])/(?1:$1_)(?2:\l$2)/g}}_form = [...]

Which is good enough as a solution, but I'd still like to know if
there is a way to solve the problem using nested regexs?

Many Thanks

Ed



More information about the textmate mailing list