mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-02-23 03:48:01 +00:00
init/autocmds: fix autogroups
Some checks are pending
Check for typos in the source tree / check-typos (push) Waiting to run
Some checks are pending
Check for typos in the source tree / check-typos (push) Waiting to run
This commit is contained in:
parent
403072cae3
commit
80fe9244e2
1 changed files with 58 additions and 37 deletions
|
@ -6,7 +6,7 @@
|
|||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.lists) filter;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.types) submodule listOf str bool;
|
||||
inherit (lib.types) nullOr submodule listOf str bool;
|
||||
inherit (lib.nvim.types) luaInline;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
inherit (lib.nvim.dag) entryAfter;
|
||||
|
@ -21,40 +21,46 @@
|
|||
};
|
||||
|
||||
event = mkOption {
|
||||
type = listOf str;
|
||||
type = nullOr (listOf str);
|
||||
default = null;
|
||||
example = ["BufRead" "BufWritePre"];
|
||||
description = "The event(s) that trigger the autocommand.";
|
||||
};
|
||||
|
||||
pattern = mkOption {
|
||||
type = listOf str;
|
||||
type = nullOr (listOf str);
|
||||
default = null;
|
||||
example = ["*.lua" "*.vim"];
|
||||
description = "The file pattern(s) that determine when the autocommand applies).";
|
||||
};
|
||||
|
||||
callback = mkOption {
|
||||
type = luaInline;
|
||||
type = nullOr luaInline;
|
||||
default = null;
|
||||
example = ''
|
||||
function()
|
||||
print("Saving a Lua file...")
|
||||
end,
|
||||
'';
|
||||
description = "The file pattern(s) that determine when the autocommand applies).";
|
||||
description = "The file pattern(s) that determine when the autocommand applies.";
|
||||
};
|
||||
|
||||
command = mkOption {
|
||||
type = str;
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
description = "Vim command string instead of a Lua function.";
|
||||
};
|
||||
|
||||
group = mkOption {
|
||||
type = str;
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
example = "MyAutoCmdGroup";
|
||||
description = "An optional autocommand group to manage related autocommands.";
|
||||
};
|
||||
|
||||
desc = mkOption {
|
||||
type = str;
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
example = "Notify when saving a Lua file";
|
||||
description = "A description for the autocommand.";
|
||||
};
|
||||
|
@ -127,13 +133,20 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
config.vim = let
|
||||
config = {
|
||||
vim = let
|
||||
enabledAutocommands = filter (cmd: cmd.enable) cfg.autocmds;
|
||||
enabledAutogroups = filter (au: au.enable) cfg.augroups;
|
||||
in {
|
||||
luaConfigRC = {
|
||||
augroups = entryAfter ["pluginConfigs"] (optionalString (enabledAutogroups != []) ''
|
||||
local nvf_autogroups = ${toLuaObject cfg.autogroups}
|
||||
local nvf_autogroups = {}
|
||||
for _, group in ipairs(${toLuaObject enabledAutogroups}) do
|
||||
if group.name then
|
||||
nvf_autogroups[group.name] = { clear = group.clear }
|
||||
end
|
||||
end
|
||||
|
||||
for group_name, options in pairs(nvf_autogroups) do
|
||||
vim.api.nvim_create_augroup(group_name, options)
|
||||
end
|
||||
|
@ -159,4 +172,12 @@ in {
|
|||
'');
|
||||
};
|
||||
};
|
||||
|
||||
assertions = [
|
||||
{
|
||||
assertion = builtins.all (cmd: !(cmd.command != null && cmd.callback != null)) cfg.autocmds;
|
||||
message = "An autocommand cannot have both 'command' and 'callback' defined at the same time.";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue