Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent indent: fix indentation of initializer lists ...
details: https://anonhg.NetBSD.org/src/rev/eeb0b0f274c2
branches: trunk
changeset: 376272:eeb0b0f274c2
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Jun 08 20:55:22 2023 +0000
description:
indent: fix indentation of initializer lists with designators
diffstat:
tests/usr.bin/indent/lsym_lparen_or_lbracket.c | 9 ++++++---
usr.bin/indent/indent.c | 7 ++++---
2 files changed, 10 insertions(+), 6 deletions(-)
diffs (57 lines):
diff -r b29e86bcc830 -r eeb0b0f274c2 tests/usr.bin/indent/lsym_lparen_or_lbracket.c
--- a/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Thu Jun 08 20:49:04 2023 +0000
+++ b/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Thu Jun 08 20:55:22 2023 +0000
@@ -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
diff -r b29e86bcc830 -r eeb0b0f274c2 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Thu Jun 08 20:49:04 2023 +0000
+++ b/usr.bin/indent/indent.c Thu Jun 08 20:55:22 2023 +0000
@@ -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]);
Home |
Main Index |
Thread Index |
Old Index