Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I control indentation of array initializers with clang-format?

Sometimes clang-format does this :

SomeType VariableName[] = {Thing1,
                           Thing2,
                           Thing3}

and sometimes clang-format does this :

SomeType VariableName[] = {
   Thing1,
   Thing2,
   Thing3}

and a single character change can make it switch between.

Is there any way to control which it does?

I'm building from the latest git source, so the latest options are available.

like image 926
Andy Jewell Avatar asked May 19 '15 13:05

Andy Jewell


1 Answers

According to this answer, clang-format in some step puts as much as possible on a single line, and applies the ColumnLimit on that.

That would explain the switching between behaviors.

One way to prevent this could be to set ColumnLimit to 0, with the cost of removing all automatic wrapping. I think it's worth the cost, I'm sure other don't agree.

like image 70
Gauthier Avatar answered Oct 16 '22 19:10

Gauthier