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

Allan Odgaard mailinglist at textmate.org
Thu Aug 30 11:19:14 UTC 2012


On Aug 30, 2012, at 11:11 AM, Hans-Jörg Bibiko <bibiko at eva.mpg.de> wrote:

> 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*//}

Neat approach but no need to call out to shell / perl:

    ${1:variable} = ${TM_SELECTED_TEXT/\A\s*\w+\s*//}
    ${TM_SELECTED_TEXT/\A\s*(\w+).*/$1/} ${1}

And here’s a tip regarding selection: in 2.0 using a “unit selection”, i.e. the stuff under Edit → Select, using shift + movement will always extend selection, so e.g. with something like:

    something a_method(with, arguments), something_else

Place caret inside parenthesis, use ⇧⌘B (select to enclosing pairs) and then one can use ⌥⇧← to extend the selection to the method name (with 1.x unit selections would produce a regular “anchored” selection, so using left/right movement would shrink/expand respectively).



More information about the textmate mailing list