diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-08 01:04:22 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-08 01:04:22 +0200 |
commit | b0e951feb9e2b17bce8fa519fd2bf1a013b987b7 (patch) | |
tree | 662ef69f6f80324a758f538da6201f59e17c2fb6 | |
parent | 5617ad54ad86c9cc9d533caf7556af9dbf5891ca (diff) |
checkpoint
-rw-r--r-- | after/plugin/conform.lua | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/after/plugin/conform.lua b/after/plugin/conform.lua index 188b499..4560bc0 100644 --- a/after/plugin/conform.lua +++ b/after/plugin/conform.lua @@ -27,14 +27,22 @@ conform.formatters["clang-format"] = { }, } +-- ID of autocmd for CFormat +vim.b.CFormatID = nil -- Enable formatting on save for C only when using the :CFormat command vim.api.nvim_create_user_command("CFormat", function() - vim.api.nvim_create_autocmd("BufWritePre", { - buffer = 0, - callback = function() - conform.format({ formatters = { "clang-format" } }) - end, - }) - conform.format({ formatters = { "clang-format" } }) - vim.cmd.write() + if vim.b.CFormatID == nil then + vim.b.CFormatID = vim.api.nvim_create_autocmd("BufWritePre", { + buffer = 0, + callback = function() + conform.format({ formatters = { "clang-format" } }) + end, + }) + conform.format({ formatters = { "clang-format" } }) + print("Auto formatting enabled.") + else + vim.api.nvim_del_autocmd(vim.b.CFormatID) + print("Auto formatting disabled.") + vim.b.CFormatID = nil + end end, {}) |