diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 0219c4c..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,8 +0,0 @@ -# Contributing - -All contributions are most welcome! Please open a PR or create an [issue](https://github.com/csessh/stopinsert.nvim/issues). - -## Coding Style - -- Follow the coding style of [LuaRocks](https://github.com/luarocks/lua-style-guide). -- Make sure you format the code with [StyLua](https://github.com/JohnnyMorganz/StyLua) before PR. diff --git a/README.md b/README.md index e9ffbb4..f00fdbe 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,16 @@ Filetypes can also be listed as regex, such as `neo%-tree*`. :StopInsertPlug enable :StopInsertPlug disable :StopInsertPlug toggle +:StopInsertPlug status ``` Each of them does exactly what it says on the tin. - ## Contribution -See [CONTRIBUTING.md](./CONTRIBUTING.md). - +All contributions are most welcome! Please open a PR or create an [issue](https://github.com/csessh/stopinsert.nvim/issues). + +### Coding Style + +- Follow the coding style of [LuaRocks](https://github.com/luarocks/lua-style-guide). +- Make sure you format the code with [StyLua](https://github.com/JohnnyMorganz/StyLua) before PR. diff --git a/lua/stopinsert/init.lua b/lua/stopinsert/init.lua index e567aec..1946c01 100644 --- a/lua/stopinsert/init.lua +++ b/lua/stopinsert/init.lua @@ -2,7 +2,7 @@ local M = {} local util = require("stopinsert.util") M.enable = true -local commands = { +local user_cmds = { enable = function() M.enable = true end, @@ -12,6 +12,13 @@ local commands = { toggle = function() M.enable = not M.enable end, + status = function() + if M.enable then + print("StopInsert is active") + else + print("StopInsert is inactive") + end + end, } ---@param opts table @@ -23,19 +30,28 @@ function M.setup(opts) vim.api.nvim_create_autocmd("InsertEnter", { group = vim.api.nvim_create_augroup("InsertEnterListener", { clear = true }), callback = function() - if not M.enable and not util.is_filetype_disabled(vim.bo.ft) then + if not M.enable then + return + end + + if util.is_filetype_disabled(vim.bo.ft) then return end + util.reset_timer() end, }) vim.on_key(function(_, _) - if not M.enable and not util.is_filetype_disabled(vim.bo.ft) then + if vim.fn.mode() ~= "i" then return end - if vim.fn.mode() ~= "i" then + if not M.enable then + return + end + + if util.is_filetype_disabled(vim.bo.ft) then return end @@ -43,13 +59,18 @@ function M.setup(opts) end) vim.api.nvim_create_user_command("StopInsertPlug", function(cmd) - if commands[cmd.args] then - commands[cmd.args]() + if user_cmds[cmd.args] then + user_cmds[cmd.args]() end end, { nargs = 1, complete = function() - return { "enable", "disable", "toggle" } + return { + "enable", + "disable", + "toggle", + "status", + } end, }) end