Skip to content

Commit

Permalink
feat: sane fast default?
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Dec 31, 2024
1 parent 6f4d03a commit a634c09
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
28 changes: 23 additions & 5 deletions lua/no-neck-pain/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function NoNeckPain.enable(scope)
_G.NoNeckPain.config = config.options
end

api.debounce(scope or "public_api_enable", main.enable)
api.debounce(scope or "public_api_enable", main.enable, 10)
end

--- Disables the plugin, clear highlight groups and autocmds, closes side buffers and resets the internal state.
Expand Down Expand Up @@ -106,7 +106,7 @@ function NoNeckPain.setup(opts)
})
end

if _G.NoNeckPain.config.autocmds.enableOnVimEnter then
if _G.NoNeckPain.config.autocmds.enableOnVimEnter == true then
vim.api.nvim_create_autocmd({ "BufEnter" }, {
pattern = "*",
callback = function()
Expand All @@ -115,9 +115,11 @@ function NoNeckPain.setup(opts)
return
end

NoNeckPain.enable()
local scope = "enable_on_vim_enter"

api.debounce("enable_on_vim_enter", function()
NoNeckPain.enable(scope)

api.debounce(scope, function()
if _G.NoNeckPain.state ~= nil then
pcall(vim.api.nvim_del_augroup_by_name, "NoNeckPainVimEnterAutocmd")
end
Expand All @@ -130,7 +132,23 @@ function NoNeckPain.setup(opts)
end

if _G.NoNeckPain.config.autocmds.enableOnVimEnter == "fast" then
main.enable("enable_on_vim_enter_fast")
vim.api.nvim_create_autocmd({ "BufWinEnter" }, {
pattern = "*",
callback = function()
local scope = "enable_on_vim_enter_fast"

main.enable(scope)

api.debounce(scope, function()
if _G.NoNeckPain.state ~= nil then
pcall(vim.api.nvim_del_augroup_by_name, "NoNeckPainVimEnterAutocmd")
end
main.init(scope)
end)
end,
group = "NoNeckPainVimEnterAutocmd",
desc = "Triggers until it finds the correct moment/buffer to enable the plugin.",
})
end

if _G.NoNeckPain.config.autocmds.enableOnTabEnter then
Expand Down
2 changes: 1 addition & 1 deletion lua/no-neck-pain/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ function main.enable(scope)
desc = "keeps track of the state after closing windows and deleting buffers",
})

vim.api.nvim_create_autocmd({ "WinLeave" }, {
vim.api.nvim_create_autocmd({ "WinEnter" }, {
callback = function(p)
vim.schedule(function()
p.event = string.format("%s:skip_entering", p.event)
Expand Down
1 change: 1 addition & 0 deletions lua/no-neck-pain/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function ui.move_sides(scope)
local curr = vim.api.nvim_get_current_win()

if curr ~= id then
print("here6")
vim.api.nvim_set_current_win(id)
end

Expand Down

0 comments on commit a634c09

Please sign in to comment.