mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 16:39:00 +02:00
modules: add autocmd (#120)
This commit is contained in:
parent
b9a4f0ca19
commit
d0910a6ddb
2 changed files with 127 additions and 0 deletions
113
modules/autocmd.nix
Normal file
113
modules/autocmd.nix
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
with lib;
|
||||||
|
let
|
||||||
|
helpers = import ../plugins/helpers.nix { inherit lib; };
|
||||||
|
|
||||||
|
autoCmdOption = types.submodule {
|
||||||
|
options = {
|
||||||
|
event = mkOption {
|
||||||
|
type = types.oneOf [
|
||||||
|
types.str
|
||||||
|
(types.listOf types.str)
|
||||||
|
];
|
||||||
|
description = "The event or events to register this autocommand.";
|
||||||
|
};
|
||||||
|
|
||||||
|
group = mkOption {
|
||||||
|
type = types.nullOr (types.oneOf [
|
||||||
|
types.str
|
||||||
|
types.int
|
||||||
|
]);
|
||||||
|
description = "The autocommand group name or id to match against.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
pattern = mkOption {
|
||||||
|
type = types.nullOr (types.oneOf [
|
||||||
|
types.str
|
||||||
|
(types.listOf types.str)
|
||||||
|
]);
|
||||||
|
description = "Pattern or patterns to match literally against.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
buffer = mkOption {
|
||||||
|
type = types.nullOr types.int;
|
||||||
|
description = "Buffer number for buffer local autocommands |autocmd-buflocal|. Cannot be used with <pattern>.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
description = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
description = "A textual description of this autocommand.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
callback = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
description = "The name of a Vimscript function to call when this autocommand is triggered. Cannot be used with <command>.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
command = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
description = "Vim command to execute on event. Cannot be used with <callback>";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
once = mkOption {
|
||||||
|
type = types.nullOr types.bool;
|
||||||
|
description = "Run the autocommand only once";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
nested = mkOption {
|
||||||
|
type = types.nullOr types.bool;
|
||||||
|
description = "Run nested autocommands.";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.autoCmd = mkOption {
|
||||||
|
type = types.listOf autoCmdOption;
|
||||||
|
default = [ ];
|
||||||
|
description = "autocmd definitions";
|
||||||
|
example = ''
|
||||||
|
autoCmd = [
|
||||||
|
{
|
||||||
|
event = [ "BufEnter" "BufWinEnter" ];
|
||||||
|
pattern = [ "*.c" "*.h" ];
|
||||||
|
command = "echo 'Entering a C or C++ file'";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
extraConfigLua = optionalString (config.autoCmd != [ ]) ''
|
||||||
|
-- Set up autocommands {{{
|
||||||
|
do
|
||||||
|
local __nixvim_autocommands = ${helpers.toLuaObject config.autoCmd}
|
||||||
|
|
||||||
|
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
|
||||||
|
-- }}}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
|
@ -247,6 +247,20 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
autoCmd = build {
|
||||||
|
autoCmd = [
|
||||||
|
{
|
||||||
|
event = [ "BufEnter" "BufWinEnter" ];
|
||||||
|
pattern = [ "*.c" "*.h" ];
|
||||||
|
command = "echo 'Entering a C or C++ file'";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
event = "InsertEnter";
|
||||||
|
command = "norm zz";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
ts-custom = build {
|
ts-custom = build {
|
||||||
plugins.treesitter = {
|
plugins.treesitter = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue