help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: How to set exit trap from inner function?
Date: Fri, 24 Feb 2023 15:41:32 -0800	[thread overview]
Message-ID: <CAH+w=7ZbNO3fhdzVH3UPFQ6vHatLy96+eKD2bhRixgzUN-QQxg@mail.gmail.com> (raw)
In-Reply-To: <CAKc7PVDooYnQ1hb-HU70rWD8oRpgQ0pR13dyPsY79BwFmqY5dw@mail.gmail.com>

On Thu, Feb 23, 2023 at 6:10 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
> I want to automatically clear all functions created from outer function.
> Any ideas on having such auto-unset-funcs function?

Unclear what side-effect messing about with localtraps may have on
this, but you can use one EXIT trap to set another EXIT trap:

inner () {
  trap "print FROM INNER: \$0; trap 'print FROM OUTER: \$0' EXIT" EXIT
outer () {

% outer

Getting the quoting right for something more complicated, is left as
an exercise.

  reply	other threads:[~2023-02-24 23:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-24  2:08 Sebastian Gniazdowski
2023-02-24 23:41 ` Bart Schaefer [this message]
2023-02-26  9:56   ` Sebastian Gniazdowski

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:

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

  git send-email \
    --in-reply-to='CAH+w=7ZbNO3fhdzVH3UPFQ6vHatLy96+eKD2bhRixgzUN-QQxg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=sgniazdowski@gmail.com \
    --cc=zsh-workers@zsh.org \


* 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


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).