From 35475d84c84c61224be1b2e086f1a4ef548ff79a Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Tue, 17 Feb 2026 09:04:01 +0100 Subject: [PATCH v5 1/2] Make pgindent add a space between comma and period Formatting of variadic functions and struct literals with named field used to be ugly due to pgindent treating period as always being binary operator for struct access, but after comma it has a different meaning. Also adds a new test case which tests the formatting of struct literals with named fields. --- src/tools/pg_bsd_indent/indent.c | 2 ++ src/tools/pg_bsd_indent/tests/struct.0 | 2 ++ src/tools/pg_bsd_indent/tests/struct.0.stdout | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/tools/pg_bsd_indent/indent.c b/src/tools/pg_bsd_indent/indent.c index 421592db928..58fa04293d9 100644 --- a/src/tools/pg_bsd_indent/indent.c +++ b/src/tools/pg_bsd_indent/indent.c @@ -1013,6 +1013,8 @@ check_type: case period: /* treat a period kind of like a binary * operation */ + if (ps.want_blank && ps.last_token == comma) + *e_code++ = ' '; *e_code++ = '.'; /* move the period into line */ ps.want_blank = false; /* dont put a blank after a period */ break; diff --git a/src/tools/pg_bsd_indent/tests/struct.0 b/src/tools/pg_bsd_indent/tests/struct.0 index 83142bfb197..6f65e461331 100644 --- a/src/tools/pg_bsd_indent/tests/struct.0 +++ b/src/tools/pg_bsd_indent/tests/struct.0 @@ -19,3 +19,5 @@ void u(struct x a) { int b; struct y c = (struct y *)&a; } + +static struct foo f = { .a = 1,.b=2 }; diff --git a/src/tools/pg_bsd_indent/tests/struct.0.stdout b/src/tools/pg_bsd_indent/tests/struct.0.stdout index 38613128654..69e321ca05f 100644 --- a/src/tools/pg_bsd_indent/tests/struct.0.stdout +++ b/src/tools/pg_bsd_indent/tests/struct.0.stdout @@ -21,3 +21,5 @@ u(struct x a) int b; struct y c = (struct y *)&a; } + +static struct foo f = {.a = 1, .b = 2}; -- 2.47.3