Skip to content

Commit

Permalink
feat(buffers): add buffers_sort option (#2793)
Browse files Browse the repository at this point in the history
* refactor: add sort_buffers option to buffers picker

* refactor: validate sort_buffers opt is a function
  • Loading branch information
protiumx authored Dec 3, 2023
1 parent e90fdba commit 3f5f165
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lua/telescope/builtin/__internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,10 @@ internal.buffers = function(opts)
end)
end

if type(opts.sort_buffers) == "function" then
table.sort(bufnrs, opts.sort_buffers)
end

local buffers = {}
local default_selection_idx = 1
for _, bufnr in ipairs(bufnrs) do
Expand Down
1 change: 1 addition & 0 deletions lua/telescope/builtin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ builtin.reloader = require_on_exported_call("telescope.builtin.__internal").relo
---@field sort_mru boolean: Sorts all buffers after most recent used. Not just the current and last one (default: false)
---@field bufnr_width number: Defines the width of the buffer numbers in front of the filenames (default: dynamic)
---@field file_encoding string: file encoding for the previewer
---@field sort_buffers function: sort fn(bufnr_a, bufnr_b). true if bufnr_a should go first. Runs after sorting by most recent (if specified)
builtin.buffers = require_on_exported_call("telescope.builtin.__internal").buffers

--- Lists available colorschemes and applies them on `<cr>`
Expand Down

0 comments on commit 3f5f165

Please sign in to comment.