mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
69 lines
1.7 KiB
Nix
69 lines
1.7 KiB
Nix
|
{
|
||
|
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})
|
||
|
'';
|
||
|
};
|
||
|
}
|