Skip to content

Commit

Permalink
conform: disable autoformat on save for specified filetypes
Browse files Browse the repository at this point in the history
Provide a method to disable autoformat on save 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
  • Loading branch information
dam9000 committed Mar 15, 2024
1 parent 7892c0c commit 63d58df
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,19 @@ require('lazy').setup({
'stevearc/conform.nvim',
opts = {
notify_on_error = false,
format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
},
format_on_save = function(bufnr)
-- Disable "autoformat on save" for languages that don't have
-- a well standardized coding style. You can add additional
-- languages here or re-enable it for the disabled ones.
local disable_filetypes = { 'c', 'cpp' }
if vim.tbl_contains(disable_filetypes, vim.bo[bufnr].filetype) then
return
end
return {
timeout_ms = 500,
lsp_fallback = true,
}
end,
formatters_by_ft = {
lua = { 'stylua' },
-- Conform can also run multiple formatters sequentially
Expand Down

0 comments on commit 63d58df

Please sign in to comment.