blob: 4761097aafa1e52818d5f26928a632e61d7fa852 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
--
-- Autoformat plugin
--
local function toggle_autoformat()
vim.b.autoformat = not vim.b.autoformat
end
-- Autoformat
vim.api.nvim_create_autocmd("BufWritePre", {
desc = "Autoformat buffer",
group = vim.g.dotfiles.augroup,
callback = function(ev)
if vim.b.autoformat then
if vim.b.format_func == nil then
vim.notify("No formatter set for " .. ev.file .. " (" .. vim.o.filetype .. ")", vim.log.levels.WARN)
return
end
vim.b.format_func()
end
end,
})
vim.api.nvim_create_user_command("AutoformatToggle", toggle_autoformat, { desc = "Toggle autoformatting" })
|