diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -1913,6 +1913,9 @@ /// line. unsigned PenaltyReturnTypeOnItsOwnLine; + /// Penalty for whitespace indentation + unsigned PenaltyIndentedWhitespace; + /// The ``&`` and ``*`` alignment style. enum PointerAlignmentStyle { /// Align pointer to the left. diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -783,6 +783,22 @@ State.Column = getNewLineColumn(State); + // Add Penalty proportional to amount of whitespace away from FirstColumn + // This tends to penalize several lines that are far-right indented, + // and prefers a line-break prior to such a block, e.g: + // + // Constructor() : + // member(value), looooooooooooooooong_member( + // looooooooooong_call(param_1, param_2, param_3)) + // would then become + // Constructor() : + // member(value), + // looooooooooooooooong_member( + // looooooooooong_call(param_1, param_2, param_3)) + if (State.Column > State.FirstIndent) + Penalty += + Style.PenaltyIndentedWhitespace * (State.Column - State.FirstIndent); + // Indent nested blocks relative to this column, unless in a very specific // JavaScript special case where: // diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -597,6 +597,8 @@ IO.mapOptional("PenaltyExcessCharacter", Style.PenaltyExcessCharacter); IO.mapOptional("PenaltyReturnTypeOnItsOwnLine", Style.PenaltyReturnTypeOnItsOwnLine); + IO.mapOptional("PenaltyIndentedWhitespace", + Style.PenaltyIndentedWhitespace); IO.mapOptional("PointerAlignment", Style.PointerAlignment); IO.mapOptional("RawStringFormats", Style.RawStringFormats); IO.mapOptional("ReflowComments", Style.ReflowComments); @@ -975,6 +977,7 @@ LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60; LLVMStyle.PenaltyBreakBeforeFirstCallParameter = 19; LLVMStyle.PenaltyBreakTemplateDeclaration = prec::Relational; + LLVMStyle.PenaltyIndentedWhitespace = 0; LLVMStyle.DisableFormat = false; LLVMStyle.SortIncludes = true;