From 03025f76e1eb8d0916d8819bcd0614c55ba19309 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 12 Mar 2024 03:48:24 +0300 Subject: [PATCH] modules/session: switch to explicit lib calls --- modules/session/default.nix | 2 +- .../session/nvim-session-manager/config.nix | 69 ++++++++++--------- .../session/nvim-session-manager/default.nix | 2 +- .../nvim-session-manager.nix | 42 +++++------ 4 files changed, 61 insertions(+), 54 deletions(-) diff --git a/modules/session/default.nix b/modules/session/default.nix index b984f72..54e7ef9 100644 --- a/modules/session/default.nix +++ b/modules/session/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./nvim-session-manager ]; diff --git a/modules/session/nvim-session-manager/config.nix b/modules/session/nvim-session-manager/config.nix index 70ed26b..91072f1 100644 --- a/modules/session/nvim-session-manager/config.nix +++ b/modules/session/nvim-session-manager/config.nix @@ -3,51 +3,58 @@ lib, ... }: 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; in { config = mkIf cfg.enable { - vim.startPlugins = - [ - "nvim-session-manager" - "plenary-nvim" - ] - ++ optionals (cfg.usePicker) ["dressing-nvim"]; + vim = { + startPlugins = + [ + "nvim-session-manager" + "plenary-nvim" + ] + ++ optionals (cfg.usePicker) ["dressing-nvim"]; - vim.maps.normal = mkMerge [ - (mkBinding cfg.mappings.loadSession ":SessionManager load_session" "Load session") - (mkBinding cfg.mappings.deleteSession ":SessionManager delete_session" "Delete session") - (mkBinding cfg.mappings.saveCurrentSession ":SessionManager save_current_session" "Save current session") - (mkBinding cfg.mappings.loadLastSession ":SessionManager load_last_session" "Load last session") - # TODO: load_current_dir_session - ]; + maps.normal = mkMerge [ + (mkBinding cfg.mappings.loadSession ":SessionManager load_session" "Load session") + (mkBinding cfg.mappings.deleteSession ":SessionManager delete_session" "Delete session") + (mkBinding cfg.mappings.saveCurrentSession ":SessionManager save_current_session" "Save current session") + (mkBinding cfg.mappings.loadLastSession ":SessionManager load_last_session" "Load last session") + # TODO: load_current_dir_session + ]; - vim.luaConfigRC.nvim-session-manager = nvim.dag.entryAnywhere '' - local Path = require('plenary.path') - local sm = require('session_manager.config') - require('session_manager').setup({ - sessions_dir = Path:new(vim.fn.stdpath('data'), 'sessions'), + luaConfigRC.nvim-session-manager = entryAnywhere '' + 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}', + 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}, - max_path_length = ${toString cfg.maxPathLength}, - }) - ''; + autosave_only_in_session = ${boolToString cfg.autoSave.onlyInSession}, + max_path_length = ${toString cfg.maxPathLength}, + }) + ''; + }; }; } diff --git a/modules/session/nvim-session-manager/default.nix b/modules/session/nvim-session-manager/default.nix index 607c453..2a99059 100644 --- a/modules/session/nvim-session-manager/default.nix +++ b/modules/session/nvim-session-manager/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./nvim-session-manager.nix ./config.nix diff --git a/modules/session/nvim-session-manager/nvim-session-manager.nix b/modules/session/nvim-session-manager/nvim-session-manager.nix index a5395a0..2182db3 100644 --- a/modules/session/nvim-session-manager/nvim-session-manager.nix +++ b/modules/session/nvim-session-manager/nvim-session-manager.nix @@ -1,99 +1,99 @@ -{ - config, - lib, - ... -}: let - inherit (lib) mkEnableOption mkOption types; +{lib, ...}: let + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) nullOr str bool int listOf enum; in { options.vim.session.nvim-session-manager = { enable = mkEnableOption "nvim-session-manager: manage sessions like folders in VSCode"; mappings = { loadSession = mkOption { - type = types.nullOr types.str; + type = nullOr str; description = "Load session"; default = "sl"; }; + deleteSession = mkOption { - type = types.nullOr types.str; + type = nullOr str; description = "Delete session"; default = "sd"; }; + saveCurrentSession = mkOption { - type = types.nullOr types.str; + type = nullOr str; description = "Save current session"; default = "sc"; }; + loadLastSession = mkOption { - type = types.nullOr types.str; + type = nullOr str; description = "Load last session"; default = "slt"; }; }; usePicker = mkOption { - type = types.bool; + type = bool; default = true; description = "Whether or not we should use dressing.nvim to build a session picker UI"; }; pathReplacer = mkOption { - type = types.str; + type = str; default = "__"; description = "The character to which the path separator will be replaced for session files"; }; colonReplacer = mkOption { - type = types.str; + type = str; default = "++"; description = "The character to which the colon symbol will be replaced for session files"; }; autoloadMode = mkOption { - type = types.enum ["Disabled" "CurrentDir" "LastSession"]; + type = 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; + type = nullOr 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; + type = bool; default = true; description = "Automatically save last session on exit and on session switch"; }; ignoreNotNormal = mkOption { - type = types.bool; + type = 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; + type = listOf str; default = []; description = "A list of directories where the session will not be autosaved"; }; ignoreFiletypes = mkOption { - type = types.listOf types.str; + type = listOf 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; + type = listOf str; default = []; description = "All buffers of these bufer types will be closed before the session is saved"; }; onlyInSession = mkOption { - type = types.bool; + type = bool; default = false; description = "Always autosaves session. If true, only autosaves after a session is active"; };