Alan Mackenzie avatar Alan Mackenzie committed 9f6a6b8

Improve indentation of bracelists defined by macros (without "=").
cc-engine.el (c-inside-bracelist-p): When a macro expansion begins with
"{", regard it as bracelist when it doesn't contain a ";".
tests/macro-28.{c,res}: New test case.

Comments (0)

Files changed (1)

 	    ;; check for the class key here.
 	    (and (c-major-mode-is 'pike-mode)
 		 c-decl-block-key))
-	   bufpos braceassignp lim next-containing)
+	   bufpos braceassignp lim next-containing macro-start)
        (while (and (not bufpos)
 		   containing-sexp)
 	 (when paren-state
 	     (if (and (eq braceassignp 'dontknow)
 		      (/= (c-backward-token-2 1 t lim) 0))
 		 (setq braceassignp nil)))
-	   (if (not braceassignp)
-	       (if (eq (char-after) ?\;)
-		   ;; Brace lists can't contain a semicolon, so we're done.
-		   (setq containing-sexp nil)
-		 ;; Go up one level.
-		 (setq containing-sexp next-containing
-		       lim nil
-		       next-containing nil))
-	     ;; we've hit the beginning of the aggregate list
+	   (cond
+	    (braceassignp
+	     ;; We've hit the beginning of the aggregate list.
 	     (c-beginning-of-statement-1
 	      (c-most-enclosing-brace paren-state))
-	     (setq bufpos (point))))
-	 )
+	     (setq bufpos (point)))
+	    ((eq (char-after) ?\;)
+	     ;; Brace lists can't contain a semicolon, so we're done.
+	     (setq containing-sexp nil))
+	    ((and (setq macro-start (point))
+		  (c-forward-to-cpp-define-body)
+		  (eq (point) containing-sexp))
+	     ;; We've a macro whose expansion starts with the '{'.
+	     ;; Heuristically, if we have a ';' in it we've not got a
+	     ;; brace list, otherwise we have.
+	     (let ((macro-end (progn (c-end-of-macro) (point))))
+	       (goto-char containing-sexp)
+	       (forward-char)
+	       (if (and (c-syntactic-re-search-forward "[;,]" macro-end t t)
+			(eq (char-before) ?\;))
+		   (setq bufpos nil
+			 containing-sexp nil)
+		 (setq bufpos macro-start))))
+	    (t
+	     ;; Go up one level
+	     (setq containing-sexp next-containing
+		   lim nil
+		   next-containing nil)))))
+
        bufpos))
    ))
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.