From 3f5f165447d797576206e3b9bd555ea8db85b6f2 Mon Sep 17 00:00:00 2001 From: Brian Mayo <43855513+protiumx@users.noreply.github.com> Date: Sun, 3 Dec 2023 19:24:07 +0100 Subject: [PATCH] feat(buffers): add buffers_sort option (#2793) * refactor: add sort_buffers option to buffers picker * refactor: validate sort_buffers opt is a function --- lua/telescope/builtin/__internal.lua | 4 ++++ lua/telescope/builtin/init.lua | 1 + 2 files changed, 5 insertions(+) diff --git a/lua/telescope/builtin/__internal.lua b/lua/telescope/builtin/__internal.lua index 38c9cf9267..7697dfbf61 100644 --- a/lua/telescope/builtin/__internal.lua +++ b/lua/telescope/builtin/__internal.lua @@ -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 diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index a0674f35d7..4af52011d0 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -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 ``