mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-24 17:58:38 +02:00
plugin/persistence: init + tests (#645)
This commit is contained in:
parent
a9698ea2b0
commit
0b87e5b70c
4 changed files with 87 additions and 0 deletions
|
@ -107,6 +107,8 @@ with lib; rec {
|
|||
then null
|
||||
else y;
|
||||
|
||||
mkRawIfNonNull = v: ifNonNull' v (mkRaw v);
|
||||
|
||||
mkCompositeOption = desc: options:
|
||||
mkNullOrOption (types.submodule {inherit options;}) desc;
|
||||
|
||||
|
|
|
@ -126,6 +126,7 @@
|
|||
./utils/nvim-osc52.nix
|
||||
./utils/nvim-ufo.nix
|
||||
./utils/oil.nix
|
||||
./utils/persistence.nix
|
||||
./utils/project-nvim.nix
|
||||
./utils/presence-nvim.nix
|
||||
./utils/quickmath.nix
|
||||
|
|
68
plugins/utils/persistence.nix
Normal file
68
plugins/utils/persistence.nix
Normal 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})
|
||||
'';
|
||||
};
|
||||
}
|
16
tests/test-sources/plugins/utils/persistence.nix
Normal file
16
tests/test-sources/plugins/utils/persistence.nix
Normal 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;
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue