clang-format 9 introduced the option "AlignConsecutiveMacros".
Set it to "AcrossEmptyLinesAndComments" in order to avoid macro
definitions of the form:
#define MAGIC_REGISTER_1 0x42
#define MAGIC_REGISTER_BIT_FLIP BIT(2)
/* important comment */
#define MAGIC_REGISTER_BIT_ENABLE BIT(12)
#define MAGIC_REGISTER_2 0x43
With the option set to "AcrossEmptyLinesAndComments", they will
be converted to
#define MAGIC_REGISTER_1 0x42
#define MAGIC_REGISTER_BIT_FLIP BIT(2)
/* important comment */
#define MAGIC_REGISTER_BIT_ENABLE BIT(12)
#define MAGIC_REGISTER_2 0x43
which seems to be the convention in the kernel code base.
Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
---
.clang-format | 1 +
1 file changed, 1 insertion(+)
diff --git a/.clang-format b/.clang-format
index 8040b516185b..30d09cb88170 100644
--- a/.clang-format
+++ b/.clang-format
@@ -13,6 +13,7 @@ AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
+AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
--
2.34.1
On Mon, Feb 10, 2025 at 09:21:01AM +0100, Michael Riesch wrote: > clang-format 9 introduced the option "AlignConsecutiveMacros". > Set it to "AcrossEmptyLinesAndComments" in order to avoid macro > definitions of the form: > > #define MAGIC_REGISTER_1 0x42 > #define MAGIC_REGISTER_BIT_FLIP BIT(2) > /* important comment */ > #define MAGIC_REGISTER_BIT_ENABLE BIT(12) > > #define MAGIC_REGISTER_2 0x43 > > With the option set to "AcrossEmptyLinesAndComments", they will > be converted to > > #define MAGIC_REGISTER_1 0x42 > #define MAGIC_REGISTER_BIT_FLIP BIT(2) > /* important comment */ > #define MAGIC_REGISTER_BIT_ENABLE BIT(12) > > #define MAGIC_REGISTER_2 0x43 > > which seems to be the convention in the kernel code base. > > Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net> I could see this being controversial in some cases but let's see what happens. Reviewed-by: Nathan Chancellor <nathan@kernel.org> > --- > .clang-format | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/.clang-format b/.clang-format > index 8040b516185b..30d09cb88170 100644 > --- a/.clang-format > +++ b/.clang-format > @@ -13,6 +13,7 @@ AccessModifierOffset: -4 > AlignAfterOpenBracket: Align > AlignConsecutiveAssignments: false > AlignConsecutiveDeclarations: false > +AlignConsecutiveMacros: AcrossEmptyLinesAndComments > AlignEscapedNewlines: Left > AlignOperands: true > AlignTrailingComments: false > > -- > 2.34.1 >
© 2016 - 2025 Red Hat, Inc.