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: make compute_code_indent more readable



details:   https://anonhg.NetBSD.org/src/rev/4e11f81eb630
branches:  trunk
changeset: 1019545:4e11f81eb630
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Mar 14 01:44:37 2021 +0000

description:
indent: make compute_code_indent more readable

The '?:' operator computing the factor was too hard to read.  When
quickly scanning the code, the 1 in the expression looked too much like
it would be added to the indentation, which would turn the indentation
length into a column number, and that again would smell like an
off-by-one error.

No functional change.

diffstat:

 usr.bin/indent/io.c |  10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diffs (31 lines):

diff -r 636fe2675311 -r 4e11f81eb630 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sun Mar 14 01:34:13 2021 +0000
+++ b/usr.bin/indent/io.c       Sun Mar 14 01:44:37 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.48 2021/03/14 00:22:16 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.49 2021/03/14 01:44:37 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.48 2021/03/14 00:22:16 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.49 2021/03/14 01:44:37 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -291,8 +291,10 @@
 
     if (ps.paren_level != 0) {
        if (!opt.lineup_to_parens)
-           target_ind += opt.continuation_indent *
-               (2 * opt.continuation_indent == opt.indent_size ? 1 : ps.paren_level);
+           if (2 * opt.continuation_indent == opt.indent_size)
+               target_ind += opt.continuation_indent;
+           else
+               target_ind += opt.continuation_indent * ps.paren_level;
        else if (opt.lineup_to_parens_always)
            /*
             * XXX: where does this '- 1' come from?  It looks strange but is



Home | Main Index | Thread Index | Old Index