Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

Clang-format struct initialization - indent with two spaces?

I'm trying to format a C file with clang-format. I want indentations to be two space characters, which mostly works except for in global variable struct initialization. For this, it continues to produce lines which are indented with four spaces.

Here is my .clang-format file

BasedOnStyle: LLVM
ColumnLimit: '80'
IndentWidth: '2'

clang-format produces this surprising output

typedef struct {
  int x;
} foo;

static foo bar{
    1, // This line is being indented with 4 spaces!
};

And this is what I'd expect the file to look like:

typedef struct {
  int x;
} foo;

static foo bar{
  1, // This line is being indented with 2 spaces!
};

I've tried using a few different values for ConstructorInitializerIndentWidth, but that field doesn't appear to affect this pattern.

Is there a setting that I could provide to get this behavior?

question from:https://stackoverflow.com/questions/65650849/clang-format-struct-initialization-indent-with-two-spaces

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try ContinuationIndentWidth: 2. That worked for me, when I had that problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...