I'm trying to use a regex transformation in a snippet that will convert the first letter of a word to uppercase and convert underscore _ followed by a letter to a space and an uppercase letter.
eg:
field_name > Field Name long_field_name > Long Field Name
I can't quite get get my head round how to do it, as it seems like two seperate transformations, but I'm not sure how to to do transformations on a string in a snippet.
Is there a collection of regexes for transforming between the main cases? (particularly Camel, Title and underscore seperated) I managed one that went from CamelCase to underscore_seperated:
${1/([a-z0-9])?([A-Z])/(?1:$1_)\l$2/g}
Thanks
Ed
On 5. Oct 2006, at 16:38, Ed Singleton wrote:
I'm trying to use a regex transformation in a snippet that will convert the first letter of a word to uppercase and convert underscore _ followed by a letter to a space and an uppercase letter.
eg:
field_name > Field Name long_field_name > Long Field Name
I think this should do: ${1/([a-z]+)(_)?/\u$1(?2: )/g}
[...] Is there a collection of regexes for transforming between the main cases?
Nope -- I’ve been wanting to start sort of a recipes section in the manual, sounds like these would be good examples to have there :)
On 10/5/06, Allan Odgaard throw-away-1@macromates.com wrote:
On 5. Oct 2006, at 16:38, Ed Singleton wrote:
I'm trying to use a regex transformation in a snippet that will convert the first letter of a word to uppercase and convert underscore _ followed by a letter to a space and an uppercase letter.
eg:
field_name > Field Name long_field_name > Long Field Name
I think this should do: ${1/([a-z]+)(_)?/\u$1(?2: )/g}
Thanks! Turns out I was looking at it backwards. I was trying to look for a single letter preceded by the beginning of the word or an underscore, rather than just any group of letters with an optional underscore after.
[...] Is there a collection of regexes for transforming between the main cases?
Nope -- I've been wanting to start sort of a recipes section in the manual, sounds like these would be good examples to have there :)
I've been playing with snippets a lot recently (best things ever), and the one thing I've really missed is a snippets bundle. I edit my snippets in Textmate using the "edit in textmate" thing and there's quite a few handy commands I could do with (like "renumber tab stops" and stuff) and snippets to insert . I may try and work out how to write the commands and stuff if no one else does soon.
Ed
Ed Singleton wrote:
I've been playing with snippets a lot recently (best things ever), and the one thing I've really missed is a snippets bundle. I edit my snippets in Textmate using the "edit in textmate" thing and there's quite a few handy commands I could do with (like "renumber tab stops" and stuff) and snippets to insert . I may try and work out how to write the commands and stuff if no one else does soon.
Add that kind of stuff to the TextMate bundle, or perhaps initially to the Experimental bundle. We do indeed need a "snippet" grammar, &c., so we can then do things like have a here-doc in a command with "SNIPPET" as a token, that will be interpreted as a snippet, &c. I think several of us have wanted to do this for a while, but never got around to it, so if you take care of it, that'd be great!
-Jacob
On 6. Oct 2006, at 00:31, Jacob Rus wrote:
[...] I think several of us have wanted to do this for a while, but never got around to it, so if you take care of it, that'd be great!
I also want pasted snippets (on pastie) syntax highlighted -- Michael Sheets promisted to do the (absurdly simple) snippet grammar when I either offer TM text fields in the bundle editor, or make the Edit in TM smart enough to switch to the proper type for invocations from the bundle editor :)