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

Re: autoload +X xxx zero reference count



On Wed, Apr 15, 2026 at 8:27 AM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>
> autoreload () {
>   unfunction - $@
>   autoload -Uz +X - $@
> }
>
> and as it turns out this doesn't work on functions that were
> autoloaded with an absolute path outside of fpath.

I know you said "beside the point" but:

autoreload () {
  [[ -n "$1" ]] || {
    return 1
    eval "echo Not running zsh. ; exit 1"
  }
  local fn w IFS
  unset IFS  # Paranoia
  for fn in "$@"
  do
    w=($(whence -v "$fn"))
    if [[ $w = *function* ]]
    then
      unfunction - "$fn"
      case $w in
        ($fn is a* shell function from *) autoload -Uz +X - ${w[-1]} ;;
        (*) autoload -Uz +X - "$fn" ;;
      esac
    else
      print -u2 -r -- $w
    fi
  done
}

Needs massaging if your autoload path has spaces in it.

> I bisected the error to 8f5fe841a63fecdab4416578653549689f2c592f but
> that's simply the commit that adds the error message.

Hm, that's supposed to be detecting a special case of a function being
removed during its own execution, but maybe it's firing for
not-yet-loaded autoloads?




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