nix-community.nixvim/lib/autocmd-helpers.nix

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

77 lines
2.6 KiB
Nix
Raw Normal View History

2024-07-28 22:30:11 +01:00
{ lib, helpers }:
with lib;
rec {
autoGroupOption = types.submodule {
options = {
clear = mkOption {
type = types.bool;
description = "Clear existing commands if the group already exists.";
default = true;
};
};
};
autoCmdOptions = {
2024-07-28 22:30:11 +01:00
event = helpers.mkNullOrOption (with types; either str (listOf str)) ''
The event or events to register this autocommand.
'';
2024-07-28 22:30:11 +01:00
group = helpers.mkNullOrOption (with types; either str int) ''
The autocommand group name or id to match against.
'';
2024-07-28 22:30:11 +01:00
pattern = helpers.mkNullOrOption (with types; either str (listOf str)) ''
Pattern or patterns to match literally against.
'';
2024-07-28 22:30:11 +01:00
buffer = helpers.mkNullOrOption types.int ''
Buffer number for buffer local autocommands |autocmd-buflocal|.
Cannot be used with `pattern`.
'';
# Introduced early October 2023.
# TODO remove in early December 2023.
2024-07-28 22:30:11 +01:00
description = helpers.mkNullOrOption types.str ''
DEPRECATED, please use `desc`.
'';
2024-07-28 22:30:11 +01:00
desc = helpers.mkNullOrOption types.str ''
A textual description of this autocommand.
'';
2024-07-28 22:30:11 +01:00
callback = helpers.mkNullOrOption (with types; either str helpers.nixvimTypes.rawLua) ''
A function or a string.
- if a string, the name of a Vimscript function to call when this autocommand is triggered.
- Otherwise, a Lua function which is called when this autocommand is triggered.
Cannot be used with `command`.
Lua callbacks can return true to delete the autocommand; in addition, they accept a single
table argument with the following keys:
- id: (number) the autocommand id
- event: (string) the name of the event that triggered the autocommand |autocmd-events|
- group: (number|nil) the autocommand group id, if it exists
- match: (string) the expanded value of |<amatch>|
- buf: (number) the expanded value of |<abuf>|
- file: (string) the expanded value of |<afile>|
- data: (any) arbitrary data passed to |nvim_exec_autocmds()|
Example using callback:
autoCmd = [
{
event = [ "BufEnter" "BufWinEnter" ];
pattern = [ "*.c" "*.h" ];
callback = { __raw = "function() print('This buffer enters') end"; };
}
'';
2024-07-28 22:30:11 +01:00
command = helpers.defaultNullOpts.mkStr "" ''
Vim command to execute on event. Cannot be used with `callback`.
'';
2024-07-28 22:30:11 +01:00
once = helpers.defaultNullOpts.mkBool false "Run the autocommand only once.";
2024-07-28 22:30:11 +01:00
nested = helpers.defaultNullOpts.mkBool false "Run nested autocommands.";
};
autoCmdOption = types.submodule { options = autoCmdOptions; };
}