pgindent vs variable declaration across multiple lines - Mailing list pgsql-hackers

From Andres Freund
Subject pgindent vs variable declaration across multiple lines
Date
Msg-id 20230120013137.7ky7nl4e4zjorrfa@awork3.anarazel.de
Whole thread Raw
Responses Re: pgindent vs variable declaration across multiple lines
Re: pgindent vs variable declaration across multiple lines
List 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



pgsql-hackers by date:

Previous
From: Jacob Champion
Date:
Subject: Re: Experiments with Postgres and SSL
Next
From: Tom Lane
Date:
Subject: Re: pgindent vs variable declaration across multiple lines