Skip to content

Commit

Permalink
bug: #3 - fix issue with checking disable filetypes (#4)
Browse files Browse the repository at this point in the history
Updated docs and status user command is added
  • Loading branch information
csessh authored Oct 7, 2024
1 parent 34a8e6e commit 1ce60cb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
8 changes: 0 additions & 8 deletions CONTRIBUTING.md

This file was deleted.

10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- panvimdoc-ignore-start -->
## Contribution

See [CONTRIBUTING.md](./CONTRIBUTING.md).
<!-- panvimdoc-ignore-end -->
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.
35 changes: 28 additions & 7 deletions lua/stopinsert/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -23,33 +30,47 @@ 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

util.reset_timer()
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
Expand Down

0 comments on commit 1ce60cb

Please sign in to comment.