Can clang-format align the #defines block for me?

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 values โ€‹โ€‹well aligned. Unfortunately, clang-format does this:

 #define ARC_V2_LP_START 0x002 #define ARC_V2_LP_END 0x003 #define ARC_V2_STATUS32 0x00a 

I found the AlignConsecutiveDeclarations and AlignConsecutiveAssignments options, but nothing that would align consecutive #defines. Can this be done?

+21
c ++ c clang-format
source share
4 answers

[UPDATE]

In the end, the request to delete operations passed, and starting with version 9.0.0 clang is valid. Functionality is activated by the option AlignConsecutiveMacros: true .

[ORIGINAL]

Oddly enough, this feature has not yet been implemented in Clang; The formatting option for sequential macros is currently missing.

This is interesting for many developers, and there is a working request that has been waiting for approval for many years: https://reviews.llvm.org/D28462?id=93341

You can integrate it or just wait if they add it to the official branch, but at the moment I doubt that they will.

+6
source share

A quick look at the style options makes it look like there is currently no choice. The only option that concerns the preprocessing that I see is IndentPPDirectives which deals with indentation of #if blocks.

+1
source share

I could not find any opportunity for this. Clang destroyed all my definitions that were emacs automatically aligned.

0
source share

Note that clang-format-9 and above has the option AlignConsecutiveMacros: true , which may help you.

To install clang-format-9 on Ubuntu / Debian you need to check http://apt.llvm.org/ .

For example, if you have Ubuntu 16.04 / xenial, you need to do the following:

 sudo sh -c 'echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main" >> /etc/apt/sources.list' sudo sh -c 'echo "deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main" >> /etc/apt/sources.list' sudo apt update sudo apt install clang-format-9 

You can handle Trusty / Ubuntu 14.04 in the same way.

0
source share

All Articles