modules: add neoformat

This commit is contained in:
Dmitriy Pleshevskiy 2024-04-21 00:22:39 +03:00
parent 1d31c3d1d2
commit 6030f1df18
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
5 changed files with 40 additions and 9 deletions

View file

@ -213,11 +213,11 @@
},
"nix2lua": {
"locked": {
"lastModified": 1713641247,
"narHash": "sha256-UDAxwO1vSkaPtmby04xjiHq5dxd03IBD3lkpFKYlV7Q=",
"lastModified": 1713645801,
"narHash": "sha256-pev5YkdskHDS4OpGdYb5F/44hKrFmqzCwNGs0vSzqM8=",
"ref": "refs/heads/main",
"rev": "8c4f3ca834ef7c07c9e3be3e006d7395c69a176c",
"revCount": 36,
"rev": "3c08fa87d14704db1c1648b2486ed49e721dfe18",
"revCount": 37,
"type": "git",
"url": "https://git.pleshevski.ru/mynix/nix2lua"
},

View file

@ -250,13 +250,10 @@
group_empty = true;
full_name = true;
};
keymaps = [
{ mode = "n"; bind = "<leader>nt"; command = "<CMD>NvimTreeToggle<CR>"; }
{ mode = "n"; bind = "<leader>nf"; command = "<CMD>NvimTreeFindFile<CR>"; }
];
};
nvim-treesitter = { };
git = { };
gitsigns-nvim = { };
neoformat = { };
};
plugins = with prev.nix2lua.lib; {

View file

@ -2,8 +2,10 @@
with nix2lua.lib;
{
g = varName: expr: set "vim.g.${varName}" expr;
fn.isdirectory = file: call1 "vim.fn.isdirectory" (var file);
cmd' = expr: call1 "vim.cmd" expr;
cmd.cd = file: call1 "vim.cmd.cd" (var file);
keymap.set = { mode, bind, command, opts ? { } }:

32
modules/neoformat.nix Normal file
View file

@ -0,0 +1,32 @@
{ vim, ... }:
{ configs ? {
neoformat_enabled_markdown = [ "denofmt" ];
neoformat_rust_rustfmt = {
exe = "rustfmt";
args = [ "--edition 2021" ];
stdin = 1;
};
}
}:
let inherit (builtins) concatLists attrValues mapAttrs; in
{
neoformat = concatLists [
[
(vim.g "neoformat_try_node_exe" 1)
(vim.g "neoformat_only_msg_on_error" 1)
]
(attrValues (mapAttrs vim.g configs))
[
(vim.cmd' ''
aug fmt
au!
au BufWritePre * try | undojoin | Neoformat | catch /E790/ | Neoformat | endtry
aug END
'')
]
];
}