Improve oldfiles Picker (#657)
This commit is contained in:
@@ -231,9 +231,37 @@ internal.loclist = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
internal.oldfiles = function(opts)
|
internal.oldfiles = function(opts)
|
||||||
local results = vim.tbl_filter(function(val)
|
opts.include_current_session = utils.get_default(opts.include_current_session, true)
|
||||||
return 0 ~= vim.fn.filereadable(val)
|
|
||||||
end, vim.v.oldfiles)
|
local current_buffer = vim.api.nvim_get_current_buf()
|
||||||
|
local current_file = vim.api.nvim_buf_get_name(current_buffer)
|
||||||
|
local results = {}
|
||||||
|
|
||||||
|
if opts.include_current_session then
|
||||||
|
for _, buffer in ipairs(vim.split(vim.fn.execute(':buffers! t'), "\n")) do
|
||||||
|
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 ~= current_buffer then
|
||||||
|
table.insert(results, file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, file in ipairs(vim.v.oldfiles) do
|
||||||
|
if vim.loop.fs_stat(file) and not vim.tbl_contains(results, file) and file ~= current_file then
|
||||||
|
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, {
|
pickers.new(opts, {
|
||||||
prompt_title = 'Oldfiles',
|
prompt_title = 'Oldfiles',
|
||||||
finder = finders.new_table{
|
finder = finders.new_table{
|
||||||
|
|||||||
Reference in New Issue
Block a user