mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-26 23:16:46 +00:00
modules/session: switch to explicit lib calls
This commit is contained in:
parent
e5383a8123
commit
03025f76e1
4 changed files with 61 additions and 54 deletions
|
@ -1,4 +1,4 @@
|
||||||
_: {
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./nvim-session-manager
|
./nvim-session-manager
|
||||||
];
|
];
|
||||||
|
|
|
@ -3,51 +3,58 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) mkIf optionals mkMerge mkBinding nvim concatStringsSep boolToString;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
|
inherit (lib.lists) optionals;
|
||||||
|
inherit (lib.strings) concatStringsSep;
|
||||||
|
inherit (lib.trivial) boolToString;
|
||||||
|
inherit (lib.nvim.binds) mkBinding;
|
||||||
|
inherit (lib.nvim.dag) entryAnywhere;
|
||||||
|
|
||||||
cfg = config.vim.session.nvim-session-manager;
|
cfg = config.vim.session.nvim-session-manager;
|
||||||
in {
|
in {
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
vim.startPlugins =
|
vim = {
|
||||||
[
|
startPlugins =
|
||||||
"nvim-session-manager"
|
[
|
||||||
"plenary-nvim"
|
"nvim-session-manager"
|
||||||
]
|
"plenary-nvim"
|
||||||
++ optionals (cfg.usePicker) ["dressing-nvim"];
|
]
|
||||||
|
++ optionals (cfg.usePicker) ["dressing-nvim"];
|
||||||
|
|
||||||
vim.maps.normal = mkMerge [
|
maps.normal = mkMerge [
|
||||||
(mkBinding cfg.mappings.loadSession ":SessionManager load_session<CR>" "Load session")
|
(mkBinding cfg.mappings.loadSession ":SessionManager load_session<CR>" "Load session")
|
||||||
(mkBinding cfg.mappings.deleteSession ":SessionManager delete_session<CR>" "Delete session")
|
(mkBinding cfg.mappings.deleteSession ":SessionManager delete_session<CR>" "Delete session")
|
||||||
(mkBinding cfg.mappings.saveCurrentSession ":SessionManager save_current_session<CR>" "Save current session")
|
(mkBinding cfg.mappings.saveCurrentSession ":SessionManager save_current_session<CR>" "Save current session")
|
||||||
(mkBinding cfg.mappings.loadLastSession ":SessionManager load_last_session<CR>" "Load last session")
|
(mkBinding cfg.mappings.loadLastSession ":SessionManager load_last_session<CR>" "Load last session")
|
||||||
# TODO: load_current_dir_session
|
# TODO: load_current_dir_session
|
||||||
];
|
];
|
||||||
|
|
||||||
vim.luaConfigRC.nvim-session-manager = nvim.dag.entryAnywhere ''
|
luaConfigRC.nvim-session-manager = entryAnywhere ''
|
||||||
local Path = require('plenary.path')
|
local Path = require('plenary.path')
|
||||||
local sm = require('session_manager.config')
|
local sm = require('session_manager.config')
|
||||||
require('session_manager').setup({
|
require('session_manager').setup({
|
||||||
sessions_dir = Path:new(vim.fn.stdpath('data'), 'sessions'),
|
sessions_dir = Path:new(vim.fn.stdpath('data'), 'sessions'),
|
||||||
|
|
||||||
path_replacer = '${toString cfg.pathReplacer}',
|
path_replacer = '${toString cfg.pathReplacer}',
|
||||||
|
|
||||||
colon_replacer = '${toString cfg.colonReplacer}',
|
colon_replacer = '${toString cfg.colonReplacer}',
|
||||||
|
|
||||||
autoload_mode = sm.AutoloadMode.${toString cfg.autoloadMode},
|
autoload_mode = sm.AutoloadMode.${toString cfg.autoloadMode},
|
||||||
|
|
||||||
autosave_last_session = ${boolToString cfg.autoSave.lastSession},
|
autosave_last_session = ${boolToString cfg.autoSave.lastSession},
|
||||||
|
|
||||||
autosave_ignore_not_normal = ${boolToString cfg.autoSave.ignoreNotNormal},
|
autosave_ignore_not_normal = ${boolToString cfg.autoSave.ignoreNotNormal},
|
||||||
|
|
||||||
autosave_ignore_dirs = {${concatStringsSep ", " (map (x: "\'" + x + "\'") cfg.autoSave.ignoreDirs)}},
|
autosave_ignore_dirs = {${concatStringsSep ", " (map (x: "\'" + x + "\'") cfg.autoSave.ignoreDirs)}},
|
||||||
|
|
||||||
autosave_ignore_filetypes = {${concatStringsSep ", " (map (x: "\'" + x + "\'") cfg.autoSave.ignoreFiletypes)}},
|
autosave_ignore_filetypes = {${concatStringsSep ", " (map (x: "\'" + x + "\'") cfg.autoSave.ignoreFiletypes)}},
|
||||||
|
|
||||||
autosave_ignore_buftypes = {${concatStringsSep ", " (map (x: "\'" + x + "\'") cfg.autoSave.ignoreBufTypes)}},
|
autosave_ignore_buftypes = {${concatStringsSep ", " (map (x: "\'" + x + "\'") cfg.autoSave.ignoreBufTypes)}},
|
||||||
|
|
||||||
autosave_only_in_session = ${boolToString cfg.autoSave.onlyInSession},
|
autosave_only_in_session = ${boolToString cfg.autoSave.onlyInSession},
|
||||||
max_path_length = ${toString cfg.maxPathLength},
|
max_path_length = ${toString cfg.maxPathLength},
|
||||||
})
|
})
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
_: {
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./nvim-session-manager.nix
|
./nvim-session-manager.nix
|
||||||
./config.nix
|
./config.nix
|
||||||
|
|
|
@ -1,99 +1,99 @@
|
||||||
{
|
{lib, ...}: let
|
||||||
config,
|
inherit (lib.options) mkOption mkEnableOption;
|
||||||
lib,
|
inherit (lib.types) nullOr str bool int listOf enum;
|
||||||
...
|
|
||||||
}: let
|
|
||||||
inherit (lib) mkEnableOption mkOption types;
|
|
||||||
in {
|
in {
|
||||||
options.vim.session.nvim-session-manager = {
|
options.vim.session.nvim-session-manager = {
|
||||||
enable = mkEnableOption "nvim-session-manager: manage sessions like folders in VSCode";
|
enable = mkEnableOption "nvim-session-manager: manage sessions like folders in VSCode";
|
||||||
|
|
||||||
mappings = {
|
mappings = {
|
||||||
loadSession = mkOption {
|
loadSession = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = nullOr str;
|
||||||
description = "Load session";
|
description = "Load session";
|
||||||
default = "<leader>sl";
|
default = "<leader>sl";
|
||||||
};
|
};
|
||||||
|
|
||||||
deleteSession = mkOption {
|
deleteSession = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = nullOr str;
|
||||||
description = "Delete session";
|
description = "Delete session";
|
||||||
default = "<leader>sd";
|
default = "<leader>sd";
|
||||||
};
|
};
|
||||||
|
|
||||||
saveCurrentSession = mkOption {
|
saveCurrentSession = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = nullOr str;
|
||||||
description = "Save current session";
|
description = "Save current session";
|
||||||
default = "<leader>sc";
|
default = "<leader>sc";
|
||||||
};
|
};
|
||||||
|
|
||||||
loadLastSession = mkOption {
|
loadLastSession = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = nullOr str;
|
||||||
description = "Load last session";
|
description = "Load last session";
|
||||||
default = "<leader>slt";
|
default = "<leader>slt";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
usePicker = mkOption {
|
usePicker = mkOption {
|
||||||
type = types.bool;
|
type = bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = "Whether or not we should use dressing.nvim to build a session picker UI";
|
description = "Whether or not we should use dressing.nvim to build a session picker UI";
|
||||||
};
|
};
|
||||||
|
|
||||||
pathReplacer = mkOption {
|
pathReplacer = mkOption {
|
||||||
type = types.str;
|
type = str;
|
||||||
default = "__";
|
default = "__";
|
||||||
description = "The character to which the path separator will be replaced for session files";
|
description = "The character to which the path separator will be replaced for session files";
|
||||||
};
|
};
|
||||||
|
|
||||||
colonReplacer = mkOption {
|
colonReplacer = mkOption {
|
||||||
type = types.str;
|
type = str;
|
||||||
default = "++";
|
default = "++";
|
||||||
description = "The character to which the colon symbol will be replaced for session files";
|
description = "The character to which the colon symbol will be replaced for session files";
|
||||||
};
|
};
|
||||||
|
|
||||||
autoloadMode = mkOption {
|
autoloadMode = mkOption {
|
||||||
type = types.enum ["Disabled" "CurrentDir" "LastSession"];
|
type = enum ["Disabled" "CurrentDir" "LastSession"];
|
||||||
default = "LastSession";
|
default = "LastSession";
|
||||||
description = "Define what to do when Neovim is started without arguments. Possible values: Disabled, CurrentDir, LastSession";
|
description = "Define what to do when Neovim is started without arguments. Possible values: Disabled, CurrentDir, LastSession";
|
||||||
};
|
};
|
||||||
|
|
||||||
maxPathLength = mkOption {
|
maxPathLength = mkOption {
|
||||||
type = types.nullOr types.int;
|
type = nullOr int;
|
||||||
default = 80;
|
default = 80;
|
||||||
description = "Shorten the display path if length exceeds this threshold. Use 0 if don't want to shorten the path at all";
|
description = "Shorten the display path if length exceeds this threshold. Use 0 if don't want to shorten the path at all";
|
||||||
};
|
};
|
||||||
|
|
||||||
autoSave = {
|
autoSave = {
|
||||||
lastSession = mkOption {
|
lastSession = mkOption {
|
||||||
type = types.bool;
|
type = bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = "Automatically save last session on exit and on session switch";
|
description = "Automatically save last session on exit and on session switch";
|
||||||
};
|
};
|
||||||
|
|
||||||
ignoreNotNormal = mkOption {
|
ignoreNotNormal = mkOption {
|
||||||
type = types.bool;
|
type = bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = "Plugin will not save a session when no buffers are opened, or all of them aren't writable or listed";
|
description = "Plugin will not save a session when no buffers are opened, or all of them aren't writable or listed";
|
||||||
};
|
};
|
||||||
|
|
||||||
ignoreDirs = mkOption {
|
ignoreDirs = mkOption {
|
||||||
type = types.listOf types.str;
|
type = listOf str;
|
||||||
default = [];
|
default = [];
|
||||||
description = "A list of directories where the session will not be autosaved";
|
description = "A list of directories where the session will not be autosaved";
|
||||||
};
|
};
|
||||||
|
|
||||||
ignoreFiletypes = mkOption {
|
ignoreFiletypes = mkOption {
|
||||||
type = types.listOf types.str;
|
type = listOf str;
|
||||||
default = ["gitcommit"];
|
default = ["gitcommit"];
|
||||||
description = "All buffers of these file types will be closed before the session is saved";
|
description = "All buffers of these file types will be closed before the session is saved";
|
||||||
};
|
};
|
||||||
|
|
||||||
ignoreBufTypes = mkOption {
|
ignoreBufTypes = mkOption {
|
||||||
type = types.listOf types.str;
|
type = listOf str;
|
||||||
default = [];
|
default = [];
|
||||||
description = "All buffers of these bufer types will be closed before the session is saved";
|
description = "All buffers of these bufer types will be closed before the session is saved";
|
||||||
};
|
};
|
||||||
|
|
||||||
onlyInSession = mkOption {
|
onlyInSession = mkOption {
|
||||||
type = types.bool;
|
type = bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Always autosaves session. If true, only autosaves after a session is active";
|
description = "Always autosaves session. If true, only autosaves after a session is active";
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue