While I am not exactly able to help on the technical details as I’m also new on Clang grounds, if you or anyone else steps forward to implement this, I think it would be nice to early on consider a few more rules, such as:
Aligning the cv-qualifiers together and indent the real type name into a separate column
Within some reasonable boundary, align template arguments.
There's a way to do exactly what you described by setting AlignConsecutiveDeclarations to true in your .clang-format configuration. It is not clear whether you also want to set AlignConsecutiveAssignments true because all names in the examples have the same width, but you might also want to consider this option.
On 10/10/2018 04:10 AM, Whisperity via cfe-dev wrote:
> While I am not exactly able to help on the technical
> details as I’m also new on Clang grounds, if you or anyone
> else steps forward to implement this, I think it would be
> nice to early on consider a few more rules, such as:
> • Aligning the cv-qualifiers together and indent the real
> type name into a separate column
Do you mean something like this:
//cv-qualifiers type varid
//------------- ---- -----
const int ci;
const T<int,char> tic;
> • Within some reasonable boundary, align template
A problem with OP requirements and the above is deciding the
"reasonable boundary". For example, if the last line in the
above example were:
then there'd be a problem finding enough room one 1 line to
contain the whole declaration.
OTOH, the "reasonable boundary" problem largely disappears
if the declaration is "structure aligned" over several lines
just as now, most people "structure align" compound
statements over several lines. For example, instead of:
if(C1)S1;else if(C2)S2;else S3;
most people "structure align" the if statement to:
where the keywords (the most important part of the
structure), are all aligned in the same leftmost column and
the "details" (the sub-statements in the branches of the if)
are indented right to signify their lesser importance.
Similarly, the declarations could be "structure aligned" by
aligning the most important part of the declaration in the
leftmost column and the lesser import parts indented right.
and let's say we're compiling on a UNIX platform, so the first branch of the preprocessor directive is enabled, but not the second.
Only the enabled block would actually be formatted, the disabled block is completely ignored.
I'm not sure if this is just because the formatter is running after the preprocessor, or if it's a lot deeper than that, and Clang is removing the unavailable preprocessor tokens before anyone else has access to it?