diff --git a/README.md b/README.md index 73c85085..09e3ba8c 100644 --- a/README.md +++ b/README.md @@ -319,8 +319,8 @@ Alternatively, resuming work on a specific provider: | `resume` | resume last command/query | | `builtin` | fzf-lua builtin commands | | `profiles` | fzf-lua configuration profiles | -| `help_tags` | help tags | -| `man_pages` | man pages | +| `helptags` | help tags | +| `manpages` | man pages | | `colorschemes` | color schemes | | `awesome_colorschemes` | Awesome Neovim color schemes | | `highlights` | highlight groups | diff --git a/lua/fzf-lua/core.lua b/lua/fzf-lua/core.lua index 24dd0b18..eb8a38b9 100644 --- a/lua/fzf-lua/core.lua +++ b/lua/fzf-lua/core.lua @@ -340,9 +340,7 @@ M.fzf = function(contents, opts) -- fzf 0.40 added 'zero' event for when there's no match -- clears the preview when there are no matching entries if opts.__FZF_VERSION and opts.__FZF_VERSION >= 0.40 and previewer.zero then - opts.keymap = opts.keymap or {} - opts.keymap.fzf = opts.keymap.fzf or {} - opts.keymap.fzf["zero"] = previewer:zero() + utils.map_set(opts, "keymap.fzf.zero", previewer:zero()) end if opts.__FZF_VERSION and opts.__FZF_VERSION >= 0.46 @@ -361,9 +359,7 @@ M.fzf = function(contents, opts) tonumber(opts.winopts.preview.flip_columns), opts.winopts.preview.vertical, opts.winopts.preview.horizontal) - opts.keymap = opts.keymap or {} - opts.keymap.fzf = opts.keymap.fzf or {} - opts.keymap.fzf["resize"] = string.format("transform(%s)", transformer) + utils.map_set(opts, "keymap.fzf.resize", string.format("transform(%s)", transformer)) end if type(previewer.preview_window) == "function" then -- do we need to override the preview_window args? diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index b993d9f2..cddd0b70 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -222,6 +222,9 @@ do tabs = { "fzf-lua.providers.buffers", "tabs" }, lines = { "fzf-lua.providers.buffers", "lines" }, blines = { "fzf-lua.providers.buffers", "blines" }, + helptags = { "fzf-lua.providers.helptags", "helptags" }, + manpages = { "fzf-lua.providers.manpages", "manpages" }, + -- backward compat help_tags = { "fzf-lua.providers.helptags", "helptags" }, man_pages = { "fzf-lua.providers.manpages", "manpages" }, colorschemes = { "fzf-lua.providers.colorschemes", "colorschemes" }, @@ -349,6 +352,11 @@ M._excluded_meta = { "get_info", "set_info", "get_last_query", + -- Exclude due to rename: + -- help_tags -> helptags + -- man_pages -> manpages + "help_tags", + "man_pages", } for _, m in ipairs(M._exported_modules) do diff --git a/plugin/fzf-lua.lua b/plugin/fzf-lua.lua new file mode 100644 index 00000000..ec47058d --- /dev/null +++ b/plugin/fzf-lua.lua @@ -0,0 +1,82 @@ +if vim.g.loaded_fzf_lua == 1 then + return +end +vim.g.loaded_fzf_lua = 1 + +-- Should never be called, below nvim 0.7 "plugin/fzf-lua.vim" +-- sets `vim.g.loaded_fzf_lua=1` +if vim.fn.has("nvim-0.7") ~= 1 then + vim.api.nvim_err_writeln("Fzf-lua minimum requirement is Neovim versions 0.5") + return +end + +vim.api.nvim_create_user_command("FzfLua", function(opts) + require("fzf-lua.cmd").load_command(unpack(opts.fargs)) +end, { + nargs = "*", + complete = function(_, line) + local metatable = require("fzf-lua") + local builtin_list = vim.tbl_filter(function(k) + return metatable._excluded_metamap[k] == nil + end, vim.tbl_keys(metatable)) + + local l = vim.split(line, "%s+") + local n = #l - 2 + + if n == 0 then + local commands = vim.tbl_flatten({ builtin_list }) + table.sort(commands) + + return vim.tbl_filter(function(val) + return vim.startswith(val, l[2]) + end, commands) + end + + local defaults = require("fzf-lua.defaults").defaults + local cmd_opts = defaults[l[2]] or {} + local opts = vim.tbl_filter(function(k) + return not k:match("^_") + end, vim.tbl_keys(cmd_opts)) + + -- Flatten map's keys recursively + -- { a = { a1 = ..., a2 = ... } } + -- will be transformed to: + -- { + -- ["a.a1"] = ..., + -- ["a.a2"] = ..., + -- } + local function map_flatten(t, prefix) + if vim.tbl_isempty(t) then return {} end + local ret = {} + prefix = prefix and string.format("%s.", prefix) or "" + for k, v in pairs(t) do + if type(v) == "table" then + local inner = map_flatten(v) + for ki, vi in pairs(inner) do + ret[prefix .. k .. "." .. ki] = vi + end + else + ret[prefix .. k] = v + end + end + return ret + end + + -- Add globals recursively, e.g. `winopts.fullscreen` + -- will be later retrieved using `utils.map_get(...)` + for _, k in ipairs({ "winopts", "keymap", "fzf_opts", "fzf_tmux_opts", "hls" }) do + opts = vim.tbl_flatten({ opts, vim.tbl_keys(map_flatten(defaults[k] or {}, k)) }) + end + + -- Add generic options that apply to all pickers + for _, o in ipairs({ "query" }) do + table.insert(opts, o) + end + + table.sort(opts) + + return vim.tbl_filter(function(val) + return vim.startswith(val, l[#l]) + end, opts) + end, +}) diff --git a/plugin/fzf-lua.vim b/plugin/fzf-lua.vim index 1fd812af..2b6282f0 100644 --- a/plugin/fzf-lua.vim +++ b/plugin/fzf-lua.vim @@ -1,3 +1,8 @@ +" Neovim >= v0.7 uses 'plugin/fzf-lua.lua' +if has('nvim-0.7') + finish +end + if !has('nvim-0.5') echohl Error echomsg "Fzf-lua is only available for Neovim versions 0.5 and above"