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

RE: PATCH: "typeset -m" plays havoc



>     erase_PS1() { typeset PS1 prompt PROMPT }

Hmm ... in case of prompts what (very probably) happens:

- for the first parameter typeset_single() calls copyparam() to save old
value; this creates new parameter and copies old *string* value. Then it sets
value to "" creating new empty parameter - that actually sets variable
"prompt" to empty string.
- for the second and third parameters exactly the same happens ... but now the
saved value is already empty string (all three actually refer to the same
variable "prompt").

When functions exits it restores values - I think, it depends on order of
paramtable scan which of three it hits. If it hits the one with empty value
last, prompt gets reset to empty value.

>     flush_history() { typeset HISTSIZE }

In case of HISTSIZE it preserves the value, of course, but in typeset_single()
it sets value of new parameter that has side effect of flushing history. So
far it is correct :-) assuming that set/get functions do what they are
expected to.

>
> That's all I have time to hunt around for right now, but it does look as
> if it's not necessary to force `typeset -m' to work on globals.  AFAICT,
> the reason it worked this way in previous versions was because of the
> parameter table search:  Since you can't possibly refer to a non-existing
> parameter with `typeset -m', you must therefore be referring to the one
> that already exists.  Now that we have `+g', though, there's no reason
> one can't say "find this global parameter and force it to be local".  So
> I'll send a revised patch (a subset of Andrej's 12806, really) as soon as
> I have time to revise the doc slightly to match.
>

I do not quite understand, what typeset -m is supposed to do.

1. If used alone, typeset -m is expected to just print parameters. It is
currently broken, because typeset_single() will print only if there are no
flags to set, and bin_typeset() will (almost) always set at least PM_LOCAL.
Patch in 12806 was wrong of course, but we should prevent setting PM_LOCAL in
this case.

2. What I do not understand, what typeset -m es expected do if any flag is
present? It may be interpreted as "print parameters that match and have this
flag set" or "set flags for matching parameters". In the former case
typeset_single() is broken. The semantic of latter is unclear (wrt
global/local *) but in any case it should not create new parameters. But,
unfortunately, this happens currently for all I can tell.

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


-andrej



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