On Fri, Jan 20, 2023 at 2:43 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Andres Freund <andres@anarazel.de> writes:
> > 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);
>
> Yeah, that's bugged me too. I suspect that the triggering factor is
> use of a typedef name within the assigned expression, but I've not
> tried to run it to ground.
>
> > I assume we'd again have to dive into pg_bsd_indent's code to fix it :(
>
> Yeah :-(. That's enough of a rat's nest that I've not really wanted to.
> But I'd support applying such a fix if someone can figure it out.
This may be a clue: the place where declarations are treated
differently seems to be (stangely) in io.c:
ps.ind_stmt = ps.in_stmt & ~ps.in_decl; /* next line should be
* indented if we have not
* completed this stmt and if
* we are not in the middle of
* a declaration */
If you just remove "& ~ps.in_decl" then it does the desired thing for
that new code in predicate.c, but it also interferes with declarations
with commas, ie int i, j; where i and j currently line up, now j just
gets one indentation level. It's probably not the right way to do it
but you can fix that with a last token kluge, something like:
#include "indent_codes.h"
ps.ind_stmt = ps.in_stmt && (!ps.in_decl || ps.last_token != comma);
That improves a lot of code in our tree IMHO but of course there is
other collateral damage...