feat: Added FormatEnable and FormatDisable for conform

This commit is contained in:
uttarayan21
2024-12-04 11:08:48 +05:30
parent 04cf152304
commit d08fcf6a43
3 changed files with 32 additions and 2 deletions

View File

@@ -49,6 +49,7 @@
programs.fish.enable = true; programs.fish.enable = true;
services.nix-daemon.enable = true; services.nix-daemon.enable = true;
services.tailscale.enable = true;
system.stateVersion = 4; system.stateVersion = 4;
system.keyboard.enableKeyMapping = true; system.keyboard.enableKeyMapping = true;

2
flake.lock generated
View File

@@ -1816,7 +1816,7 @@
}, },
"locked": { "locked": {
"lastModified": 1, "lastModified": 1,
"narHash": "sha256-jcGDQxNvo9hLGOcoVWLaAD4N0S9hWjzmudCr4n84YOo=", "narHash": "sha256-Zoq4MEovQdTzsJOX7dBaYsH6VpoDEizvVNC39HcP/7U=",
"path": "./neovim", "path": "./neovim",
"type": "path" "type": "path"
}, },

View File

@@ -36,7 +36,18 @@ in rec {
conform-nvim = { conform-nvim = {
enable = true; enable = true;
settings = { settings = {
format_on_save.lsp_format = "fallback"; format_on_save =
/*
lua
*/
''
function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
return { timeout_ms = 500, lsp_format = "fallback" }
end
'';
formatters_by_ft = { formatters_by_ft = {
d2 = ["d2"]; d2 = ["d2"];
sql = ["sleek"]; sql = ["sleek"];
@@ -632,6 +643,24 @@ in rec {
end, end,
{}) {})
vim.api.nvim_create_user_command("FormatDisable", function(args)
if args.bang then
-- FormatDisable! will disable formatting just for this buffer
vim.b.disable_autoformat = true
else
vim.g.disable_autoformat = true
end
end, {
desc = "Disable autoformat-on-save",
bang = true,
})
vim.api.nvim_create_user_command("FormatEnable", function()
vim.b.disable_autoformat = false
vim.g.disable_autoformat = false
end, {
desc = "Re-enable autoformat-on-save",
})
vim.api.nvim_create_user_command('Sqlfmt', vim.api.nvim_create_user_command('Sqlfmt',
function() function()
pcall(vim.cmd'%!${pkgs.sleek}/bin/sleek') pcall(vim.cmd'%!${pkgs.sleek}/bin/sleek')