acoomans created this revision. Herald added a subscriber: cfe-commits. When running clang-format on specific lines, two types of indentation could be expectedi:
- absolute indentation: the indentation one would get if the whole file were formatted; or - relative indentation: keep the indentation relative to the previous lines, even if those are not indented correctly (i.e. would be indented differently if the whole file was formatted) and are not in the range of lines to format clang-format does relative indentation. This diff is a proposal to change to absolute indentation -- WIP existing tests would need to be fixed if we're ok with this diff Repository: rC Clang https://reviews.llvm.org/D49580 Files: lib/Format/UnwrappedLineFormatter.cpp test/Format/line-ranges-indent.cpp Index: test/Format/line-ranges-indent.cpp =================================================================== --- /dev/null +++ test/Format/line-ranges-indent.cpp @@ -0,0 +1,13 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s \ +// RUN: | clang-format -style=LLVM -lines=3:3 \ +// RUN: | FileCheck -strict-whitespace %s +// CHECK: {{^\@protocol\ A$}} +@protocol A +// CHECK: {{^\ \@optional$}} + @optional +// CHECK: {{^//\ comment$}} +// comment +// CHECK: {{^-\ \(void\)f;$}} +- (void)f; +// CHECK: {{^\@end$}} +@end Index: lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -1092,7 +1092,7 @@ // unless the current \c AnnotatedLine is not at the beginning of a line. bool StartsNewLine = TheLine.First->NewlinesBefore > 0 || TheLine.First->IsFirst; - if (StartsNewLine) + if (TheLine.Affected && StartsNewLine) IndentTracker.adjustToUnmodifiedLine(TheLine); if (!DryRun) { bool ReformatLeadingWhitespace =
Index: test/Format/line-ranges-indent.cpp =================================================================== --- /dev/null +++ test/Format/line-ranges-indent.cpp @@ -0,0 +1,13 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s \ +// RUN: | clang-format -style=LLVM -lines=3:3 \ +// RUN: | FileCheck -strict-whitespace %s +// CHECK: {{^\@protocol\ A$}} +@protocol A +// CHECK: {{^\ \@optional$}} + @optional +// CHECK: {{^//\ comment$}} +// comment +// CHECK: {{^-\ \(void\)f;$}} +- (void)f; +// CHECK: {{^\@end$}} +@end Index: lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -1092,7 +1092,7 @@ // unless the current \c AnnotatedLine is not at the beginning of a line. bool StartsNewLine = TheLine.First->NewlinesBefore > 0 || TheLine.First->IsFirst; - if (StartsNewLine) + if (TheLine.Affected && StartsNewLine) IndentTracker.adjustToUnmodifiedLine(TheLine); if (!DryRun) { bool ReformatLeadingWhitespace =
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits