Re: Emacs vs pg_indent's weird indentation for function declarations
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>,
Michael Paquier <michael@paquier.xyz>
Date: 2019-05-15T21:17:01Z
Lists: pgsql-hackers
Attachments
- bsdindent.patch (text/x-diff) patch
- indent-delta-results.patch.gz (application/x-gzip) patch
I wrote: > I experimented with fixing this. I was able to get pg_bsd_indent to > distinguish multi-line function declarations from definitions, but it > turns out that it doesn't help your concern about the lines being too > long after re-indenting. Contrary to what you imagine above, it seems > pg_bsd_indent will not reflow argument lists, regardless of whether it > thinks there needs to be more or less leading whitespace. Actually, now that I think about it, pgindent seldom revisits line-break decisions in code anyway; it's only aggressive about reflowing comments. So maybe we shouldn't be expecting it to fix this. Also, looking at sample results (attached), it seems like we don't have such a large problem as one might guess. It looks like people have mostly formatted declarations to work with this indentation already, either because their editors did it automatically, or because they were thinking that this might get fixed someday. (I know I've often had that in the back of my mind.) There are some places in the attached diff that I might take the trouble to clean up manually, but not that many. I found out that my initial draft of a multi-line lookahead function was not nearly smart enough to survive contact with the PG source corpus, but after rejiggering it to cope with comments and attributes, it seems to do quite well. A small problem with the "rejiggering" is that it now makes the wrong choice for K&R-style function definitions, causing them to be weirdly indented. For our purposes, that's a non-problem so I'm not excited about trying to make it smart enough to recognize those. We do have a couple of amazingly old and crufty K&R-style functions in src/port/, though, so probably we'd wish to fix those. Attached is working draft of pg_bsd_indent changes (still sans comments) as well as a patch showing the difference between current pgindent results on HEAD and the results of this version. I think there's no question that this is an improvement. regards, tom lane
Commits
-
Phase 2 pgindent run for v12.
- 8255c7a5eeba 12.0 landed
-
ANSI-ify a few straggler K&R-style function definitions.
- da71f98efba9 12.0 landed