[llvm-dev] Clang-format: Allow alignment across empty lines and comments

Lukas Barth via llvm-dev
Fri, 01 Jan 2021 16:07:30 -0000

Paul C. Anagnostopoulos via llvm-dev writes:
> How would the formatter know whether the declarations following the
> comment are a continuation of the preceding series of declarations?

If "across comments" is set, it would always assume that declarations
following a comment are a continuation of the previous ones. Only a line
containing anything but a declaration or a comment would break alignment.

One could further control this by distinguishing between block and line
comments. So for example:

int bar = 1;
// int baz = 2;
int longfoo = 3;

would be aligned to

int bar     = 1;
// int baz = 2;
int longfoo = 3;

But

int bar = 1;
/* This comment is meant to break alignment */
int longfoo = 3;

would stay as-is.

Would you prefer this behavior? I can see its appeal - it gets rid of
all the "superfluous change" when commenting-out an assignment in the
middle of a block, without lobbing together blocks of alignment you want
separated. However, this would make configuration more complicated. For
full flexibility, the enum would then need to have the members:

  - `<Something>_None` (the old `false`)
  - `<Something>_Consecutive` (the old `true`)
  - `<Something>_AcrossComments`
  - `<Something>_AcrossBlockComments`
  - `<Something>_AcrossLineComments`
  - `<Something>_AcrossEmptyLines`
  - `<Something>_AcrossEmptyLinesAndComments`
  - `<Something>_AcrossEmptyLinesAndBlockComments`
  - `<Something>_AcrossEmptyLinesAndLineComments`

Regards,
Lukas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 861 bytes
Desc: not available
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20210101/4782a1bf/attachment.sig>