Sublime Forum

Reindent is broken by trailing comments in C++

#1

Trailing comments break reindenting in C++. The line is not moved and everything after it is then broken.

Here is an example:

void test()
{
	int maxX=0;
	int thisLine=rubbish; 
// previous line reindented ok
int numed   = 0;  // this line will not reindent correctly
int Ihaveno{crap};

}

This is after doing select all and reindent line. The line with a trailing comment gets left alone and breaks all following indenting. For example if I put a pile of space in front of it I get this…

void test()
{
	int maxX=0;
	int thisLine=rubbish; 
// previous line reindented ok
                  int numed   = 0;  // this line will not reindent correctly
                  int Ihaveno{crap};

              }

I am using Sublime Text 4 build 4107 on Centos 7.9. I have deliberately removed any configurations or settings to make sure it isn’t something I’ve done.

0 Likes

#2

An issue at https://github.com/sublimehq/Packages/issues might help to prevent it being burried.

0 Likes

#3

Thanks. Have to admit I’m surprised no-one else has reported such a serious problem, and that no-one else has responded. I’ll post it as an issue.

0 Likes

#4

Indentation engine has its limitations especially with regards to comments, so I guess people just gave up reporting such issues as it is likely not to be able to fix it.

I spent some time implementing indentation rules for Java recently. So it appears your issue might be fixable with reasonable effort. Hence an issue is worth it.

0 Likes