Module Name:    src
Committed By:   rillig
Date:           Thu Jun 15 10:34:12 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: lsym_tag.c
        src/usr.bin/indent: indent.c io.c

Log Message:
indent: fix indentation of multi-line enum constant initializers


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/lsym_tag.c
cvs rdiff -u -r1.369 -r1.370 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.222 -r1.223 src/usr.bin/indent/io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/indent/lsym_tag.c
diff -u src/tests/usr.bin/indent/lsym_tag.c:1.8 src/tests/usr.bin/indent/lsym_tag.c:1.9
--- src/tests/usr.bin/indent/lsym_tag.c:1.8	Thu Jun 15 09:19:07 2023
+++ src/tests/usr.bin/indent/lsym_tag.c	Thu Jun 15 10:34:12 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_tag.c,v 1.8 2023/06/15 09:19:07 rillig Exp $ */
+/* $NetBSD: lsym_tag.c,v 1.9 2023/06/15 10:34:12 rillig Exp $ */
 
 /*
  * Tests for the token lsym_tag, which represents one of the keywords
@@ -142,12 +142,17 @@ struct outer {
  */
 //indent input
 enum multi_line {
-	constant = 1
-// $ TODO: Indent the continuation line.
-	+ 2
-// $ TODO: Indent the continuation line.
-	+ 3,
+	ml1 = 1
+	    + 2
+	    + offsetof(struct s, member)
+	    + 3,
+	ml2 = 1
+	    + 2
+	    + offsetof(struct s, member)
+	    + 3,
 };
 //indent end
 
-//indent run-equals-input
+//indent run-equals-input -ci4
+
+//indent run-equals-input -ci4 -nlp

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.369 src/usr.bin/indent/indent.c:1.370
--- src/usr.bin/indent/indent.c:1.369	Thu Jun 15 09:19:06 2023
+++ src/usr.bin/indent/indent.c	Thu Jun 15 10:34:12 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.369 2023/06/15 09:19:06 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.370 2023/06/15 10:34:12 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.369 2023/06/15 09:19:06 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.370 2023/06/15 10:34:12 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -562,6 +562,12 @@ process_newline(void)
 
 	output_line();
 
+	if (ps.psyms.len >= 2
+	    && ps.psyms.sym[ps.psyms.len - 2] == psym_lbrace_enum
+	    && ps.paren.len == 0
+	    && ps.prev_lsym == lsym_comma)
+		ps.in_stmt_cont = false;
+
 stay_in_line:
 	++line_no;
 }

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.222 src/usr.bin/indent/io.c:1.223
--- src/usr.bin/indent/io.c:1.222	Thu Jun 15 09:19:06 2023
+++ src/usr.bin/indent/io.c	Thu Jun 15 10:34:12 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.222 2023/06/15 09:19:06 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.223 2023/06/15 10:34:12 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.222 2023/06/15 09:19:06 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.223 2023/06/15 10:34:12 rillig Exp $");
 
 #include <stdio.h>
 
@@ -254,9 +254,6 @@ compute_code_indent(void)
 	int base_ind = ps.ind_level * opt.indent_size;
 
 	if (ps.ind_paren_level == 0) {
-		if (ps.psyms.len >= 2
-		    && ps.psyms.sym[ps.psyms.len - 2] == psym_lbrace_enum)
-			return base_ind;
 		if (ps.in_stmt_cont)
 			return base_ind + opt.continuation_indent;
 		return base_ind;

Reply via email to