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 adjacent '{'



details:   https://anonhg.NetBSD.org/src/rev/1cea1107a5b9
branches:  trunk
changeset: 376189:1cea1107a5b9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 03 21:44:08 2023 +0000

description:
indent: fix indentation of adjacent '{'

diffstat:

 tests/usr.bin/indent/indent_off_on.c |   6 +++---
 tests/usr.bin/indent/lsym_lbrace.c   |  11 ++++++-----
 tests/usr.bin/indent/lsym_rbrace.c   |  11 ++++++-----
 usr.bin/indent/indent.c              |   7 ++++---
 4 files changed, 19 insertions(+), 16 deletions(-)

diffs (100 lines):

diff -r 8acd8d86bd52 -r 1cea1107a5b9 tests/usr.bin/indent/indent_off_on.c
--- a/tests/usr.bin/indent/indent_off_on.c      Sat Jun 03 21:33:25 2023 +0000
+++ b/tests/usr.bin/indent/indent_off_on.c      Sat Jun 03 21:44:08 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent_off_on.c,v 1.13 2023/05/21 10:18:44 rillig Exp $ */
+/* $NetBSD: indent_off_on.c,v 1.14 2023/06/03 21:44:08 rillig Exp $ */
 
 /*
  * Tests for the comments 'INDENT OFF' and 'INDENT ON', which temporarily
@@ -134,8 +134,8 @@ int format( void ) {{{
 /* No formatting takes place here. */
 int format( void ) {{{
 /*INDENT ON*/
-}
-}
+               }
+       }
 }
 //indent end
 
diff -r 8acd8d86bd52 -r 1cea1107a5b9 tests/usr.bin/indent/lsym_lbrace.c
--- a/tests/usr.bin/indent/lsym_lbrace.c        Sat Jun 03 21:33:25 2023 +0000
+++ b/tests/usr.bin/indent/lsym_lbrace.c        Sat Jun 03 21:44:08 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lbrace.c,v 1.6 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: lsym_lbrace.c,v 1.7 2023/06/03 21:44:08 rillig Exp $ */
 
 /*
  * Tests for the token lsym_lbrace, which represents a '{' in these contexts:
@@ -40,11 +40,12 @@ void function(void) {{{ body(); }}}
 //indent run
 void
 function(void)
-/* $ FIXME: Each '{' must be properly indented. */
-{{{
+{
+       {
+               {
                        body();
-}
-}
+               }
+       }
 }
 //indent end
 
diff -r 8acd8d86bd52 -r 1cea1107a5b9 tests/usr.bin/indent/lsym_rbrace.c
--- a/tests/usr.bin/indent/lsym_rbrace.c        Sat Jun 03 21:33:25 2023 +0000
+++ b/tests/usr.bin/indent/lsym_rbrace.c        Sat Jun 03 21:44:08 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_rbrace.c,v 1.4 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: lsym_rbrace.c,v 1.5 2023/06/03 21:44:08 rillig Exp $ */
 
 /*
  * Tests for the token lsym_rbrace, which represents a '}' in these contexts:
@@ -43,11 +43,12 @@ void function(void) {{{ body(); }}}
 //indent run
 void
 function(void)
-/* $ FIXME: Each '{' must be properly indented. */
-{{{
+{
+       {
+               {
                        body();
-}
-}
+               }
+       }
 }
 //indent end
 
diff -r 8acd8d86bd52 -r 1cea1107a5b9 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Jun 03 21:33:25 2023 +0000
+++ b/usr.bin/indent/indent.c   Sat Jun 03 21:44:08 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.316 2023/06/03 21:24:26 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.317 2023/06/03 21:44:08 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.316 2023/06/03 21:24:26 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.317 2023/06/03 21:44:08 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -425,7 +425,8 @@ maybe_break_line(lexer_symbol lsym)
                return;
        if (lsym == lsym_semicolon)
                return;
-       if (lsym == lsym_lbrace && opt.brace_same_line)
+       if (lsym == lsym_lbrace && opt.brace_same_line
+           && ps.prev_token != lsym_lbrace)
                return;
 
        if (opt.verbose)



Home | Main Index | Thread Index | Old Index