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",
|
colorscheme = "rose-pine",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vim.g.disable_autoformat = false
|
||||||
|
|
||||||
---@param name "options" | "keymaps" | "clipboard"
|
---@param name "options" | "keymaps" | "clipboard"
|
||||||
function M.load(name)
|
function M.load(name)
|
||||||
local mod = "juancwu.config." .. name
|
local mod = "juancwu.config." .. name
|
||||||
|
|
@ -48,6 +50,14 @@ function M.setup(opts)
|
||||||
end
|
end
|
||||||
vim.cmd.colorscheme("rose-pine")
|
vim.cmd.colorscheme("rose-pine")
|
||||||
end)
|
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
|
end
|
||||||
|
|
||||||
setmetatable(M, {
|
setmetatable(M, {
|
||||||
|
|
@ -57,7 +67,7 @@ setmetatable(M, {
|
||||||
end
|
end
|
||||||
|
|
||||||
return options[k]
|
return options[k]
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,12 @@ return {
|
||||||
javascriptreact = { "prettierd" },
|
javascriptreact = { "prettierd" },
|
||||||
typescriptreact = { "prettierd" },
|
typescriptreact = { "prettierd" },
|
||||||
},
|
},
|
||||||
format_on_save = {
|
format_on_save = function(bufnr)
|
||||||
timeout_ms = 500,
|
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
||||||
lsp_fallback = true,
|
return
|
||||||
},
|
end
|
||||||
|
return { timeout_ms = 500, lsp_fallback = true }
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue