From 58543c40348f0d1e6c7ba2b4f0e3e6b7641de757 Mon Sep 17 00:00:00 2001 From: John Bernard <38332081+loqusion@users.noreply.github.com> Date: Sun, 14 May 2023 01:42:31 -0500 Subject: [PATCH] feat: toggle tidy on or off --- lua/tidy/init.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lua/tidy/init.lua b/lua/tidy/init.lua index a2bc336..234db6c 100644 --- a/lua/tidy/init.lua +++ b/lua/tidy/init.lua @@ -1,5 +1,21 @@ local M = {} +M.enabled = true + +function M.toggle() + if vim.b.tidy_enabled == false then + vim.b.tidy_enabled = nil + M.enabled = true + 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 + local function list_to_set(list) local set = {} @@ -37,7 +53,6 @@ local function reset_cursor_pos(pos) end function M.setup(opts) - local defaults = { filetype_exclude = {}, } @@ -49,7 +64,7 @@ function M.setup(opts) vim.api.nvim_create_autocmd("BufWritePre", { group = tidy_grp, callback = function() - if is_excluded_ft(opts) then + if not M.enabled or vim.b.tidy_enabled == false or is_excluded_ft(opts) then return false end