[txmt-dev] Re: Working with indentation rules

Allan Odgaard mailinglist at textmate.org
Tue Sep 17 09:17:49 UTC 2013


On 17 Sep 2013, at 9:38, Jacob Carlborg wrote:

> […] If a type a function declaration (same syntax as in C), like 
> this:
>
> void foo ()
> {|}
>
> When I've typed the opening brace it will look like the above (the 
> pipe being the position of the cursor). But
> setting the language to C and doing the same will decrease the 
> indentation, as it should.

In the C bundle this was fixed by 
https://github.com/textmate/c.tmbundle/commit/776da04eda90a8af9ae4e0d20381765caaca5655

Basically the indent patterns must deal with the user having typed 
‘{}’ and decrease indent for that case, because of ‘indent as you 
type’ and auto-pairing of characters.

> Also, pressing enter the indention will increase, if the language is 
> set to C.

You mean pressing return here ‘{‸}’ will insert ‘\n\t‸\n’?

In 2.0 this is done by a snippet scoped to “between empty pairs”. 
For this to work, we require the grammar to assign punctuation scopes to 
braces (and other paired characters where it should work), but I’ve 
been wanting to inject a rule just for empty braces, so that the 1.x 
behavior works even if the grammar has not been updated.

This is basically what I wish to inject into all scopes, sans the D 
suffix:

     {   match = '(\{)(\})';
         captures = {
             1 = { name = 'punctuation.section.block.begin.d'; };
             2 = { name = 'punctuation.section.block.end.d'; };
         };
     },

If the grammar alredy match (stand-alone) braces, it doesn’t need the 
rule, instead it can assign the above begin/end scopes to these matches.


More information about the textmate-dev mailing list