Fri Jun 9 06:36:58 2023 UTC ()
indent: indent multi-line expressions according to parentheses
This reverts the FreeBSD change from 2004-02-12 that had been imported
on 2019-04-04.
(rillig)
diff -r1.9 -r1.10 src/tests/usr.bin/indent/opt_ci.c
diff -r1.9 -r1.10 src/tests/usr.bin/indent/opt_lp.c
diff -r1.32 -r1.33 src/usr.bin/indent/indent.1
diff -r1.204 -r1.205 src/usr.bin/indent/io.c
--- src/tests/usr.bin/indent/opt_ci.c 2023/05/18 05:33:27 1.9
+++ src/tests/usr.bin/indent/opt_ci.c 2023/06/09 06:36:58 1.10
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_ci.c,v 1.9 2023/05/18 05:33:27 rillig Exp $ */
+/* $NetBSD: opt_ci.c,v 1.10 2023/06/09 06:36:58 rillig Exp $ */
/*
* Tests for the option '-ci', which controls the indentation of continuation
@@ -47,17 +47,18 @@
//indent end
/*
- * Since '-ci4' is half an indentation level, indent all continuations using
- * the same level, no matter how many parentheses there are. The rationale for
- * this may have been to prevent that the continuation line has the same
- * indentation as a follow-up statement, such as in 'if' statements.
+ * Between 2019-04-04 and 2023-06-09, there was a special rule that prevented
+ * indentation based on the number of open parentheses, in the case that the
+ * continuation indentation is half an indentation level, maybe to prevent that
+ * the continuation line has the same indentation as a follow-up statement,
+ * such as in 'if' statements. To prevent such ambiguities, see '-eei'.
*/
//indent run -ci4 -nlp
int top_level = 1 +
2;
int top_level = (1 +
2 + (
- 3));
+ 3));
//indent end
@@ -165,12 +166,6 @@
}
//indent end
-/*
- * Since '-ci4' is half an indentation level, indent all continuations using
- * the same level, no matter how many parentheses there are. The rationale for
- * this may have been to prevent that the continuation line has the same
- * indentation as a follow-up statement, such as in 'if' statements.
- */
//indent run -ci4 -nlp
int
sum(int a, int b)
@@ -179,7 +174,7 @@
b);
return (first +
second + (
- third));
+ third));
}
//indent end
--- src/tests/usr.bin/indent/opt_lp.c 2023/06/08 20:36:35 1.9
+++ src/tests/usr.bin/indent/opt_lp.c 2023/06/09 06:36:58 1.10
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_lp.c,v 1.9 2023/06/08 20:36:35 rillig Exp $ */
+/* $NetBSD: opt_lp.c,v 1.10 2023/06/09 06:36:58 rillig Exp $ */
/*
* Tests for the options '-lp' and '-nlp'.
@@ -66,10 +66,6 @@
}
//indent end
-/*
- * XXX: Combining the options '-nlp' and '-ci4' is counterproductive as the
- * indentation does not make the nesting level of the function calls visible.
- */
//indent run -nlp -ci4
void
example(void)
@@ -78,9 +74,9 @@
third_procedure(p4, p5));
p1 = first_procedure(second_procedure(p2,
- p3),
+ p3),
third_procedure(p4,
- p5));
+ p5));
p1 = first_procedure(
second_procedure(p2, p3),
--- src/usr.bin/indent/indent.1 2023/06/05 10:12:21 1.32
+++ src/usr.bin/indent/indent.1 2023/06/09 06:36:57 1.33
@@ -1,4 +1,4 @@
-.\" $NetBSD: indent.1,v 1.32 2023/06/05 10:12:21 rillig Exp $
+.\" $NetBSD: indent.1,v 1.33 2023/06/09 06:36:57 rillig Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -32,7 +32,7 @@
.\" @(#)indent.1 8.1 (Berkeley) 7/1/93
.\" $FreeBSD: head/usr.bin/indent/indent.1 334944 2018-06-11 05:35:57Z pstef $
.\"
-.Dd June 5, 2023
+.Dd June 9, 2023
.Dt INDENT 1
.Os
.Sh NAME
@@ -246,8 +246,7 @@
Parenthesized expressions have extra indentation added to
indicate the nesting, unless
.Fl \&lp
-is in effect
-or the continuation indent is exactly half of the main indent.
+is in effect.
.Fl \&ci
defaults to the same value as
.Fl i .
--- src/usr.bin/indent/io.c 2023/06/08 20:36:35 1.204
+++ src/usr.bin/indent/io.c 2023/06/09 06:36:57 1.205
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.204 2023/06/08 20:36:35 rillig Exp $ */
+/* $NetBSD: io.c,v 1.205 2023/06/09 06:36:57 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.204 2023/06/08 20:36:35 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.205 2023/06/09 06:36:57 rillig Exp $");
#include <stdio.h>
@@ -252,11 +252,7 @@
if (ps.extra_expr_indent != eei_no)
return base_ind + 2 * opt.continuation_indent;
- if (2 * opt.continuation_indent == opt.indent_size)
- return base_ind + opt.continuation_indent;
- else
- return base_ind +
- opt.continuation_indent * ps.line_start_nparen;
+ return base_ind + opt.continuation_indent * ps.line_start_nparen;
}
static void