-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins/persistence: convert to mkNeovimPlugin and fix settings
Restrict no nonnegative numbers Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com> chore: include optionsRenamedToSettings in TODO Merge imports Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
- Loading branch information
1 parent
0ebc64a
commit 8899663
Showing
2 changed files
with
53 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,57 @@ | ||
{ | ||
lib, | ||
helpers, | ||
config, | ||
pkgs, | ||
... | ||
}: | ||
with lib; | ||
{ | ||
options.plugins.persistence = lib.nixvim.plugins.neovim.extraOptionsOptions // { | ||
enable = mkEnableOption "persistence.nvim"; | ||
{ lib, ... }: | ||
let | ||
inherit (lib.nixvim) defaultNullOpts literalLua; | ||
in | ||
lib.nixvim.plugins.mkNeovimPlugin { | ||
name = "persistence"; | ||
packPathName = "persistence.nvim"; | ||
package = "persistence-nvim"; | ||
description = "A simple lua plugin for automated session management."; | ||
|
||
package = lib.mkPackageOption pkgs "persistence.nvim" { | ||
default = [ | ||
"vimPlugins" | ||
"persistence-nvim" | ||
]; | ||
}; | ||
maintainers = [ lib.maintainers.jolars ]; | ||
|
||
dir = helpers.defaultNullOpts.mkStr { | ||
__raw = ''vim.fn.expand(vim.fn.stdpath("state") .. "/sessions/")''; | ||
} "directory where session files are saved"; | ||
# TODO: introduced 2025-01-08: remove after 25.05 | ||
optionsRenamedToSettings = [ | ||
"dir" | ||
]; | ||
imports = | ||
let | ||
basePluginPath = [ | ||
"plugins" | ||
"persistence" | ||
]; | ||
in | ||
map | ||
( | ||
option: | ||
lib.mkRemovedOptionModule (basePluginPath ++ [ option ]) '' | ||
This option has been deprecated upstream. The plugin now provides | ||
user events to hook into instead. | ||
'' | ||
) | ||
[ | ||
"options" | ||
"preSave" | ||
"saveEmpty" | ||
]; | ||
|
||
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.mkListOf (types.enum sessionOpts) [ | ||
"buffers" | ||
"curdir" | ||
"tabpages" | ||
"winsize" | ||
"skiprtp" | ||
] "sessionoptions used for saving"; | ||
settingsOptions = { | ||
branch = defaultNullOpts.mkBool true '' | ||
Use git branch to save session. | ||
''; | ||
|
||
preSave = helpers.defaultNullOpts.mkLuaFn "nil" "a function to call before saving the session"; | ||
dir = defaultNullOpts.mkStr (literalLua "vim.fn.expand(vim.fn.stdpath('state') .. '/sessions/')") '' | ||
Directory where session files are saved. | ||
''; | ||
|
||
saveEmpty = helpers.defaultNullOpts.mkBool false '' | ||
don't save if there are no open file buffers | ||
need = defaultNullOpts.mkUnsignedInt 1 '' | ||
Minimum number of file buffers that need to be open to save. Set to | ||
0 to always save. | ||
''; | ||
}; | ||
|
||
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(${lib.nixvim.toLuaObject opts}) | ||
''; | ||
}; | ||
settingsExample = { | ||
need = 0; | ||
branch = false; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters