Skip to content

Commit 1ce60cb

Browse files
authored
bug: #3 - fix issue with checking disable filetypes (#4)
Updated docs and status user command is added
1 parent 34a8e6e commit 1ce60cb

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

CONTRIBUTING.md

-8
This file was deleted.

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ Filetypes can also be listed as regex, such as `neo%-tree*`.
5252
:StopInsertPlug enable
5353
:StopInsertPlug disable
5454
:StopInsertPlug toggle
55+
:StopInsertPlug status
5556
```
5657

5758
Each of them does exactly what it says on the tin.
5859

59-
<!-- panvimdoc-ignore-start -->
6060
## Contribution
6161

62-
See [CONTRIBUTING.md](./CONTRIBUTING.md).
63-
<!-- panvimdoc-ignore-end -->
62+
All contributions are most welcome! Please open a PR or create an [issue](https://github.com/csessh/stopinsert.nvim/issues).
63+
64+
### Coding Style
65+
66+
- Follow the coding style of [LuaRocks](https://github.com/luarocks/lua-style-guide).
67+
- Make sure you format the code with [StyLua](https://github.com/JohnnyMorganz/StyLua) before PR.

lua/stopinsert/init.lua

+28-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local M = {}
22
local util = require("stopinsert.util")
33
M.enable = true
44

5-
local commands = {
5+
local user_cmds = {
66
enable = function()
77
M.enable = true
88
end,
@@ -12,6 +12,13 @@ local commands = {
1212
toggle = function()
1313
M.enable = not M.enable
1414
end,
15+
status = function()
16+
if M.enable then
17+
print("StopInsert is active")
18+
else
19+
print("StopInsert is inactive")
20+
end
21+
end,
1522
}
1623

1724
---@param opts table
@@ -23,33 +30,47 @@ function M.setup(opts)
2330
vim.api.nvim_create_autocmd("InsertEnter", {
2431
group = vim.api.nvim_create_augroup("InsertEnterListener", { clear = true }),
2532
callback = function()
26-
if not M.enable and not util.is_filetype_disabled(vim.bo.ft) then
33+
if not M.enable then
34+
return
35+
end
36+
37+
if util.is_filetype_disabled(vim.bo.ft) then
2738
return
2839
end
40+
2941
util.reset_timer()
3042
end,
3143
})
3244

3345
vim.on_key(function(_, _)
34-
if not M.enable and not util.is_filetype_disabled(vim.bo.ft) then
46+
if vim.fn.mode() ~= "i" then
3547
return
3648
end
3749

38-
if vim.fn.mode() ~= "i" then
50+
if not M.enable then
51+
return
52+
end
53+
54+
if util.is_filetype_disabled(vim.bo.ft) then
3955
return
4056
end
4157

4258
util.reset_timer()
4359
end)
4460

4561
vim.api.nvim_create_user_command("StopInsertPlug", function(cmd)
46-
if commands[cmd.args] then
47-
commands[cmd.args]()
62+
if user_cmds[cmd.args] then
63+
user_cmds[cmd.args]()
4864
end
4965
end, {
5066
nargs = 1,
5167
complete = function()
52-
return { "enable", "disable", "toggle" }
68+
return {
69+
"enable",
70+
"disable",
71+
"toggle",
72+
"status",
73+
}
5374
end,
5475
})
5576
end

0 commit comments

Comments
 (0)