plugins/typst-vim: switch to mkVimPlugin

This commit is contained in:
Gaetan Lepage 2024-02-13 16:56:32 +01:00 committed by Gaétan Lepage
parent f744a7f8a4
commit 66c019d638
2 changed files with 80 additions and 86 deletions

View file

@ -5,91 +5,82 @@
pkgs, pkgs,
... ...
}: }:
with lib; let with lib;
cfg = config.plugins.typst-vim; helpers.vim-plugin.mkVimPlugin config {
in { name = "typst-vim";
options.plugins.typst-vim = { originalName = "typst.vim";
enable = mkEnableOption "typst.vim"; defaultPackage = pkgs.vimPlugins.typst-vim;
globalPrefix = "typst_";
package = helpers.mkPackageOption "typst-vim" pkgs.vimPlugins.typst-vim;
cmd = helpers.defaultNullOpts.mkStr "typst" ''
Specifies the location of the Typst executable.
'';
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 # Add the typst compiler to nixvim packages
extraPackages = with pkgs; [typst]; extraPackages = [pkgs.typst];
globals = maintainers = [maintainers.GaetanLepage];
mapAttrs'
(name: nameValuePair ("typst_" + name))
(
with cfg;
{
inherit cmd;
pdf_viewer = pdfViewer;
conceal_math = concealMath;
auto_close_toc = autoCloseToc;
}
// extraConfig
);
keymaps = with cfg.keymaps; # TODO introduced 2024-02-20: remove 2024-04-20
helpers.keymaps.mkKeymaps deprecateExtraConfig = true;
{ optionsRenamedToSettings = [
mode = "n"; "cmd"
options.silent = silent; "pdfViewer"
} "concealMath"
( "autoCloseToc"
optional ];
(watch != null)
extraOptions = {
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 = cfg: {
keymaps = with cfg.keymaps;
helpers.keymaps.mkKeymaps
{ {
# mode = "n"; mode = "n";
key = watch; options.silent = silent;
action = ":TypstWatch<CR>";
} }
); (
}; optional
} (watch != null)
{
# mode = "n";
key = watch;
action = ":TypstWatch<CR>";
}
);
};
settingsOptions = {
cmd = helpers.defaultNullOpts.mkStr "typst" ''
Specifies the location of the Typst executable.
'';
pdf_viewer = helpers.mkNullOrOption types.str ''
Specifies pdf viewer that `typst watch --open` will use.
'';
conceal_math = 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
'';
auto_close_toc = helpers.defaultNullOpts.mkBool false ''
Specifies whether TOC will be automatically closed after using it.
'';
};
settingsExample = {
cmd = "typst";
conceal_math = true;
auto_close_toc = true;
};
}

View file

@ -7,10 +7,13 @@
plugins.typst-vim = { plugins.typst-vim = {
enable = true; enable = true;
cmd = "typst"; settings = {
pdfViewer = "zathura"; cmd = "typst";
concealMath = false; pdf_viewer = "zathura";
autoCloseToc = false; conceal_math = false;
auto_close_toc = false;
};
keymaps = { keymaps = {
silent = true; silent = true;
watch = "<leader>w"; watch = "<leader>w";