Module Name:    src
Committed By:   rillig
Date:           Mon May 15 12:59:44 UTC 2023

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

Log Message:
indent: fix indentation of expressions in -nlp -eei mode


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/opt_eei.c
cvs rdiff -u -r1.274 -r1.275 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.137 -r1.138 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.167 -r1.168 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/opt_eei.c
diff -u src/tests/usr.bin/indent/opt_eei.c:1.9 src/tests/usr.bin/indent/opt_eei.c:1.10
--- src/tests/usr.bin/indent/opt_eei.c:1.9	Mon May 15 12:11:07 2023
+++ src/tests/usr.bin/indent/opt_eei.c	Mon May 15 12:59:43 2023
@@ -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

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.274 src/usr.bin/indent/indent.c:1.275
--- src/usr.bin/indent/indent.c:1.274	Mon May 15 10:13:40 2023
+++ src/usr.bin/indent/indent.c	Mon May 15 12:59:43 2023
@@ -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);

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.137 src/usr.bin/indent/indent.h:1.138
--- src/usr.bin/indent/indent.h:1.137	Mon May 15 10:13:40 2023
+++ src/usr.bin/indent/indent.h	Mon May 15 12:59:43 2023
@@ -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' */

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.167 src/usr.bin/indent/io.c:1.168
--- src/usr.bin/indent/io.c:1.167	Mon May 15 08:11:27 2023
+++ src/usr.bin/indent/io.c	Mon May 15 12:59:43 2023
@@ -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

Reply via email to