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

Re: PATCH: sticky emulation



On Feb 11,  8:28pm, Peter Stephenson wrote:
}
} I'll submit the lot and it can be modified later if necessary.

Documentation nit:  My info-viewer and my emacs both display the list
of emulate rules like so:

     The documentation above is typically sufficient for the intended
     purpose of executing code designed for other shells in a suitable
     environment.  More detailed rules follow.
    1.
          The sticky emulation environment provided by `emulate SHELL
          -c' is identical to that provided by entry to a function
          marked for sticky emulation as a consequence of being defined
          in such an environment.  Hence, for example, the sticky
          emulation is inherited by subfunctions defined within
          functions with sticky emulation.

    2.
          No change of options takes place on entry to or exit from
          functions that are not marked for sticky emulation, other
          than those that would normally take place, even if those
          functions are called within sticky emulation.

(and so on with the floating numbers one line up and one character too
far "outdented").

I compiled this and started poking around and immediately encountered
an interesting side-effect.  Consider the function "allopt" which is
autoloaded and dumps out a list of the options and their states.

Starting from

% emulate sh -c "allopt"
(list of options appears as expected, with "sh" states)
zsh: allopt: function not defined by file

OK, clearly allopt should be getting "autoload -z" treatment.  (Aside:
Does the doc really not explain "autoload -z" anywhere?  Have I just
missed it?)

On reflection the rest of what follows is exactly as I should have
expected it to be, but having rambled on writing it all down I'm
going to send it anyway.

Exit and start a new shell, try this:

% emulate sh -c "ao() { allopt; }"
% ao
(list of options appears as expected, with "sh" states)
zsh: allopt: function not defined by file
% allopt
(list of options appears with zsh states)

Exit and start again:

% autoload -z allopt
% emulate sh -c "allopt"
(list of options appears as expected, with "sh" states)
% allopt
(list of options appears with zsh states)

Exit and start again:

% unfunction allopt
% emulate sh -c "autoload -z allopt; allopt"
(list of options appears as expected, with "sh" states)
% allopt
(list of options appears with zsh states)

So there's no way to cause an autoloaded function to acquire sticky
emulation, which is what's meant by "No special handling for ...
autoload."

-- 



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