summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-08 00:41:48 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-08 00:41:48 +0200
commit5617ad54ad86c9cc9d533caf7556af9dbf5891ca (patch)
tree3f5dbad56f9ed4c800de2cb89f80ab4a5696208d
parentafbe8af709360c025b5b00448f154d4ac9c336b3 (diff)
checkpoint
-rw-r--r--after/plugin/conform.lua30
1 files changed, 25 insertions, 5 deletions
diff --git a/after/plugin/conform.lua b/after/plugin/conform.lua
index d233d3a..188b499 100644
--- a/after/plugin/conform.lua
+++ b/after/plugin/conform.lua
@@ -1,20 +1,40 @@
-require("conform").setup({
+local conform = require("conform")
+conform.setup({
formatters_by_ft = {
lua = { "stylua" },
-- html = { "prettier" },
go = { "goimports", "gofmt" },
- c = { "clang-format" },
},
format_on_save = {
-- These options will be passed to conform.format()
timeout_ms = 500,
- lsp_format = "fallback",
+ lsp_format = "never",
},
})
-require("conform").formatters["clang-format"] = {
+conform.formatters["clang-format"] = {
prepend_args = {
"--style",
- "{IndentWidth: 4, AlignAfterOpenBracket: BlockIndent, AlignConsecutiveAssignments: Consecutive, AlignArrayOfStructures: Right, BreakBeforeBraces: Linux}",
+ "{"
+ .. "IndentWidth: 4, "
+ .. "AlignAfterOpenBracket: BlockIndent, "
+ .. "AlignConsecutiveAssignments: Consecutive, "
+ .. "AlignArrayOfStructures: Right, "
+ .. "BreakBeforeBraces: Linux, "
+ .. "ColumnLimit: "
+ .. vim.o.tw
+ .. "}",
},
}
+
+-- 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()
+end, {})