From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22125 invoked from network); 24 Feb 2023 02:09:22 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Feb 2023 02:09:22 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1677204562; b=F7JRZw/7zjpXHp7dCmqjwa5Cu8R0uwpJCbw5Vzh3+xi0DOKMz4EJnANQq8cbd0p43GUNtwpobw 6zTDlBaA0PszNz55omCqpKSnXmn0+rwLt51GPYIXW7VtfQm53w6zGTy6t/HfCZ6vwWSb8KHPAy V9qglksSY35NIwB3A05rZrrUnobFHWGqYs3B2UvQvVbkzhDtARWyuCkAwCkF8HMNGltextQJqV UKt9q0Hb2dvyJfPsP0WU3X5O+PtUpjK/zHhsNagT8t/9GIKYb6QcR9TbEwUWSL17Pov3cSyfay K4ekZA6R4HIf6ovrLcztEtfoi/AKmHiPx0k/9g7FXrgbAA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f173.google.com) smtp.remote-ip=209.85.208.173; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1677204562; bh=NQC5htVlWrouQcKlfo7JwacFIOmI9XbCqSU3HXwkhFA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=gyXU+/ywnfsK/xYbU+kuZyGaFMKkjK/TPdYoT5FXEQdJ6ssBupFziVNqTBSL8o6SbK11/nh/dl tITHqySomHbyEXx1M0g1s2mShO7Ktlz/SF3RHvj/DNjN7CfIQ/8Bd8+4yA9HdMBrLKmqWYiwpY z8jurs7yoJNHBNYHRGAxkvcnjzT/OKFkTcUtfJiBcMblwn2WMNI0V6QZy1l8UEgq4Kv/mcW03n i6feRxv8WXkbAmHpnkZ0vnMNa8610pQbHtfl3s3pENahUOYfVb4DXrvkOYZqMTfJnI7tStOvjO PWVCqsoSsuHxFICKoFkik8xbGX218uWXdScLqldnixVm6w==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=8INpLp66i0wNtSXTuiBGYLXXJE/Db2G6KLFbQB6QDz8=; b=PmtRA42U9wibELO0tS8jIvnJLe 4jZin5ZAz1Z1oxFIt/W+q01X/8CjmNJ9yNE5ZOTEr8VFCMprnuISqotse7LSHgoNJWfvVit7L91v0 rwPAR1D8zVbQyCD8wDNBwoFNDdici52ZUM7wsPR0tLcrbTKDOcmJm4AGoe7B2CJmLFoo0aC0d78KV KstaAF8+Ax2kGYRphazgG3xREytdXKSBcEgChz+ppi9dcXAuy4l+clbE1nOCHnOXkZ8uO7dLay5N3 K5PvHCskdy43byKuseCzhRLetWi526tw5M7zZUYYX+9dpNyrbEBN2X+GFsweOBQ4e0ewghZenN4e4 gMBK1xCw==; Received: by zero.zsh.org with local id 1pVNWS-000LHK-ED; Fri, 24 Feb 2023 02:09:20 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f173.google.com) smtp.remote-ip=209.85.208.173; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f173.google.com ([209.85.208.173]:36436) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pVNWB-000L0B-LJ; Fri, 24 Feb 2023 02:09:04 +0000 Received: by mail-lj1-f173.google.com with SMTP id e24so6507677ljj.3 for ; Thu, 23 Feb 2023 18:09:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=8INpLp66i0wNtSXTuiBGYLXXJE/Db2G6KLFbQB6QDz8=; b=bBSI/pSkXtaoG845iqR1ufT3oJMWqAIabWxX3Qv/a3b6Ohlhr7ezQGGEVhzZsZCfnN fzYKTYarpge/gMo+pJbfFuskpar2nn7A9iWnua3EwwV4hE2XIj/b2sl5+hC7Nno+24sD OBfHbiDSDd9GMe5BWGZouqvQhQSZqFg8zZg+Gx8qdvprlCrXJ7jrMoVa7CrQ7u7g3Yat dIK/MVklikQLaZlHa0J0QTMqmyILVRlVw7jEy1BIMNMn02ABmnD66mBQzomJGDKccsqy XQcraz0uWP1GAv+qBPPCZyahehLLEhziGUx1N4UyDwmLwkNB+8J99gOR2OjLPUySxhdp vxug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8INpLp66i0wNtSXTuiBGYLXXJE/Db2G6KLFbQB6QDz8=; b=r1yEiQ0ZtLdcj/OTq6H8SNczdlkYmGcwEB05A48o7MutIqCWplqZafFaQSq/EC5hmV wThqtouS+cqHg1G00A9XV3lWitmbytR5+hrwZ6bY1KmcNq1g0gbCAxwuVQ3rTXhJ+sp3 ypRRR2p77mtAz6zV55I5nEtl6B7zk0Q+V6gaSBdbA17AhaCxsvRK1V3e8dlbh512d1ZQ kusPALgNYMRIJpVY4Anw/0TeVMQAld4gE51YybwYCBTaEBUEMcshETJW73dtuQGd3MTy M3RUM3/qjvlcnd3nSdfP31RRf7B09MzavtVQuNuTdjvI2T9sWG3YjFZmMl7r78fjSexQ NiXg== X-Gm-Message-State: AO0yUKVjpD5F+VEX+i+7ntI0r6xOUdE7i1GTOpZTdCe7hGHvP0HxKEq2 gtv9AVeQWxcGIvVvB967j6hCsrZYbQwa97sXry2+xP21+Ik= X-Google-Smtp-Source: AK7set8Xmn17gh+jm6U6UcduYSa0deNZuWEFT3gtXMDWUfAcYJwhSLtfRj4ZUMzBGR/Cd1o7UkJ5PVkxGNNMC2U5n5k= X-Received: by 2002:a05:651c:3cd:b0:293:261e:74ce with SMTP id f13-20020a05651c03cd00b00293261e74cemr4403942ljp.4.1677204542307; Thu, 23 Feb 2023 18:09:02 -0800 (PST) MIME-Version: 1.0 From: Sebastian Gniazdowski Date: Fri, 24 Feb 2023 02:08:35 +0000 Message-ID: Subject: How to set exit trap from inner function? To: Zsh hackers list Content-Type: multipart/alternative; boundary="000000000000f5c19f05f5689c39" X-Seq: 51475 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: --000000000000f5c19f05f5689c39 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I want to automatically clear all functions created from outer function. auto-unset-funcs() { # Don't leak any functions typeset -ga ef ef=3D( ${(k)functions} ) # No localtraps =E2=80=93 sets in outside scope trap "unset -f -- \"\${(k)functions[@]:|ef}\" &>/dev/null; unset ef" EXIT trap "return 1" INT } Above code correctly clears new functions when pasted into the outer function. However, I would like to avoid pasting and simply do: outer() { emulate -L zsh auto-unset-funcs # freely define new functions=E2=80=A6 } However, the EXIT trap is executed when auto-unset-funcs exits, not when outer() does=E2=80=A6 I thought that lack of localoptions localtraps would = declare the EXIT trap in the first function that has it (outer does, via emulate -L). Doing setopt localoptions nolocaltraps in auto-unset-funcs didn't help. Any ideas on having such auto-unset-funcs function? --=20 Best regards, Sebastian Gniazdowski --000000000000f5c19f05f5689c39 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I want to automatically clear all functions created from out= er function.

auto-unset-funcs() {
=C2=A0 =C2=A0 # Don't l= eak any functions
=C2=A0 =C2=A0 typeset -ga ef
=C2=A0 =C2=A0 ef=3D( $= {(k)functions} )
=C2=A0 =C2=A0 # No localtraps =E2=80=93=C2=A0sets in ou= tside scope
=C2=A0 =C2=A0 trap "unset -f -- \"\${(k)functions[= @]:|ef}\" &>/dev/null; unset ef" EXIT
=C2=A0 =C2=A0 tra= p "return 1" INT
}

Above code correctly clears new = functions when pasted into the outer function. However, I would like to avo= id pasting and simply do:

outer() {
=C2=A0 =C2=A0 emulate -= L zsh
=C2=A0 =C2=A0 auto-unset-funcs
=C2=A0 =C2=A0 # freely defin= e new functions=E2=80=A6
}

However, the EXIT trap is executed= when auto-unset-funcs exits, not when outer() does=E2=80=A6 I thought that= lack of localoptions localtraps would declare the EXIT trap in the first f= unction that has it (outer does, via emulate -L). Doing setopt localoptions= nolocaltraps in auto-unset-funcs didn't help. Any ideas on having such= auto-unset-funcs function?
--
Best regar= ds,
Sebastian Gniazdowski

--000000000000f5c19f05f5689c39--