nvim: FormatDisable disables globally with a bang

Switch the functionality of `FormatDisable` command around: Disables for
the local buffer by default and disables globally if called with a bang.
This commit is contained in:
Marty Oehme 2024-07-20 16:50:00 +02:00
parent d2a2537df0
commit 88f187160a
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -141,7 +141,9 @@ return {
"stevearc/conform.nvim", "stevearc/conform.nvim",
config = function() config = function()
require("conform").setup({ require("conform").setup({
lsp_format = "fallback", lsp_format = "fallback",
format_after_save = function(bufnr) format_after_save = function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return return
@ -152,10 +154,10 @@ return {
}) })
vim.api.nvim_create_user_command("FormatDisable", function(args) vim.api.nvim_create_user_command("FormatDisable", function(args)
if args.bang then if args.bang then
-- FormatDisable! will disable formatting just for this buffer
vim.b.disable_autoformat = true
else
vim.g.disable_autoformat = true vim.g.disable_autoformat = true
else
-- FormatDisable! will disable formatting globally
vim.b.disable_autoformat = true
end end
end, { end, {
desc = "Disable formatting on save", desc = "Disable formatting on save",