From 3f08cff1d0c2a45e5bf0448a074c5bcc152cf2c5 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Fri, 26 May 2023 11:00:04 +0200 Subject: [PATCH] plugins/typst-vim: init plugin + test --- plugins/default.nix | 1 + plugins/languages/typst/typst-vim.nix | 42 +++++++++++++++++++ .../plugins/languages/typst/typst-vim.nix | 17 ++++++++ 3 files changed, 60 insertions(+) create mode 100644 plugins/languages/typst/typst-vim.nix create mode 100644 tests/test-sources/plugins/languages/typst/typst-vim.nix diff --git a/plugins/default.nix b/plugins/default.nix index b37471fe..5d9b90d6 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -43,6 +43,7 @@ ./languages/treesitter/treesitter-playground.nix ./languages/treesitter/treesitter-rainbow.nix ./languages/treesitter/treesitter-refactor.nix + ./languages/typst/typst-vim.nix ./languages/vimtex.nix ./languages/zig.nix diff --git a/plugins/languages/typst/typst-vim.nix b/plugins/languages/typst/typst-vim.nix new file mode 100644 index 00000000..7c15b84f --- /dev/null +++ b/plugins/languages/typst/typst-vim.nix @@ -0,0 +1,42 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; let + cfg = config.plugins.typst-vim; + helpers = import ../../helpers.nix {inherit lib;}; +in { + options.plugins.typst-vim = + helpers.extraOptionsOptions + // { + enable = mkEnableOption "typst.vim"; + + package = helpers.mkPackageOption "typst-vim" pkgs.vimPlugins.typst-vim; + + keymaps = { + silent = mkOption { + type = types.bool; + description = "Whether typst-vim keymaps should be silent."; + default = false; + }; + + watch = + helpers.mkNullOrOption types.str + "Keymap to preview the document and recompile on change."; + }; + }; + + config = mkIf cfg.enable { + extraPlugins = [cfg.package]; + + # Add the typst compiler to nixvim packages + extraPackages = with pkgs; [typst]; + + maps.normal = with cfg.keymaps; + helpers.mkModeMaps {inherit silent;} { + ${watch} = ":TypstWatch"; + }; + }; +} diff --git a/tests/test-sources/plugins/languages/typst/typst-vim.nix b/tests/test-sources/plugins/languages/typst/typst-vim.nix new file mode 100644 index 00000000..9c09092e --- /dev/null +++ b/tests/test-sources/plugins/languages/typst/typst-vim.nix @@ -0,0 +1,17 @@ +{ + empty = { + plugins.typst-vim.enable = true; + }; + + example = { + plugins.typst-vim = { + enable = true; + + keymaps = { + silent = true; + + watch = "w"; + }; + }; + }; +}