2024-04-30 01:29:37 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
2024-04-30 01:25:36 +03:00
|
|
|
|
|
|
|
let cfg = config.plugins.style.neoformat; in
|
|
|
|
{
|
|
|
|
options.plugins.style.neoformat = with lib; {
|
|
|
|
enable = mkEnableOption "neoformat";
|
|
|
|
|
|
|
|
package = mkPackageOption pkgs.vimPlugins "neoformat" { };
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
See: https://github.com/sbdchd/neoformat?tab=readme-ov-file#config-optional
|
|
|
|
'';
|
|
|
|
example = {
|
|
|
|
neoformat_enabled_markdown = [ "denofmt" ];
|
|
|
|
neoformat_rust_rustfmt = {
|
|
|
|
exe = "rustfmt";
|
|
|
|
args = [ "--edition 2021" ];
|
|
|
|
stdin = 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-17 01:25:54 +03:00
|
|
|
autoformat = {
|
|
|
|
enable = mkEnableOption "Autoformat on save file";
|
2024-05-17 13:20:16 +03:00
|
|
|
pattern = mkOption {
|
|
|
|
type = types.extCommas;
|
2024-05-17 01:25:54 +03:00
|
|
|
default = "*";
|
|
|
|
};
|
|
|
|
};
|
2024-04-30 01:25:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2024-05-10 01:31:47 +03:00
|
|
|
# we shouldn't import this plugin
|
|
|
|
plugin.neoformat.package = cfg.package;
|
2024-04-30 01:25:36 +03:00
|
|
|
|
|
|
|
vim.g = {
|
|
|
|
neoformat_try_node_exe = 1;
|
|
|
|
neoformat_only_msg_on_error = 1;
|
|
|
|
} // cfg.settings;
|
|
|
|
|
|
|
|
vim.namedCmd = lib.mkIf cfg.autoformat.enable {
|
|
|
|
autoformat = ''
|
2024-04-30 10:42:51 +03:00
|
|
|
augroup autoformat
|
|
|
|
autocmd!
|
2024-05-17 01:25:54 +03:00
|
|
|
autocmd BufWritePre ${cfg.autoformat.pattern} try | undojoin | Neoformat | catch /E790/ | Neoformat | endtry
|
2024-04-30 10:42:51 +03:00
|
|
|
augroup END
|
2024-04-30 01:25:36 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|