zsh-workers
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Prompt expansion on signals
Date: Sun, 28 Nov 2021 21:31:54 +0100	[thread overview]
Message-ID: <CAN=4vMr8=AZWn0dte_UGJX2vRxkeAQMzVfVx1vvjEAp8h2q_Uw@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7at6wN1VfWA7=_HEuaHkCREBfES=Z5sTrHrBY4n2SR9YA@mail.gmail.com>

On Sun, Nov 28, 2021 at 8:50 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Sun, Nov 28, 2021 at 2:01 AM Roman Perepelitsa
> <roman.perepelitsa@gmail.com> wrote:
> >
> > For this to work correctly, prompt_subst must be set when prompt is
> > expanded. However, this requirement can be violated when prompt is
> > expanded in a signal handler.
>
> A more egregious example might be when the global settings have
> "unsetopt promptpercent".

I can control these in my config. I cannot control options that are
active when zsh processes SIGCHLD though (unless I never change
options in zle widgets).

To clarify, I'd like to:

1. Be able to resize my terminal and run background jobs.
2. Use zle widgets that set local_options and any other options
together with it.
3. Never have my prompt expanded with wrong options.

I don't know how to satisfy all three. If I drop the first point, then
I do know. That is, I have control of shell options in all cases
except when zsh expands prompt in a signal handler.

These requirements look reasonable to me. Isn't it something that
virtually everyone wants? I was surprised when I realized that I
cannot have these things simultaneously (or don't know how).

> Are prompts the only case where this is an issue, though?  The most
> visible, certainly, but "zle -F" for example?

As far as I'm aware, prompt expansion on signals is the only place
where it's impossible to set options. Perhaps I'm misunderstanding
what you mean by "zle -F" in this context?

> What about the reverse situation, where the signal handler is a
> function that changes options locally?

What do you mean?

> > Prompt expansion can be affected by options other than prompt_*.
>
> Are you aware of any cases where this is true but prompt_subst is false?

Hm... multibyte? There are also special parameters like LC_ALL that
cause the same issue. For example, doing the following in a widget can
break prompt if SIGCHLD arrives at the wrong moment:

    local LC_ALL=C
    ...

> Either way that doesn't fix an explicit setopt of those.

I sometimes change prompt_* options in functions when I want to use `print -P`.

    emulate -L zsh -o prompt_percent no_prompt_subst
    print -Pru2 -- '%F{1}error%f: missing required parameter: %F{3}--foo%f'

This seemed smart at the time...

What do you think about not running signal handlers for SIGCHLD and
SIGWINCH while zle widgets are running? Postpone them. This already
sort of happens when a signal arrives during recursive-edit.

Roman.


  reply	other threads:[~2021-11-28 20:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-28  9:59 Roman Perepelitsa
2021-11-28 19:50 ` Bart Schaefer
2021-11-28 20:31   ` Roman Perepelitsa [this message]
2021-11-28 21:10     ` Oliver Kiddle
2021-11-28 21:36       ` Roman Perepelitsa
2021-11-29  1:38     ` Bart Schaefer
2021-11-29 11:36       ` Roman Perepelitsa
2021-11-29 17:42         ` Roman Perepelitsa

Reply instructions:

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

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

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=4vMr8=AZWn0dte_UGJX2vRxkeAQMzVfVx1vvjEAp8h2q_Uw@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).