zsh-users
 help / color / mirror / code / Atom feed
* Set option in parent after emulate -L zsh
@ 2017-03-09  8:58 Sebastian Gniazdowski
  2017-03-09 22:06 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Gniazdowski @ 2017-03-09  8:58 UTC (permalink / raw)
  To: zsh-users

Hello,
doing:

% unsetopt promptsubst   # Should see garbage in prompt
% () { setopt promptsubst; }

restores correct prompt. Then, to handle emulate -L:

emulate -L zsh
unsetopt promptsubst
() { setopt promptsubst; }   # no change
() { unsetopt localoptions; setopt promptsubst; }   # prompt restored
echo $options[localoptions] $options[promptsubst]   # shows "on on"

I wonder what does the "unsetopt localoptions" do. It connects current
function's level with parent locallevel in context of options, not
harming parent "localoptions" setting? That would be the best
possibility, but I'm afraid something different might be happening
maybe?

-- 
  Sebastian Gniazdowski
  psprint3@fastmail.com


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Set option in parent after emulate -L zsh
  2017-03-09  8:58 Set option in parent after emulate -L zsh Sebastian Gniazdowski
@ 2017-03-09 22:06 ` Bart Schaefer
  2017-03-10  5:47   ` Daniel Shahaf
  2017-03-14 19:17   ` Sebastian Gniazdowski
  0 siblings, 2 replies; 6+ messages in thread
From: Bart Schaefer @ 2017-03-09 22:06 UTC (permalink / raw)
  To: zsh-users

The options
  XTRACE
  LOCAL_OPTIONS
  LOCAL_LOOPS
  WARN_NESTED_VAR
are always reset on function scope exit.  The options
  PRIVILEGED
  RESTRICTED
are never restored as an effect of LOCAL_OPTIONS (but might be in case
of a "sticky emulation").


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Set option in parent after emulate -L zsh
  2017-03-09 22:06 ` Bart Schaefer
@ 2017-03-10  5:47   ` Daniel Shahaf
  2017-03-14 19:17   ` Sebastian Gniazdowski
  1 sibling, 0 replies; 6+ messages in thread
From: Daniel Shahaf @ 2017-03-10  5:47 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer wrote on Thu, Mar 09, 2017 at 14:06:13 -0800:
> The options
>   XTRACE
>   LOCAL_OPTIONS
>   LOCAL_LOOPS
>   WARN_NESTED_VAR

and 
    PRINT_EXIT_VALUE

> are always reset on function scope exit.  The options
>   PRIVILEGED
>   RESTRICTED
> are never restored as an effect of LOCAL_OPTIONS (but might be in case
> of a "sticky emulation").


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Set option in parent after emulate -L zsh
  2017-03-09 22:06 ` Bart Schaefer
  2017-03-10  5:47   ` Daniel Shahaf
@ 2017-03-14 19:17   ` Sebastian Gniazdowski
  2017-03-14 20:24     ` Bart Schaefer
  1 sibling, 1 reply; 6+ messages in thread
From: Sebastian Gniazdowski @ 2017-03-14 19:17 UTC (permalink / raw)
  To: zsh-users

On Thu, Mar 9, 2017, at 03:06 PM, Bart Schaefer wrote:
> The options
>   XTRACE
>   LOCAL_OPTIONS
>   LOCAL_LOOPS
>   WARN_NESTED_VAR
> are always reset on function scope exit.  The options
>   PRIVILEGED
>   RESTRICTED
> are never restored as an effect of LOCAL_OPTIONS (but might be in case
> of a "sticky emulation").

But this doesn't answer my question. I'm wondering what happens here:

() { unsetopt localoptions; setopt promptsubst; }   # prompt restored

Doing this I'm able to set promptsubst in caller (which used emulate
-LR). This looks like: option-scope of (anon) is equated with scope of
caller. Is it really what happens?

-- 
  Sebastian Gniazdowski
  psprint3@fastmail.com


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Set option in parent after emulate -L zsh
  2017-03-14 19:17   ` Sebastian Gniazdowski
@ 2017-03-14 20:24     ` Bart Schaefer
  2017-03-14 20:39       ` Sebastian Gniazdowski
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2017-03-14 20:24 UTC (permalink / raw)
  To: zsh-users

On Mar 14, 12:17pm, Sebastian Gniazdowski wrote:
}
} () { unsetopt localoptions; setopt promptsubst; }   # prompt restored
} 
} Doing this I'm able to set promptsubst in caller (which used emulate
} -LR). This looks like: option-scope of (anon) is equated with scope of
} caller. Is it really what happens?

There is only one option scope: the global one.  When a function call
is made, the current values of all the options are stored.  When the
call returns, the setting of localoptions is checked, and if set, then
the saved options from the start of the call are restored (with those
exceptions previously noted); otherwise the options are not changed
(again with noted exceptions).

Given thusly that all option scopes are the same, yes, the scope of
(anon) is the scope of the caller, and as long as the options you are
frobbing are not among those exceptions, you can disrupt the caller's
settings all you like.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Set option in parent after emulate -L zsh
  2017-03-14 20:24     ` Bart Schaefer
@ 2017-03-14 20:39       ` Sebastian Gniazdowski
  0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Gniazdowski @ 2017-03-14 20:39 UTC (permalink / raw)
  To: zsh-users

On Tue, Mar 14, 2017, at 01:24 PM, Bart Schaefer wrote:
> There is only one option scope: the global one.  When a function call
> is made, the current values of all the options are stored.  When the
> call returns, the setting of localoptions is checked, and if set, then
> the saved options from the start of the call are restored (with those
> exceptions previously noted); otherwise the options are not changed
> (again with noted exceptions).
> 
> Given thusly that all option scopes are the same, yes, the scope of
> (anon) is the scope of the caller, and as long as the options you are
> frobbing are not among those exceptions, you can disrupt the caller's
> settings all you like.

Cool, ensured that this works (forgive one-liness, but maybe it's better
that way):

() { emulate -LR zsh; echo 1_$options[promptsubst]; () { emulate -LR
zsh; () { unsetopt localoptions; setopt promptsubst; }; echo
2_$options[promptsubst]; }; echo 3_$options[promptsubst]; }
1_off
2_on
3_off

-- 
Sebastian Gniazdowski
psprint3@fastmail.com


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-14 20:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-09  8:58 Set option in parent after emulate -L zsh Sebastian Gniazdowski
2017-03-09 22:06 ` Bart Schaefer
2017-03-10  5:47   ` Daniel Shahaf
2017-03-14 19:17   ` Sebastian Gniazdowski
2017-03-14 20:24     ` Bart Schaefer
2017-03-14 20:39       ` Sebastian Gniazdowski

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).