diff options
| author | rillig <rillig@NetBSD.org> | 2023-06-10 18:46:42 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-06-10 18:46:42 +0000 |
| commit | a220cfbaefe1f97cd83fab8a158b6bb5502b330c (patch) | |
| tree | 93bafe1485fdcb366ebc7440f07283c00e0916c1 /usr.bin/indent | |
| parent | e9ab7102fd7aff1f39b396d6564f79f5451e3d50 (diff) | |
indent: fix line break between semicolon and brace
Diffstat (limited to 'usr.bin/indent')
| -rw-r--r-- | usr.bin/indent/debug.c | 6 | ||||
| -rw-r--r-- | usr.bin/indent/indent.c | 28 |
2 files changed, 17 insertions, 17 deletions
diff --git a/usr.bin/indent/debug.c b/usr.bin/indent/debug.c index dfb2a7fcf2f..564c6d5b588 100644 --- a/usr.bin/indent/debug.c +++ b/usr.bin/indent/debug.c @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.50 2023/06/10 16:43:55 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.51 2023/06/10 18:46:42 rillig Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: debug.c,v 1.50 2023/06/10 16:43:55 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.51 2023/06/10 18:46:42 rillig Exp $"); #include <stdarg.h> #include <string.h> @@ -395,6 +395,6 @@ debug_psyms_stack(const char *situation) for (int i = 0; i <= psyms->top; ++i) debug_printf(" %d %s", psyms->ind_level[i], psym_name[psyms->sym[i]]); - debug_blank_line(); + debug_println(""); } #endif diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c index 05636d596ff..c4f0205c14c 100644 --- a/usr.bin/indent/indent.c +++ b/usr.bin/indent/indent.c @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.354 2023/06/10 16:43:55 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.355 2023/06/10 18:46:42 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: indent.c,v 1.354 2023/06/10 16:43:55 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.355 2023/06/10 18:46:42 rillig Exp $"); #include <sys/param.h> #include <err.h> @@ -314,19 +314,16 @@ set_initial_indentation(void) ps.ind_level = ps.ind_level_follow = ind / opt.indent_size; } -static void -maybe_break_line(lexer_symbol lsym) +static bool +should_break_line(lexer_symbol lsym) { - if (!ps.force_nl) - return; if (lsym == lsym_semicolon) - return; - if (lsym == lsym_lbrace && opt.brace_same_line - && ps.prev_lsym != lsym_lbrace) - return; - - output_line(); - ps.force_nl = false; + return false; + if (ps.prev_lsym == lsym_lbrace || ps.prev_lsym == lsym_semicolon) + return true; + if (lsym == lsym_lbrace && opt.brace_same_line) + return false; + return true; } static void @@ -1051,7 +1048,10 @@ indent(void) else if (lsym == lsym_comment) { /* no special processing */ } else { - maybe_break_line(lsym); + if (ps.force_nl && should_break_line(lsym)) { + ps.force_nl = false; + output_line(); + } ps.in_stmt_or_decl = true; if (com.len > 0) move_com_to_code(lsym); |
