modules: add neoformat module
This commit is contained in:
parent
71303ad324
commit
0aede48d79
3 changed files with 59 additions and 0 deletions
|
@ -11,6 +11,7 @@
|
||||||
./modules/plugin.nix
|
./modules/plugin.nix
|
||||||
|
|
||||||
./modules/plugins/theme/catppuccin.nix
|
./modules/plugins/theme/catppuccin.nix
|
||||||
|
./modules/plugins/style/neoformat.nix
|
||||||
./modules/plugins/navigation/telescope.nix
|
./modules/plugins/navigation/telescope.nix
|
||||||
./modules/plugins/navigation/nvim-tree.nix
|
./modules/plugins/navigation/nvim-tree.nix
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,11 @@ let
|
||||||
name = mkOption {
|
name = mkOption {
|
||||||
type = str;
|
type = str;
|
||||||
};
|
};
|
||||||
|
extraImports = mkOption {
|
||||||
|
type = attrsOf str;
|
||||||
|
default = { };
|
||||||
|
example = { hint = "hop.hint"; };
|
||||||
|
};
|
||||||
varName = mkOption {
|
varName = mkOption {
|
||||||
type = str;
|
type = str;
|
||||||
# TODO: add validation
|
# TODO: add validation
|
||||||
|
@ -58,6 +63,7 @@ let
|
||||||
|
|
||||||
genConfig = with lib.nix2lua; lib.mkIf (!config.isDependency) (lib.flatten [
|
genConfig = with lib.nix2lua; lib.mkIf (!config.isDependency) (lib.flatten [
|
||||||
(local (set config.varName (require config.name)))
|
(local (set config.varName (require config.name)))
|
||||||
|
(lib.mapAttrsToList (k: v: local (set k) (require v)) config.extraImports)
|
||||||
config.beforeSetup
|
config.beforeSetup
|
||||||
(lib.optional (config.setupSettings != null)
|
(lib.optional (config.setupSettings != null)
|
||||||
(pipe1 (var config.varName) (call config.setupFnName config.setupSettings))
|
(pipe1 (var config.varName) (call config.setupFnName config.setupSettings))
|
||||||
|
|
52
modules/plugins/style/neoformat.nix
Normal file
52
modules/plugins/style/neoformat.nix
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
autoformat.enable = mkEnableOption "Autoformat on save file";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
plugin.neoformat = {
|
||||||
|
# we shouldn't import this plugin
|
||||||
|
isDependency = true;
|
||||||
|
package = cfg.package;
|
||||||
|
};
|
||||||
|
|
||||||
|
vim.g = {
|
||||||
|
neoformat_try_node_exe = 1;
|
||||||
|
neoformat_only_msg_on_error = 1;
|
||||||
|
} // cfg.settings;
|
||||||
|
|
||||||
|
vim.namedCmd = lib.mkIf cfg.autoformat.enable {
|
||||||
|
autoformat = ''
|
||||||
|
aug fmt
|
||||||
|
au!
|
||||||
|
au BufWritePre * try | undojoin | Neoformat | catch /E790/ | Neoformat | endtry
|
||||||
|
aug END
|
||||||
|
'';
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue