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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14431 invoked from network); 24 Mar 2022 18:42:29 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Mar 2022 18:42:29 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1648147349; b=HkNA/AsJU9kdm7qfon4Pse1tRYixhOzA0sWR1QhnE9UOdzyFEfVRxUsOtgETKb5lodiDedi9ZM xlb16kd4nzFN4xtugRzf7AN1jzWJZk3c/hRtl+9cdLu4f8FHGNWzacT7ui2tS8eoTcqfZM0W5p hF7wliXUgx48X2Cn2Wt0ceWhJ/g3ToknT0HtOtYpnH03Y+jLTqrkN5HNbolTAu6GwQPbhRZhrw 2u76zVRaOW+bwYXS4ZiGinohK3QX2zrQokDdEbJnv6ynR4VGTnSHtEQRPw7AwEKLfz4ncHyy43 NIzSqekoJfC9ubA23WqumIxkYVq4uREuxmNQnYImEpNv7w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yw1-f180.google.com) smtp.remote-ip=209.85.128.180; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1648147349; bh=IOq6XzuBtSalsSXLU2PQOC4ICup36q7vkkRYKMEn5z0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=J937kEevByHrS820QbubOMzg7WcwzYmxvjsdhguoUPqiidkU8han72+YjrI1qtJPVONVaXWrxD fQlAHv8STCY4yBfk/7evDw8wDwEpIF9Ba6t0whIQ1ahUu4pigZ5BVh1oyL9wnKbnxYTInOgtfG 3yF4VVWxJmdUiwX+7QyMp8/z2DfPvehquRD+1w1Dv5lcBCyknQ2HYBEQ1ZLw5ZjxTWKdcBrRJV TwA5aYavuB45uRb5Msdbrpj0gMew6Qt9hZfLo6DkS0NxPPKlJ7572w2g94bCKZ6zBI8ijnReaa 5BM7CwjQsYIYSng5eN1YcgpRHRsFaBiydmgmercLwhJspQ==; 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:In-Reply-To:References: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; bh=+fuaUuQkpZ3TR7SeoOsJRSTPs7T5nnmLKa6G4dG42tk=; b=DYNHzAXMD7VIAc2vkttSkh4KDt wBliCVAPQ6aYlvFD4A9FfrusAaWHkqZ8JeW32+JnvZ4aaLr0cFx6D23timHWJNYSYsvyApY0p3Neu kGIdVWiGo2jSbyPdwNCIhp9GK14MfVaRSAkS4hyZPJ2YXkRBKM2jJZ+4MkESuhQoonTQUNZGz5fbY MhOoQKI6D4vr8Uhc+xl2nxnc3+ReqR+4RFC9QZAKGgYTUxVE95oVsjza6GYLf22/YQD/j06TB/SyJ UXKgXcY8GVeQT7JV7VOpv1iOjUCRFI6uhnV9VldvNyILdIjybka7ukkA2ntAtsvC4/Kf2KOM3GSlw nubCgP1w==; Received: from authenticated user by zero.zsh.org with local id 1nXSPk-000944-7Y; Thu, 24 Mar 2022 18:42:28 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yw1-f180.google.com) smtp.remote-ip=209.85.128.180; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-yw1-f180.google.com ([209.85.128.180]:36757) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1nXSIA-00084W-8E; Thu, 24 Mar 2022 18:34:38 +0000 Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-2e64a6b20eeso60409157b3.3 for ; Thu, 24 Mar 2022 11:34:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=+fuaUuQkpZ3TR7SeoOsJRSTPs7T5nnmLKa6G4dG42tk=; b=Pmguvp3VeTZJ1crjNW4dMUJDC4MKv19aF0d0fzlMAvwLPfzZOtaj1zfot78apcCrqQ NqIxYiehblXYb6+wXNjLsTNT4XLSD/hWhicj4jBmPhO7ls1CVGlcLmUTmHJabnTcXf1Y Ih5TAx/A+Pg3DDJTu6+lXP7Pei3phAFIpVEZ4ZZfq+STG36uzxW8PZ9PfZvnvQQov2EK ereKz5MkwjPtuWnNDRFV2lJWDHthxADpbKO3k9rSZZca8KzpIY7qv5LX4SA4GGMcC2c3 iFwJqllurFx9oBUtjYcQX5tgCWXxk3n6qLCVTYWuQiJkbIsnc0Ehc8obd342XIjCUWQW Y7+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=+fuaUuQkpZ3TR7SeoOsJRSTPs7T5nnmLKa6G4dG42tk=; b=E8W49g+NwiokKfDFvvMGp3Jom/J6nbMdna+TaEs0Xt53gg1O1yFNJs3Sy8rfav2mdy OrmvwSxSJFMpHxWg1i1Z+wLYW/RQftxE/InMgKgw2ef8ts5BRQU/l2wfNtgAPh+UerFC mjZe6w2dO7rPS4DKzjCuRGaNHpkoOnISzLYE292QTPtPZOe0y4AAow0mZLBEiS5qtmGV LpEA7lsmRZCFup9mrl1fiqEbGAyiSa1Sr3fcFGN5MRvhBP+zczum8hWP2UvS+/RH3TJO g7vpNUnxZQ9I0PmQ53uUtPh5oqCc+QMo0ifYJcW2H7A+pYnk2cbLu7IbRkK2e4UUSiDK OXBg== X-Gm-Message-State: AOAM5313jUpUhZr56i5reyW2odGQY2zS5q8LqQKfeb62XOEkrCEyNrZn GIDavVxy47OGerTi+/rxdz0WNXCs2WRIsskPnP3ILPhhlCk2Xg== X-Google-Smtp-Source: ABdhPJx2wcbTVcmCnj4CAZkZzW6IhWJQLAPx4LVZrMOmZtscXLoWImH5tmEueOAGGd0L5vZg4HEtdjaJ1ah+RG1lu6g= X-Received: by 2002:a81:5514:0:b0:2e6:d51e:8aaf with SMTP id j20-20020a815514000000b002e6d51e8aafmr2316721ywb.442.1648146877167; Thu, 24 Mar 2022 11:34:37 -0700 (PDT) MIME-Version: 1.0 References: <306931674.638268.1648141537809@mail2.virginmedia.com> In-Reply-To: From: Bart Schaefer Date: Thu, 24 Mar 2022 11:34:26 -0700 Message-ID: Subject: Re: Load autoloadable function, but only in enclosing function scope To: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 27613 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Thu, Mar 24, 2022 at 10:51 AM Bart Schaefer wrote: > > On Thu, Mar 24, 2022 at 10:06 AM Peter Stephenson > > > > With that key limitation --- if you've already got functions with the > > names of the ones you're creating, you're stuffed --- you can automate > > it like this. > > It actually can be even shorter than that, depending on how carefully > the context needs to be preserved. Copy-paste error, I missed the closing paren on this assignment: local funcs=(${(kv)functions}) One more note after re-reading the original request more closely: On Thu, Mar 24, 2022 at 9:13 AM Zach Riggle wrote: > > myfunc() { > autoload foo && foo > } > > Such that foo and any other functions it declares are local-scope only? If "foo" is already defined, it has to be removed with "unfunction foo" before "autoload foo" will have any effect. The "&&" there doesn't help, because autoload is a silent but status-zero no-op for functions that are already defined. "autoload -R foo && foo" would solve that.