From d2b5aee3731c2cbb3238cdfc16e089a993c45d26 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 8 Apr 2023 01:44:40 +0300 Subject: [PATCH] feat: more configuration options for nvim-session-manager --- extra.nix | 2 +- .../session/nvim-session-manager/config.nix | 32 ++++++++- .../nvim-session-manager.nix | 68 +++++++++++++++++++ 3 files changed, 99 insertions(+), 3 deletions(-) diff --git a/extra.nix b/extra.nix index 63f0f0e..55a2f6a 100644 --- a/extra.nix +++ b/extra.nix @@ -173,7 +173,7 @@ inputs: let }; vim.session = { - nvim-session-manager.enable = false; + nvim-session-manager.enable = true; }; vim.gestures = { diff --git a/modules/session/nvim-session-manager/config.nix b/modules/session/nvim-session-manager/config.nix index 8d8e26b..695346e 100644 --- a/modules/session/nvim-session-manager/config.nix +++ b/modules/session/nvim-session-manager/config.nix @@ -8,10 +8,38 @@ with builtins; let cfg = config.vim.session.nvim-session-manager; in { config = mkIf cfg.enable { - vim.startPlugins = ["nvim-session-manager"]; + vim.startPlugins = + [ + "nvim-session-manager" + "plenary-nvim" + ] + ++ optionals (cfg.usePicker) ["dressing-nvim"]; vim.luaConfigRC.nvim-session-manager = nvim.dag.entryAnywhere '' - require('session_manager').setup({}) + local Path = require('plenary.path') + local sm = require('session_manager.config') + require('session_manager').setup({ + sessions_dir = Path:new(vim.fn.stdpath('data'), 'sessions'), + + path_replacer = '${toString cfg.pathReplacer}', + + colon_replacer = '${toString cfg.colonReplacer}', + + autoload_mode = sm.AutoloadMode.${toString cfg.autoloadMode}, + + autosave_last_session = ${boolToString cfg.autoSave.lastSession}, + + autosave_ignore_not_normal = ${boolToString cfg.autoSave.ignoreNotNormal}, + + autosave_ignore_dirs = {${concatStringsSep ", " (map (x: "\'" + x + "\'") cfg.autoSave.ignoreDirs)}}, + + autosave_ignore_filetypes = {${concatStringsSep ", " (map (x: "\'" + x + "\'") cfg.autoSave.ignoreFiletypes)}}, + + autosave_ignore_buftypes = {${concatStringsSep ", " (map (x: "\'" + x + "\'") cfg.autoSave.ignoreBufTypes)}}, + + autosave_only_in_session = ${boolToString cfg.autoSave.onlyInSession}, + max_path_length = ${toString cfg.maxPathLength}, + }) ''; }; } diff --git a/modules/session/nvim-session-manager/nvim-session-manager.nix b/modules/session/nvim-session-manager/nvim-session-manager.nix index 062b02d..74ec434 100644 --- a/modules/session/nvim-session-manager/nvim-session-manager.nix +++ b/modules/session/nvim-session-manager/nvim-session-manager.nix @@ -7,5 +7,73 @@ with lib; with builtins; { options.vim.session.nvim-session-manager = { enable = mkEnableOption "Enable nvim-session-manager"; + + usePicker = mkOption { + type = types.bool; + default = true; + description = "Whether or not we should use dressing.nvim to build a session picker UI"; + }; + + pathReplacer = mkOption { + type = types.str; + default = "__"; + description = "The character to which the path separator will be replaced for session files"; + }; + + colonReplacer = mkOption { + type = types.str; + default = "++"; + description = "The character to which the colon symbol will be replaced for session files"; + }; + + autoloadMode = mkOption { + type = types.enum ["Disabled" "CurrentDir" "LastSession"]; + default = "LastSession"; + description = "Define what to do when Neovim is started without arguments. Possible values: Disabled, CurrentDir, LastSession"; + }; + + maxPathLength = mkOption { + type = types.nullOr types.int; + default = 80; + description = "Shorten the display path if length exceeds this threshold. Use 0 if don't want to shorten the path at all"; + }; + + autoSave = { + lastSession = mkOption { + type = types.bool; + default = true; + description = "Automatically save last session on exit and on session switch"; + }; + + ignoreNotNormal = mkOption { + type = types.bool; + default = true; + description = "Plugin will not save a session when no buffers are opened, or all of them aren't writable or listed"; + }; + + ignoreDirs = mkOption { + type = types.listOf types.str; + default = []; + description = "A list of directories where the session will not be autosaved"; + }; + + ignoreFiletypes = mkOption { + type = types.listOf types.str; + default = ["gitcommit"]; + description = "All buffers of these file types will be closed before the session is saved"; + }; + + ignoreBufTypes = mkOption { + type = types.listOf types.str; + default = []; + description = "All buffers of these bufer types will be closed before the session is saved"; + }; + + onlyInSession = mkOption { + type = types.bool; + default = false; + description = "Always autosaves session. If true, only autosaves after a session is active"; + }; + }; }; }