zsh-users
 help / color / mirror / code / Atom feed
* Scope of local parameters
@ 2003-05-01 17:20 Haakon Riiser
  2003-05-05  6:47 ` Borzenkov Andrey
  0 siblings, 1 reply; 6+ messages in thread
From: Haakon Riiser @ 2003-05-01 17:20 UTC (permalink / raw)
  To: zsh-users

Are there ways to limit the scope of local parameters besides
functions?  Say you want to colorize the prompt, and you use
helper variables for the color escape sequences:

  local RED=...
  local GREEN=...
  local BLUE=...

  PS1=<use RGB variables here>

If I do this in ~/.zshrc, or a file sourced by .zshrc, the
variables declared local do not disappear after sourcing ~/.zshrc.

One way to work around this is to wrap the PS1 initialization in
an auxiliary function, but then you have the same problem with
the scope of the function. :-)  Alternatively, one could

  unset RED GREEN BLUE

after setting PS1, but this doesn't feel quite right.  What if
the parameters RED GREEN BLUE already existed?  There has to be
a better way.

-- 
 Haakon


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

* RE: Scope of local parameters
  2003-05-01 17:20 Scope of local parameters Haakon Riiser
@ 2003-05-05  6:47 ` Borzenkov Andrey
  2003-05-05  6:57   ` 'Haakon Riiser'
  0 siblings, 1 reply; 6+ messages in thread
From: Borzenkov Andrey @ 2003-05-05  6:47 UTC (permalink / raw)
  To: 'Haakon Riiser', zsh-users

> 
> Are there ways to limit the scope of local parameters besides
> functions?  Say you want to colorize the prompt, and you use
> helper variables for the color escape sequences:
> 
>   local RED=...
>   local GREEN=...
>   local BLUE=...
> 
>   PS1=<use RGB variables here>
> 
> If I do this in ~/.zshrc, or a file sourced by .zshrc, the
> variables declared local do not disappear after sourcing ~/.zshrc.
> 
> One way to work around this is to wrap the PS1 initialization in
> an auxiliary function, but then you have the same problem with
> the scope of the function. :-)  Alternatively, one could
> 
>   unset RED GREEN BLUE
> 
> after setting PS1, but this doesn't feel quite right.  What if
> the parameters RED GREEN BLUE already existed?  There has to be
> a better way.
> 

Would you please next time specify Zsh version?


local foo=XXX
"~/.zshrc" 127L, 1859C written

bor@itsrm2% zsh
bor@itsrm2% echo $foo

bor@itsrm2% echo $ZSH_VERSION
4.1.1-test-1

-andrey


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

* Re: Scope of local parameters
  2003-05-05  6:47 ` Borzenkov Andrey
@ 2003-05-05  6:57   ` 'Haakon Riiser'
  2003-05-05  7:37     ` Borzenkov Andrey
  2003-05-05  8:06     ` Borzenkov Andrey
  0 siblings, 2 replies; 6+ messages in thread
From: 'Haakon Riiser' @ 2003-05-05  6:57 UTC (permalink / raw)
  To: Borzenkov Andrey; +Cc: zsh-users

[Borzenkov Andrey]

>> Are there ways to limit the scope of local parameters besides
>> functions? [...]

> Would you please next time specify Zsh version?

Sorry:  zsh 4.0.6 (i386-slackware-linux-gnu).

-- 
 Haakon


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

* RE: Scope of local parameters
  2003-05-05  6:57   ` 'Haakon Riiser'
@ 2003-05-05  7:37     ` Borzenkov Andrey
  2003-05-05  8:06     ` Borzenkov Andrey
  1 sibling, 0 replies; 6+ messages in thread
From: Borzenkov Andrey @ 2003-05-05  7:37 UTC (permalink / raw)
  To: 'Haakon Riiser'; +Cc: zsh-users

> 
> >> Are there ways to limit the scope of local parameters besides
> >> functions? [...]
> 
> > Would you please next time specify Zsh version?
> 
> Sorry:  zsh 4.0.6 (i386-slackware-linux-gnu).
> 

Oops, sorry, still the same in 4.1 as in 4.0.

Hopefully Peter can comment on whether it is intentional. What I miss is
local functions as well :)


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

* RE: Scope of local parameters
  2003-05-05  6:57   ` 'Haakon Riiser'
  2003-05-05  7:37     ` Borzenkov Andrey
@ 2003-05-05  8:06     ` Borzenkov Andrey
  2003-05-06 10:04       ` Peter Stephenson
  1 sibling, 1 reply; 6+ messages in thread
From: Borzenkov Andrey @ 2003-05-05  8:06 UTC (permalink / raw)
  To: 'Haakon Riiser'; +Cc: zsh-users


Actually I am not sure why I assumed source supports local parameters in any
form. Probably I was distracted by the fact that $* _is_ made local.

Hmm ... making typeset create local parameters in sourced script by default
will definitely break a lot of existing scripts. Probably extra argument to
typeset or (better) extra options to treat typesets in script as local. Hmm
the same options could make function definitions local as well ...


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

* Re: Scope of local parameters
  2003-05-05  8:06     ` Borzenkov Andrey
@ 2003-05-06 10:04       ` Peter Stephenson
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2003-05-06 10:04 UTC (permalink / raw)
  To: zsh-users

Borzenkov Andrey wrote:
> Actually I am not sure why I assumed source supports local parameters
> in any form.

You're right not to be sure, it doesn't.

> Hmm ... making typeset create local parameters in sourced script by default
> will definitely break a lot of existing scripts.

Correct.

> Probably extra argument to
> typeset or (better) extra options to treat typesets in script as local.

Certainly possible, but will need some extra wiring.  I should think
thre's some possible fudge involving locallevel, scanendscope and a new
parameter flag, rather than adding a completely new mechanism.  I think
options could be a bit tricky, given that we're talking about having the
mechanism apply exactly around the point at which most people set their
options.  You need to set up the local parameter scope immediately on
entry to .zshrc.

Followups to this should go to zsh-workers.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

end of thread, other threads:[~2003-05-06 10:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-01 17:20 Scope of local parameters Haakon Riiser
2003-05-05  6:47 ` Borzenkov Andrey
2003-05-05  6:57   ` 'Haakon Riiser'
2003-05-05  7:37     ` Borzenkov Andrey
2003-05-05  8:06     ` Borzenkov Andrey
2003-05-06 10:04       ` Peter Stephenson

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