neovim-flake/modules/plugins/languages/tex/build/default.nix

122 lines
3.7 KiB
Nix
Raw Normal View History

2025-01-23 19:35:00 -07:00
{
config,
lib,
...
}: let
inherit (lib.options) mkOption;
inherit (lib.modules) mkIf;
inherit (lib.types) str nullOr;
inherit (builtins) filter isAttrs hasAttr attrNames length elemAt;
inherit (lib.nvim.config) mkBool;
2025-01-23 19:35:00 -07:00
cfg = config.vim.languages.tex;
enabledBuildersCount = let
# This function will sort through the builder options and count how many
# builders have been enabled.
getEnabledBuildersCount = {
enabledBuildersCount ? 0,
index ? 0,
builderNamesList ? (
filter (
x: let
y = cfg.build.builders.${x};
in (isAttrs y && hasAttr "enable" y)
) (attrNames cfg.build.builders)
),
}: let
currentBuilderName = elemAt builderNamesList index;
currentBuilder = cfg.build.builders.${currentBuilderName};
nextIndex = index + 1;
newEnabledBuildersCount =
if currentBuilder.enable
then enabledBuildersCount + 1
else enabledBuildersCount;
in
if length builderNamesList > nextIndex
then
getEnabledBuildersCount {
inherit builderNamesList;
enabledBuildersCount = newEnabledBuildersCount;
index = nextIndex;
}
else newEnabledBuildersCount;
in (getEnabledBuildersCount {});
2025-01-23 19:35:00 -07:00
in {
imports = [
./builders
];
options.vim.languages.tex.build = {
enable =
mkBool (enabledBuildersCount == 1) ''
Whether to enable configuring the builder.
2025-01-23 19:35:00 -07:00
By enabling any of the builders, this option will be automatically set.
If you enable more than one builder then an error will be thrown.
2025-01-23 19:35:00 -07:00
'';
forwardSearchAfter = mkBool false "Set this property to true if you want to execute a forward search after a build.";
onSave = mkBool false "Set this property to true if you want to compile the project after saving a file.";
useFileList = mkBool false ''
When set to `true`, the server will use the `.fls` files produced by the TeX engine as an additional input for the project detection.
Note that enabling this property might have an impact on performance.
'';
2025-01-23 19:35:00 -07:00
auxDirectory = mkOption {
type = str;
default = ".";
description = ''
When not using latexmk, provides a way to define the directory containing the .aux files.
Note that you need to set the aux directory in latex.build.args too.
When using a latexmkrc file, texlab will automatically infer the correct setting.
'';
};
2025-01-23 19:35:00 -07:00
logDirectory = mkOption {
type = str;
default = ".";
description = ''
When not using latexmk, provides a way to define the directory containing the build log files.
Note that you need to change the output directory in your build arguments too.
When using a latexmkrc file, texlab will automatically infer the correct setting.
'';
};
2025-01-23 19:35:00 -07:00
pdfDirectory = mkOption {
type = str;
default = ".";
description = ''
When not using latexmk, provides a way to define the directory containing the output files.
Note that you need to set the output directory in latex.build.args too.
When using a latexmkrc file, texlab will automatically infer the correct setting.
'';
};
2025-01-23 19:35:00 -07:00
filename = mkOption {
type = nullOr str;
default = null;
2025-01-23 19:35:00 -07:00
description = ''
Allows overriding the default file name of the build artifact.
This setting is used to find the correct PDF file to open during forward search.
2025-01-23 19:35:00 -07:00
'';
};
};
config = mkIf (enabledBuildersCount > 0) {
assertions = [
{
assertion = (enabledBuildersCount < 2);
message = "The nvf-tex-language implementation does not support having more than 1 builders enabled.";
}
];
};
2025-01-23 19:35:00 -07:00
}