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 expressions in -nl...



details:   https://anonhg.NetBSD.org/src/rev/49dca9eabba0
branches:  trunk
changeset: 375346:49dca9eabba0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon May 15 12:59:43 2023 +0000

description:
indent: fix indentation of expressions in -nlp -eei mode

diffstat:

 tests/usr.bin/indent/opt_eei.c |  17 ++++++-----------
 usr.bin/indent/indent.c        |  10 ++++++++--
 usr.bin/indent/indent.h        |   4 +++-
 usr.bin/indent/io.c            |   7 +++++--
 4 files changed, 22 insertions(+), 16 deletions(-)

diffs (121 lines):

diff -r 36235c4ce87f -r 49dca9eabba0 tests/usr.bin/indent/opt_eei.c
--- a/tests/usr.bin/indent/opt_eei.c    Mon May 15 12:11:07 2023 +0000
+++ b/tests/usr.bin/indent/opt_eei.c    Mon May 15 12:59:43 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_eei.c,v 1.9 2023/05/15 12:11:07 rillig Exp $ */
+/* $NetBSD: opt_eei.c,v 1.10 2023/05/15 12:59:43 rillig Exp $ */
 
 /*
  * Tests for the options '-eei' and '-neei'.
@@ -127,22 +127,17 @@ b)
 //indent run -eei -i4 -nlp
 {
     if (a <
-/* $ FIXME: Needs extra indentation. */
-       b)
+           b)
        stmt();
     if (a
-/* $ FIXME: Needs extra indentation. */
-       <
-/* $ FIXME: Needs extra indentation. */
-       b)
+           <
+           b)
        stmt();
     while (a
-/* $ FIXME: Needs extra indentation. */
-       < b)
+           < b)
        stmt();
     switch (
-/* $ FIXME: Needs extra indentation. */
-       a)
+           a)
        stmt();
 }
 //indent end
diff -r 36235c4ce87f -r 49dca9eabba0 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Mon May 15 12:11:07 2023 +0000
+++ b/usr.bin/indent/indent.c   Mon May 15 12:59:43 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.274 2023/05/15 10:13:40 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.275 2023/05/15 12:59:43 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.274 2023/05/15 10:13:40 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.275 2023/05/15 12:59:43 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -348,6 +348,7 @@ maybe_break_line(lexer_symbol lsym)
        diag(0, "Line broken");
     output_line();
     ps.force_nl = false;
+    ps.extra_expr_indent = false;
 }
 
 static void
@@ -432,6 +433,11 @@ process_lparen_or_lbracket(void)
     debug_println("paren_indents[%d] is now %d",
        ps.nparen - 1, ps.paren[ps.nparen - 1].indent);
 
+    if (opt.extra_expr_indent && !opt.lineup_to_parens
+           && ps.spaced_expr_psym != psym_0 && ps.nparen == 1
+           && opt.continuation_indent == opt.indent_size)
+       ps.extra_expr_indent = true;
+
     if (opt.extra_expr_indent && ps.spaced_expr_psym != psym_0
            && ps.nparen == 1 && ps.paren[0].indent < 2 * opt.indent_size) {
        ps.paren[0].indent = (short)(2 * opt.indent_size);
diff -r 36235c4ce87f -r 49dca9eabba0 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Mon May 15 12:11:07 2023 +0000
+++ b/usr.bin/indent/indent.h   Mon May 15 12:59:43 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.137 2023/05/15 10:13:40 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.138 2023/05/15 12:59:43 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -308,6 +308,8 @@ extern struct parser_state {
     int di_stack[20];          /* a stack of structure indentation levels */
     bool tabs_to_var;          /* true if using tabs to indent to var name */
 
+    bool extra_expr_indent;
+
     enum {
        in_enum_no,             /* outside any 'enum { ... }' */
        in_enum_enum,           /* after keyword 'enum' */
diff -r 36235c4ce87f -r 49dca9eabba0 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Mon May 15 12:11:07 2023 +0000
+++ b/usr.bin/indent/io.c       Mon May 15 12:59:43 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.167 2023/05/15 08:11:27 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.168 2023/05/15 12:59:43 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.167 2023/05/15 08:11:27 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.168 2023/05/15 12:59:43 rillig Exp $");
 
 #include <stdio.h>
 #include <string.h>
@@ -338,6 +338,9 @@ compute_code_indent(void)
        return compute_code_indent_lineup(base_ind);
     }
 
+    if (ps.extra_expr_indent)
+       return base_ind + 2 * opt.continuation_indent;
+
     if (2 * opt.continuation_indent == opt.indent_size)
        return base_ind + opt.continuation_indent;
     else



Home | Main Index | Thread Index | Old Index