From 0785b9cef662ba6006062ff33087c3fcc28b0a31 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 25 Dec 2024 22:36:21 +0100 Subject: [PATCH 1/9] feat(enableOnVimEnter): add `fast` mode --- README.md | 4 +++- doc/no-neck-pain.txt | 4 +++- lua/no-neck-pain/config.lua | 4 +++- lua/no-neck-pain/init.lua | 8 ++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c8281af..59c889e 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,9 @@ require("no-neck-pain").setup({ -- When `true`, enables the plugin when you start Neovim. -- If the main window is a side tree (e.g. NvimTree) or a dashboard, the command is delayed until it finds a valid window. -- The command is cleaned once it has successfuly ran once. - ---@type boolean + -- When `fast`, no autocmds are created, `enable` is called as soon as possible without debounce. This option can lead to + -- race conditions if you have other plugins enabled on startup (e.g. file explorers or dashboards). + ---@type boolean | "fast" enableOnVimEnter = false, -- When `true`, enables the plugin when you enter a new Tab. -- note: it does not trigger if you come back to an existing tab, to prevent unwanted interfer with user's decisions. diff --git a/doc/no-neck-pain.txt b/doc/no-neck-pain.txt index 2617e13..2ef99ea 100644 --- a/doc/no-neck-pain.txt +++ b/doc/no-neck-pain.txt @@ -234,7 +234,9 @@ Default values: -- When `true`, enables the plugin when you start Neovim. -- If the main window is a side tree (e.g. NvimTree) or a dashboard, the command is delayed until it finds a valid window. -- The command is cleaned once it has successfuly ran once. - ---@type boolean + -- When `fast`, no autocmds are created, `enable` is called as soon as possible without debounce. This option can lead to + -- race conditions if you have other plugins enabled on startup (e.g. file explorers or dashboards). + ---@type boolean | "fast" enableOnVimEnter = false, -- When `true`, enables the plugin when you enter a new Tab. -- note: it does not trigger if you come back to an existing tab, to prevent unwanted interfer with user's decisions. diff --git a/lua/no-neck-pain/config.lua b/lua/no-neck-pain/config.lua index aa52c77..ff90aef 100644 --- a/lua/no-neck-pain/config.lua +++ b/lua/no-neck-pain/config.lua @@ -173,7 +173,9 @@ NoNeckPain.options = { -- When `true`, enables the plugin when you start Neovim. -- If the main window is a side tree (e.g. NvimTree) or a dashboard, the command is delayed until it finds a valid window. -- The command is cleaned once it has successfuly ran once. - ---@type boolean + -- When `fast`, no autocmds are created, `enable` is called as soon as possible without debounce. This option can lead to + -- race conditions if you have other plugins enabled on startup (e.g. file explorers or dashboards). + ---@type boolean | "fast" enableOnVimEnter = false, -- When `true`, enables the plugin when you enter a new Tab. -- note: it does not trigger if you come back to an existing tab, to prevent unwanted interfer with user's decisions. diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index 3ad263a..bc98c8e 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -67,7 +67,7 @@ function NoNeckPain.enable(scope) _G.NoNeckPain.config = config.options end - api.debounce(scope or "public_api_enable", main.enable, 10) + api.debounce(scope or "public_api_enable", main.enable) end --- Disables the plugin, clear highlight groups and autocmds, closes side buffers and resets the internal state. @@ -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() @@ -129,6 +129,10 @@ function NoNeckPain.setup(opts) }) end + if _G.NoNeckPain.config.autocmds.enableOnVimEnter == "fast" then + NoNeckPain.enable() + end + if _G.NoNeckPain.config.autocmds.enableOnTabEnter then vim.api.nvim_create_autocmd({ "TabEnter" }, { callback = function(p) From a73b52de9b48487532f80bbf082071ea860ec74f Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 25 Dec 2024 23:00:07 +0100 Subject: [PATCH 2/9] chore: log on fast --- lua/no-neck-pain/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index bc98c8e..71fe1fa 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -106,7 +106,7 @@ function NoNeckPain.setup(opts) }) end - if _G.NoNeckPain.config.autocmds.enableOnVimEnter == true then + if _G.NoNeckPain.config.autocmds.enableOnVimEnter then vim.api.nvim_create_autocmd({ "BufEnter" }, { pattern = "*", callback = function() @@ -130,7 +130,7 @@ function NoNeckPain.setup(opts) end if _G.NoNeckPain.config.autocmds.enableOnVimEnter == "fast" then - NoNeckPain.enable() + NoNeckPain.enable("enable_on_vim_enter_fast") end if _G.NoNeckPain.config.autocmds.enableOnTabEnter then From 10bdc03841d2bf99df492173e545e72886f33549 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 25 Dec 2024 23:01:23 +0100 Subject: [PATCH 3/9] chore: safe check --- lua/no-neck-pain/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index 71fe1fa..c9efbee 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -88,7 +88,7 @@ function NoNeckPain.setup(opts) vim.api.nvim_create_augroup("NoNeckPainVimEnterAutocmd", { clear = true }) end - if _G.NoNeckPain.config.autocmds.reloadOnColorSchemeChange then + if _G.NoNeckPain.config.autocmds.reloadOnColorSchemeChange == true then vim.api.nvim_create_autocmd({ "ColorScheme" }, { pattern = "*", callback = function(p) From 6f4d03adf330db641585ec4ca3e6f0ed0b15980e Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 31 Dec 2024 23:39:11 +0100 Subject: [PATCH 4/9] fix: remove debounce --- lua/no-neck-pain/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index c9efbee..22af02b 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -130,7 +130,7 @@ function NoNeckPain.setup(opts) end if _G.NoNeckPain.config.autocmds.enableOnVimEnter == "fast" then - NoNeckPain.enable("enable_on_vim_enter_fast") + main.enable("enable_on_vim_enter_fast") end if _G.NoNeckPain.config.autocmds.enableOnTabEnter then From a634c09058844d02ce6bd7f1105e56d4e7df7d76 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 1 Jan 2025 00:31:32 +0100 Subject: [PATCH 5/9] feat: sane fast default? --- lua/no-neck-pain/init.lua | 28 +++++++++++++++++++++++----- lua/no-neck-pain/main.lua | 2 +- lua/no-neck-pain/ui.lua | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index 22af02b..52d20fc 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -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. @@ -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() @@ -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 @@ -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 diff --git a/lua/no-neck-pain/main.lua b/lua/no-neck-pain/main.lua index ed822e3..61c9db3 100644 --- a/lua/no-neck-pain/main.lua +++ b/lua/no-neck-pain/main.lua @@ -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) diff --git a/lua/no-neck-pain/ui.lua b/lua/no-neck-pain/ui.lua index a2970bb..00f4193 100644 --- a/lua/no-neck-pain/ui.lua +++ b/lua/no-neck-pain/ui.lua @@ -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 From 14de8a666a3aa9021340aa86df856a35c289d6e6 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 1 Jan 2025 00:37:08 +0100 Subject: [PATCH 6/9] feat: wwooooowwww --- lua/no-neck-pain/init.lua | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index 52d20fc..e9ca6e6 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -67,7 +67,7 @@ function NoNeckPain.enable(scope) _G.NoNeckPain.config = config.options end - api.debounce(scope or "public_api_enable", main.enable, 10) + main.enable(scope or "public_api_enable") end --- Disables the plugin, clear highlight groups and autocmds, closes side buffers and resets the internal state. @@ -106,43 +106,20 @@ function NoNeckPain.setup(opts) }) end - if _G.NoNeckPain.config.autocmds.enableOnVimEnter == true then - vim.api.nvim_create_autocmd({ "BufEnter" }, { - pattern = "*", - callback = function() - vim.schedule(function() - if _G.NoNeckPain.state ~= nil and _G.NoNeckPain.state.enabled then - return - end - - local scope = "enable_on_vim_enter" - - NoNeckPain.enable(scope) - - api.debounce(scope, function() - if _G.NoNeckPain.state ~= nil then - pcall(vim.api.nvim_del_augroup_by_name, "NoNeckPainVimEnterAutocmd") - end - end, 20) - end) - end, - group = "NoNeckPainVimEnterAutocmd", - desc = "Triggers until it finds the correct moment/buffer to enable the plugin.", - }) - end - - if _G.NoNeckPain.config.autocmds.enableOnVimEnter == "fast" then + if _G.NoNeckPain.config.autocmds.enableOnVimEnter then vim.api.nvim_create_autocmd({ "BufWinEnter" }, { pattern = "*", callback = function() - local scope = "enable_on_vim_enter_fast" + local scope = "enable_on_vim_enter" - main.enable(scope) + NoNeckPain.enable(scope) api.debounce(scope, function() if _G.NoNeckPain.state ~= nil then pcall(vim.api.nvim_del_augroup_by_name, "NoNeckPainVimEnterAutocmd") end + end) + vim.schedule(function() main.init(scope) end) end, From 2853e72fed55aadd46c8871a86f8470202ddbaaf Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 1 Jan 2025 00:38:28 +0100 Subject: [PATCH 7/9] chore: unrelated changes --- README.md | 4 +--- doc/no-neck-pain.txt | 4 +--- lua/no-neck-pain/config.lua | 4 +--- lua/no-neck-pain/init.lua | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 59c889e..c8281af 100644 --- a/README.md +++ b/README.md @@ -145,9 +145,7 @@ require("no-neck-pain").setup({ -- When `true`, enables the plugin when you start Neovim. -- If the main window is a side tree (e.g. NvimTree) or a dashboard, the command is delayed until it finds a valid window. -- The command is cleaned once it has successfuly ran once. - -- When `fast`, no autocmds are created, `enable` is called as soon as possible without debounce. This option can lead to - -- race conditions if you have other plugins enabled on startup (e.g. file explorers or dashboards). - ---@type boolean | "fast" + ---@type boolean enableOnVimEnter = false, -- When `true`, enables the plugin when you enter a new Tab. -- note: it does not trigger if you come back to an existing tab, to prevent unwanted interfer with user's decisions. diff --git a/doc/no-neck-pain.txt b/doc/no-neck-pain.txt index 2ef99ea..2617e13 100644 --- a/doc/no-neck-pain.txt +++ b/doc/no-neck-pain.txt @@ -234,9 +234,7 @@ Default values: -- When `true`, enables the plugin when you start Neovim. -- If the main window is a side tree (e.g. NvimTree) or a dashboard, the command is delayed until it finds a valid window. -- The command is cleaned once it has successfuly ran once. - -- When `fast`, no autocmds are created, `enable` is called as soon as possible without debounce. This option can lead to - -- race conditions if you have other plugins enabled on startup (e.g. file explorers or dashboards). - ---@type boolean | "fast" + ---@type boolean enableOnVimEnter = false, -- When `true`, enables the plugin when you enter a new Tab. -- note: it does not trigger if you come back to an existing tab, to prevent unwanted interfer with user's decisions. diff --git a/lua/no-neck-pain/config.lua b/lua/no-neck-pain/config.lua index ff90aef..aa52c77 100644 --- a/lua/no-neck-pain/config.lua +++ b/lua/no-neck-pain/config.lua @@ -173,9 +173,7 @@ NoNeckPain.options = { -- When `true`, enables the plugin when you start Neovim. -- If the main window is a side tree (e.g. NvimTree) or a dashboard, the command is delayed until it finds a valid window. -- The command is cleaned once it has successfuly ran once. - -- When `fast`, no autocmds are created, `enable` is called as soon as possible without debounce. This option can lead to - -- race conditions if you have other plugins enabled on startup (e.g. file explorers or dashboards). - ---@type boolean | "fast" + ---@type boolean enableOnVimEnter = false, -- When `true`, enables the plugin when you enter a new Tab. -- note: it does not trigger if you come back to an existing tab, to prevent unwanted interfer with user's decisions. diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index e9ca6e6..2cb6084 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -88,7 +88,7 @@ function NoNeckPain.setup(opts) vim.api.nvim_create_augroup("NoNeckPainVimEnterAutocmd", { clear = true }) end - if _G.NoNeckPain.config.autocmds.reloadOnColorSchemeChange == true then + if _G.NoNeckPain.config.autocmds.reloadOnColorSchemeChange then vim.api.nvim_create_autocmd({ "ColorScheme" }, { pattern = "*", callback = function(p) From 143d119ff5cd6752e493b68ac3b4c46eed87778e Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 1 Jan 2025 00:46:36 +0100 Subject: [PATCH 8/9] chore: direct call --- lua/no-neck-pain/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index 2cb6084..04bb369 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -67,7 +67,7 @@ function NoNeckPain.enable(scope) _G.NoNeckPain.config = config.options end - main.enable(scope or "public_api_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. @@ -112,7 +112,8 @@ function NoNeckPain.setup(opts) callback = function() local scope = "enable_on_vim_enter" - NoNeckPain.enable(scope) + + main.enable(scope) api.debounce(scope, function() if _G.NoNeckPain.state ~= nil then From 49504143fa558021e47eaa0d4f9ee7f58c79b7bc Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 1 Jan 2025 00:48:28 +0100 Subject: [PATCH 9/9] chore: remove print --- lua/no-neck-pain/ui.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/no-neck-pain/ui.lua b/lua/no-neck-pain/ui.lua index 00f4193..a2970bb 100644 --- a/lua/no-neck-pain/ui.lua +++ b/lua/no-neck-pain/ui.lua @@ -43,7 +43,6 @@ 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