2023-05-26 11:00:04 +02:00
|
|
|
{
|
|
|
|
lib,
|
2023-11-06 15:04:08 +01:00
|
|
|
helpers,
|
|
|
|
config,
|
|
|
|
pkgs,
|
2023-05-26 11:00:04 +02:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.plugins.typst-vim;
|
|
|
|
in {
|
2023-11-17 19:44:54 +01:00
|
|
|
options.plugins.typst-vim = {
|
|
|
|
enable = mkEnableOption "typst.vim";
|
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
2023-05-26 11:00:04 +02:00
|
|
|
|
2023-11-17 19:44:54 +01:00
|
|
|
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;
|
2023-05-26 11:00:04 +02:00
|
|
|
};
|
2023-11-17 19:44:54 +01:00
|
|
|
|
|
|
|
watch =
|
|
|
|
helpers.mkNullOrOption types.str
|
|
|
|
"Keymap to preview the document and recompile on change.";
|
2023-05-26 11:00:04 +02:00
|
|
|
};
|
|
|
|
|
2023-11-17 19:44:54 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-05-26 11:00:04 +02:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
extraPlugins = [cfg.package];
|
|
|
|
|
|
|
|
# Add the typst compiler to nixvim packages
|
|
|
|
extraPackages = with pkgs; [typst];
|
|
|
|
|
2023-11-17 19:44:54 +01:00
|
|
|
globals =
|
|
|
|
mapAttrs'
|
|
|
|
(name: nameValuePair ("typst_" + name))
|
|
|
|
(
|
|
|
|
with cfg;
|
|
|
|
{
|
|
|
|
inherit cmd;
|
|
|
|
pdf_viewer = pdfViewer;
|
|
|
|
conceal_math = concealMath;
|
|
|
|
auto_close_toc = autoCloseToc;
|
|
|
|
}
|
|
|
|
// extraConfig
|
|
|
|
);
|
|
|
|
|
2023-09-15 14:35:13 +02:00
|
|
|
keymaps = with cfg.keymaps;
|
2023-10-02 15:44:06 +02:00
|
|
|
helpers.keymaps.mkKeymaps
|
2023-09-15 14:35:13 +02:00
|
|
|
{
|
|
|
|
mode = "n";
|
|
|
|
options.silent = silent;
|
|
|
|
}
|
|
|
|
(
|
|
|
|
optional
|
|
|
|
(watch != null)
|
|
|
|
{
|
|
|
|
# mode = "n";
|
|
|
|
key = watch;
|
|
|
|
action = ":TypstWatch<CR>";
|
|
|
|
}
|
|
|
|
);
|
2023-05-26 11:00:04 +02:00
|
|
|
};
|
|
|
|
}
|