Thread: [HACKERS] pg_bsd_indent: implement -lps ("leave preprocessor space")

[HACKERS] pg_bsd_indent: implement -lps ("leave preprocessor space")

From
Piotr Stefaniak
Date:
Hello,

this is a patch that Andres asked me for. It makes pg_bsd_indent leave
preprocessor space alone, as in this example:

#if 0
#  if 0
#    if 0
#      error
#    endif
#  endif
#else
#  line 7
#endif

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachment

Re: [HACKERS] pg_bsd_indent: implement -lps ("leave preprocessor space")

From
Tom Lane
Date:
Piotr Stefaniak <postgres@piotr-stefaniak.me> writes:
> this is a patch that Andres asked me for. It makes pg_bsd_indent leave
> preprocessor space alone, as in this example:

> #if 0
> #  if 0
> #    if 0
> #      error
> #    endif
> #  endif
> #else
> #  line 7
> #endif

Um ... but the point of pgindent is to standardize spacing, not to let
people invent their own style.  If you wanted to have a discussion about
whether pgindent should force preprocessor directives to look like the
above, we could talk about that.  But I do not want to be reading code that
looks like the above in one place and code that does not ten lines away.
        regards, tom lane



Re: [HACKERS] pg_bsd_indent: implement -lps ("leave preprocessorspace")

From
Andres Freund
Date:
On 2017-02-07 23:30:44 -0500, Tom Lane wrote:
> Piotr Stefaniak <postgres@piotr-stefaniak.me> writes:
> > this is a patch that Andres asked me for. It makes pg_bsd_indent leave
> > preprocessor space alone, as in this example:
> 
> > #if 0
> > #  if 0
> > #    if 0
> > #      error
> > #    endif
> > #  endif
> > #else
> > #  line 7
> > #endif

For context: I'd asked Piotr how dificult it'd be to add this.

> Um ... but the point of pgindent is to standardize spacing, not to let
> people invent their own style. If you wanted to have a discussion about
> whether pgindent should force preprocessor directives to look like the
> above, we could talk about that.  But I do not want to be reading code that
> looks like the above in one place and code that does not ten lines away.

I don't think that's something easily done in an automatic
manner. Because you'd e.g. obviously not want to indent everything
within include guards.   I don't really buy the danger of large
divergances in code nearby - this seems mostly useful when writing a bit
more complicated macros, and I don't think they'll be that frequently
added in existing files.

I do think this makes the nesting for #ifdefs a *lot* more readable, and
we have plenty of cases where it's currently really hard to discern what
"branch" one is currently reading.  Allowing to opt-in into the "newer"
formatting in places where it makes sense, seems reasonable to me.

Regards,

Andres



Re: [HACKERS] pg_bsd_indent: implement -lps ("leave preprocessor space")

From
Antonin Houska
Date:
Andres Freund <andres@anarazel.de> wrote:

> On 2017-02-07 23:30:44 -0500, Tom Lane wrote:
> > Piotr Stefaniak <postgres@piotr-stefaniak.me> writes:
> > > this is a patch that Andres asked me for. It makes pg_bsd_indent leave
> > > preprocessor space alone, as in this example:
> >
> > > #if 0
> > > #  if 0
> > > #    if 0
> > > #      error
> > > #    endif
> > > #  endif
> > > #else
> > > #  line 7
> > > #endif
>
> For context: I'd asked Piotr how dificult it'd be to add this.
>
> > Um ... but the point of pgindent is to standardize spacing, not to let
> > people invent their own style. If you wanted to have a discussion about
> > whether pgindent should force preprocessor directives to look like the
> > above, we could talk about that.  But I do not want to be reading code that
> > looks like the above in one place and code that does not ten lines away.
>
> I don't think that's something easily done in an automatic
> manner. Because you'd e.g. obviously not want to indent everything
> within include guards.   I don't really buy the danger of large
> divergances in code nearby - this seems mostly useful when writing a bit
> more complicated macros, and I don't think they'll be that frequently
> added in existing files.
>
> I do think this makes the nesting for #ifdefs a *lot* more readable, and
> we have plenty of cases where it's currently really hard to discern what
> "branch" one is currently reading.  Allowing to opt-in into the "newer"
> formatting in places where it makes sense, seems reasonable to me.

As an alternative approach, the formatting can be implemented in elisp and
added to src/tools/editors/emacs.samples. In particular I mean one function to
make the code human readable and another one to turn it back to the concise
style. User would only call the function on text selection (region) as opposed
to the whole file.

--
Antonin Houska
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt
Web: http://www.postgresql-support.de, http://www.cybertec.at