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

Re: autoload



On Sep 14,  7:48pm, Ray Andrews wrote:
}
} One more thing if you would Bart: get me started with combining zcompile 
} with autoload as you mentioned.  It sounds like a good idea but I can't 
} find anything on it.

I wrote about this in workers/36529 -- but I see that Sebastian had
redirected that thread from zsh-users to zsh-workers, so perhaps it
wasn't seen.  I'll reproduce here (so workers readers can stop now).


Take a look at the "zcompile" builtin and the "zrecompile" utility.
If you zcompile a collection of functions into a .zwc file, you can --

-- add the .zwc file name directly to $fpath and it will be searched
   like a directory at autoloaded-function execution time

-- specify the -z / -k behavior options at zcompile time so they don't
   have to be passed to autoload

-- easily autoload everything in the file:   autoload -w functions.zwc

ZWC files are machine-independent but zsh-version-dependent.  They get
memory-mapped when that's supported so the OS pages them efficiently.
The drawbacks are the version dependency if you frequently rebuild a
bleeding-edge shell (but see zrecompile) and that zcompile doesn't yet
support "sticky emulation" in any meaningful way.  Also, a ZWC file is
not like an archive file (e.g., a ZIP); you can't append or remove
individual functions, the whole file has to be rebuilt.

Finally, for Ray, you can for example replace your entire $fpath with
a single ZWC file:

    # Assume starting here with the default $fpath
    zsh_default_functions=~/.zsh-default-functions.zwc
    if ! zcompile -t $zsh_default_functions >&/dev/null
    then
      # File is missing or out of date.  Rebuild it.
      # Removes the file if any function cannot be compiled.
      zcompile $zsh_default_functions $^fpath/*(N.:A)
    fi
    if [[ -f $zsh_default_functions ]]
    then
      fpath=( $zsh_default_functions )
      autoload -w $zsh_default_functions
    fi



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