add commands to enable/disable format on save
This commit is contained in:
parent
7325c06a75
commit
512ab888d1
2 changed files with 53 additions and 41 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue