nix-community.nixvim/plugins/utils/persistence.nix
traxys 1d8e7906c9
plugins: Introduce helpers.defaultNullOpts.mkLuaFn (#855)
This allows to avoid calling `mkRaw` on lua functions, as they will get
applied automatically.

This could also help in the future to refactor the use of Lua code to
make it more user-friendly.
2023-12-29 15:24:42 +01:00

67 lines
1.7 KiB
Nix

{
lib,
helpers,
config,
pkgs,
...
}:
with lib; {
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.defaultNullOpts.mkLuaFn "nil" "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 = cfg.preSave;
save_empty = cfg.saveEmpty;
};
in ''
require('persistence').setup(${helpers.toLuaObject opts})
'';
};
}