add commands to enable/disable format on save

This commit is contained in:
jc 2023-12-28 14:11:44 -05:00
commit 512ab888d1
No known key found for this signature in database
2 changed files with 53 additions and 41 deletions

View file

@ -7,6 +7,8 @@ local defaultOpts = {
colorscheme = "rose-pine",
}
vim.g.disable_autoformat = false
---@param name "options" | "keymaps" | "clipboard"
function M.load(name)
local mod = "juancwu.config." .. name
@ -48,6 +50,14 @@ function M.setup(opts)
end
vim.cmd.colorscheme("rose-pine")
end)
-- create command to disable autoformat
vim.api.nvim_create_user_command("FormatDisable", function(args)
vim.g.disable_autoformat = true
end, { desc = "Disable Autoformat" })
vim.api.nvim_create_user_command("FormatEnable", function(args)
vim.g.disable_autoformat = false
end, { desc = "Enable Autoformat" })
end
setmetatable(M, {
@ -57,7 +67,7 @@ setmetatable(M, {
end
return options[k]
end
end,
})
return M

View file

@ -37,10 +37,12 @@ return {
javascriptreact = { "prettierd" },
typescriptreact = { "prettierd" },
},
format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
},
format_on_save = function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
return { timeout_ms = 500, lsp_fallback = true }
end,
},
},
},