Home > Blockchain >  how to only indent brackets after case labels using clang-format
how to only indent brackets after case labels using clang-format

Time:08-20

I wanna a style that only indent brackets after case labels, while keeping case label not indented.

this is what I want:

switch(a)
{
case 1:
    {
        do_some_thing();
    }
    break;
}

I find an option IndentCaseLabels, but it will the whole things include the case label, neither true or false isn't what I want

true:
switch(a)
{
    case 1:
    {
        do_some_thing();
    }
    break;
}

false:
switch(a)
{
case 1:
{
    do_some_thing();
}
break;
}

Is this style possible in clang-format? If is, how could I Configure it?

CodePudding user response:

It's just immediate above one you found in the manual.

IndentCaseBlocks: true

Indent case label blocks one level from the case label.

false:                                 true:
switch (fool) {                vs.     switch (fool) {
case 1: {                              case 1:
  bar();                                 {
} break;                                   bar();
default: {                               }
  plop();                                break;
}                                      default:
}                                        {
                                           plop();
                                         }
                                       
  • Related