Bug 243328 - [formatter] Allow lining up struct, enum, and #define values
Summary: [formatter] Allow lining up struct, enum, and #define values
Status: ASSIGNED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 8.2   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-06 11:21 EDT by Nathan Baker CLA
Modified: 2020-09-04 15:24 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Baker CLA 2008-08-06 11:21:16 EDT
Build ID: I20080617-2000

Steps To Reproduce:
Example:
before
------
struct foo {
   uint32_t foo_a;
   uint8_t foo_b;
   uint64_t* foo_c;
   struct really_long_name* foo_d;
};
after
-----
struct foo {
   uint32_t  foo_a;
   uint8_t   foo_b;
   uint64_t* foo_c;
   struct really_long_name* foo_d;
};
It would also be OK to line up everything with foo_d, but it would be fancy if a couple long poles didn't throw off the formatting for everything (off the top of my head, I would suggest calculating the average displacement required to line up the element and then not including elements that are more than one or two standard deviations from the average...but this may be overly-complicated).

Example 2:
before
------
enum baz {
   BAZ_FLOOBLE = 82,     /* Blah blah */
   BAZ_GARBLE = 49,      /* Blah blah */
   BAZ_FARGWITZ = 19,    /* Blah blah */
};

after
-----
enum baz {
   BAZ_FLOOBLE  = 82, /* Blah blah */
   BAZ_GARBLE   = 49, /* Blah blah */
   BAZ_FARGWITZ = 19, /* Blah blah */
};

Two other things to note from this example:
1) Obviously, enum values need to be lined up at the equal sign.
2) Comments trailing the values may need to be realigned (this applies to structs/#defines as well.

Thanks!
Nathan

More information:
Comment 1 C. Ening CLA 2019-05-02 05:18:17 EDT
This is already available for JDT as 'Align items in columns' (previously 'Align fields in columns'), see
https://www.eclipse.org/eclipse/news/4.9/jdt.php#align-spaces
so could be a good start for the CDT implementation.