Reimplemented formatters

This commit is contained in:
isaacST08 2025-12-19 21:32:51 -07:00
commit dc5a2b8f37
5 changed files with 57 additions and 284 deletions

View file

@ -1,70 +0,0 @@
{
config,
pkgs,
lib,
...
}: let
inherit (lib.options) mkOption;
inherit (lib.types) enum listOf package str;
inherit (lib.nvim.config) mkBool;
inherit (builtins) attrNames filter isAttrs hasAttr elemAt length;
cfg = config.vim.languages.tex;
in {
imports = [
./latexmk.nix
./tectonic.nix
];
options.vim.languages.tex.build.builder = {
name = mkOption {
type = enum (attrNames cfg.build.builders);
default = "latexmk";
description = ''
The tex builder to use.
This is just the default custom option. By setting any of the
builders to true, this will be overwritten by that builder's
parameters.
Setting this parameter to the name of a declared builder will
not automatically enable that builder.
'';
};
args = mkOption {
type = listOf str;
default = [
"-pdf"
"%f"
];
description = ''
The list of args to pass to the builder.
This is just the default custom option. By setting any of the
builders to true, this will be overwritten by that builder's
parameters.
'';
};
package = mkOption {
type = package;
default = pkgs.texlive.withPackages (ps: [ps.latexmk]);
description = ''
The tex builder package to use.
This is just the default custom option. By setting any of the
builders to true, this will be overwritten by that builder's
parameters.
'';
};
executable = mkOption {
type = str;
default = "latexmk";
description = ''
The tex builder executable to use.
This is just the default custom option. By setting any of the
builders to true, this will be overwritten by that builder's
parameters.
'';
};
};
}

View file

@ -1,53 +0,0 @@
# TODO: I need testing.
{
config,
lib,
pkgs,
...
}: let
# The name of the builder
name = "latexmk";
inherit (lib.modules) mkIf;
inherit (lib.nvim.config) mkBool;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) package str;
texCfg = config.vim.languages.tex;
cfg = texCfg.build.builders.${name};
in {
options.vim.languages.tex.build.builders.${name} = {
enable = mkEnableOption "Whether to enable Tex Compilation Via latexmk";
package = mkOption {
type = package;
default = pkgs.texlive.withPackages (ps: [ps.latexmk]);
description = "latexmk package";
};
executable = mkOption {
type = str;
default = "latexmk";
description = "The executable name from the build package that will be used to build/compile the tex.";
};
# Flag options
pdfOutput = mkBool true "Insure the output file is a pdf.";
};
config = mkIf (texCfg.enable && cfg.enable) {
vim.languages.tex.build.builder = {
inherit name;
inherit (cfg) package executable;
args = (
# Flags
(lib.lists.optional cfg.pdfOutput "-pdf")
# Base args
++ [
"-quiet"
"%f"
]
);
};
};
}

View file

@ -1,161 +0,0 @@
{
config,
lib,
pkgs,
...
}: let
# The name of the builder
name = "tectonic";
inherit (builtins) concatLists elem map toString match;
inherit (lib.modules) mkIf;
inherit (lib.nvim.config) mkBool;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.strings) toLower optionalString stringAsChars;
inherit (lib.types) enum ints listOf package str;
texCfg = config.vim.languages.tex;
cfg = texCfg.build.builders.${name};
in {
options.vim.languages.tex.build.builders.${name} = {
enable = mkEnableOption "Whether to enable Tex Compilation Via Tectonic";
package = mkOption {
type = package;
default = pkgs.tectonic;
description = "tectonic package";
};
executable = mkOption {
type = str;
default = "tectonic";
description = "The executable name from the build package that will be used to build/compile the tex.";
};
# -- Flags --
keepIntermediates = mkBool false ''
Keep the intermediate files generated during processing.
If texlab is reporting build errors when there shouldn't be, disable this option.
'';
keepLogs = mkBool true ''
Keep the log files generated during processing.
Without the keepLogs flag, texlab won't be able to report compilation warnings.
'';
onlyCached = mkBool false "Use only resource files cached locally";
synctex = mkBool true "Generate SyncTeX data";
untrustedInput = mkBool false "Input is untrusted -- disable all known-insecure features";
# -- Options --
reruns = mkOption {
type = ints.unsigned;
default = 0;
example = 2;
description = ''
Rerun the TeX engine exactly this many times after the first.
Setting this value to 0 will disable setting this option.
'';
};
bundle = mkOption {
type = str;
default = "";
description = "Use this directory or Zip-format bundle file to find resource files instead of the default";
};
webBundle = mkOption {
type = str;
default = "";
description = "Use this URL to find resource files instead of the default";
};
outfmt = mkOption {
type = enum [
"pdf"
"html"
"xdv"
"aux"
"fmt"
""
];
default = "";
description = "The kind of output to generate";
};
hidePaths = mkOption {
type = listOf str;
default = [];
example = [
"./secrets.tex"
"./passwords.tex"
];
description = "Tell the engine that no file at <hide_path> exists, if it tries to read it.";
};
format = mkOption {
type = str;
default = "";
description = "The name of the \"format\" file used to initialize the TeX engine";
};
color = mkOption {
type = enum [
"always"
"auto"
"never"
""
];
default = "";
example = "always";
description = "Enable/disable colorful log output";
};
extraOptions = {
type = listOf str;
default = [];
description = ''
Add extra command line options to include in the tectonic build command.
Extra options added here will not overwrite the options set in as nvf options.
'';
};
};
config = mkIf (texCfg.enable && cfg.enable) {
vim.languages.tex.build.builder = {
inherit name;
inherit (cfg) package executable;
args = let
inherit (lib.lists) optional optionals;
snakeCaseToKebabCase = str: stringAsChars (x: "${optionalString ((match "[A-Z]" x) != null) "-"}${toLower x}") str;
generateOptionFlag = option: (optionals (cfg.${option} != "") ["--${snakeCaseToKebabCase option}" "${toString cfg.${option}}"]);
in (
# Base args
[
"-X"
"compile"
"%f"
]
# Flags
++ (optional cfg.keepIntermediates "--keep-intermediates")
++ (optional cfg.keepLogs "--keep-logs")
++ (optional cfg.onlyCached "--only-cached")
++ (optional cfg.synctex "--synctex")
++ (optional cfg.untrustedInput "--untrusted")
# Options
++ (optionals (cfg.reruns > 0) ["--reruns" "${toString cfg.reruns}"])
++ (generateOptionFlag "bundle")
++ (generateOptionFlag "webBundle")
++ (generateOptionFlag "outfmt")
++ (concatLists (map (x: ["--hide" x]) cfg.hidePaths))
++ (generateOptionFlag "format")
++ (generateOptionFlag "color")
# Still options but these are not defined by builder specific options but
# instead synchronize options between the global build options and builder
# specific options.
++ (optionals (!(elem texCfg.build.pdfDirectory ["." ""])) ["--outdir" "${texCfg.build.pdfDirectory}"])
);
};
};
}

View file

@ -12,6 +12,7 @@
in {
imports = [
./build
./formatter.nix
./lsp.nix
./pdfViewer.nix
./treesitter.nix

View file

@ -0,0 +1,56 @@
{
config,
lib,
pkgs,
...
}: let
inherit (lib.options) mkEnableOption mkOption literalMD;
inherit (lib.nvim.types) deprecatedSingleOrListOf;
inherit (lib.attrsets) attrNames;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.attrsets) mapListToAttrs;
cfg = config.vim.languages.tex;
defaultFormat = ["latexindent"];
formats = {
latexindent = {
command = "${pkgs.texlive.withPackages (ps: [ps.latexindent])}/bin/latexindent";
};
};
in {
options.vim.languages.tex.format = {
enable =
mkEnableOption "TeX formatting"
// {
default = !cfg.lsp.enable && config.vim.languages.enableFormat;
defaultText = literalMD ''
diabled if TeX LSP is enabled, otherwise follows {option}`vim.languages.enableFormat`
'';
};
type = mkOption {
description = "TeX formatter to use";
type = with lib.types; deprecatedSingleOrListOf "vim.language.tex.format.type" (enum (attrNames formats));
default = defaultFormat;
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts = {
formatters_by_ft.tex = cfg.format.type;
formatters =
mapListToAttrs (name: {
inherit name;
value = formats.${name};
})
cfg.format.type;
};
};
})
]);
}