Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: "typeset -m" plays havoc

On Sep 15,  9:36pm, Andrej Borsenkow wrote:
> I do not quite understand, what typeset -m is supposed to do.

Historically (e.g., zsh 2.4, which I happen to have found on an old disk
and recompiled recently):

-  `typeset -m' always works on existing parameters that are "visible" in
   the current scope, regardless of the scope in which they were set or
   will be unset/restored.
-  `typeset -m ...' with no other options prints those parameters.
-  with other options, it changes the associated attributes of all the
   existing, matching parameters.

That last is a lot of rope with which to hang yourself, and zsh was never
thoroughly tested to be sure you couldn't take the whole shell with you.

What I propose is to make the rope slightly longer, and actually cause `+g'
to mean something:

	typeset +g -m foo

would mean to create a local parameter named foo if an only if there is
already a parameter named foo visible in the current scope.  (Without the
`-m', `+g' already unconditionally creates a local parameter.)

This would be useful mostly as a shorthand, e.g. (assuming the other bugs
with localizing certain parameters get fixed) the prompt preview code may
want to do something like:

	typeset +g -h -m '(#i)(prompt|ps)*'

> *) I mean, allowing it to change global parameters makes things really
> confusing. Typeset is expected normally to work for local parameters only.

My position is that:

-  There's historical precedent for this behavior.
-  `typeset -m' is unique to zsh, so it's not a conflict with semantics
   for sh or ksh scripts.
-  You can't otherwise refer to a parameter by pattern, so it shouldn't
   be too difficult to realize you're doing something unusual.
-  It's useful to be able to dump the values of selected parameters in
   the current scope without jumping through the sorts of hoops that
   e.g. Util/reporter does.

On the latter note, I'd like to change `typeset +m' to mean something akin
to `typeset +' in that it would dump only the names and type information
rather than the values.  (`typeset + name' dumps the name and value.)  But
that's a more significant change, so I probably won't, just yet.

Messages sorted by: Reverse Date, Date, Thread, Author