Subject: Re: Proof of concept mainstream plugin manager
From: Bart Schaefer <[email-masked]>
To: Zsh hackers list <[email-masked]>
Date: Sat, 23 Jan 2016 12:00:55 -0800
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Jan 23, 11:20am, I wrote:
}
}      eval "function $func {
}        unfunction $func
}        local FPATH=${(q)PLUGIN_DIR}"'":${FPATH}"'"
}        autoload $opts $func
}        $func
}      }"

The last line of course needs to be 

    $func "$@"

If that's the approach, it might be useful to do something like this:

    _reload_and_run () {
      local fpath_prefix="$1" autoload_opts="$2" func="$3"
      shift 3
      unfunction "$func"
      local FPATH="$fpath_prefix":"${FPATH}"
      builtin autoload $=autoload_opts "$func"
      "$func" "$@"
    }

    shadow-autoload () {
      local -a opts
      local func
      zparseopts -a opts -D ${(s::):-TUXkmtzw}
      if (( $opts[(I)(-|+)X] ))
      then
        print -u2 "builtin autoload required for $opts"
        return 1
      fi
      if (( $opts[(I)-w] ))
      then
        builtin autoload $opts "$@"
        return
      fi
      for func
      do
        eval "function $func { 
          _reload_and_run ${(q)PLUGIN_DIR} ${(qq)opts} $func "'"$@"
        }'
      done
    }