diff --git a/doc/telescope.txt b/doc/telescope.txt index f5c89e6762..c98b1525e1 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1454,7 +1454,8 @@ builtin.buffers({opts}) *telescope.builtin.buffers()* {cwd} (string) specify a working directory to filter buffers list by {show_all_buffers} (boolean) if true, show all buffers, - including unloaded buffers + including unloaded buffers and + unlisted buffers (default: true) {ignore_current_buffer} (boolean) if true, don't show the current buffer in the list (default: diff --git a/lua/telescope/builtin/__internal.lua b/lua/telescope/builtin/__internal.lua index 2b801dff94..14a9b8be4e 100644 --- a/lua/telescope/builtin/__internal.lua +++ b/lua/telescope/builtin/__internal.lua @@ -926,13 +926,17 @@ internal.buffers = function(opts) opts = apply_cwd_only_aliases(opts) local bufnrs = vim.tbl_filter(function(bufnr) - if 1 ~= vim.fn.buflisted(bufnr) then - return false - end - -- only hide unloaded buffers if opts.show_all_buffers is false, keep them listed if true or nil - if opts.show_all_buffers == false and not api.nvim_buf_is_loaded(bufnr) then - return false + -- only hide unlisted and unloaded buffers if opts.show_all_buffers is + -- false, keep them listed if true or nil + if opts.show_all_buffers == false then + if 1 ~= vim.fn.buflisted(bufnr) then + return false + end + if not api.nvim_buf_is_loaded(bufnr) then + return false + end end + if opts.ignore_current_buffer and bufnr == api.nvim_get_current_buf() then return false end