Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to indent after access modifiers with clang-format

How can I realize the following indentation after access modifiers:

class A{ public: int a; } 

should result in

class A {     public:         int a; // note the indentation } 

clang-format only allows the access modifiers to be on the same level as the int a AccessModifierOffset: 0 resulting in

class A {     public:     int a; } 
like image 584
Gabriel Avatar asked Dec 07 '16 16:12

Gabriel


1 Answers

Where I work, we've stumbled upon the same problem. Since the IndentWidth parameter controls the indentation everywhere (classes, functions, etc.) what you're trying to achieve seems impossible. The next best thing, in my opinion, is to keep IndentWidth=4 and set AccessModifierOffset=-2. That way you get:

class Foo {   public:     Foo() = default; };  bool foo() {     return true; } 
like image 169
ronhe Avatar answered Oct 20 '22 13:10

ronhe