On 21 Aug 2016, at 14:15, Fabian Zeindl wrote:
[…] given the following code is it possible to do this in TextMate:
let x = { number: 42 }
- I want to place the cursor after the { and when I press return, I
the closing bracket should too go on a new line
let x = { number: 42 }
In the Ruby bundle there is a “Toggle ‘do … end’ / ‘{ … }’” command bound to ⌃{ which does something very similar, so for the implementation you can look at this command.
Though I took a quick look, and it seems surprisingly complex, and it even reads the selection or document (when there is no selection) in TextMate’s XML format (which include scope info). I am not sure why this is necessary.
For actually overloading return and backspace in these locations, this is possible if you make the grammar match them and assign a scope at the desired locations, but I think it would be better with a toggle key like the Ruby bundle.
Come to think of it, there is also _Fold/Unfold Code_ in the C bundle (also bound to ⌃{) which also does something similar.