diff --git a/README.md b/README.md index 1b1aee8..b95fa11 100644 --- a/README.md +++ b/README.md @@ -220,8 +220,9 @@ vim.api.nvim_set_keymap('n', '', | `registers` | :registers | | `tagstack` | :tags | | `keymaps` | key mappings | +| `filetypes` | filetypes | +| `menus` | menus | | `spell_suggest` | spelling suggestions | -| `filetypes` | neovim filetypes | | `packadd` | :packadd | ### Neovim API diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index 91a26bd..2b0b9fa 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -256,8 +256,9 @@ MISC *fzf-lua-misc* | `registers` | :registers | | `tagstack` | :tags | | `keymaps` | key mappings | +| `filetypes` | filetypes | +| `menus` | menus | | `spell_suggest` | spelling suggestions | -| `filetypes` | neovim filetypes | | `packadd` | :packadd | diff --git a/lua/fzf-lua/actions.lua b/lua/fzf-lua/actions.lua index 7254381..569bdd8 100644 --- a/lua/fzf-lua/actions.lua +++ b/lua/fzf-lua/actions.lua @@ -343,6 +343,12 @@ M.ex_run_cr = function(selected) vim.fn.histadd("cmd", cmd) end +M.exec_menu = function(selected) + local cmd = selected[1] + vim.cmd("emenu " .. cmd) +end + + M.search = function(selected) local query = selected[1] vim.cmd("stopinsert") diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 0880e89..9cc87d2 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -581,6 +581,12 @@ M.globals.nvim = { ["default"] = actions.packadd, }, }, + menus = { + prompt = 'Menu> ', + actions = { + ["default"] = actions.exec_menu, + }, + }, } M.globals.dap = { @@ -898,6 +904,7 @@ M._action_to_helpstr = { [actions.run_builtin] = "run-builtin", [actions.ex_run] = "edit-cmd", [actions.ex_run_cr] = "exec-cmd", + [actions.exec_menu] = "exec-menu", [actions.search] = "edit-search", [actions.search_cr] = "exec-search", [actions.goto_mark] = "goto-mark", diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index 3b0c0f3..3a41dd5 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -120,6 +120,7 @@ M.jumps = require'fzf-lua.providers.nvim'.jumps M.changes = require'fzf-lua.providers.nvim'.changes M.tagstack = require'fzf-lua.providers.nvim'.tagstack M.marks = require'fzf-lua.providers.nvim'.marks +M.menus = require'fzf-lua.providers.nvim'.menus M.keymaps = require'fzf-lua.providers.nvim'.keymaps M.registers = require'fzf-lua.providers.nvim'.registers M.commands = require'fzf-lua.providers.nvim'.commands diff --git a/lua/fzf-lua/providers/nvim.lua b/lua/fzf-lua/providers/nvim.lua index 2645c65..6b9c90e 100644 --- a/lua/fzf-lua/providers/nvim.lua +++ b/lua/fzf-lua/providers/nvim.lua @@ -407,4 +407,46 @@ M.packadd = function(opts) end +M.menus = function(opts) + + opts = config.normalize_opts(opts, config.globals.nvim.menus) + if not opts then return end + + -- @param prefix will be prepended to the entry name + local function gen_menu_entries(prefix, entry) + local name = prefix and ("%s.%s"):format(prefix, entry.name) or entry.name + if entry.submenus then + -- entry.submenus is a list of {} + return vim.tbl_map( + function(x) + return gen_menu_entries(name, x) + end, entry.submenus) + else + -- if we reached a leaf + return name + end + end + + local entries = vim.tbl_flatten(vim.tbl_map( + function (x) + return gen_menu_entries(nil, x) + end, vim.fn.menu_get(''))) + + if vim.tbl_isempty(entries) then + utils.info("No menus available") + return + end + + opts.fzf_opts['--no-multi'] = '' + opts.fzf_opts['--preview-window'] = 'hidden:right:0' + + core.fzf_wrap(opts, entries, function(selected) + + if not selected then return end + actions.act(opts.actions, selected) + + end)() + +end + return M