Reputation: 1510
I'm trying to match my clang-format as close as possible to our eclipse formatter.
In this migration I have realised that eclipse prefers to keep the parameters/arguments in same line as much as possible:
Example:
If I change BinPackParameters i will either get:
or:
I want to have the same behaviour as eclipse: "Keep putting parameters in same line as function/method name then wrap when column limit is reached"
How can I achieve this?
Edit: I'm extending Google style
Upvotes: 0
Views: 1254
Reputation: 1924
A few thoughts:
AlignAfterOpenBracket: DontAlign
. Given the two inputs you show above, the command clang-format -style='{BasedOnStyle: Google,AlignAfterOpenBracket: DontAlign}'
gives:
virtual int *XXXXXXXXXXXXX(int *parentaaaa, unsigned int x.unsigned int y,
int index, int resolution, int zoom);
virtual int XXXXXXXXXXXXX(int *attrasdasdasd, char *outstr,
unsigned char mode, unsigned int minlen, unsigned int maxlen);
AlignAfterOpenBracket: DontAlign
where clang-format
will move all parameters to the next line. You may be seeing one of those cases, and I don't believe there is any good workaround for this. Because of this, you may want to use AlignAfterOpenBrackets: Align
(which is the default for Google style). This doesn't exactly match your Eclipse example, but it is reasonably close most of the time. For example, the command clang-format -style='{BasedOnStyle: Google}'
gives:
virtual int* XXXXXXXXXXXXX(int* parentaaaa, unsigned int x.unsigned int y,
int index, int resolution, int zoom);
virtual int XXXXXXXXXXXXX(int* attrasdasdasd, char* outstr,
unsigned char mode, unsigned int minlen,
unsigned int maxlen);
eclipse
example (the first example in your question) has the continuation lines indented further. To exactly match that, you would use ContinuationIndentWidth: 8
. So the command clang-format -style='{BasedOnStyle: Google,AlignAfterOpenBracket: DontAlign, ContinuationIndentWidth: 8}'
gives:
virtual int *XXXXXXXXXXXXX(int *parentaaaa, unsigned int x.unsigned int y,
int index, int resolution, int zoom);
virtual int XXXXXXXXXXXXX(int *attrasdasdasd, char *outstr,
unsigned char mode, unsigned int minlen, unsigned int maxlen);
clang-format
, is the configurator.Upvotes: 2