Skip to content

Commit 54005a6

Browse files
phanenibhagwan
authored andcommitted
feat: more options can be function
Fix #1870 (reply in thread). ```lua require('fzf-lua').setup { tabs = { keymap = function() local curtab = fn.tabpagenr() local pos = 1 for i, t in ipairs(api.nvim_list_tabpages()) do if i < curtab then pos = pos + 1 + #api.nvim_tabpage_list_wins(t) end end return { fzf = { load = string.format("transform:echo 'pos(%d)'", pos) } } end, }, } ```
1 parent f970eaf commit 54005a6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lua/fzf-lua/config.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ do
127127
m.globals = M.globals
128128
end
129129

130+
local eval = function(v, ...)
131+
if vim.is_callable(v) then return v(...) end
132+
return v
133+
end
134+
130135
---@param opts table<string, unknown>|fun():table?
131136
---@param globals string|table?
132137
---@param __resume_key string?
@@ -223,10 +228,10 @@ function M.normalize_opts(opts, globals, __resume_key)
223228
} or nil
224229
end
225230
local exclude_case_sensitive_alt = "^alt%-%a$"
226-
opts.keymap = keymap_tolower(opts.keymap, exclude_case_sensitive_alt)
227-
opts.actions = utils.map_tolower(opts.actions, exclude_case_sensitive_alt)
228-
globals.keymap = keymap_tolower(globals.keymap, exclude_case_sensitive_alt)
229-
globals.actions = utils.map_tolower(globals.actions, exclude_case_sensitive_alt)
231+
opts.keymap = keymap_tolower(eval(opts.keymap, opts), exclude_case_sensitive_alt)
232+
opts.actions = utils.map_tolower(eval(opts.actions, opts), exclude_case_sensitive_alt)
233+
globals.keymap = keymap_tolower(eval(globals.keymap, opts), exclude_case_sensitive_alt)
234+
globals.actions = utils.map_tolower(eval(globals.actions, opts), exclude_case_sensitive_alt)
230235

231236
-- inherit from globals.actions?
232237
if type(globals._actions) == "function" then

0 commit comments

Comments
 (0)