It's easy enough to change the current selection with a macro but is it possible in a command written in Ruby?
I've written various scripts for TextMate 1 and 2 but I don't remember doing this.
Thanks, Richard
skype: rdrake98 blog https://dl.dropboxusercontent.com/u/51971271/drake/index.html - twitter https://twitter.com/rdrake98
On 7 Oct 2014, at 21:42, Richard Drake wrote:
It's easy enough to change the current selection with a macro but is it possible in a command written in Ruby?
If you want to insert partially selected text then you can insert as snippet and use the snippet syntax to make parts selected.
If you only want to select things in the document (and not insert anything) then (in ruby) you can call:
%x{ "$TM_MATE" -l«selection» }
Here «selection» should be a string in the format described here http://manual.textmate.org/references.html#selection-string
Be aware though that such command should be asynchronous, since normally TextMate would wait for your command to finish and use its result to change the document/selection (which you do not want here).
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?
07952130635 skype: rdrake98 blog https://dl.dropboxusercontent.com/u/51971271/drake/index.html - twitter https://twitter.com/rdrake98
On 11 October 2014 13:42, Allan Odgaard mailinglist@textmate.org wrote:
On 7 Oct 2014, at 21:42, Richard Drake wrote:
It's easy enough to change the current selection with a macro but is it
possible in a command written in Ruby?
If you want to insert partially selected text then you can insert as snippet and use the snippet syntax to make parts selected.
If you only want to select things in the document (and not insert anything) then (in ruby) you can call:
%x{ "$TM_MATE" -l«selection» }
Here «selection» should be a string in the format described here http://manual.textmate.org/references.html#selection-string
Be aware though that such command should be asynchronous, since normally TextMate would wait for your command to finish and use its result to change the document/selection (which you do not want here).
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
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-com... Sent from the textmate users mailing list archive at Nabble.com.
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.
07952130635 skype: rdrake98 blog https://dl.dropboxusercontent.com/u/51971271/drake/index.html - twitter https://twitter.com/rdrake98
On 12 October 2014 08:00, René Schwaiger sanssecours@f-m.fm wrote:
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:
- Split on `-` then get the last part of the resulting list
- 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-com... Sent from the textmate users mailing list archive at Nabble.com.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
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.
Hi Richard,
I guess I should not have copied `TM_SELECTED_TEXT` from your second post :). Sorry for using the wrong variable name.
Kind regards, René
-- View this message in context: http://textmate.1073791.n5.nabble.com/Changing-the-selection-in-a-script-com... Sent from the textmate users mailing list archive at Nabble.com.
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”.
Brilliant, thanks
07952130635 skype: rdrake98 blog https://dl.dropboxusercontent.com/u/51971271/drake/index.html - twitter https://twitter.com/rdrake98
On 12 October 2014 08:46, Allan Odgaard mailinglist@textmate.org wrote:
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”.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate