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

@@ -36,7 +36,18 @@ in rec {
conform-nvim = {
enable = true;
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 = {
d2 = ["d2"];
sql = ["sleek"];
@@ -632,6 +643,24 @@ in rec {
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',
function()
pcall(vim.cmd'%!${pkgs.sleek}/bin/sleek')