diff options
| author | rillig <rillig@NetBSD.org> | 2023-05-15 13:33:19 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-05-15 13:33:19 +0000 |
| commit | 5dd2ebe8f66efa8ed8ff6c8ba74fc38f7aead677 (patch) | |
| tree | 28af3fd3f7d53c37bdf1f61b0aea3999dcf1e249 | |
| parent | 66c71b93761af227bd520fd6c9597b39b8fcdfc3 (diff) | |
indent: fix indentation of statements after controlling expression
| -rw-r--r-- | tests/usr.bin/indent/opt_eei.c | 4 | ||||
| -rw-r--r-- | usr.bin/indent/indent.c | 9 | ||||
| -rw-r--r-- | usr.bin/indent/indent.h | 8 | ||||
| -rw-r--r-- | usr.bin/indent/io.c | 8 |
4 files changed, 18 insertions, 11 deletions
diff --git a/tests/usr.bin/indent/opt_eei.c b/tests/usr.bin/indent/opt_eei.c index cb04cf6b8d1..25458bc1922 100644 --- a/tests/usr.bin/indent/opt_eei.c +++ b/tests/usr.bin/indent/opt_eei.c @@ -1,4 +1,4 @@ -/* $NetBSD: opt_eei.c,v 1.11 2023/05/15 13:28:05 rillig Exp $ */ +/* $NetBSD: opt_eei.c,v 1.12 2023/05/15 13:33:19 rillig Exp $ */ /* * Tests for the options '-eei' and '-neei'. @@ -183,7 +183,7 @@ b) cond ) stmt( - arg + arg ); } //indent end diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c index cd9acdf2526..1757ab089cf 100644 --- a/usr.bin/indent/indent.c +++ b/usr.bin/indent/indent.c @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.275 2023/05/15 12:59:43 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.276 2023/05/15 13:33:19 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: indent.c,v 1.275 2023/05/15 12:59:43 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.276 2023/05/15 13:33:19 rillig Exp $"); #include <sys/param.h> #include <err.h> @@ -348,7 +348,6 @@ maybe_break_line(lexer_symbol lsym) diag(0, "Line broken"); output_line(); ps.force_nl = false; - ps.extra_expr_indent = false; } static void @@ -436,7 +435,7 @@ process_lparen_or_lbracket(void) 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; + ps.extra_expr_indent = eei_yes; if (opt.extra_expr_indent && ps.spaced_expr_psym != psym_0 && ps.nparen == 1 && ps.paren[0].indent < 2 * opt.indent_size) { @@ -484,6 +483,8 @@ unbalanced: buf_add_char(&code, token.st[0]); if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) { + if (ps.extra_expr_indent == eei_yes) + ps.extra_expr_indent = eei_last; ps.force_nl = true; ps.next_unary = true; ps.in_stmt_or_decl = false; diff --git a/usr.bin/indent/indent.h b/usr.bin/indent/indent.h index 82a1b54f22a..379d485f566 100644 --- a/usr.bin/indent/indent.h +++ b/usr.bin/indent/indent.h @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.138 2023/05/15 12:59:43 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.139 2023/05/15 13:33:19 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -308,7 +308,11 @@ 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 { + eei_no, + eei_yes, + eei_last + } extra_expr_indent; enum { in_enum_no, /* outside any 'enum { ... }' */ diff --git a/usr.bin/indent/io.c b/usr.bin/indent/io.c index 92a8e6b8ecc..a42fab39ff4 100644 --- a/usr.bin/indent/io.c +++ b/usr.bin/indent/io.c @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.168 2023/05/15 12:59:43 rillig Exp $ */ +/* $NetBSD: io.c,v 1.169 2023/05/15 13:33:19 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: io.c,v 1.168 2023/05/15 12:59:43 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.169 2023/05/15 13:33:19 rillig Exp $"); #include <stdio.h> #include <string.h> @@ -274,6 +274,8 @@ output_complete_line(char line_terminator) ps.decl_on_line = ps.in_decl; /* for proper comment indentation */ ps.in_stmt_cont = ps.in_stmt_or_decl && !ps.in_decl; ps.decl_indent_done = false; + if (ps.extra_expr_indent == eei_last) + ps.extra_expr_indent = eei_no; lab.len = 0; code.len = 0; @@ -338,7 +340,7 @@ compute_code_indent(void) return compute_code_indent_lineup(base_ind); } - if (ps.extra_expr_indent) + if (ps.extra_expr_indent != eei_no) return base_ind + 2 * opt.continuation_indent; if (2 * opt.continuation_indent == opt.indent_size) |
