nix-community.nixvim/modules/autocmd.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

94 lines
2.4 KiB
Nix
Raw Permalink Normal View History

{
lib,
helpers,
config,
...
}:
{
options = {
2024-08-30 14:37:41 -05:00
autoGroups = lib.mkOption {
type = lib.types.attrsOf helpers.autocmd.autoGroupOption;
default = { };
description = "augroup definitions";
example = {
my_augroup = {
clear = true;
};
};
};
2024-08-30 14:37:41 -05:00
autoCmd = lib.mkOption {
type = lib.types.listOf helpers.autocmd.autoCmdOption;
default = [ ];
description = "autocmd definitions";
example = [
{
event = [
"BufEnter"
"BufWinEnter"
];
pattern = [
"*.c"
"*.h"
];
command = "echo 'Entering a C or C++ file'";
}
];
};
2023-01-17 00:40:29 +01:00
};
config =
let
inherit (config) autoGroups autoCmd;
in
2024-08-30 14:37:41 -05:00
lib.mkIf (autoGroups != { } || autoCmd != [ ]) {
# Introduced early October 2023.
# TODO remove in early December 2023.
assertions = [
{
2024-08-30 14:37:41 -05:00
assertion = lib.all (x: x.description == null) autoCmd;
message = ''
RENAMED OPTION: `autoCmd[].description` has been renamed `autoCmd[].desc`.
Please update your configuration.
'';
}
];
extraConfigLuaPost =
2024-08-30 14:37:41 -05:00
(lib.optionalString (autoGroups != { }) ''
-- Set up autogroups {{
do
local __nixvim_autogroups = ${lib.nixvim.toLuaObject autoGroups}
for group_name, options in pairs(__nixvim_autogroups) do
vim.api.nvim_create_augroup(group_name, options)
end
end
-- }}
'')
2024-08-30 14:37:41 -05:00
+ (lib.optionalString (autoCmd != [ ]) ''
-- Set up autocommands {{
do
local __nixvim_autocommands = ${lib.nixvim.toLuaObject autoCmd}
2023-01-17 00:40:29 +01:00
for _, autocmd in ipairs(__nixvim_autocommands) do
vim.api.nvim_create_autocmd(
autocmd.event,
{
group = autocmd.group,
pattern = autocmd.pattern,
buffer = autocmd.buffer,
desc = autocmd.desc,
callback = autocmd.callback,
command = autocmd.command,
once = autocmd.once,
nested = autocmd.nested
}
)
end
end
-- }}
'');
};
2023-01-17 00:40:29 +01:00
}