Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Methods of shadowing a builtin call
- X-seq: zsh-users 21205
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Methods of shadowing a builtin call
- Date: Fri, 29 Jan 2016 15:09:09 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=+3tVYTcchXxZjWVgNSmfoVzOsJNtvwuvi3b/pSbMIIY=; b=rDVP/pQ9RcmGacDd0in+3ES5gw/DhTyuSFHsZWcRBj72Wv5Z04Y3kBjiTGRkwb/LzH WghSSpKPURccoo98LDovXtUFi6AWTgVEubT6CpKw6ED2CD/RiPstHOZIetPaqqSRGkN8 pGhBGoNqxgKW0EurDM5ckGT+3hE06E3h3fFCjjBC+bksXWoCrxQ14OQ4gaBRxK9DN8uG 7MMaoq+w7nnRqrJxs0+k/YlcguU5gq5ScUvwy6yPlsymR03tdRgo5AcUGQmFHCdd190m xzyHeeuCOh8gHIURZPz/CZfa0lA3ghKhDy7GqUIWMhaxB3xNicjx4GM+1JqgJPBaTIlW 29tA==
- In-reply-to: <CAKc7PVAS=iT0t6exL8Z+xYrnyN1O7zx_MEu0smnWXRyq8X6VrA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVAS=iT0t6exL8Z+xYrnyN1O7zx_MEu0smnWXRyq8X6VrA@mail.gmail.com>
On Jan 29, 10:33pm, Sebastian Gniazdowski wrote:
}
} I shadow setopt to gather data of what is being done in sourced
} script.
As I alluded to in an earlier message, there is *no* effective way
to shadow "setopt" because of the way "localoptions" works. If you
have
--shadow-setopt() { builtin setopt "$@" }
and you execute e.g.
--shadow-setopt localoptions shglob shwordsplit
then when --shadow-setopt exits, shglob and shwordplit will revert
to their previous settings and the whole thing is a no-op. The same
thing will happen if you have
emulate -L zsh
--shadow-setopt shglob shwordsplit
because "emulate -L" turns on "localoptions".
And if you try to avoid that with this:
--shadow-setopt() { unsetopt localoptions; builtin setopt "$@" }
then
some_func() {
--shadow-setopt localoptions shglob shwordsplit
}
some_func
will incorrectly leave shglob and shwordsplit turned *on* after the
function completes, because localoptions will never be seen in the
context of some_func.
The only way to track option changes is by examining deltas of values
in the $options hash.
} I currently use alias setopt=--setopt-shadow and then source a
} script. This works fine except for z-sy-h. For that project, when I
} source it with the alias being in place, interiors of it then still
} use the shadowing function during their later operations. How to
} suppress this?
It depends how z-sy-h declares or defines its functions. If they are
declared with "autoload" but the -U option is not being used, then any
aliases defined at the time the function is first executed will expand
(because parsing and execution are effectively simultaneous, see next
sentence).
If instead the functions are fully defined, body and all, "in-line" in
the z-sy-h source files, there is no way to suppress this, because the
aliases expand when the function is *parsed*, and therefore the expanded
command text is already in place later when it is executed.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author