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

setopt localfunctions, and two bugs with disable?



On Nov 3, 12:53am, I wrote:
} 
} (Aside #2:  Does anybody wish there were an equivalent of "localoptions"
} that applied to functions and aliases, so that autoloads could blow away
} all the possible screwy redefinitions of builtins from their environment,
} yet have them magically restored when the function exits?)

Some thoughts that occur to me:

1.  One can of course use `disable -fm \*` and `disable -am \*`.  This
    requires that you remember to `enable -fm \*` etc. before returning,
    and doesn't provide for local redefinition of functions.  (BTW, I
    think there are some bugs in `disable -fm`.  See below.)

2.  It's difficult to make this work for aliases, because they're applied
    at lex time.  You can play some sneaky games with "eval" or "autoload"
    to defer lexing, but I'm not sure it's worth the effort.

3.  A possible implementation is to save and restore the function hash
    table, under control of a "localfunctions" option, exactly as the
    options array is saved and restored under control of "localoptions",
    upon every function entry/exit.  Doing so efficiently might be hard.
    (The options array is saved/restored on every call, no matter what
    the current setting of localoptions.  It occurs to me that there is
    probably a more efficient way to handle *that*, too.)

4.  Another possible implementation is to temporarily switch the order
    in which the builtin and function hash tables are searched.  That
    would mask all functions that have the same names as builtins, but
    leave other functions available.  However, it doesn't permit local
    redefinition of functions without loss of the original definitions,
    and it doesn't provide for local overrides of builtins (maybe some
    further tricks with "disable" would solve that).

Anyone else have thoughts on this?

The bugs in disable that I mentioned:

zagzig[440] functions
	(... lots of output suppressed ...)
undefined work () { }
undefined xvi () { }
undefined zed () { }
undefined zfind () { }
undefined zlook () { }
undefined zm () { }
	(... more output suppressed ...)
zagzig[441] disable -fm \*
zagzig[442] functions
undefined xvi () { }
zagzig[443] enable -fm \*
zagzig[444] functions
	(... same output as history 440 ...)
zagzig[445]

How did `xvi' survive through the "disable" command?

Also, the shell in which I performed the above actions appears to have
silently exited (and without saving history) upon the next expiration of
TMOUT.  I suspect that `disable -fm \*` did something bad with respect
to my TRAPALRM() function and the associated signal handlers, or at least
that `enable -fm \*` failed to restore something.

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern



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