mirror of
https://github.com/Theaninova/TheaninovOS.git
synced 2025-12-12 11:36:20 +00:00
feat: nixvim refactor
This commit is contained in:
71
modules/home-manager/programs/nixvim/presets/auto-format.nix
Normal file
71
modules/home-manager/programs/nixvim/presets/auto-format.nix
Normal file
@@ -0,0 +1,71 @@
|
||||
{ lib, config, ... }:
|
||||
let
|
||||
cfg = config.presets.auto-format;
|
||||
in
|
||||
{
|
||||
options.presets.auto-format = {
|
||||
enable = lib.mkEnableOption "auto-format";
|
||||
varName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "disable_autoformat";
|
||||
};
|
||||
commandName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "AutoFormatToggle";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
userCommands.${cfg.commandName} = {
|
||||
command = {
|
||||
__raw = ''
|
||||
function(args)
|
||||
if args.bang then
|
||||
vim.b.${cfg.varName} = not vim.b.${cfg.varName}
|
||||
else
|
||||
vim.g.${cfg.varName} = not vim.g.${cfg.varName}
|
||||
end
|
||||
end
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
keymaps = [
|
||||
{
|
||||
key = "<leader>af";
|
||||
mode = "n";
|
||||
options.silent = true;
|
||||
action = "<cmd>:${cfg.commandName}<CR>";
|
||||
}
|
||||
{
|
||||
key = "<leader>aF";
|
||||
mode = "n";
|
||||
options.silent = true;
|
||||
action = "<cmd>:${cfg.commandName}!<CR>";
|
||||
}
|
||||
];
|
||||
|
||||
plugins = {
|
||||
which-key.registrations = {
|
||||
"<leader>a" = {
|
||||
name = "Auto Actions";
|
||||
f = "Toggle auto-format";
|
||||
F = "Toggle auto-format (buffer)";
|
||||
};
|
||||
};
|
||||
|
||||
conform-nvim.formatAfterSave = ''
|
||||
function(bufnr)
|
||||
if vim.g.${cfg.varName} or vim.b[bufnr].${cfg.varName} then
|
||||
return
|
||||
end
|
||||
return { timeout_ms = 500, lsp_fallback = true };
|
||||
end
|
||||
'';
|
||||
|
||||
lualine.sections.lualine_x = lib.mkOrder 600 [
|
||||
"(vim.g.${cfg.varName} or vim.b.${cfg.varName}) and '' or nil"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user