rabbit-buffers.nvim/lua/rabbit-buffers/init.lua

64 lines
1.4 KiB
Lua

local set = require("rabbit.plugins.util")
---@class Rabbit.Plugin.Buffers.Options
---@field public ignore_unlisted? boolean If true, will ignore unlisted buffers (like Oil)
---@class Rabbit.Plugin.Buffers: Rabbit.Plugin
local M = { ---@type Rabbit.Plugin
color = "#1ae5d4",
name = "buffers",
func = {},
switch = "b",
listing = {},
empty_msg = "No opened buffers",
skip_same = false,
keys = {},
evt = {},
---@param p Rabbit.Plugin.Buffers
init = function(p)
p.listing[0] = {}
p.listing.bufnrs = {}
end,
---@type Rabbit.Plugin.Buffers.Options
opts = {
-- ignore_unlisted = true,
},
}
local get_buffers = function()
M.listing.bufnrs = {}
M.listing[0] = {}
local bufs = vim.fn.getbufinfo({ buflisted = 1 })
table.sort(bufs, function(a, b)
return a.lastused > b.lastused
end)
for _, b in ipairs(bufs) do
-- set.add(M.listing.bufnrs, b.bufnr)
-- set.add(M.listing[0], b.name)
table.insert(M.listing[0], b.name)
table.insert(M.listing.bufnrs, b.bufnr)
end
table.insert(M.listing[0], M.listing[0][1])
table.insert(M.listing.bufnrs, M.listing.bufnrs[1])
table.remove(M.listing[0], 1)
table.remove(M.listing.bufnrs, 1)
end
function M.evt.RabbitEnter()
M.opts = { window = { title = vim.fn.bufname() } }
get_buffers()
end
---@param n integer
function M.func.file_del(n)
require("bufdelete").bufdelete(M.listing.bufnrs[n])
table.remove(M.listing, n)
require("rabbit").Redraw()
end
return M