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

Re: Function not found

On Dec 20,  4:03am, Brandon Sandrowicz wrote:
} On Wed, Dec 19, 2012 at 10:44:23PM -0800, czech@xxxxxxxxx wrote:
} > 
} > _ssh() {
} >     ssh -XC "czechar@$@"
} > }
} > 
} > autoload -- ~/.zfunc/[^_]*(:t)
} > fpath=( ~/.zfunc $fpath )
} The autoload command you have here appears to be your problem.
} If your _ssh function is defined in the file ~/.zfunc/_ssh, your
} original command *could* work, but you would have to remove the '[^_]'
} which prevents files beginning with underscores.

My guess is that the [^_] was copied from a recipe related to the
completion system.  In most cases (as Jeremie later mentioned) any
file with a leading underscore in its name would contain a completion
function of some kind, and would therefore have a "#compdef" line at
the top.  These files are autoloaded by the compinit command (if the
$fpath is properly set when compinit is run) and therefore don't need
to be autoloaded a second time from .zshrc.
} To be clear, autoload wants the names of the *functions*, not the names
} of the files. Your approach above could work so long as each function is
} in a separate file, and both (file and function) share the same exact
} name (i.e. can't be _ssh.zsh).

To be even more specific, autoload depends upon the names of the files
being the *same* as the names of the functions.  Generally, the file
should contain only the function body, not the func() { ... } syntax.
If that syntax is used in the file, you need "autoload -k".  There are
exceptions, and reasons for a file to contain more than one function,
but you should avoid that until you understand the operation in detail.

Barton E. Schaefer

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