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

René Schwaiger sanssecours at f-m.fm
Sun Oct 12 07:00:11 UTC 2014


Richard Drake wrote
> That part works, thanks.
> 
> What seems to have changed from TM1 is that when $TM_SELECTED_TEXT is set
> all of
> 
> $TM_LINE_NUMBER
> $TM_LINE_INDEX
> $TM_CURRENT_WORD
> $TM_CURRENT_LINE
> 
> are blank. The first two at least I need. Is this a bug?

Hi Richard,

I think the way TextMate exports the current selection has changed.
`TM_SELECTED_TEXT` is now always set, even if there is no selection. It
contains the current line number and column number.  If there is a selection
it contains both the start and end position in the form:
`start_line:start_column-end_line:end_column`. You can also see the content
of this variable at the very left in the status bar after the text “Line: ”.

`TM_LINE_NUMBER` and `TM_LINE_INDEX` in TextMate 1 seem to be the line
number and column number of the “end” of the selection. We can get these
values in TextMate 2 by using `TM_SELECTED_TEXT`. We apply the following
steps:

1. Split on `-` then get the last part of the resulting list
2. Split on `:` and check how many items the resulting list contains
2.1. If it contains one item then this item is the line number
(`TM_LINE_NUMBER`). 
     The column number (`TM_LINE_INDEX`) is 0.
2.2. If it contains two items, then the first one is the line number and the
second one is the column number.

Kind regards,
  René



--
View this message in context: http://textmate.1073791.n5.nabble.com/Changing-the-selection-in-a-script-command-tp28328p28335.html
Sent from the textmate users mailing list archive at Nabble.com.


More information about the textmate mailing list