plugin/persistence: init + tests (#645)

This commit is contained in:
traxys 2023-10-16 23:54:41 +02:00 committed by GitHub
parent a9698ea2b0
commit 0b87e5b70c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 0 deletions

View file

@ -107,6 +107,8 @@ with lib; rec {
then null then null
else y; else y;
mkRawIfNonNull = v: ifNonNull' v (mkRaw v);
mkCompositeOption = desc: options: mkCompositeOption = desc: options:
mkNullOrOption (types.submodule {inherit options;}) desc; mkNullOrOption (types.submodule {inherit options;}) desc;

View file

@ -126,6 +126,7 @@
./utils/nvim-osc52.nix ./utils/nvim-osc52.nix
./utils/nvim-ufo.nix ./utils/nvim-ufo.nix
./utils/oil.nix ./utils/oil.nix
./utils/persistence.nix
./utils/project-nvim.nix ./utils/project-nvim.nix
./utils/presence-nvim.nix ./utils/presence-nvim.nix
./utils/quickmath.nix ./utils/quickmath.nix

View file

@ -0,0 +1,68 @@
{
config,
lib,
pkgs,
...
}:
with lib; let
helpers = import ../helpers.nix {inherit lib;};
in {
options.plugins.persistence =
helpers.extraOptionsOptions
// {
enable = mkEnableOption "persistence.nvim";
package = helpers.mkPackageOption "persistence.nvim" pkgs.vimPlugins.persistence-nvim;
dir =
helpers.defaultNullOpts.mkNullable (with types; either str helpers.rawType)
''vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/")''
"directory where session files are saved";
options = let
# https://neovim.io/doc/user/options.html#'sessionoptions'
sessionOpts = [
"blank"
"buffers"
"curdir"
"folds"
"globals"
"help"
"localoptions"
"options"
"skiprtp"
"resize"
"sesdir"
"tabpages"
"terminal"
"winpos"
"winsize"
];
in
helpers.defaultNullOpts.mkNullable (with types; listOf (enum sessionOpts))
''["buffers" "curdir" "tabpages" "winsize" "skiprtp"]'' "sessionoptions used for saving";
preSave = helpers.mkNullOrOption types.str "a function to call before saving the session";
saveEmpty = helpers.defaultNullOpts.mkBool false ''
don't save if there are no open file buffers
'';
};
config = let
cfg = config.plugins.persistence;
in
mkIf cfg.enable {
extraPlugins = [cfg.package];
extraConfigLua = let
opts = {
inherit (cfg) dir options;
pre_save = helpers.mkRawIfNonNull cfg.preSave;
save_empty = cfg.saveEmpty;
};
in ''
require('persistence').setup(${helpers.toLuaObject opts})
'';
};
}

View file

@ -0,0 +1,16 @@
{
empty = {
plugins.persistence.enable = true;
};
defaults = {
plugins.persistence = {
enable = true;
dir.__raw = ''vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/")'';
options = ["buffers" "curdir" "tabpages" "winsize"];
preSave = null;
saveEmpty = false;
};
};
}