From ae4f9b5e823335a8b60383d42bf43c23a6c1898f Mon Sep 17 00:00:00 2001 From: McAuley Penney Date: Mon, 5 Jun 2023 16:26:00 -0700 Subject: [PATCH] refactor: make toggle functionality more concise vim.b.tidy_enabled appears to be redundant because of M.enabled. This commit removes it. --- lua/tidy/init.lua | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lua/tidy/init.lua b/lua/tidy/init.lua index 234db6c..f2e8eef 100644 --- a/lua/tidy/init.lua +++ b/lua/tidy/init.lua @@ -3,16 +3,12 @@ local M = {} M.enabled = true function M.toggle() - if vim.b.tidy_enabled == false then - vim.b.tidy_enabled = nil - M.enabled = true + M.enabled = not M.enabled + + if not M.enabled then + vim.notify("Tidy disabled on save", vim.log.levels.WARN, { title = "Tidy" }) else - M.enabled = not M.enabled - end - if M.enabled then vim.notify("Tidy enabled on save", vim.log.levels.INFO, { title = "Tidy" }) - else - vim.notify("Tidy disabled on save", vim.log.levels.WARN, { title = "Tidy" }) end end @@ -61,10 +57,10 @@ function M.setup(opts) local tidy_grp = vim.api.nvim_create_augroup("tidy", { clear = true }) - vim.api.nvim_create_autocmd("BufWritePre", { + vim.api.nvim_create_autocmd("BufWritePre", { group = tidy_grp, callback = function() - if not M.enabled or vim.b.tidy_enabled == false or is_excluded_ft(opts) then + if not M.enabled or is_excluded_ft(opts) then return false end