[PATCH] D49580: [WIP] Change clang-format to absolute indentation

Arnaud Coomans via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 19 17:26:37 PDT 2018


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$}}
+ at protocol A
+// CHECK: {{^\ \@optional$}}
+ @optional
+// CHECK: {{^//\ comment$}}
+// comment
+// CHECK: {{^-\ \(void\)f;$}}
+- (void)f;
+// CHECK: {{^\@end$}}
+ at 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 =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49580.156408.patch
Type: text/x-patch
Size: 1105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180720/1cf0f903/attachment.bin>


More information about the cfe-commits mailing list