zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Philippe Troin <phil@fifi.org>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Re-loading files loaded via "autoload"
Date: Fri, 13 Aug 2021 04:29:15 +0200	[thread overview]
Message-ID: <CAHYJk3TXd9HqBrMMaNq0j2pJKOM6r81tsYuG75yuw_P1X2RyYg@mail.gmail.com> (raw)
In-Reply-To: <aeaa13fda1ea2aa79443f1ed966a6b25f4d5ef50.camel@fifi.org>

On 8/12/21, Philippe Troin <phil@fifi.org> wrote:
> On Wed, 2021-08-11 at 20:25 +0200, Mikael Magnusson wrote:
>> eg, we have this, which mentions it in a comment of the example code:
>>        It is also possible to create a function that is not  marked
>> as  autoloaded,
>>        but which loads its own definition by searching fpath, by using
>> `autoload -X'
>>        within a shell function.  For example, the following are
>> equivalent:
>>
>>               myfunc() {
>>                 autoload -X
>>               }
>>               myfunc args...
>>
>>        and
>>
>>               unfunction myfunc   # if myfunc was defined
>>               autoload myfunc
>>               myfunc args...
>
> I use this function as a convenience when I work on autoloaded
> functions:
>
>    autoreload () {
>    	emulate -L zsh
>    	local i
>    	for i in $@
>    	do
>    		(( $+functions[$i] )) && unfunction $i
>    		autoload -U $i
>    	done
>    }

Both unfunction and autoload -U will happily handle $@, so there's no
real need for the loop. You can redirect the unfunction 2> /dev/null
if you don't want to be informed that you specified a nonexisting
function as in the above.

You should also use - in case you ever want to specify a function
starting with - or +, eg unfunction - $@; autoload -U - $@ (another
non-equivalence in the code example above btw, -myfunc() autoload -X
will work as specified, but the second one will break for
-myfunc/+myfunc :)

-- 
Mikael Magnusson


      reply	other threads:[~2021-08-13  2:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-11  7:49 Zach Riggle
2021-08-11 18:25 ` Mikael Magnusson
2021-08-11 18:56   ` Bart Schaefer
2021-08-12 16:04   ` Philippe Troin
2021-08-13  2:29     ` Mikael Magnusson [this message]

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=CAHYJk3TXd9HqBrMMaNq0j2pJKOM6r81tsYuG75yuw_P1X2RyYg@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=phil@fifi.org \
    --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).