I want my visibility modifiers (public
, protected
and private
) to be indented by clang-format who currently leaves them at the same level as the class declaration. I've looked for indent
and visibility
on a dump of the default format options but couldn't find anything.
From the Clang-Format Style Options documentation:
AccessModifierOffset (int) The extra indent or outdent of access modifiers, e.g. public:.
So, add the appropriate entry to your .clang-format
. For example,
AccessModifierOffset: 2
If you want to give the access modifiers themselves their own level of indentation, you can use IndentAccessModifiers: true
. This will give you code that looks like the following.
class my_class {
public:
my_class() = default;
};
With IndentAccessModifiers: false
, by default you'll get the access modifiers not indented at all, and class members will be indented only one level beyond the surrounding scope.
class my_class {
public:
my_class() = default;
};
You can then use AccessModifierOffset
to adjust the alignment of the access modifiers only, without affecting the alignment of the class members. With IndentAccessModifiers: false
and AccessModifierOffset: 1
, you'd get this.
class my_class {
public:
my_class() = default;
};
With IndentAccessModifiers: true
, AccessModifierOffset
is ignored.
I'm sure all reasonable programmers would agree that only one of these options is even remotely acceptable. Though they probably wouldn't agree on which one it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With