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: remove blank between comment and pare...
details: https://anonhg.NetBSD.org/src/rev/fbd109f4c3f0
branches: trunk
changeset: 375384:fbd109f4c3f0
user: rillig <rillig%NetBSD.org@localhost>
date: Tue May 16 08:22:11 2023 +0000
description:
indent: remove blank between comment and parentheses or brackets
Finally, indent formats its own source code without messing up the
layout.
diffstat:
tests/usr.bin/indent/fmt_decl.c | 6 +++---
usr.bin/indent/indent.c | 23 +++++++++++++++++------
2 files changed, 20 insertions(+), 9 deletions(-)
diffs (82 lines):
diff -r 869ff6c1592b -r fbd109f4c3f0 tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c Tue May 16 08:04:03 2023 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c Tue May 16 08:22:11 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_decl.c,v 1.42 2023/05/15 21:51:46 rillig Exp $ */
+/* $NetBSD: fmt_decl.c,v 1.43 2023/05/16 08:22:11 rillig Exp $ */
/*
* Tests for declarations of global variables, external functions, and local
@@ -128,7 +128,7 @@ void t2 (char *x, int y)
,n
,o
;
- int chars[ /* push the comma beyond column 74 .... */ ], x;
+ int chars[ /* push the comma beyond column 74 ...... */ ], x;
}
//indent end
@@ -145,7 +145,7 @@ t2(char *x, int y)
,n
,o
;
- int chars[ /* push the comma beyond column 74 .... */ ],
+ int chars[/* push the comma beyond column 74 ...... */],
x;
}
//indent end
diff -r 869ff6c1592b -r fbd109f4c3f0 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Tue May 16 08:04:03 2023 +0000
+++ b/usr.bin/indent/indent.c Tue May 16 08:22:11 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.287 2023/05/16 08:04:03 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.288 2023/05/16 08:22:11 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.287 2023/05/16 08:04:03 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.288 2023/05/16 08:22:11 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -357,13 +357,24 @@ maybe_break_line(lexer_symbol lsym)
ps.force_nl = false;
}
+static bool
+want_blank_before_comment(void)
+{
+ if (code.len > 0) {
+ char ch = code.mem[code.len - 1];
+ return ch != '[' && ch != '(';
+ }
+ return lab.len > 0;
+}
+
static void
-move_com_to_code(void)
+move_com_to_code(lexer_symbol lsym)
{
- if (lab.len > 0 || code.len > 0)
+ if (want_blank_before_comment())
buf_add_char(&code, ' ');
buf_add_buf(&code, &com);
- buf_add_char(&code, ' ');
+ if (lsym != lsym_rparen_or_rbracket)
+ buf_add_char(&code, ' ');
com.len = 0;
ps.want_blank = false;
}
@@ -1022,7 +1033,7 @@ main_loop(void)
ps.in_stmt_or_decl = true; /* add an extra level of indentation;
* turned off again by a ';' or '}' */
if (com.len > 0)
- move_com_to_code();
+ move_com_to_code(lsym);
}
switch (lsym) {
Home |
Main Index |
Thread Index |
Old Index