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:

<key>fallbackInput</key>
<string>line</string>

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.