From a62319a224b73b70af47a48ba076d7ec67b08526 Mon Sep 17 00:00:00 2001 From: edluffy Date: Wed, 5 May 2021 15:46:06 +0100 Subject: [PATCH] feat: add option to toggle --- README.md | 3 +++ lua/specs/init.lua | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index d16650d..88bcb82 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,9 @@ require('specs').setup{ } ``` +- `:lua require('specs').toggle()` + - Toggle Specs on/off + Faders: - linear_fader `▁▂▂▃▃▄▄▅▅▆▆▇▇██` - exp_fader `▁▁▁▁▂▂▂▃▃▃▄▄▅▆▇` diff --git a/lua/specs/init.lua b/lua/specs/init.lua index c9cba4b..4857275 100644 --- a/lua/specs/init.lua +++ b/lua/specs/init.lua @@ -2,6 +2,7 @@ local M = {} local opts = {} local old_cur +local au_toggle function M.on_cursor_moved() local cur = vim.api.nvim_win_get_cursor(0) @@ -184,13 +185,27 @@ function M.setup(user_opts) M.create_autocmds() end +function M.toggle() + if au_toggle then + M.clear_autocmds() + else + M.create_autocmds() + end +end + function M.create_autocmds() vim.cmd("augroup Specs") vim.cmd("autocmd!") if opts.show_jumps then vim.cmd("silent autocmd CursorMoved * :lua require('specs').on_cursor_moved()") end vim.cmd("augroup END") + au_toggle = true end +function M.clear_autocmds() + vim.cmd("augroup Specs") vim.cmd("autocmd!") + vim.cmd("augroup END") + au_toggle = false +end return M