From ae897c8d275e96edf9f645489bf7ab1e8d97a811 Mon Sep 17 00:00:00 2001 From: Bryan Date: Fri, 18 Oct 2024 09:31:07 -0600 Subject: [PATCH] See if it works with an existing plugin --- lua/rabbit-buffers/init.lua | 56 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/lua/rabbit-buffers/init.lua b/lua/rabbit-buffers/init.lua index ff6aa1d..4faafdc 100644 --- a/lua/rabbit-buffers/init.lua +++ b/lua/rabbit-buffers/init.lua @@ -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 +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.RabbitEnter(_, winid) 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) + 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.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.WinClosed(_, winid) if M.listing[winid] ~= nil and #M.listing[winid] > 0 then