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

Dynamic Require Expressions #276

Open
Talia-12 opened this issue Oct 22, 2024 · 4 comments
Open

Dynamic Require Expressions #276

Talia-12 opened this issue Oct 22, 2024 · 4 comments

Comments

@Talia-12
Copy link
Contributor

This refers to require expressions that can be outside of the top-level scope, or can accept arbitrary strings to determine where to require from (i.e. require at runtime). The usecase I have for this is that I'd like to add a system for project-specific plugins to my helix config (i.e. have a bunch of .scm files in the .helix directory in the project, and run all of them if I open helix in that project), and this is as far as I can tell currently not possible. (I have no idea how annoying this would be to add 😅)

@mattwparas
Copy link
Owner

If you're willing to wait a couple days, I will have a lot of examples of this functioning in a certain form. It is possible today, and I can follow up with some examples in a few minutes

eval or load currently work, however they're limited to running at the top level environment, as in running (eval (require ...)) within a function somewhere, will actually insert the definitions into the global top level environment. This ends up working well within helix since the "top level" is effectively the interface to calling functions within the interpreter itself.

I would like to enable eval within a certain namespace, however that isn't yet implemented. It is on my to do list, however it unfortunately, is quite annoying 😄

@Talia-12
Copy link
Contributor Author

some examples would be helpful! The interface I was originally intending to use was to iterate over all files in .helix/plugins/, load them, and call a helix-plugin! or init-plugin! method on them; I would also be fine with a solution that involved single .helix/helix.scm and .helix/init.scm files which are responsible for calling out to individual plugins. I think this would actually also require something like (map provide *some-list-of-functions*), not sure if that's supported either.

Also, while I'm asking questions, what do you think the most ergonomic way of taking a function required from somewhere and reproviding it in .helix with documentation describing what it does? If you're defining the function yourself you can add a ;;@doc comment where you define it, but if you're pulling it in from somewhere I'm not sure how to add an explainer to the helix command menu for it.

@mattwparas
Copy link
Owner

So I've adjusted the interface within helix to alleviate this. I just have some merge conflicts to address and then will have the update pushed - but the new way of doing this will just be to look at the global environment and find doc comments there.

So really, all that should be needed is a single init.scm which can call either (require ...) or (load-package! ...) (that is what I've called the dynamic require) - and if its exported (and has a doc comment), it will be available at the top level with the little pop up describing it.

@mattwparas
Copy link
Owner

Alright - apologies for the delay, but all of that is pushed now. You can find some examples here:

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

No branches or pull requests

2 participants