Skip to content

Instantly share code, notes, and snippets.

@LinArcX
Created December 24, 2021 07:54
Show Gist options
  • Save LinArcX/1d46cf87a0d55f5313060d4581cebb17 to your computer and use it in GitHub Desktop.
Save LinArcX/1d46cf87a0d55f5313060d4581cebb17 to your computer and use it in GitHub Desktop.
local function bar(opts)
opts = opts or {}
pickers.new(opts, {
prompt_title = "bar",
finder = finders.new_table {
results = { ":Telescope grep_string", ":Telescope find_files" , ":Telescope registers"},
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
print(vim.inspect(selection.value))
vim.api.nvim_exec(selection.value, true)
end)
return true
end,
}):find()
end
local function foo(opts)
opts = opts or {}
pickers.new(opts, {
prompt_title = "foo",
finder = finders.new_table {
results = { "hi", "bye" , "tye"},
},
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
bar(opts)
end)
return true
end,
}):find()
end
foo()
@renerocksai
Copy link

In my plugin, I managed to get correct behavior when I wrapped bar in a vim.schedule() call:

-- ...
actions.close(prompt_bufnr) -- I use actions._close(prompt_bufnr, true) -- to keep insert mode
vim.schedule(function()
    bar()
end)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment