telescope.nvim
telescope.nvim copied to clipboard
Independent Resume for each picker
Hello. I wanna have ability to resume each picker independently. E.g. I open find_file do something and the open live_grep and do something. And I want to resume find_file state.
Describe the solution you'd like It would be cool to have independent resume state and option to resume last searching for each picker.
:help telescope.defaults.cache_picker you can cache how many pickers you want and fuzzy find/open them again with :help builtin.pickers
:help telescope.defaults.cache_pickeryou can cache how many pickers you want and fuzzy find/open them again with:help builtin.pickers
Thanks. I'll try it.
I have two more questions.
Is any way to bind specific picker resume to some shortcut?
E.g I want to bind find_files to
May resume be default behavior for specific pickers?
If we track the name of the picker (as per https://github.com/nvim-telescope/telescope.nvim/pull/1473), the back-end would be straightforward. Nevertheless, the canonical way to pick another cached picker would be builtin.pickers.
Is any way to bind specific picker resume to some bind?
No
May resume be default behavior for specific pickers?
Definitely no. Maybe opt-in? I guess that would be the one way to use the proposed feature request ergonomically.
Can wholeheartedly recommend https://github.com/nvim-telescope/telescope-smart-history.nvim
Read a bit though the source code & made a hacky implementation of this
local state = require "telescope.state"
local function resume_via_query(query)
local cached_pickers = state.get_global_key "cached_pickers"
if cached_pickers == nil or vim.tbl_isempty(cached_pickers) then
return false
end
local newest = math.huge
for i, v in ipairs(cached_pickers) do
if v.prompt_title == query then
newest = math.min(newest, i)
end
end
if newest == math.huge then
return false
end
builtin.resume({ cache_index = newest })
return true
end
vim.keymap.set('n', '<leader>P', function()
if not resume_via_query("Live Grep") then
builtin.live_grep()
end
end, { desc = "Greps in git" })
It doesn't actually tests what builtin you've used, but it uses the builtin prompt_title to find the builtin picker. To find the names you can open the picker you want to find print v.promt_title instead of testing its value, it should print all the cached value.
I'm no good at lua or vim so I can't guarentee that the code above would always work.