zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: Announce of Zsh Navigation Tools
Date: Sat, 12 Sep 2015 14:03:06 -0700	[thread overview]
Message-ID: <55F4930A.40608@eastlink.ca> (raw)
In-Reply-To: <2125131442086868@web14o.yandex.ru>

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.

>


  reply	other threads:[~2015-09-12 21:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-08 12:32 Sebastian Gniazdowski
2015-09-12 17:50 ` Ray Andrews
2015-09-12 19:41   ` ZyX
2015-09-12 21:03     ` Ray Andrews [this message]
2015-09-12 22:10       ` Bart Schaefer
2015-09-12 23:03         ` Ray Andrews
2015-09-12 23:43           ` Bart Schaefer
2015-09-12 23:53             ` Bart Schaefer
2015-09-13  0:41             ` Ray Andrews
2015-09-13  2:36               ` Bart Schaefer
2015-09-13  3:33                 ` Ray Andrews
2015-09-14  2:14             ` autoload Ray Andrews
2015-09-14  2:38               ` autoload Bart Schaefer
2015-09-14  3:34                 ` autoload Ray Andrews
2015-09-14 20:21                   ` autoload Bart Schaefer
2015-09-15  2:48                     ` autoload Ray Andrews
2015-09-15  3:48                       ` autoload Bart Schaefer
2015-09-15 16:18                         ` autoload Ray Andrews
2015-09-16  4:09                         ` autoload Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55F4930A.40608@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).