From 77e1ea97a3dbf22b33b40a31b9cb59160fbc92a8 Mon Sep 17 00:00:00 2001 From: Bryan Date: Fri, 18 Oct 2024 09:36:34 -0600 Subject: [PATCH] Try another thing --- lua/rabbit-buffers/init.lua | 56 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/lua/rabbit-buffers/init.lua b/lua/rabbit-buffers/init.lua index 4faafdc..433265e 100644 --- a/lua/rabbit-buffers/init.lua +++ b/lua/rabbit-buffers/init.lua @@ -10,15 +10,19 @@ local M = { ---@type Rabbit.Plugin func = {}, switch = "b", listing = {}, - empty_msg = "There's nowhere to jump to! Get started by opening another buffer", + empty_msg = "No opened buffers", skip_same = true, keys = {}, evt = {}, ---@param p Rabbit.Plugin.Buffers init = function(p) - p.listing.last_closed = {} - p.listing.opened = {} + -- 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 end, ---@type Rabbit.Plugin.Buffers.Options @@ -27,35 +31,29 @@ local M = { ---@type Rabbit.Plugin }, } -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) +function M.evt.RabbitEnter(_, _) + M.listing.paths = nil 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") + 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) 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