Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: function lazy loading. #273

Closed
wants to merge 1 commit into from
Closed

feat: function lazy loading. #273

wants to merge 1 commit into from

Conversation

alxbl
Copy link
Collaborator

@alxbl alxbl commented Oct 11, 2019

As mentioned in #272, this PR adds lazy loading capabilities to the function arrays. It will only source the functions that are requested in one of the prompts. I've done a quick spot check and it doesn't seem to cause any issues.

Cheers,
Alex

@jedahan
Copy link
Member

jedahan commented Oct 11, 2019

So I think the only downside of this, is if someone adds a function to either array that was supposed to be sourced first.

I think by understanding autoload/fpath we could have our cake and eat it too, but we might have to ask #zsh-users for help.

@jedahan
Copy link
Member

jedahan commented Oct 11, 2019

I would love to have this feature, btw

@alxbl
Copy link
Collaborator Author

alxbl commented Oct 11, 2019 via email

@alxbl
Copy link
Collaborator Author

alxbl commented Oct 16, 2019

Good news!

autoload works very nicely. It can even be used without touching fpath manually by specifying absolute paths. I've still got to test it with the existing plugin system, but initial tests show that

autoload -Uk /absolute/path/to/function_name will have the desired behavior of running the initialization code once upon first call and calling the function. The only caveat right now is that function files are suffixed with .zsh, and I think that this won't play nice with autoload (which expects file_name==function_name for the auto-call to work. I'll see if this can be modified, otherwise it might be necessary to follow autoload's syntax.

Cheers,
Alex

@jedahan
Copy link
Member

jedahan commented Oct 17, 2019

Thanks for the research and testing. I think it’s fine to rename the function files to not have a zsh extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants