Module Name:    src
Committed By:   rillig
Date:           Thu Jun  8 20:55:22 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: lsym_lparen_or_lbracket.c
        src/usr.bin/indent: indent.c

Log Message:
indent: fix indentation of initializer lists with designators


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c
cvs rdiff -u -r1.339 -r1.340 src/usr.bin/indent/indent.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_lparen_or_lbracket.c
diff -u src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.14 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.15
--- src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.14	Thu Jun  8 20:49:04 2023
+++ src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c	Thu Jun  8 20:55:22 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.14 2023/06/08 20:49:04 rillig Exp $ */
+/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.15 2023/06/08 20:55:22 rillig Exp $ */
 
 /*
  * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '['
@@ -338,6 +338,10 @@ cover_want_blank_before_lparen(void)
 /* See t_errors.sh, test case 'compound_literal'. */
 
 
+/*
+ * Ensure that a designated initializer after a comma is not indented further
+ * than necessary, as in most other contexts, there is no space before a '['.
+ */
 //indent input
 int arr[] = {
 ['0'] = 1,
@@ -348,7 +352,6 @@ int arr[] = {
 //indent run -di0
 int arr[] = {
 	['0'] = 1,
-// $ FIXME: 1 space extra indentation.
-	 ['1'] = 2,
+	['1'] = 2,
 };
 //indent end

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.339 src/usr.bin/indent/indent.c:1.340
--- src/usr.bin/indent/indent.c:1.339	Thu Jun  8 06:47:13 2023
+++ src/usr.bin/indent/indent.c	Thu Jun  8 20:55:22 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.339 2023/06/08 06:47:13 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.340 2023/06/08 20:55:22 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.339 2023/06/08 06:47:13 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.340 2023/06/08 20:55:22 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -513,7 +513,8 @@ process_lbracket(void)
 		ps.nparen--;
 	}
 
-	if (ps.prev_lsym == lsym_comma || ps.prev_lsym == lsym_binary_op)
+	if (code.len > 0
+	    && (ps.prev_lsym == lsym_comma || ps.prev_lsym == lsym_binary_op))
 		buf_add_char(&code, ' ');
 	ps.want_blank = false;
 	buf_add_char(&code, token.s[0]);

Reply via email to