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

Re: wheels within wheels



On Wed, Sep 30, 2015 at 5:40 AM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Sep 29,  7:55pm, Kurtis Rader wrote:
> }
> } In short: don't do it.
>
> That's a bit too short.  Nesting function definitions is exactly what a
> lot of autoloadable functions do.  The difference is that autoloadable
> functions also redefine *themselves* this way, to change what happens
> the second time the "same" function (in name only) is called.

Another example where this is needed is to do this:

function _zle_line_init() {
  zle set-local-history -n 1
  function _zle_line_init() {
    # do whatever it is you actually wanted to do in zle-line-init here
  }
  _zle_line_init
}

Ie, to set local history by default when you start the shell, because
it has to be run from within a widget, but you may want to toggle it
while running the shell so it can't stay in the line-init hook.
Therefore, do it the first time, and then redefine the hook to do
something else.

-- 
Mikael Magnusson



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