From: Bart Schaefer <schaefer@brasslantern.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: local unfunction
Date: Fri, 30 Mar 2018 11:47:18 -0700 [thread overview]
Message-ID: <CAH+w=7aY8CTAKDUO1cyOACYUUATtiKGJAMYutYuh=acMozTxGw@mail.gmail.com> (raw)
In-Reply-To: <9e0faf6b-b19e-b6d6-0eb7-6ea20b2c2154@eastlink.ca>
On Fri, Mar 30, 2018 at 9:11 AM, Ray Andrews <rayandrews@eastlink.ca> wrote:
> Is it possible to unfunction something just within another function? I've
> tried:
>
> unset -fm ....
>
> ... but the functions remain dead after the calling function returns. I can
> of course just resource them, but I'll bet the unset can be made local.
You can get that effect like this:
% zmodload zsh/parameter
% inner() { print $0 }
% outer() { local +h functions; unfunction inner; which inner }
% which inner
inner () {
print $0
}
% outer
inner not found
% which inner
inner () {
print $0
}
HOWEVER, this not "safe" with autoloaded functions that have not been
loaded yet:
% zmodload zsh/parameter
% outer() { local +h functions; unfunction inner; which inner }
% autoload -U -k inner
% which inner
inner () {
# undefined
builtin autoload -XUk
}
% outer
inner not found
% which inner
inner () {
builtin autoload -XU
}
Note that the "# undefined" tag and the -k flag have been lost;
"inner" is no longer a true autoloaded function. (I think it is
probably a bug that $functions[inner] does not have the -k flag.)
next prev parent reply other threads:[~2018-03-30 18:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-30 16:11 Ray Andrews
2018-03-30 18:47 ` Bart Schaefer [this message]
2018-03-31 0:30 ` Ray Andrews
2018-03-31 5:23 ` Bart Schaefer
2018-03-31 14:58 ` Ray Andrews
2018-03-30 20:10 ` Mikael Magnusson
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='CAH+w=7aY8CTAKDUO1cyOACYUUATtiKGJAMYutYuh=acMozTxGw@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=rayandrews@eastlink.ca \
--cc=zsh-users@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).