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

Re: Announce of Zsh Navigation Tools



On 09/12/2015 12:41 PM, ZyX wrote:
They will work if located in *any* directory listed in $fpath. And they *are* functions, you need to read about autoload functions in man zshmisc, section AUTOLOADING FUNCTIONS:

I see. So we very elegantly have it both ways--a script as it appears to be, but also as a function via autoload.

        If  the  KSH_AUTOLOAD option is set, or the file contains only a simple definition of the function, the file's contents will be executed.  This will normally define the function in question, but may also per‐
        form initialization, which is executed in the context of the function execution, and may therefore define local parameters.  It is an error if the function is not defined by loading the file.

        Otherwise, the function body (with no surrounding `funcname() {...}') is taken to be the complete contents of the file.  This form allows the file to be used directly as an executable shell script.   If  pro‐
        cessing  of the file results in the function being re-defined, the function itself is not re-executed.  To force the shell to perform initialization and then call the function defined, the file should contain
        initialization code (which will be executed then discarded) in addition to a complete function definition (which will be retained for subsequent calls to the function), and  a  call  to  the  shell  function,
        including any arguments, at the end.
That clarifies things greatly. I've had a vague wondering what autoload was, just took it on faith that it was important. What are the pros and cons of doing things that way vs. what might seem to be the more obvious function definition? It's more compact, but then requires the special calling via autoload. I expect there will be some substantial difference.





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