From c2ccb2dfabbac067193119cae4fd46d78acc03a2 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Fri, 17 Nov 2023 19:44:54 +0100 Subject: [PATCH] plugins/typst: add options --- plugins/languages/typst/typst-vim.nix | 70 +++++++++++++++---- .../plugins/languages/typst/typst-vim.nix | 5 +- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/plugins/languages/typst/typst-vim.nix b/plugins/languages/typst/typst-vim.nix index ca5b3089..4d8f1e5b 100644 --- a/plugins/languages/typst/typst-vim.nix +++ b/plugins/languages/typst/typst-vim.nix @@ -8,32 +8,74 @@ with lib; let cfg = config.plugins.typst-vim; in { - options.plugins.typst-vim = - helpers.extraOptionsOptions - // { - enable = mkEnableOption "typst.vim"; + options.plugins.typst-vim = { + enable = mkEnableOption "typst.vim"; - package = helpers.mkPackageOption "typst-vim" pkgs.vimPlugins.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; - }; + cmd = helpers.defaultNullOpts.mkStr "typst" '' + Specifies the location of the Typst executable. + ''; - watch = - helpers.mkNullOrOption types.str - "Keymap to preview the document and recompile on change."; + pdfViewer = helpers.mkNullOrOption types.str '' + Specifies pdf viewer that `typst watch --open` will use. + ''; + + concealMath = helpers.defaultNullOpts.mkBool false '' + Enable concealment for math symbols in math mode (i.e. replaces symbols with their actual + unicode character). + Warning: this can affect performance + ''; + + autoCloseToc = helpers.defaultNullOpts.mkBool false '' + Specifies whether TOC will be automatically closed after using it. + ''; + + 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."; }; + extraConfig = mkOption { + type = types.attrs; + default = {}; + description = '' + The configuration options for typst-vim without the 'typst_' prefix. + Example: To set 'typst_foobar' to 1, write + extraConfig = { + foobar = true; + }; + ''; + }; + }; + config = mkIf cfg.enable { extraPlugins = [cfg.package]; # Add the typst compiler to nixvim packages extraPackages = with pkgs; [typst]; + globals = + mapAttrs' + (name: nameValuePair ("typst_" + name)) + ( + with cfg; + { + inherit cmd; + pdf_viewer = pdfViewer; + conceal_math = concealMath; + auto_close_toc = autoCloseToc; + } + // extraConfig + ); + keymaps = with cfg.keymaps; helpers.keymaps.mkKeymaps { diff --git a/tests/test-sources/plugins/languages/typst/typst-vim.nix b/tests/test-sources/plugins/languages/typst/typst-vim.nix index 9c09092e..ebc4661a 100644 --- a/tests/test-sources/plugins/languages/typst/typst-vim.nix +++ b/tests/test-sources/plugins/languages/typst/typst-vim.nix @@ -7,9 +7,12 @@ plugins.typst-vim = { enable = true; + cmd = "typst"; + pdfViewer = "zathura"; + concealMath = false; + autoCloseToc = false; keymaps = { silent = true; - watch = "w"; }; };