Re: Invisible PROMPT2

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: david(at)fetter(dot)org
Cc: alvherre(at)2ndquadrant(dot)com, tgl(at)sss(dot)pgh(dot)pa(dot)us, ilmari(at)ilmari(dot)org, thomas(dot)munro(at)gmail(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Invisible PROMPT2
Date: 2019-11-14 06:37:55
Message-ID: 20191114.153755.1362733040437410253.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

At Wed, 13 Nov 2019 20:57:04 +0100, David Fetter <david(at)fetter(dot)org> wrote in
> On Wed, Nov 13, 2019 at 03:58:38PM -0300, Alvaro Herrera wrote:
> > On 2019-Nov-13, David Fetter wrote:
> >
> > > On Wed, Nov 13, 2019 at 03:06:08PM -0300, Alvaro Herrera wrote:
> > > > On 2019-Nov-13, David Fetter wrote:
> > > >
> > > > > On Wed, Nov 13, 2019 at 09:47:01AM -0500, Tom Lane wrote:
> > > >
> > > > > > > How about a circumfix directive (like the existing %[ ... %])
> > > > > > > that replaces everything inside with whitespace, but keeps the width?
> >
> > > > This seems way too specific to me. I like the "circumfix" directive
> > > > better, because it allows one to do more things. I don't have any
> > > > immediate use for it, but it doesn't seem completely far-fetched that
> > > > there are some.
> >
> > > So something like %w[...%w] where people could put things like PROMPT1
> > > inside?
> >
> > Hmm, (I'm not sure your proposed syntax works, but let's assume that
> > it does.) I'm saying you'd define
> > \set PROMPT1 '%a%b%c '
> > \set PROMPT2 '%w[%a%b%c %w]'
> >
> > and you'd end up with matching indentation on multiline queries.

This seems assuming %x are a kind of stable (until semicolon)
function. But at least %`..` can be volatile. So, I think the %w
thing in PROMPT2 should be able to refer the actual prompt string
resulted from PROMPT1.

> > I'm not sure that we'd need to make something like this work:
> > PROMPT1="%w[$PROMPT1%w]"
> > which I think is what you're saying.
>
> PROMPT2="%w[$PROMPT1%w]", and basically yes.

Like this. Or may be a bit too-much and I don't came up with a
lialistic use-case, but I think of the following syntax.

\set PROMPT1 '%w[%a%b%c%w] '
\set PROMPT2 '%w '

where %w in PROMPT2 is replaced by a whitespace with the same length
to the output of %w[..%w] part in PROMPT1.

> > We already have "%:PROMPT1:" but that expands to the literal value of
> > prompt1, not to the value that prompt1 would expand to:
>
> Yeah, that's not so great for this usage. I guess "expand variables"
> could be a separate useful feature (and patch) all by itself...

+1.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2019-11-14 06:40:07 Re: PATCH: logical_work_mem and logical streaming of large in-progress transactions
Previous Message Pavel Stehule 2019-11-14 06:12:21 Re: dropdb --force