[TxMt] Re: Changing the selection in a script/command

Allan Odgaard mailinglist at textmate.org
Sun Oct 12 07:46:20 UTC 2014


On 12 Oct 2014, at 9:25, Richard Drake wrote:

> Thanks René
>
> You gave me the crucial clue but, for the record, it's (for example)
>
> TM_SELECTED_TEXT="some text"
> TM_SELECTION="14:6-14:15"
>
> and it's the second one I was missing.

For the records, TM_SELECTION follows the selection string syntax 
documented here: 
http://manual.textmate.org/references.html#selection-string

For example with multiple selections or columnar selections, you will 
see & and x in the string, and with “freehanded” placement of caret 
(e.g. option click past end of line) you will see + (which can also 
occur for column selections).

I think a regexp like this can be used for a simple parser:

     
/^(\d+)(?::(\d+))?(?:\+\d+)?(-|x)(\d+)(?::(\d+))?(?:\+\d+)?(?:&.*)?$/

	$1 = from line
	$2 = from column
	$3 = - or x indicating regular or columnar selection
	$4 = to line
	$5 = to column

I didn’t capture the “past EOL offsets”.


More information about the textmate mailing list