public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aleksander Alekseev <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Cc: Bruce Momjian <[email protected]>
Cc: Arseniy Mukhin <[email protected]>
Cc: Michael Paquier <[email protected]>
Subject: Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
Date: Fri, 20 Jun 2025 17:01:41 +0300
Message-ID: <CAJ7c6TOCJG2p0Ob9Z7mXQRhkmRX_mxBay198Z173t4=PZr=yEQ@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s+_V4=t+xgSnZm1cFw@mail.gmail.com>
	<CAE7r3MJ=CcWw65=C=tET32z5joixFqMDY_XhCxvjpLcOL3nVAQ@mail.gmail.com>
	<CAJ7c6TOp_h5Ueu8tPTnmponG84oFrm3D+zFWBwae-80do6o-rA@mail.gmail.com>
	<[email protected]>

Hi,

> Given the quality of BSD indent code, I have _always_ found it easier to
> modify pgindent.  ;-

:D Initially I thought that the problem was simple enough to solve it
in C, but this turned out not to be true.

> It's going to be simpler to modify pgindent then. PFA the updated patch.

I noticed a mistake in v2. Here is the corrected patch. Changes
comparing to the previous version:

```
-    $lines[-1] =~ s!/(.+)\*/!/$1\n \*/!;
+    $lines[-1] =~ s!(.+) \*/!$1\n \*/!;
```

-- 
Best regards,
Aleksander Alekseev


Attachments:

  [application/octet-stream] v3-0001-pgindent-improve-formatting-of-multiline-comments.patch (1.9K, 2-v3-0001-pgindent-improve-formatting-of-multiline-comments.patch)
  download | inline diff:
From 97bfd645a9313b8892d64fc9acc063d9e982e9d7 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <[email protected]>
Date: Fri, 20 Jun 2025 16:31:36 +0300
Subject: [PATCH v3] pgindent: improve formatting of multiline comments

Format multiline comments like this:

/* line 1
 * line 2
 */

... into:

/*
 * line 1
 * line 2
 */

This is more consistent with what we currently have in the tree.

Author: Aleksander Alekseev
Reported-by: Michael Paquier
Reviewed-by: Arseniy Mukhin
Discussion: https://postgr.es/m/CAJ7c6TPQ0kkHQG-AqeAJ3PV_YtmDzcc7s%2B_V4%3Dt%2BxgSnZm1cFw%40mail.gmail.com
---
 src/tools/pgindent/pgindent | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index b7d71808924..13944730a39 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -281,6 +281,9 @@ sub post_indent
 	# Fix run-together comments to have a tab between them
 	$source =~ s!\*/(/\*.*\*/)$!*/\t$1!gm;
 
+	# Postprocess multiline comments
+	$source =~ s!^(/\*.*?\*/)!postprocess_multiline_comment($1)!mgse;
+
 	## Functions
 
 	# Use a single space before '*' in function return types
@@ -289,6 +292,37 @@ sub post_indent
 	return $source;
 }
 
+sub postprocess_multiline_comment
+{
+    my $source = shift;
+    my @lines = split "\n", $source;
+
+    if($lines[0] ne "/*" && $lines[-1] ne " */")
+    {
+        # Don't change comments like:
+        # /* line 1
+        #    line 2 */
+        # and similar.
+        return $source;
+    }
+
+    if($lines[0] =~ m!/\*(\-|\*)!)
+    {
+        # Don't change comments that start with:
+        # /****
+        # or:
+        # /*---
+        return $source;
+    }
+
+    $lines[0] =~ s!/\*(.+)!/\*\n *$1!;
+    $lines[-1] =~ s!(.+) \*/!$1\n \*/!;
+
+    $source = join "\n", @lines;
+
+    return $source;
+}
+
 sub run_indent
 {
 	my $source = shift;
-- 
2.49.0



view thread (26+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: [PATCH] pg_bsd_indent: improve formatting of multiline comments
  In-Reply-To: <CAJ7c6TOCJG2p0Ob9Z7mXQRhkmRX_mxBay198Z173t4=PZr=yEQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox