Skip to content

Commit 7d6a4dd

Browse files
dam9000angerborn
authored andcommitted
conform: disable autoformat on save for specified filetypes (nvim-lua#694)
Provide a method to disable autoformat on save lsp fallback for specified filetypes. By default disable for C/C++ as an example, because it does not have a well standardized coding style. Based on conform recipe: https://github.com/stevearc/conform.nvim/blob/master/doc/recipes.md
1 parent f7e0d9a commit 7d6a4dd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

init.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,16 @@ require('lazy').setup({
603603
'stevearc/conform.nvim',
604604
opts = {
605605
notify_on_error = false,
606-
format_on_save = {
607-
timeout_ms = 500,
608-
lsp_fallback = true,
609-
},
606+
format_on_save = function(bufnr)
607+
-- Disable "format_on_save lsp_fallback" for languages that don't
608+
-- have a well standardized coding style. You can add additional
609+
-- languages here or re-enable it for the disabled ones.
610+
local disable_filetypes = { c = true, cpp = true }
611+
return {
612+
timeout_ms = 500,
613+
lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype],
614+
}
615+
end,
610616
formatters_by_ft = {
611617
lua = { 'stylua' },
612618
-- Conform can also run multiple formatters sequentially

0 commit comments

Comments
 (0)