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

lib/vim-plugin: Add support for luaConfig #2624

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

traxys
Copy link
Member

@traxys traxys commented Dec 9, 2024

This series allows to use luaConfig for vim plugins that are configured through global variables

lib/types.nix Outdated Show resolved Hide resolved
lib/types.nix Outdated Show resolved Hide resolved
@traxys traxys force-pushed the vim-lua-config branch 2 times, most recently from 86fb737 to d63acc9 Compare December 11, 2024 18:13
This will be used to implement `luaConfig` for plugins that use global
variables for their configuration
Copy link
Member

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took me until now to read past lib/types.nix and actually look at the main part of the PR...

Comment on lines +124 to +127
(lib.optionalAttrs createSettingsOption {
globalsPre = lib.nixvim.mkIfNonNull cfg.luaConfig.pre;
globalsPost = lib.nixvim.mkIfNonNull cfg.luaConfig.post;
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial reaction: I'm not a fan of this.

I don't think it makes sense to assign lua code to an option named "globals*".

Comment on lines +49 to +61
// {
globalsPre = lib.mkOption {
type = lib.types.lines;
default = "";
internal = true;
};

globalsPost = lib.mkOption {
type = lib.types.lines;
default = "";
internal = true;
};
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the intention is that this is lua code injected pre/post the lua impl for the globals option.

But reading the option name I'd half-expect to be able to assign globals earlier or later than normal.

This feels like working around a poor design rather than an objective improvement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if instead, each plugin should be responsible for using vim.g[k] = itself. Perhaps within luaConfig.init ?

Yes, this would mean vim-plugins aren't taking advantage of the globals option, and consiquently end-users won't see the configured globals when inspecting the option's value. But perhaps that is worth it in order to locate the globals in a more predictable location?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea: Perhaps the luaConfig submodule could also be used for non-plugin modules too? E.g. we could have a globalsLuaConfig option, and move the lua impl to globalsLuaConfig.init?

(maybe rename init something like main, content, text, etc?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really a fan of any of the three solutions, tbh. So open to alternative proposals too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if instead, each plugin should be responsible for using vim.g[k] = itself. Perhaps within luaConfig.init ?

Yes, this would mean vim-plugins aren't taking advantage of the globals option, and consiquently end-users won't see the configured globals when inspecting the option's value. But perhaps that is worth it in order to locate the globals in a more predictable location?

I though about that, but I think setting the global options in nix is a bit better, as it allows to do more compile time stuff (though you could still do compile time stuff by accessing the plugin's settings)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea: Perhaps the luaConfig submodule could also be used for non-plugin modules too? E.g. we could have a globalsLuaConfig option, and move the lua impl to globalsLuaConfig.init?

(maybe rename init something like main, content, text, etc?)

There could be a use for it, for example to define helpers for keymaps, or options

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