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
On 4/3/07, Allan Odgaard throw-away-1@macromates.com wrote:
On 3. Apr 2007, at 17:05, Ed Singleton wrote:
[...] 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?
Nested regexps are currently not supported.
Fair enough. Is that 'currently' as in 'it's on the todo list' or as in 'it's not considered a particularly important feature'?
Thanks
Ed
On 4. Apr 2007, at 10:49, Ed Singleton wrote:
On 4/3/07, Allan Odgaard throw-away-1@macromates.com wrote:
On 3. Apr 2007, at 17:05, Ed Singleton wrote:
[...] 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?
Nested regexps are currently not supported.
Fair enough. Is that 'currently' as in 'it's on the todo list' or as in 'it's not considered a particularly important feature'?
There will be “nesting” in 2.0, that is re-applying a regexp on a capture variable.
For example you can do:
${1/(.*)Form/${1/…/…/}Field/}
Here the inner substitution on capture 1 would do the CamelCase to underscore_case or vice versa.
But chaining regexp substitutions, as what you really asked for, that is not presently planned mainly because I don’t like the syntax I have been able to come up with for it, and the usefulness is even less when nesting is introduced.
On 4/4/07, Allan Odgaard throw-away-1@macromates.com wrote:
On 4. Apr 2007, at 10:49, Ed Singleton wrote:
On 4/3/07, Allan Odgaard throw-away-1@macromates.com wrote:
On 3. Apr 2007, at 17:05, Ed Singleton wrote:
[...] 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?
Nested regexps are currently not supported.
Fair enough. Is that 'currently' as in 'it's on the todo list' or as in 'it's not considered a particularly important feature'?
There will be "nesting" in 2.0, that is re-applying a regexp on a capture variable.
For example you can do:
${1/(.*)Form/${1/…/…/}Field/}
Here the inner substitution on capture 1 would do the CamelCase to underscore_case or vice versa.
But chaining regexp substitutions, as what you really asked for, that is not presently planned mainly because I don't like the syntax I have been able to come up with for it, and the usefulness is even less when nesting is introduced.
That looks like a perfectly fine system. I get more excited about version 2.0 every time I hear about it.
Ed