From c5763b912e5919dbad5611693aa3c060cf5e5e4e Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 26 Aug 2024 00:47:57 +0100 Subject: [PATCH] Allow for disabling auto-formatting Allow for disabling auto-formatting with a global or buffer-local variable, based on https://github.com/stevearc/conform.nvim/blob/62eba813b7501b39612146cbf29cd07f1d4ac29c/doc/recipes.md#autoformat-with-extra-features. In the future, it would be interesting to do this based on the presence of a file in the repository, such as `.do-not-auto-format`. --- plugin/conform.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugin/conform.lua b/plugin/conform.lua index 21f1b38..702d4d8 100644 --- a/plugin/conform.lua +++ b/plugin/conform.lua @@ -12,8 +12,15 @@ conform.setup { yaml = { "yamlfmt" }, }, - format_on_save = { - lsp_fallback = false, - quiet = true, - }, + format_on_save = function(bufnr) + -- Disable with a global or buffer-local variable. + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + + return { + lsp_fallback = false, + quiet = true, + } + end, }