Sublime Forum

The indenting of a C++ for loop is incorrect under certain conditions

#1

One of the authors of code in a large project I am working on likes to format his for loops as in the example1 below. I find sublime text gets the indenting on the second and subsequent lines of the body of the loop incorrect and the final } is wrong a well. The condition for this to happen is if the items in the () after the for statement are spread over several lines and the opening { of the body is on the same line as the closing ).
void example1()
{
for (int i=0;
i<10;
i++) {
int a=1;
int b=2; // Why has the indent gone back one tab stop here?
} // and why does this not line up with the rest of the for loop?
}
void example2()
{
for (int i=0;
i<10;
i++)
{ // Moving this bracket gets correct behaviour.
int a=1;
int b=2;
}
}
void example3()
{
for (int i=0;i<10;i++) { // This is fine too
int a=1;
int b=2;
}
}

0 Likes

#2

Didn’t realise the formatting would get messed up when I posted, will try again.

            void example1()
{
	for (int i=0;
		i<10;
		i++) {
		int a=1;
	int b=2;  // Why has the indent gone back one tab stop here?
}
}
void example2()
{
	for (int i=0;
		i<10;
		i++) 
	{       // Moving this bracket gets correct behaviour.
		int a=1;
		int b=2;  
	}
}
void example3()
{
	for (int i=0;i<10;i++) {       // This is fine too
		int a=1;
		int b=2;  
	}
}
Summary

This text will be hidden

0 Likes

#3

I’ve found the indenting on ST3 to be: not sure how i can be completely fair; it sort of works. Comments disrupt the indent, so I’ve worked out some macros to go to comments, uncomment them. Then I can indent, then I can restore the comments. It’s taken me hours over a few months to get things vaguely to be how I want them.
I guess maybe “;” disrupt the indent function too?

It just seems to be how things are.
I’m sure someone will put me right

0 Likes

#4

This is still the case 2 years later. Major fault in Sublime Text but no-one cares apparently.

0 Likes

#5

Issue reports tend to get lost in the forum. A better place to report syntax issues is https://github.com/sublimehq/Packages/issues

A solution is proposed at:

0 Likes

#6

Thanks. I hope to see this fix in a new release soon then.

0 Likes