Hi, I'm doing a little housekeeping on my Rebol bundle. I've one command that takes a selection, evaluates the content and replaces the selection with the product. I'm using TM_SELECTION to determine the various selection modes:
• No selection: use TM_CURRENT_LINE as input • Regular selection: use TM_SELECTED_TEXT as input • Columnar selection: use TM_SELECTED_TEXT splitting on LF
I don't currently handle multiple caret selection, though I see that I can read from STDIN to obtain that input. The tricky part seems to be discerning how to break that input to match the respective selections. I could split by LF, though that doesn't work if any of the selections themselves span multiple lines. Otherwise it seems it's a walk through each line to match up with the TM_SELECTION entries (which I've not attempted thus far, in fairness).
Am I missing anything obvious here? Has there been any consideration of using some of the ASCII field separators (e.g. 0x1D-1F) to delimit these and permitting use of said separators as a way of directing the response to fill each of these selections respectively?
Thanks, – Chris
On 9 Feb 2021, at 4:27, Chris Ross-Gill via TextMate wrote:
I don't currently handle multiple caret selection […] Am I missing anything obvious here?
TextMate tries to handle multiple selections/insertion points for “simple” commands (filters).
Set Input to Selection and Output to Replace Input.
Save this. Then use proxy icon in Bundle Editor to locate the `.tmCommand` file in your bundle, open it in TextMate (hold down ⌥ to open the XML).
Now add this line below the input key/string pair:
This means when there is no selection, TextMate will provide current line on stdin.
Furthermore, as output is set to replace input, TextMate knows whether to replace selection or entire line.
And, if there are multiple selections or insertion points, it *should* be able to handle that as well.
But for this to work, your command should always read data from stdin and shouldn’t look at `TM_SELECTION` (although it could change how it process the output based on whether or not that variable is set).
Also, your command will be called multiple times, once for each selection/insertion point.