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 multi-line enum co...



details:   https://anonhg.NetBSD.org/src/rev/10a52a5ba77f
branches:  trunk
changeset: 376391:10a52a5ba77f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jun 15 10:34:12 2023 +0000

description:
indent: fix indentation of multi-line enum constant initializers

diffstat:

 tests/usr.bin/indent/lsym_tag.c |  19 ++++++++++++-------
 usr.bin/indent/indent.c         |  10 ++++++++--
 usr.bin/indent/io.c             |   7 ++-----
 3 files changed, 22 insertions(+), 14 deletions(-)

diffs (92 lines):

diff -r 1df7b88a48a8 -r 10a52a5ba77f tests/usr.bin/indent/lsym_tag.c
--- a/tests/usr.bin/indent/lsym_tag.c   Thu Jun 15 09:19:06 2023 +0000
+++ b/tests/usr.bin/indent/lsym_tag.c   Thu Jun 15 10:34:12 2023 +0000
@@ -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
diff -r 1df7b88a48a8 -r 10a52a5ba77f usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Thu Jun 15 09:19:06 2023 +0000
+++ b/usr.bin/indent/indent.c   Thu Jun 15 10:34:12 2023 +0000
@@ -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;
 }
diff -r 1df7b88a48a8 -r 10a52a5ba77f usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Thu Jun 15 09:19:06 2023 +0000
+++ b/usr.bin/indent/io.c       Thu Jun 15 10:34:12 2023 +0000
@@ -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;



Home | Main Index | Thread Index | Old Index