zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: "rehash" but for autoloaded functions
Date: Thu, 15 Sep 2022 12:07:09 -0700	[thread overview]
Message-ID: <CAH+w=7aYvV6vig2+g32wobiVcgE=wekw4tcBvjaF3ssBK+YHLw@mail.gmail.com> (raw)
In-Reply-To: <CAMP9c5k1xn59T+z-dSyQh0ZY=8borFYZfR_gzsbpjPwnijMZmA@mail.gmail.com>

On Thu, Sep 15, 2022 at 10:24 AM Zach Riggle <zachriggle@gmail.com> wrote:
>
> Is there an equivalent to "rehash" for autoloaded functions?

Presumably you mean functions that have already been loaded once, and
you want something to pick up the changes from disk?

Unfortunately once the function is loaded, there's no direct way to
determine HOW it was loaded.  You can find the file from which it was
loaded, but not whether that file was read from fpath or directly
sourced.

> It's fine if they revert to being not-autoloaded-yet, just looking for a simple solution other than "exec zsh -il" to get this effect.

But "not-autoloaded-yet" does mean still marked for future autoload, right?

> I expect I can write something to this effect with "$functions_source[pip]" and compare the ${filename:t} to the function name, but I expect there's something for this already.

If you already know the name of the function(s) you want to "rehash"
this is easy; I have a little (also autoloaded) function:

reload() { unfunction $* ; autoload $* }

The tricky bit (where you might be able to use some sort of heuristic
on $functions_source) is finding the names of all functions that need
re-auto-loading.  This is more delicate than "rehash" (which simply
discards the entire command table) because you have to avoid
"unfunction"-ing anything that can't be re-"autoload"-ed.

That "reload" has been unchanged since zsh2.4, could probably stand
updating for some of the new options available to autoload.


      reply	other threads:[~2022-09-15 19:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15 17:24 Zach Riggle
2022-09-15 19:07 ` Bart Schaefer [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='CAH+w=7aYvV6vig2+g32wobiVcgE=wekw4tcBvjaF3ssBK+YHLw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --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).