[TxMt] How to extract part of a line of code and make it a variable?
jeremy.lecour at gmail.com
Thu Aug 30 08:43:05 UTC 2012
I'm a long time TextMate user which I love more than any other editor.
Before writing that e-mail I've looked on the web, downloaded the full archives of this list and grep it with some keywords and nothing came out.
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
my_variable = a_method(with, arguments)
something my_variable, something_else
I can't figure how to :
* extract the selected text and put it in a new line on top of the current, prefixed by a variable assignment
* have the variable name selected and ready to overwrite, mirrored where it has been extracted from
* preserve the indentation (on both lines)
* preserve what was before and after the extracted part
I've seen people do this in Vim and Emacs, but never in TextMate.
I've asked for help and James Edward Gray II gave me some advice on Twitter and here https://gist.github.com/3515210
It seems that the best way would be to replace the whole document.
I don't really see what I should use : a macro, a snippet, a command, or a combination of them.
I guess that I could do this with a macro + snippet, but I've not found (yet) the list of available commands (moveToEndOfParagraph, insertText, …) and their documentation.
I'd be happy to have a pre-cooked solution if it exists, but any advice would be helpful
http://jeremy.wordpress.com - http://twitter.com/jlecour
More information about the textmate