I have a source file containing some lines like this;
#define ARC_V2_LP_START 0x002 #define ARC_V2_LP_END 0x003 #define ARC_V2_STATUS32 0x00a
With all the values nicely aligned. Unfortunately clang-format does this;
#define ARC_V2_LP_START 0x002 #define ARC_V2_LP_END 0x003 #define ARC_V2_STATUS32 0x00a
I have found the AlignConsecutiveDeclarations and AlignConsecutiveAssignments options, but nothing that will align consecutive #defines. Is it possible to do this?
Short answer: YES. The clang-format tool has a -sort-includes option. Changing the order of #include directives can definitely change the behavior of existing code, and may break existing code.
clang-format is a tool to automatically format C/C++/Objective-C code, so that developers don't need to worry about style issues during code reviews. It is highly recommended to format your changed C++ code before opening pull requests, which will save you and the reviewers' time.
Clang-Format is a widely-used C++ code formatter. As it provides an option to define code style options in YAML-formatted files — named . clang-format or _clang-format — these files often become a part of your project where you keep all code style rules.
clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the . clang-format or _clang-format file in the project directory.
[UPDATE]
The op's pull request finally went through and as of clang version 9.0.0 is live. The functionality is enabled by the AlignConsecutiveMacros: true
option.
[ORIGINAL]
Weirdly enough this feature is yet to be implemented in clang; the formatting option for consecutive macros is currently missing.
Many developers are interested and there is a working pull request that has been waiting for approval for years: https://reviews.llvm.org/D28462?id=93341
You can integrate it or just wait whether they add it on the official branch, but at this point I doubt they will.
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