[cfe-dev] Clang Format: Add option to align types?
Kirill Bobyrev via cfe-dev
cfe-dev at lists.llvm.org
Wed Oct 10 02:51:06 PDT 2018
Hi Marcus,
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.
You can see more Clang-Format options and their descriptions in the
documentation: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
-Kirill
On Wed, Oct 10, 2018 at 1:41 AM Marcus Johnson via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> I'm not sure if this is even the right place to ask, I did a quick search
> looking for a clang-format specific list but couldn't find one, does anyone
> know if there even is one?
>
> I'm trying to add an option to Clang-Format that would allow users to
> align variables in structs/classes and functions based on the width of the
> type identifier.
>
> Here's a couple examples to better illustrate what I'm talking about:
>
> typedef struct Unaligned_Struct {
> int wat;
> uint8_t huh;
> uint64_t who;
> } Unaligned_Struct;
>
> int Unaligned_Average(int A, int B, int num) {
> int Average = A + B;
> int32_t Divided = Average / num;
> return Divided;
> }
>
> vs
>
> typedef struct Aligned_Struct {
> int wat;
> uint8_t huh;
> uint64_t who;
> } Aligned_Struct;
>
> int Aligned_Average(int A, int B, int num) {
> int Average = A + B;
> int32_t Divided = Average / num;
> return Divided;
> }
>
> I'm not sure if the formatting is showing up, so I geuss I'l have to
> describe it.
>
> The Aligned blocks all of the variables have X number of spaces added
> between the type and the variable name, so that they're all aligned in a
> single column.
>
> it makes reading the code a lot easier, I've been doing thi manually with
> my code for a while, and Clang-Format not having this feature is the
> biggest reason I don't currently use it.
>
> As for my questions, they are:
>
> How exactly do I do this?
>
> Should I write a new enum (I've been thinking about calling it
> "AlignTypeDeclarationStyle", but that seems a little clunky, and I'm not
> sure if it's the best way to describe what exactly is going on)
>
> and how exactly would I hook this into the Clang-Format library?
>
> I've never contributed to the LLVM project before, I've read the documents
> a few times, and I've tried reading the code, but it's very intertwined and
> it's hard to drill down as deep as I need.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181010/5013fc6a/attachment.html>
More information about the cfe-dev
mailing list