Module Name:    src
Committed By:   rillig
Date:           Sat Oct 30 11:37:38 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/usr.bin/indent/indent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.185 src/usr.bin/indent/indent.c:1.186
--- src/usr.bin/indent/indent.c:1.185	Sat Oct 30 11:10:36 2021
+++ src/usr.bin/indent/indent.c	Sat Oct 30 11:37:38 2021
@@ -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 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #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 @@ process_comma(int decl_ind, bool tabs_to
     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;
     }
 }

Reply via email to