2024-05-17 21:19:46 +03:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
options = import ./vim/options.nix { inherit lib; };
|
|
|
|
|
|
|
|
bufferOpts = { name, config, ... }: {
|
|
|
|
options = with lib; {
|
|
|
|
filetypes = mkOption {
|
|
|
|
type = types.extCommas;
|
|
|
|
description = "File types for which the buffer is enabled";
|
|
|
|
};
|
2024-05-17 21:23:34 +03:00
|
|
|
opt = options.buffer // options.window;
|
2024-05-17 21:19:46 +03:00
|
|
|
};
|
|
|
|
config = {
|
|
|
|
filetypes = lib.mkDefault name;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkFiletypeBuffer = name: cfg:
|
|
|
|
lib.nameValuePair
|
|
|
|
"buffer-${name}"
|
|
|
|
{
|
|
|
|
event = "FileType";
|
|
|
|
pattern = cfg.filetypes;
|
|
|
|
callback = with lib; with nix2lua; lambda ["ev"] (lib.flatten [
|
|
|
|
(flip mapAttrsToList cfg.opt (k: v: if v == null then null else set "vim.opt.${k}" v))
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.buffer = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (submodule bufferOpts);
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
vim.augroup = lib.mkIf (config.buffer != {}) (lib.listToAttrs (lib.mapAttrsToList mkFiletypeBuffer config.buffer));
|
|
|
|
};
|
|
|
|
}
|