summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorJesse Leite <jesseleite@gmail.com>2021-03-18 03:21:25 -0400
committerGitHub <noreply@github.com>2021-03-18 10:21:25 +0300
commitd4bf1181ea6ef9aec675ff404d65098cbb91d9b1 (patch)
tree81bf80044f21e66076f80e9385d2d42c938f062b /lua
parentc50eaf5c9ad0a2db4e9403625df84ace4a51187b (diff)
Improve oldfiles Picker (#657)
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/builtin/internal.lua34
1 files changed, 31 insertions, 3 deletions
diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua
index 14c05ae..18820f8 100644
--- a/lua/telescope/builtin/internal.lua
+++ b/lua/telescope/builtin/internal.lua
@@ -231,9 +231,37 @@ 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 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, {
prompt_title = 'Oldfiles',
finder = finders.new_table{