pgindent vs variable declaration across multiple lines

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: pgindent vs variable declaration across multiple lines
Date: 2023-01-20 01:31:37
Message-ID: 20230120013137.7ky7nl4e4zjorrfa@awork3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

There's a few places in the code that try to format a variable definition like this

ReorderBufferChange *next_change =
dlist_container(ReorderBufferChange, node, next);

but pgindent turns that into

ReorderBufferChange *next_change =
dlist_container(ReorderBufferChange, node, next);

even though the same pattern works, and is used fairly widely for assignments

amroutine->amparallelvacuumoptions =
VACUUM_OPTION_PARALLEL_BULKDEL;

Particularly when variable and/or types names are longer, it's sometimes hard
to fit enough into one line to use a different style. E.g., the code I'm
currently hacking on has

RWConflict possibleUnsafeConflict = dlist_container(RWConflictData, inLink, iter.cur);

There's simply no way to make break that across lines that doesn't either
violate the line length limit or makes pgindent do odd things:

too long line:
RWConflict possibleUnsafeConflict = dlist_container(RWConflictData,
inLink,
iter.cur);

pgindent will move start of second line:
RWConflict possibleUnsafeConflict =
dlist_container(RWConflictData, inLink, iter.cur);

I know I can leave the variable initially uninitialized and then do a separate
assignment, but that's not a great fix. And sometimes other initializations
want to access the variable alrady.

Do others dislike this as well?

I assume we'd again have to dive into pg_bsd_indent's code to fix it :(

And even if we were to figure out how, would it be worth the
reindent-all-branches pain? I'd say yes, but...

Greetings,

Andres Freund

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2023-01-20 01:43:44 Re: pgindent vs variable declaration across multiple lines
Previous Message Jacob Champion 2023-01-20 01:28:18 Re: Experiments with Postgres and SSL