Align consecutive declarations only if they are of the same kind

40 views Asked by At

Consider this C code snippet:

typedef unsigned char BOOL;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;

int main() { 
    return 0; 
}

Using clang-format, I would like to align the typedef declarations. To do this, I set the property AlignConsecutiveDeclarations to true with AcrossEmptyLines also to true. The problem is that this formats the code in the following way:

typedef unsigned char  BOOL;
typedef unsigned char  uint8;
typedef unsigned short uint16;
typedef unsigned int   uint32;

int                    main() { return 0; }

As you can see, the main function is also aligned with the typedef declarations. As far as I can see, there is no property that detects whether the declarations change "kind" (for lack of a better word). Declarations can only be divided using comments and newlines. Am I missing something? Is there no option to have the code formatted like this?:

typedef unsigned char  BOOL;
typedef unsigned char  uint8;
typedef unsigned short uint16;
typedef unsigned int   uint32;

int main() { return 0; }

0

There are 0 answers