zsh-users
 help / color / mirror / Atom feed
* Re-loading files loaded via "autoload"
@ 2021-08-11  7:49 Zach Riggle
  2021-08-11 18:25 ` Mikael Magnusson
  0 siblings, 1 reply; 5+ messages in thread
From: Zach Riggle @ 2021-08-11  7:49 UTC (permalink / raw)
  To: Zsh Users

Hello all!

Thanks in advance for my spam.  I recently spent some time spelunking
in the Zsh docs for how to get an "autoload"ed module (sorry if the
terminology is incorrect) to be re-loaded.

It appears this is possible, but not well documented.

Specifically, "unfunction" or "unset -f" work to permit the "autoload
foo" to run again, and re-define the various functions declared in the
module.

What's the appropriate venue to ask for documentation updates, since
this should likely be in the documentation for [1].

# Homework

I looked at the documentation page for autoloading functions [1] as
well as the page for the autoload builtin itself [2].

As always, SEARCHING the man page / info page / HTML pages are
difficult, because it's not possible to scope the search results to
"just this section here" so searching for "remove" or "reload" shows
lots of unrelated hits.

Because "autoload" has its own page, the behavior of unfunction /
unset -f should probably be documented there.

[1]: https://zsh.sourceforge.io/Doc/Release/Functions.html#Functions
[2]: https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html

Zach Riggle


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re-loading files loaded via "autoload"
  2021-08-11  7:49 Re-loading files loaded via "autoload" Zach Riggle
@ 2021-08-11 18:25 ` Mikael Magnusson
  2021-08-11 18:56   ` Bart Schaefer
  2021-08-12 16:04   ` Philippe Troin
  0 siblings, 2 replies; 5+ messages in thread
From: Mikael Magnusson @ 2021-08-11 18:25 UTC (permalink / raw)
  To: Zach Riggle; +Cc: Zsh Users

On 8/11/21, Zach Riggle <zachriggle@gmail.com> wrote:
> Hello all!
>
> Thanks in advance for my spam.  I recently spent some time spelunking
> in the Zsh docs for how to get an "autoload"ed module (sorry if the
> terminology is incorrect) to be re-loaded.
>
> It appears this is possible, but not well documented.
>
> Specifically, "unfunction" or "unset -f" work to permit the "autoload
> foo" to run again, and re-define the various functions declared in the
> module.
>
> What's the appropriate venue to ask for documentation updates, since
> this should likely be in the documentation for [1].
>
> # Homework
>
> I looked at the documentation page for autoloading functions [1] as
> well as the page for the autoload builtin itself [2].
>
> As always, SEARCHING the man page / info page / HTML pages are
> difficult, because it's not possible to scope the search results to
> "just this section here" so searching for "remove" or "reload" shows
> lots of unrelated hits.
>
> Because "autoload" has its own page, the behavior of unfunction /
> unset -f should probably be documented there.
>
> [1]: https://zsh.sourceforge.io/Doc/Release/Functions.html#Functions
> [2]: https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html
>
> Zach Riggle

It is implied in some places that you can do this, but perhaps it is
worth mentioning explicitly somewhere?

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...


But then this introductory paragraph for the autoload builtin:
              If name consists of an absolute path, the function is
defined to  load
              from  the  file  given (searching as usual for dump
files in the given
              location).  The name of the function is  the  basename
(non-directory

makes no mention of the fact that this is not true if 'name' is
already a defined function, and it also doesn't seem to mention it in
any of the subsequent paragraphs.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re-loading files loaded via "autoload"
  2021-08-11 18:25 ` Mikael Magnusson
@ 2021-08-11 18:56   ` Bart Schaefer
  2021-08-12 16:04   ` Philippe Troin
  1 sibling, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2021-08-11 18:56 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Zach Riggle, Zsh Users

On Wed, Aug 11, 2021 at 11:25 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> On 8/11/21, Zach Riggle <zachriggle@gmail.com> wrote:
> >
> > Thanks in advance for my spam.  I recently spent some time spelunking
> > in the Zsh docs for how to get an "autoload"ed module (sorry if the
> > terminology is incorrect) to be re-loaded.

A "module" usually refers to a binary object managed by "zmodload".
There really isn't a consistent shorthand terminology for an
"autoload" function that happens to define multiple helpers in its
source file.

> It is implied in some places that you can do this, but perhaps it is
> worth mentioning explicitly somewhere?

Given that we have an entire section dedicated to "Autoloading
functions" it would seem reasonable to mention it there.

> 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:

Those are no longer entirely equivalent, for one thing as you noted
about loading from absolute paths.  There's no way to attach this
metadata to the function definition when wrapping up an "autoload -X"
command yourself.  Some update of that example is probably worthwhile.
(This shortcoming does not apply to "autoload +X" as far as I know.)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re-loading files loaded via "autoload"
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Philippe Troin @ 2021-08-12 16:04 UTC (permalink / raw)
  To: Zsh Users

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
   }

Phil.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re-loading files loaded via "autoload"
  2021-08-12 16:04   ` Philippe Troin
@ 2021-08-13  2:29     ` Mikael Magnusson
  0 siblings, 0 replies; 5+ messages in thread
From: Mikael Magnusson @ 2021-08-13  2:29 UTC (permalink / raw)
  To: Philippe Troin; +Cc: Zsh Users

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-13  2:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11  7:49 Re-loading files loaded via "autoload" 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

zsh-users

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/zsh-users

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-users zsh-users/ https://inbox.vuxu.org/zsh-users \
		zsh-users@zsh.org
	public-inbox-index zsh-users

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git