zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Methods of shadowing a builtin call
Date: Fri, 29 Jan 2016 15:09:09 -0800	[thread overview]
Message-ID: <160129150909.ZM24728@torch.brasslantern.com> (raw)
In-Reply-To: <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.


  parent reply	other threads:[~2016-01-29 23:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-29 21:33 Sebastian Gniazdowski
2016-01-29 22:20 ` Sebastian Gniazdowski
2016-01-29 23:09 ` Bart Schaefer [this message]
2016-01-30  9:31   ` Sebastian Gniazdowski
2016-01-30 20:48     ` Bart Schaefer

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=160129150909.ZM24728@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --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).