[PATCH] Add option to disable alignment after opening bracket

Daniel Jasper djasper at google.com
Tue Nov 18 01:43:08 PST 2014


================
Comment at: include/clang/Format/Format.h:233
@@ +232,3 @@
+  ///
+  /// This will result in formattings like
+  /// \code
----------------
Maybe add: "This applies to round brackets (parentheses), angle brackets and square brackets."

================
Comment at: lib/Format/ContinuationIndenter.cpp:304-306
@@ -303,2 +303,5 @@
   if (Previous.opensScope() && Previous.Type != TT_ObjCMethodExpr &&
+      !(!Style.AlignAfterOpenBracket && Previous.is(tok::l_paren) &&
+        Previous.getPreviousNonComment() &&
+        Previous.getPreviousNonComment()->Type == TT_FunctionDeclarationName) &&
       (Current.Type != TT_LineComment || Previous.BlockKind == BK_BracedInit))
----------------
If we apply to all brackets, then this should mostly just go away, right?

Also, generally try to add at least one test for the different cases handled here. Just removing everything but "Style.AlignAfterOpenABracket" doesn't break any tests.

================
Comment at: lib/Format/ContinuationIndenter.cpp:741-757
@@ -737,5 +740,19 @@
 
-    // Indent from 'LastSpace' unless this the fake parentheses encapsulating a
-    // builder type call after 'return'. If such a call is line-wrapped, we
-    // commonly just want to indent from the start of the line.
+    bool PreviousIsFunctionDeclParen =
+        Previous && Previous->is(tok::l_paren) &&
+        Previous->getPreviousNonComment() &&
+        Previous->getPreviousNonComment()->Type == TT_FunctionDeclarationName &&
+        *I == prec::Comma;
+
+    // We can disable alignment after an open bracket by not allowing line
+    // breaks within a scope unless we broke immediately after the scope opener.
+    if (!Style.AlignAfterOpenBracket && Previous && Previous->opensScope() &&
+        !PreviousIsFunctionDeclParen && !Newline && canBreak(State))
+      NewParenState.NoLineBreak = true;
+
+    // Indent from 'LastSpace' unless this is the fake parenthesis encapsulating
+    // a builder type call after 'return' or, if the alignment after opening
+    // brackets is disabled, a left paren of a method declaration argument list.
+    // If such a call is line-wrapped, we commonly just want to indent from the
+    // start of the line.
     if (!Current.isTrailingComment() &&
----------------
I think most of this can go away if we really want to disable alignment for all parentheses.

http://reviews.llvm.org/D6297






More information about the cfe-commits mailing list