From d18218ccf285c343fe82271f326c0c06af7891f1 Mon Sep 17 00:00:00 2001 From: JohnWilliston Date: Tue, 25 Feb 2025 12:48:34 -0800 Subject: [PATCH 1/3] Added an extras function for tab mappings, similar to buffers and windows. --- README.md | 1 + lua/which-key/extras.lua | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 35f3d114..88bce86a 100644 --- a/README.md +++ b/README.md @@ -282,6 +282,7 @@ The `expand` property allows to create dynamic mappings. Only functions as `rhs` Two examples are included in `which-key.extras`: - `require("which-key.extras").expand.buf`: creates numerical key to buffer mappings +- `require("which-key.extras").expand.tab`: creates numerical key to tab mappings - `require("which-key.extras").expand.win`: creates numerical key to window mappings ```lua diff --git a/lua/which-key/extras.lua b/lua/which-key/extras.lua index a89ef7e0..6b1f9008 100644 --- a/lua/which-key/extras.lua +++ b/lua/which-key/extras.lua @@ -67,4 +67,25 @@ function M.expand.win() return M.add_keys(ret) end +function M.expand.tab() + local ret = {} + local current = vim.api.nvim_get_current_tabpage() + vim.print("Current = " .. current) + for _, tab in ipairs(vim.api.nvim_list_tabpages()) do + vim.print(tab) + if tab ~= current then + local num = vim.api.nvim_tabpage_get_number(tab) + ret[#ret + 1] = { + "", + function () + vim.api.nvim_set_current_tabpage(tab) + end, + desc = "Goto tab " .. tostring(num), + icon = { cat = "file", name = tostring(num) }, + } + end + end + return M.add_keys(ret) +end + return M From 1924a706b51a22e5ac32f7337000fb3d0710c281 Mon Sep 17 00:00:00 2001 From: John Williston Date: Tue, 25 Feb 2025 14:27:30 -0800 Subject: [PATCH 2/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 88bce86a..8e7ccb79 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,7 @@ When `desc`, `group`, or `icon` are functions, they are evaluated every time the popup is shown. The `expand` property allows to create dynamic mappings. Only functions as `rhs` are supported for dynamic mappings. -Two examples are included in `which-key.extras`: +Three examples are included in `which-key.extras`: - `require("which-key.extras").expand.buf`: creates numerical key to buffer mappings - `require("which-key.extras").expand.tab`: creates numerical key to tab mappings From a82419123bed7ff770acfc1e21a8e1e96c3ec5f3 Mon Sep 17 00:00:00 2001 From: John Williston Date: Tue, 25 Feb 2025 17:37:41 -0800 Subject: [PATCH 3/3] Removed a couple vim.print statements overlooked. --- lua/which-key/extras.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/which-key/extras.lua b/lua/which-key/extras.lua index 6b1f9008..a8459201 100644 --- a/lua/which-key/extras.lua +++ b/lua/which-key/extras.lua @@ -70,9 +70,7 @@ end function M.expand.tab() local ret = {} local current = vim.api.nvim_get_current_tabpage() - vim.print("Current = " .. current) for _, tab in ipairs(vim.api.nvim_list_tabpages()) do - vim.print(tab) if tab ~= current then local num = vim.api.nvim_tabpage_get_number(tab) ret[#ret + 1] = {