Skip to content

Commit

Permalink
feat: support both toml and lua configuration
Browse files Browse the repository at this point in the history
mrcjkb committed Jun 17, 2024
1 parent c2fb58f commit c6e0be3
Showing 5 changed files with 73 additions and 8 deletions.
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -63,11 +63,11 @@ and you are good to go!

## :books: Usage

### Via `rocks.toml`

With this module installed, you can add the following fields to a `[plugins]` entry
in your `rocks.toml`:

### Fields

#### `event`

Lazy-load on an event (`:h autocmd-events`).
@@ -206,6 +206,56 @@ colorscheme = [
> keys = [ { lhs = "<leader>t", rhs = "<CMD>Telescope<CR>" } ]
> ```
### Lua configuration
If you prefer using Lua for configuration,
you can use the `vim.g.rocks_nvim.lz_spec` field, which can be
- A [`lz.n.PluginSpec`](https://github.com/nvim-neorocks/lz.n?tab=readme-ov-file#plugin-spec).
- A Lua module name (`string`) that contains your plugin spec.
See [the `lz.n` documentation](https://github.com/nvim-neorocks/lz.n?tab=readme-ov-file#structuring-your-plugins).
> [!IMPORTANT]
>
> If you use a module name to import your plugin specs
> and you also use `rocks-config.nvim`,
> the `lz_spec` module name **must not clash** with the `rocks-config` `plugins_dir`.
Examples:
```lua
vim.g.rocks_nvim = {
-- ...
lz_spec = {
{
"crates.nvim",
-- lazy-load when opening a toml file
ft = "toml",
},
{
"sweetie.nvim",
-- lazy-load when setting the `sweetie` colorscheme
colorscheme = "sweetie",
},
},
}
```
Or

```lua
vim.g.rocks_nvim = {
-- ...
lz_spec = "lazy_specs", -- Spec modules in nvim/lua/lazy_specs/<spec>.lua
}
```

> [!TIP]
>
> You can use both `rocks.toml` entries and a Lua config to configure
> your plugin specs.
> `rocks-lazy.nvim` will merge the resulting specs.
## :book: License

`rocks-lazy.nvim` is licensed under [GPLv3](./LICENSE).
3 changes: 3 additions & 0 deletions lua/rocks-lazy/meta.lua
Original file line number Diff line number Diff line change
@@ -30,3 +30,6 @@ error("Cannot require a meta module")
---@field nowait? boolean
---@field ft? string|string[]
---@field mode? string|string[]

---@type lz.n.Spec
vim.g.rocks_nvim.lz_spec = vim.g.rocks_nvim.lz_spec
10 changes: 5 additions & 5 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -13,16 +13,16 @@
}:
buildLuarocksPackage {
pname = "lz.n";
version = "1.2.3-1";
version = "1.2.4-1";
knownRockspec =
(fetchurl {
url = "mirror://luarocks/lz.n-1.2.3-1.rockspec";
sha256 = "1h89pkj8j82wfzqvia54q70y1zpdwkc4j8kifl3xpmyyp4kgibkw";
url = "mirror://luarocks/lz.n-1.2.4-1.rockspec";
sha256 = "sha256-DR0wr7wczl0P1PEMDSc9w9gU30KstX/rWBjAcx97k7A=";
})
.outPath;
src = fetchzip {
url = "https://github.com/nvim-neorocks/lz.n/archive/v1.2.3.zip";
sha256 = "1bms3ynha48mar2zfmyd3vlvxz7v3q1v5jxp1dhxwmyxa1dp2vhc";
url = "https://github.com/nvim-neorocks/lz.n/archive/v1.2.4.zip";
sha256 = "sha256-T4gRlf7GoiPhwvQnvomKLU4y21v1zFm3YcKvsdgkSds=";
};
disabled = luaOlder "5.1";
}) {};
12 changes: 12 additions & 0 deletions plugin/rocks-lazy.lua
Original file line number Diff line number Diff line change
@@ -76,4 +76,16 @@ local specs = vim.iter(user_rocks)
end)
:totable()

local lz_spec = vim.g.rocks_nvim and vim.g.rocks_nvim.lz_spec or {}
if type(lz_spec) == "string" then
table.insert(specs, { import = lz_spec })
else
local is_single_plugin_spec = type(lz_spec[1]) == "string"
if is_single_plugin_spec then
table.insert(specs, lz_spec)
elseif vim.islist(lz_spec) then
vim.list_extend(specs, lz_spec)
end
end

lz_n.load(specs)
2 changes: 1 addition & 1 deletion rocks-lazy.nvim-scm-1.rockspec
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ version = _MODREV .. _SPECREV
dependencies = {
"lua >= 5.1",
"rocks.nvim >= 1.19.0",
"lz.n >= 1.2.3",
"lz.n >= 1.2.4",
}

source = {

0 comments on commit c6e0be3

Please sign in to comment.