-
As title. The first snippet I provided below indeed updates the list, but it has two problems:
-- a part of the fzf-lua's `setup`.
require('fzf-lua').setup {
'hide', -- I assume everything is run on hide-profile.
-- ...
actions = {
['ctrl-g'] = {
fn = function (selected, opts)
-- print(vim.inspect(opts))
require('fzf-lua').tabs { query = ('^%d: '):format(vim.fn.tabpagenr()) }
end,
},
-- ...
}
-- ...
}
-- The `opts` might be `nil`.
require('fzf-lua').tabs()
-- Or a complex table to fit my need.
require('fzf-lua').tabs { ... } I did read the Wiki but I'm still confused, for example: {
fn = function(selected, opts)
-- I want to get the arguments of the current command.
local original_args = get_original_args(opts)
-- so that I can modify it to prepare for the rerun:
local modified_args = do_something(original_args)
-- In the end, I will try to rerun the command variant derived from the current command
require('fzf-lua').tabs(modified_args)
-- Or this, since I don't know:
get_rerun_fn(opts)(modified_args)
end,
reload = true, -- Since I called `fzf.tabs` above, what's the point I set `reload=true` or `require('fzf-lua').actions.resume` here?
} I know this is a bit confusing, so let me describe a simple use case:
ReferenceI have read #1626 and #499, and the Wiki-advanced section. None of these seem to mention about:
I described in the second snippet above. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 19 replies
-
I just found the answer to my 2. in the file action.lua: fzf-lua/lua/fzf-lua/actions.lua Lines 964 to 969 in 54005a6 Still finding the answer to avoid 1. EDIT: both 1. and 2. are solved! EDIT2: This is the final config, tested against 494af9d : local pos_offset = function (tabnr)
local pos = 1
for i, t in ipairs(vim.api.nvim_list_tabpages()) do
if i < tabnr then pos = pos + 1 + #vim.api.nvim_tabpage_list_wins(t) end
end
return pos
end
tabs = {
fzf_opts = {
['--with-nth'] = '3,5..', -- show tabnr for each entry.
-- ['--query'] = '', -- prefill.
},
formatter = 'path.filename_first',
actions = {
['enter'] = {
fn = function (selected, opts)
if #selected == 0 then
print('fzf-lua: no entry for action.')
opts.__call_fn(vim.tbl_deep_extend('keep', {}, opts.__call_opts))
return
end
local _, _, entry = unpack(selected, 1, 3)
local tabnr, win_id = entry:match(':(%d+):(%d+)%)')
tabnr = tonumber(tabnr) or 0
win_id = tonumber(win_id) or 0
if win_id > 0
then vim.api.nvim_set_current_win(win_id)
else vim.api.nvim_set_current_tabpage(tabnr)
end
end,
field_index = '{q} $FZF_POS {}',
-- reset prompt for reload. (buggy, discarded)
-- postfix = ...
},
['ctrl-g'] = {
fn = function (selected, opts)
-- when no match, we get `selected == {}`.
if #selected == 0 then
print('fzf-lua: no entry for action.')
return
end
local query, _, entry = unpack(selected, 1, 3)
if -- current scope: single tabpage.
query:match('%^%d+:')
then -- change scope to all tabpages, and update pos.
local tabnr_entry = tonumber(query:match('%^(%d+):'))
opts.__call_fn(vim.tbl_deep_extend('keep', {
query = '',
['keymap.fzf.load'] = ("transform:echo 'pos(%s)'"):format(pos_offset(tabnr_entry))
}, opts.__call_opts))
return
end
-- current scope: all tabpages.
local tabnr_entry = tonumber(entry:match(':(%d+):'))
-- change scope to single tabpage, and update pos.
opts.__call_fn(vim.tbl_deep_extend('keep', {
query = ('^%d: '):format(tabnr_entry),
['keymap.fzf.load'] = "transform:echo 'pos(2)'", -- skip `tab_title` entry.
}, opts.__call_opts))
end,
reload = true,
field_index = '{q} $FZF_POS {}',
},
['ctrl-b'] = actions.dummy_abort
},
} |
Beta Was this translation helpful? Give feedback.
-
with
|
Beta Was this translation helpful? Give feedback.
-
@ibhagwan So, long story short, I want to achieve the following sequence of events:
While @phanen has helped me a lot, but the way facilitating The following code is a workaround to simulate the sequence of events above, but the only problem is that I make use of
So I ended up having a not-perfect sequence of events:
But "unhide fzf-lua with updated query --> hide fzf-lua with " creates a "blink", i.e. there is an extra pair of unhide-hide. I really like to achieve the first sequence of events I pointed out. Do you have any idea how to do that? NOTE regarding "why" this feature: After my pressing 'enter', the current buffer will become actions = {
['enter'] = {
fn = function (selected, opts)
if #selected == 0 then
print('fzf-lua: no entry for action.')
return
end
local _, _, entry = unpack(selected, 1, 3)
local tabnr, win_id = entry:match(':(%d+):(%d+)%)')
tabnr = tonumber(tabnr) or 0
win_id = tonumber(win_id) or 0
if win_id > 0
then vim.api.nvim_set_current_win(win_id)
else vim.api.nvim_set_current_tabpage(tabnr)
end
-- NOTE1: I want to update the query to `^{tabnr}: `, but `opts.__call_fn` reopen the fzf-lua window.
opts.__call_fn(vim.tbl_deep_extend('keep', {
query = ('^%d: '):format(tabnr),
-- ['keymap.fzf.load'] = ("transform:echo 'pos(%s)'"):format(pos_offset(tabnr_entry))
}, opts.__call_opts))
-- NOTE2: So I close it with a feedkey <Esc>.
vim.api.nvim_feedkeys('�', 'n', true)
end,
field_index = '{q} $FZF_POS {}',
-- reset prompt for reload. (buggy, can't work)
-- postfix = ...
}, |
Beta Was this translation helpful? Give feedback.
I just found the answer to my 2. in the file action.lua:
fzf-lua/lua/fzf-lua/actions.lua
Lines 964 to 969 in 54005a6
Still finding the answer to avoid 1.
EDIT: both 1. and 2. are solved!
EDIT2: This is the final config, tested against 494af9d :