Sublime Forum

indent_to_bracket with multiple brackets on one line

#1

Hi

When I use indent_to_bracket with python I’m seeing the following behavior if there are multiple brackets on one line:

fieldList.append(INPUT(name='searchText', _id='searchText',_style="width: 150px;", ))

I think it should be indented underneath the second ( on the first line instead of under the first (. Is this a bug or a feature request? Also, reading around the web I’ve seen that indent_to_bracket is only good on () and not ] or {}. Any plans to expand the functionality there?

0 Likes

#2

Yes, this is a bug or perhaps a missing feature. I just came to the forum to see if anybody else has reported it.

In the case of () or ], it should find the matching open ( or to the close ) or ] you haven’t yet typed. And in fact, that’s exactly what it’s doing.

Unfortunately, it’s what it does next that fails: it goes to the beginning of the line it found the matching “(” on and then finds the first “(” on that line as the indent position. At least I think that’s what is happening based on this test:

        foobar(
               self.innerFunctionCall(a,
                                      b))

You can see that if the inner function call is on its own line, it works. If I put the inner call on the same line it fails:

        foobar(self.innerFunctionCall(a,
               b))

If this were implemented in python (and it should be) it would be easy to sort out.

What I wish for is a better API to manage paren matching in general. I think it might be time to implement one or borrow or modify the awesome BracketHighlighter package.

BTW, in the case of curly braces, it has to (1) find the matching “{” and THEN (for languages like C and Java) needs to go back another set of matching “()” to find the beginning of the if/else if/while/for statement to figure out the proper indent. Again this would be easy to do in python with the right primitives.

0 Likes