Thread: pgindent and multiline string constants

pgindent and multiline string constants

From
Peter Eisentraut
Date:
Somehow pgindent appears to do odd things with multiline string constants, 
such as

somefunc(&blah,        "lots of text"        "with mulitple lines"        "like this");

Afterwards this looks more like this:

somefunc(&blah,    "lots of text"        "with mulitple lines"      "like this");

As an example, compare these two files:

http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/adt/xml.c?rev=1.56;content-type=text%2Fplain
http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/adt/xml.c?rev=1.57;content-type=text%2Fplain

function map_sql_type_to_xmlschema_type() somewhere near the end of the file; 
look at the appendStringInfo(&result, ...) calls.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


Re: pgindent and multiline string constants

From
Tom Lane
Date:
Peter Eisentraut <peter_e@gmx.net> writes:
> Somehow pgindent appears to do odd things with multiline string constants, 
> such as

> somefunc(&blah,
>          "lots of text"
>          "with mulitple lines"
>          "like this");

> Afterwards this looks more like this:

> somefunc(&blah,
>      "lots of text"
>          "with mulitple lines"
>        "like this");

Sometimes it does that to keep the lines from extending past column 80.
I'm not sure that this is an improvement :-(, but anyway you can fix it
by breaking the string literal into smaller chunks so that there's no
line-wrapping going on in an 80-column view.
        regards, tom lane


Re: pgindent and multiline string constants

From
Bruce Momjian
Date:
Tom Lane wrote:
> Peter Eisentraut <peter_e@gmx.net> writes:
> > Somehow pgindent appears to do odd things with multiline string constants, 
> > such as
> 
> > somefunc(&blah,
> >          "lots of text"
> >          "with mulitple lines"
> >          "like this");
> 
> > Afterwards this looks more like this:
> 
> > somefunc(&blah,
> >      "lots of text"
> >          "with mulitple lines"
> >        "like this");
> 
> Sometimes it does that to keep the lines from extending past column 80.
> I'm not sure that this is an improvement :-(, but anyway you can fix it
> by breaking the string literal into smaller chunks so that there's no
> line-wrapping going on in an 80-column view.

Yes, I talked to Peter via IM on this.  A good example is xml.c::3033
that looks like this:
               appendStringInfo(&result,                                "  <xsd:restriction base=\"xsd:long\">\n"
              "    <xsd:maxInclusive value=\"" INT64_FORMAT "\"/>\n"                      "    <xsd:minInclusive
value=\""INT64_FORMAT "\"/>\n"                                "  </xsd:restriction>\n",
(((uint64)1) << (sizeof(int64) * 8 - 1)) - 1,                                (((uint64) 1) << (sizeof(int64) * 8 -
1)));

The problem is that the lines with INT64_FORMAT are shifted to the left
to be < 80 characters.  What is really odd is line 3071 where the first
and third quote lines are short enough to shift to the left, while the
second line is so long that it doesn't to shift it at all:
                       appendStringInfo(&result,                                   "  <xsd:restriction
base=\"xsd:time\">\n"                                       "    <xsd:pattern
value=\"\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}.\\p{Nd}{%d}%s\"/>\n"                          "  </xsd:restriction>\n", typmod
-VARHDRSZ, tz);
 

Not sure what we can do to improve pgindent in this area.  It treats
these strings like function parameters, trying to keep them <80.
--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://postgres.enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +