2024-05-17 21:19:46 +03:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
let
|
2024-05-20 10:46:25 +03:00
|
|
|
cfg = config.buffer;
|
|
|
|
|
2024-05-17 21:19:46 +03:00
|
|
|
options = import ./vim/options.nix { inherit lib; };
|
|
|
|
|
|
|
|
bufferOpts = { name, config, ... }: {
|
|
|
|
options = with lib; {
|
2024-05-20 10:46:25 +03:00
|
|
|
pattern = mkOption {
|
2024-05-17 21:19:46 +03:00
|
|
|
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 = {
|
2024-05-20 10:46:25 +03:00
|
|
|
pattern = lib.mkIf (!lib.hasPrefix "[definition " name) (lib.mkDefault name);
|
2024-05-17 21:19:46 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-20 10:46:25 +03:00
|
|
|
mkBuffer = { prefix, event }: name: cfg:
|
2024-05-17 21:19:46 +03:00
|
|
|
lib.nameValuePair
|
2024-05-20 10:46:25 +03:00
|
|
|
"buffer-${prefix}-${name}"
|
2024-05-17 21:19:46 +03:00
|
|
|
{
|
2024-05-20 10:46:25 +03:00
|
|
|
inherit event;
|
|
|
|
inherit (cfg) pattern;
|
|
|
|
callback = with lib; with nix2lua; lambda [ "ev" ] (lib.flatten [
|
2024-05-20 14:25:39 +03:00
|
|
|
(flip mapAttrsToList cfg.opt (k: set "vim.opt.${k}"))
|
2024-05-17 21:19:46 +03:00
|
|
|
]);
|
|
|
|
};
|
2024-05-20 10:46:25 +03:00
|
|
|
|
|
|
|
mkFiletypeBuffer = mkBuffer { prefix = "filetype"; event = "FileType"; };
|
|
|
|
|
|
|
|
mkReadBuffer = cfg:
|
|
|
|
mkBuffer
|
|
|
|
{ prefix = "read"; event = [ "BufNewFile" "BufRead" ]; }
|
|
|
|
(builtins.hashString "sha1" cfg.patterns)
|
|
|
|
cfg;
|
2024-05-17 21:19:46 +03:00
|
|
|
in
|
|
|
|
{
|
2024-05-20 10:46:25 +03:00
|
|
|
options.buffer = {
|
|
|
|
read = lib.mkOption {
|
|
|
|
type = with lib.types; listOf (submodule bufferOpts);
|
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
filetype = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf (submodule bufferOpts);
|
|
|
|
default = { };
|
|
|
|
};
|
2024-05-17 21:19:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2024-05-20 10:46:25 +03:00
|
|
|
vim.augroup = lib.mkMerge [
|
|
|
|
(lib.mkIf (cfg.filetype != { }) (lib.listToAttrs (lib.mapAttrsToList mkFiletypeBuffer cfg.filetype)))
|
|
|
|
(lib.mkIf (cfg.read != [ ]) (lib.listToAttrs (lib.map mkReadBuffer cfg.read)))
|
|
|
|
];
|
2024-05-17 21:19:46 +03:00
|
|
|
};
|
|
|
|
}
|