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: replace tabsize with hardcoded 8 in p...



details:   https://anonhg.NetBSD.org/src/rev/9443c2526f3f
branches:  trunk
changeset: 1024646:9443c2526f3f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 30 11:37:38 2021 +0000

description:
indent: replace tabsize with hardcoded 8 in process_comma

On 2018-07-25, FreeBSD added the option '-ts' to make the tabulator size
configurable, replacing several constants 7, 8, 9 with tabsize. The 8 in
the expression 'max_col - 8' was not related to the tabulator size but
instead represents the typical width of a variable name. Subtracting a
tab from the right margin doesn't make sense since the right margin need
not be aligned on a tabstop.

See the test fmt_decl.c, where the declaration 'struct s0 a,b;' is split
into several lines because the estimate for the variable name following
the comma is too high. There would have been plenty of space to the
right to keep the whole declaration in a single line.

No functional change.

diffstat:

 usr.bin/indent/indent.c |  8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diffs (31 lines):

diff -r 28dce58dcb87 -r 9443c2526f3f usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Oct 30 11:37:18 2021 +0000
+++ b/usr.bin/indent/indent.c   Sat Oct 30 11:37:38 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.185 2021/10/30 11:10:36 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.186 2021/10/30 11:37:38 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.185 2021/10/30 11:10:36 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.186 2021/10/30 11:37:38 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -1169,9 +1169,11 @@
     if (ps.p_l_follow == 0) {
        if (ps.block_init_level <= 0)
            ps.block_init = false;
+       int varname_len = 8;    /* rough estimate for the length of a typical
+                                * variable name */
        if (break_comma && (opt.break_after_comma ||
                indentation_after_range(compute_code_indent(), code.s, code.e)
-               >= opt.max_line_length - opt.tabsize))
+               >= opt.max_line_length - varname_len))
            *force_nl = true;
     }
 }



Home | Main Index | Thread Index | Old Index