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: don't remove blank line after 'if (ex...



details:   https://anonhg.NetBSD.org/src/rev/f39ddaaa8fd5
branches:  trunk
changeset: 376232:f39ddaaa8fd5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jun 05 12:01:33 2023 +0000

description:
indent: don't remove blank line after 'if (expr) {'

diffstat:

 tests/usr.bin/indent/opt_sob.c |  30 +++++++++++++++++++++++++++---
 usr.bin/indent/indent.c        |   9 +++++++--
 usr.bin/indent/io.c            |   7 +++----
 3 files changed, 37 insertions(+), 9 deletions(-)

diffs (122 lines):

diff -r 57bb72685c06 -r f39ddaaa8fd5 tests/usr.bin/indent/opt_sob.c
--- a/tests/usr.bin/indent/opt_sob.c    Mon Jun 05 11:59:12 2023 +0000
+++ b/tests/usr.bin/indent/opt_sob.c    Mon Jun 05 12:01:33 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_sob.c,v 1.9 2023/06/02 13:59:33 rillig Exp $ */
+/* $NetBSD: opt_sob.c,v 1.10 2023/06/05 12:01:34 rillig Exp $ */
 
 /*
  * Tests for the options '-sob' and '-nsob'.
@@ -115,8 +115,8 @@ function_with_1_blank_line(void)
                var--;
 
        if (var > 0) {
+
                var--;
-// $ XXX: The following blank line may be considered optional.
 
        }
 
@@ -137,8 +137,8 @@ function_with_2_blank_lines(void)
                var--;
 
        if (var > 0) {
+
                var--;
-// $ XXX: The following blank line may be considered optional.
 
        }
 
@@ -148,3 +148,27 @@ function_with_2_blank_lines(void)
 //indent end
 
 //indent run-equals-input -nsob
+
+
+//indent input
+{
+       switch (expr) {
+
+       case 1:
+
+       }
+}
+//indent end
+
+//indent run-equals-input -sob
+
+//indent run -sob -bl
+{
+       switch (expr)
+       {
+
+       case 1:
+
+       }
+}
+//indent end
diff -r 57bb72685c06 -r f39ddaaa8fd5 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Mon Jun 05 11:59:12 2023 +0000
+++ b/usr.bin/indent/indent.c   Mon Jun 05 12:01:33 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.333 2023/06/05 10:12:21 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.334 2023/06/05 12:01:33 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.333 2023/06/05 10:12:21 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.334 2023/06/05 12:01:33 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -682,6 +682,8 @@ process_colon_other(void)
 static void
 process_semicolon(void)
 {
+       if (out.line_kind == lk_stmt_head)
+               out.line_kind = lk_other;
        if (ps.decl_level == 0)
                ps.init_or_struct = false;
        ps.seen_case = false;   /* only needs to be reset on error */
@@ -737,6 +739,9 @@ process_lbrace(void)
                ps.init_or_struct = true;
        }
 
+       if (out.line_kind == lk_stmt_head)
+               out.line_kind = lk_other;
+
        ps.in_stmt_or_decl = false;     /* don't indent the {} */
 
        if (!ps.block_init)
diff -r 57bb72685c06 -r f39ddaaa8fd5 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Mon Jun 05 11:59:12 2023 +0000
+++ b/usr.bin/indent/io.c       Mon Jun 05 12:01:33 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.196 2023/06/05 09:41:40 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.197 2023/06/05 12:01:33 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.196 2023/06/05 09:41:40 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.197 2023/06/05 12:01:33 rillig Exp $");
 
 #include <stdio.h>
 
@@ -169,8 +169,7 @@ want_blank_line(void)
 static bool
 is_blank_line_optional(void)
 {
-       if (out.prev_line_kind == lk_stmt_head
-           && ps.prev_lsym != lsym_semicolon)
+       if (out.prev_line_kind == lk_stmt_head)
                return wrote_newlines >= 1;
        if (ps.tos >= 2)
                return wrote_newlines >= 2;



Home | Main Index | Thread Index | Old Index