See if it works with an existing plugin

master
Bryan 2024-10-18 09:31:07 -06:00
parent a588d666e3
commit ae897c8d27
1 changed files with 29 additions and 27 deletions

View File

@ -10,19 +10,15 @@ local M = { ---@type Rabbit.Plugin
func = {},
switch = "b",
listing = {},
empty_msg = "No opened buffers",
empty_msg = "There's nowhere to jump to! Get started by opening another buffer",
skip_same = true,
keys = {},
evt = {},
---@param p Rabbit.Plugin.Buffers
init = function(p)
p.listing[0] = {}
p.listing.paths = {}
-- p.listing.persist = {} --set.clean(set.read(p.memory))
-- p.listing.opened = {}
-- p.listing.collections = {}
-- p.listing.recursive = nil
p.listing.last_closed = {}
p.listing.opened = {}
end,
---@type Rabbit.Plugin.Buffers.Options
@ -31,29 +27,35 @@ local M = { ---@type Rabbit.Plugin
},
}
function M.evt.RabbitEnter(_, _)
M.listing.paths = nil
M.listing[0] = nil
local bufs = vim.api.nvim_list_bufs()
for _, b in ipairs(bufs) do
local path = vim.api.nvim_buf_get_name(b)
set.add(M.listing.paths, path)
set.add(M.listing[0], path)
function M.evt.BufEnter(evt, winid)
local is_listed = vim.api.nvim_get_option_value("buflisted", { buf = evt.buf })
if M.opts.ignore_unlisted and not is_listed then
return
end
set.add(M.listing[winid], evt.buf)
set.add(M.listing.opened, evt.buf)
end
-- function M.evt.BufEnter(evt, winid)
-- local is_listed = vim.api.nvim_get_option_value("buflisted", { buf = evt.buf })
-- if M.opts.ignore_unlisted and not is_listed then
-- return
-- end
-- set.add(M.listing[winid], evt.buf)
-- set.add(M.listing.opened, evt.buf)
-- end
-- function M.evt.BufDelete(evt, winid)
-- set.sub(M.listing[winid], evt.buf)
-- set.sub(M.listing.opened, evt.buf)
-- end
function M.evt.BufDelete(evt, winid)
set.sub(M.listing[winid], evt.buf)
set.sub(M.listing.opened, evt.buf)
end
function M.evt.RabbitEnter(_, winid)
M.listing[0] = nil
if #M.listing[winid] > 1 then
return
end
if #M.listing.last_closed > 1 then
M.listing[0] = vim.deepcopy(M.listing.last_closed)
table.insert(M.listing[0], 1, "rabbitmsg://Restore full history")
M.listing.last_closed = {}
elseif #M.listing.opened > 1 then
M.listing[0] = vim.deepcopy(M.listing.opened)
table.insert(M.listing[0], 1, "rabbitmsg://Open all buffers")
end
end
function M.evt.WinClosed(_, winid)
if M.listing[winid] ~= nil and #M.listing[winid] > 0 then