From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 3b962035 for ; Sun, 29 Sep 2019 22:28:35 +0000 (UTC) Received: (qmail 5646 invoked by alias); 29 Sep 2019 22:28:29 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 24317 Received: (qmail 25464 invoked by uid 1010); 29 Sep 2019 22:28:29 -0000 X-Qmail-Scanner-Diagnostics: from mail-vs1-f41.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25587. spamassassin: 3.4.2. Clear:RC:0(209.85.217.41):SA:0(-2.0/5.0):. Processed in 1.309578 secs); 29 Sep 2019 22:28:29 -0000 X-Envelope-From: sgniazdowski@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.217.41 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=zHXoFfx3BnB3RLS2kDgss6ANt6DLB1xD4DjNozGDjac=; b=vJFD7yuxrQXAw/L78NKgORBKnigZrnKdBFYYVwzqW8MAxZzHah91RNUEXCKjOWX/I9 zgo3MPQOddSIfqq1mAU6Cd8ylfbqE3XdjilWfPIaKT0lra1T4dzwp3YfRz2HTa8kpbQs MdQ55VS6USZdwfqmd0b1Kc4P6CtBRx4j10N4DQgzUnER+ib9EOWydQMJPctbqav+xmCM WFZE4yoVNPKh41Ib8rCOvZe8791PIuHo6IUxVaw3byoPLqdPp2yiKkAxA0OGA4UoMqYs 18eLhruNsJUjVycVTDmFO0rXIn60o8Lt7QiCUjZ28d2/MpzT151dhUH/ZBAZVDmwCLfO PrcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=zHXoFfx3BnB3RLS2kDgss6ANt6DLB1xD4DjNozGDjac=; b=Brzy2kjlI2nY1u9iCaz2MO6TvGN4Fdba6cEtXmsGHGlhPi3Q4PLRCXU2kPNKDz9DdA aQ0uvwhJLiou0/Yf3OSk4l4eQGriMXw8eF8fR/d2DHO2zwf78Cqhm7/Otgy6S+jFDOOw 6520aCGPzhABnGgH3ibRch7FyL0RcYyKjPI+li3+0rGkm1rQjs8V7M/adJCSc4vWhhrO sj+qDg+8LIxU9AlO0mWlVgs9JvgZtIuSa1V8Jty2sMhix1S7pjdbgk45kt2/P7gaCchy 2A7iPEMvBhaHW/Ks9hCX9sHG0FyQD1CUQfjK8j+mQhGhtY+4S0P0La01gP2UydvQnetc EAvw== X-Gm-Message-State: APjAAAUbiYL4+bFim2X0jDgMqCHbPzHGb8iH9Cb06NW3C3sR53vH1SVN +bEl2w6jpMiQ3cLGwrg0VeTU3TCK2M1hY0NRXuG8eg== X-Google-Smtp-Source: APXvYqxr7EqOz1BF1zjdFAC/ivWNLvWXxerd4hHfQV932VW5MLkvaqjHf/l91PTbkJcdBsqINz3/ZieVrYsIB0fGgcE= X-Received: by 2002:a67:ec09:: with SMTP id d9mr8047793vso.215.1569796074924; Sun, 29 Sep 2019 15:27:54 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Sebastian Gniazdowski Date: Mon, 30 Sep 2019 00:25:12 +0200 Message-ID: Subject: Re: A method to not leak unneeded functions To: Zsh Users Content-Type: text/plain; charset="UTF-8" PS. The block of code should be added at the beginning of the autoload file, after possible emulate -L zsh, or at least after `setopt localtraps' (which is being done by the emulate builtin). After this the setup is complete and the functions will get automatically unset. On Mon, 30 Sep 2019 at 00:22, Sebastian Gniazdowski wrote: > > Hello, > it's often the case when one declares sub-functions inside an autoload > function. The function will leak into the shell and also get redefined > on the next run of the main function. Here's a method to prevent this > from happening: > > local -a entry_funs > entry_funs=( ${(k)functions} ) > trap "unset -f \"\${(k)functions[@]:#(${(j:|:)${(q@)entry_funs}})}\" > &>/dev/null" EXIT > trap "unset -f \"\${(k)functions[@]:#(${(j:|:)${(q@)entry_funs}})}\" > &>/dev/null; return 1" INT > > It will unset any newly detected functions at the moment of leaving of > the main function. > -- > Sebastian Gniazdowski > News: https://twitter.com/ZdharmaI > IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin > Blog: http://zdharma.org -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org