From 6f4df2e8aa6440ea1013dac93d5e6179f5543a20 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Fri, 2 Aug 2024 13:34:16 +0200 Subject: [PATCH] plugins/new-file-template: init module --- flake.nix | 8 +++- modules/plugins/utility/default.nix | 1 + .../utility/new-file-template/config.nix | 23 +++++++++ .../utility/new-file-template/default.nix | 6 +++ .../new-file-template/new-file-template.nix | 48 +++++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 modules/plugins/utility/new-file-template/config.nix create mode 100644 modules/plugins/utility/new-file-template/default.nix create mode 100644 modules/plugins/utility/new-file-template/new-file-template.nix diff --git a/flake.nix b/flake.nix index 0290638..c00e9b8 100644 --- a/flake.nix +++ b/flake.nix @@ -628,9 +628,15 @@ }; plugin-nvim-nio = { - # (required nvim-dap-ui) + # (required by nvim-dap-ui) url = "github:nvim-neotest/nvim-nio"; flake = false; }; + + plugin-new-file-template-nvim = { + # (required by new-file-template.nvim) + url = "github:otavioschwanck/new-file-template.nvim"; + flake = false; + }; }; } diff --git a/modules/plugins/utility/default.nix b/modules/plugins/utility/default.nix index a5a8892..835ebf6 100644 --- a/modules/plugins/utility/default.nix +++ b/modules/plugins/utility/default.nix @@ -4,6 +4,7 @@ ./ccc ./gestures ./motion + ./new-file-template ./telescope ./icon-picker ./images diff --git a/modules/plugins/utility/new-file-template/config.nix b/modules/plugins/utility/new-file-template/config.nix new file mode 100644 index 0000000..8f23973 --- /dev/null +++ b/modules/plugins/utility/new-file-template/config.nix @@ -0,0 +1,23 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; + + cfg = config.vim.utility.new-file-template; +in { + config = mkIf cfg.enable { + vim = { + startPlugins = [ + "new-file-template-nvim" + ]; + + pluginRC.new-file-template = entryAnywhere '' + require('new-file-template').setup(${toLuaObject cfg.setupOpts}) + ''; + }; + }; +} diff --git a/modules/plugins/utility/new-file-template/default.nix b/modules/plugins/utility/new-file-template/default.nix new file mode 100644 index 0000000..7bcfbd1 --- /dev/null +++ b/modules/plugins/utility/new-file-template/default.nix @@ -0,0 +1,6 @@ +_: { + imports = [ + ./config.nix + ./new-file-template.nix + ]; +} diff --git a/modules/plugins/utility/new-file-template/new-file-template.nix b/modules/plugins/utility/new-file-template/new-file-template.nix new file mode 100644 index 0000000..808cd5a --- /dev/null +++ b/modules/plugins/utility/new-file-template/new-file-template.nix @@ -0,0 +1,48 @@ +{ + lib, + ... +}: let + inherit (lib.options) mkOption; + inherit (lib.types) attrsOf bool listOf str; + inherit (lib.nvim.types) mkPluginSetupOption; +in { + options.vim.utility.new-file-template = { + enable = mkOption { + type = bool; + default = false; + description = "new-file-template.nvim: Automatically insert a template on new files in neovim"; + }; + + setupOpts = mkPluginSetupOption "nvim-file-template.nvim" { + disableInsert = mkOption { + type = bool; + default = false; + description = "Enter insert mode after inserting the template"; + }; + + disableAutocmd = mkOption { + type = bool; + default = false; + description = "Disable the autocmd that creates the template"; + }; + + disableFiletype = mkOption { + type = listOf str; + default = []; + description = "Disable templates for specific filetypes (only disables default templates, user templates will still work)"; + }; + + disableSpecific = mkOption { + type = attrsOf (listOf str); + default = {}; + description = "Disable specific regexp for the default templates. Example: { ruby = [ \".*\" ]; }"; + }; + + suffixAsFiletype = mkOption { + type = bool; + default = false; + description = "Use suffix of filename rather than vim.bo.filetype as filetype"; + }; + }; + }; +}