Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve oldfiles finder #657

Merged
merged 10 commits into from
Mar 18, 2021
32 changes: 29 additions & 3 deletions lua/telescope/builtin/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,35 @@ internal.loclist = function(opts)
end

internal.oldfiles = function(opts)
local results = vim.tbl_filter(function(val)
return 0 ~= vim.fn.filereadable(val)
end, vim.v.oldfiles)
opts.include_current_session = utils.get_default(opts.include_current_session, true)

local results = {}

if opts.include_current_session then
for _, buffer in ipairs(vim.split(vim.fn.execute(':buffers! t'), "\n")) do
jesseleite marked this conversation as resolved.
Show resolved Hide resolved
local match = tonumber(string.match(buffer, '%s*(%d+)'))
if match then
local file = vim.api.nvim_buf_get_name(match)
if vim.loop.fs_stat(file) and match ~= vim.api.nvim_get_current_buf() then
jesseleite marked this conversation as resolved.
Show resolved Hide resolved
table.insert(results, file)
end
end
end
end

for _, file in ipairs(vim.v.oldfiles) do
if vim.loop.fs_stat(file) and vim.fn.index(results, file) == -1 then
jesseleite marked this conversation as resolved.
Show resolved Hide resolved
table.insert(results, file)
end
end

if opts.cwd_only then
local cwd = vim.loop.cwd()
results = vim.tbl_filter(function(file)
return vim.fn.matchstrpos(file, cwd)[2] ~= -1
end, results)
end

pickers.new(opts, {
prompt_title = 'Oldfiles',
finder = finders.new_table{
Expand Down