From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: How to set exit trap from inner function?
Date: Sun, 26 Feb 2023 09:56:37 +0000 [thread overview]
Message-ID: <CAKc7PVBKaN8uzSbVS=p_T26ArzWoUTgbOyrSS7f+NNLB4C3Rmg@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7ZbNO3fhdzVH3UPFQ6vHatLy96+eKD2bhRixgzUN-QQxg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 927 bytes --]
Thanks. I've found a less invasive solution – to name all inner functions
witu tmp/… prefix, and unset them with nset -f -m tmp/\*
On Fri, 24 Feb 2023 at 23:41, Bart Schaefer <schaefer@brasslantern.com>
wrote:
> 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 () {
> inner
> }
>
> % outer
> FROM INNER: outer
> FROM OUTER: Src/zsh
>
>
> Getting the quoting right for something more complicated, is left as
> an exercise.
>
--
Best regards,
Sebastian Gniazdowski
[-- Attachment #2: Type: text/html, Size: 1631 bytes --]
prev parent reply other threads:[~2023-02-26 9:57 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
2023-02-26 9:56 ` Sebastian Gniazdowski [this message]
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='CAKc7PVBKaN8uzSbVS=p_T26ArzWoUTgbOyrSS7f+NNLB4C3Rmg@mail.gmail.com' \
--to=sgniazdowski@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).