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 in multi-line else-if...



details:   https://anonhg.NetBSD.org/src/rev/fa6522b36cad
branches:  trunk
changeset: 376270:fa6522b36cad
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jun 08 20:36:35 2023 +0000

description:
indent: fix indentation in multi-line else-if conditions

diffstat:

 tests/usr.bin/indent/opt_lp.c |  13 ++++++++-----
 usr.bin/indent/io.c           |   8 +++++---
 2 files changed, 13 insertions(+), 8 deletions(-)

diffs (70 lines):

diff -r 97555eaea49d -r fa6522b36cad tests/usr.bin/indent/opt_lp.c
--- a/tests/usr.bin/indent/opt_lp.c     Thu Jun 08 20:28:50 2023 +0000
+++ b/tests/usr.bin/indent/opt_lp.c     Thu Jun 08 20:36:35 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_lp.c,v 1.8 2023/06/08 20:28:50 rillig Exp $ */
+/* $NetBSD: opt_lp.c,v 1.9 2023/06/08 20:36:35 rillig Exp $ */
 
 /*
  * Tests for the options '-lp' and '-nlp'.
@@ -89,6 +89,11 @@ example(void)
 //indent end
 
 
+/*
+ * Ensure that in multi-line else-if conditions, all lines are indented by the
+ * correct amount.  The 'else if' condition is tricky because it has the same
+ * indentation as the preceding 'if' condition.
+ */
 //indent input
 {
 if (cond11a
@@ -121,8 +126,7 @@ stmt22;
            && cond11c) {
                stmt11;
        } else if (cond12a
-// $ FIXME: Wrong indentation, should be 4 spaces only.
-                   && cond12b
+           && cond12b
            && cond12c) {
                stmt12;
        }
@@ -134,8 +138,7 @@ stmt22;
            && cond21c)
                stmt21;
        else if (cond22a
-// $ FIXME: Wrong indentation, should be 4 spaces only.
-                   && cond22b
+           && cond22b
            && cond22c)
                stmt22;
 }
diff -r 97555eaea49d -r fa6522b36cad usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Thu Jun 08 20:28:50 2023 +0000
+++ b/usr.bin/indent/io.c       Thu Jun 08 20:36:35 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.203 2023/06/08 06:47:13 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.204 2023/06/08 20:36:35 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.203 2023/06/08 06:47:13 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.204 2023/06/08 20:36:35 rillig Exp $");
 
 #include <stdio.h>
 
@@ -378,7 +378,9 @@ prepare_next_line:
        ps.decl_indent_done = false;
        if (ps.extra_expr_indent == eei_last)
                ps.extra_expr_indent = eei_no;
-       ps.ind_level = ps.ind_level_follow;
+       if (!(ps.psyms.sym[ps.psyms.top] == psym_if_expr_stmt_else
+           && ps.nparen > 0))
+               ps.ind_level = ps.ind_level_follow;
        ps.line_start_nparen = ps.nparen;
        ps.want_blank = false;
 



Home | Main Index | Thread Index | Old Index