[TxMt] Re: How to extract part of a line of code and make it a variable?

Hans-Jörg Bibiko bibiko at eva.mpg.de
Thu Aug 30 09:11:43 UTC 2012


On Aug 30, 2012, at 10:43 AM, Jérémy Lecour wrote:

> As a developer I often want to extract a part of a line of code into a variable, and put it's assignment in the previous line. Example :
> 
> 	something a_method(with, arguments), something_else
> 
> would become
> 
> 	my_variable = a_method(with, arguments)
> 	something my_variable, something_else
> 

hmm, since you select something anyway, one could think of selecting 'something' as well.

If 'something' consists of one word only then this _very fast written_ snippet should work:


select: "something a_method(with, arguments)"

and invoke that snippet

${1:variable} = `echo -ne "$TM_SELECTED_TEXT" | perl -pe 's/^\s*\w+\s*//'`
`echo -ne "$TM_SELECTED_TEXT" | perl -pe 's/^\s*(\w+)\s*.*/\1/'` ${1/\s*//}


Cheers,
--Hans


More information about the textmate mailing list