Sublime Forum

Auto-indentation problem

#1

With sublime default settings it works fine:

[code]Indented code:

if($this == $that) {
    echo 1;
}[/code]

When I open the {, it automatically closes and sends the pointer to the middle of the braces.
But I like to have “autoMatchEnabled false” and when I try the same code, right after I write echo 1; I hit ENTER, the cursor goes to the right place (below “if”), then I close the brace “}” and it goes to the start of the line instead of keeping below the “if”, like this:

[code]Indented code:

if($this == $that) {
    echo 1;

}[/code]

Is there a fix?
Thanks.

0 Likes

#2

I just tested it, and for me, after entering “echo 1;” and then “enter”, the cursor doesn’t go below the if, it goes below the “echo”.
Then, hitting the “}” key places the brace below the if.
The algorithm seems to be that inserting the “}” will automatically indent it one tab stop left of wherever the cursor is now.

Are you sure you’re not “manually” hitting backspace after entering the “echo 1;” line?

By the way, out of curiosity, why do you turn off autoMatchEnabled? I find it amazingly helpful.
At the worst, it doesn’t get in your way since entering the extra brace will override the first.
At best, after hitting the first brace and getting the second one automatically, hitting enter will (like magic) position the second brace in the appropriate place, and the cursor in between them.
After an hour of getting used to this, I now find it really awesome.

0 Likes

#3

I guess I have explained it wrong. When you hit ENTER, the cursor goes to the right place (below echo and not if), but then I have to do a backspace so I can close the brace below the if, when I click the brace key, it unindents one more tab. It should work fine if I don’t use the backspace to keep the cursor below the if but this is wrong.

Thanks.

By the way, I am starting to like auto match… :smiley:

0 Likes

#4

Glad to hear it! :smile:

I think the behavior right now is that a brace key automatically unindents by tab-size, so you’re supposed to not hit backspace before inserting the closing brace.

That said, a new beta just came out which Jon says has big changes to autoindenting, and I haven’t had a chance to look at it yet, so it hopefully solve this issue.

0 Likes

#5

This should no longer be an issue in 20100527: if you press backspace after pressing enter, that’ll be taken as a signal for manual indentation control, and the brace won’t be automatically unindented.

0 Likes