···6464| focus_gain_poll | boolean | `nil` |
6565| registers | table container for register overrides | `{ }` |
6666| registers.yank_register | default register to yank from popup to | `"+"` |
6767-| persist_type | string defining persistence type "memory" or "sqlite" | `"memory"` |
6767+| persist_type | string defining persistence type "sqlite" or nil | `nil` |
686869697070#### Example Configuration
+30
lua/yankbank/api.lua
···11+local M = {}
22+33+-- TODO: figure out how api should get 'yanks' and 'reg_types'
44+-- - possibly rewrite these to be global variables
55+66+--- DOC:
77+---@param i integer
88+---@return table
99+function M.get_entry(i)
1010+ -- TODO: figure out how tables are being populated for the api
1111+ return {
1212+ yank_text = YANKS[i],
1313+ reg_type = REG_TYPES[i],
1414+ }
1515+end
1616+1717+--- DOC:
1818+---@return table
1919+function M.get_all()
2020+ local out = {}
2121+ for i, v in ipairs(YANKS) do
2222+ table.insert(out, {
2323+ yank_text = v,
2424+ reg_type = REG_TYPES[i],
2525+ })
2626+ end
2727+ return out
2828+end
2929+3030+return M
+14-18
lua/yankbank/clipboard.lua
···33-- import persistence module
44local persistence = require("yankbank.persistence")
5566--- Function to add yanked text to table
77----@param yanks table
88----@param reg_types table
66+--- Function to add yanked text to table
97---@param text string
108---@param reg_type string
119---@param opts table
1212-function M.add_yank(yanks, reg_types, text, reg_type, opts)
1010+function M.add_yank(text, reg_type, opts)
1311 -- avoid adding empty strings
1412 if text == "" and text == " " and text == "\n" then
1513 return
1614 end
17151816 -- check for duplicate values already inserted
1919- for i, entry in ipairs(yanks) do
1717+ for i, entry in ipairs(YANKS) do
2018 if entry == text then
2119 -- remove matched entry so it can be inserted at 1st position
2222- table.remove(yanks, i)
2323- table.remove(reg_types, i)
2020+ table.remove(YANKS, i)
2121+ table.remove(REG_TYPES, i)
2422 break
2523 end
2624 end
27252826 -- add entry to bank
2929- table.insert(yanks, 1, text)
3030- table.insert(reg_types, 1, reg_type)
2727+ table.insert(YANKS, 1, text)
2828+ table.insert(REG_TYPES, 1, reg_type)
31293230 -- trim table size if necessary
3333- if #yanks > opts.max_entries then
3434- table.remove(yanks)
3535- table.remove(reg_types)
3131+ if #YANKS > opts.max_entries then
3232+ table.remove(YANKS)
3333+ table.remove(REG_TYPES)
3634 end
37353836 -- add entry to persistent store
3937 persistence.add_entry(text, reg_type, opts)
4038end
41394242--- autocommand to listen for yank events
4343----@param yanks table
4444----@param reg_types table
4040+--- autocommand to listen for yank events
4541---@param opts table
4646-function M.setup_yank_autocmd(yanks, reg_types, opts)
4242+function M.setup_yank_autocmd(opts)
4743 vim.api.nvim_create_autocmd("TextYankPost", {
4844 callback = function()
4945 -- get register information
···6258 return
6359 end
64606565- M.add_yank(yanks, reg_types, yank_text, reg_type, opts)
6161+ M.add_yank(yank_text, reg_type, opts)
6662 end
6763 end,
6864 })
···8379 return
8480 end
85818686- M.add_yank(yanks, reg_types, yank_text, reg_type, opts)
8282+ M.add_yank(yank_text, reg_type, opts)
8783 end,
8884 })
8985 end
+8-10
lua/yankbank/data.lua
···11local M = {}
2233----reformat yanks table for popup
44----@param yanks table
55----@param sep string
33+--- reformat yanks table for popup
44+---@param opts table
65---@return table, table
77-function M.get_display_lines(yanks, sep)
66+function M.get_display_lines(opts)
87 local display_lines = {}
98 local line_yank_map = {}
109 local yank_num = 0
11101211 -- calculate the maximum width needed for the yank numbers
1313- local max_digits = #tostring(#yanks)
1212+ local max_digits = #tostring(#YANKS)
14131514 -- assumes yanks is table of strings
1616- for i, yank in ipairs(yanks) do
1515+ for i, yank in ipairs(YANKS) do
1716 yank_num = yank_num + 1
18171919- -- FIX: there were changes here, might need further changes
2018 local yank_lines = yank
2119 if type(yank) == "string" then
2220 -- remove trailing newlines
···5149 table.insert(line_yank_map, i)
5250 end
53515454- if i < #yanks then
5252+ if i < #YANKS then
5553 -- Add a visual separator between yanks, aligned with the yank content
5656- if sep ~= "" then
5454+ if opts.sep ~= "" then
5755 table.insert(
5856 display_lines,
5959- string.rep(" ", max_digits + 2) .. sep
5757+ string.rep(" ", max_digits + 2) .. opts.sep
6058 )
6159 end
6260 table.insert(line_yank_map, false)
+3-7
lua/yankbank/helpers.lua
···11local M = {}
2233--- navigate to the next numbered item
33+--- navigate to the next numbered item
44---@param steps integer
55function M.next_numbered_item(steps)
66 steps = steps or 1 -- Default to 1 if no steps are provided
···2323 vim.api.nvim_win_set_cursor(0, { last_entry, 0 })
2424end
25252626--- navigate to the previous numbered item
2626+--- navigate to the previous numbered item
2727---@param steps integer
2828function M.prev_numbered_item(steps)
2929 steps = steps or 1 -- Default to 1 if no steps are provided
···4343 vim.api.nvim_win_set_cursor(0, { 1, 0 })
4444end
45454646--- customized paste function that functions like 'p'
4646+--- customized paste function that functions like 'p'
4747---@param text string|table
4848---@param reg_type string
4949function M.smart_paste(text, reg_type)
···6161 lines = text
6262 end
63636464- -- remove last newline character to replicate base put behavior
6565- -- if lines[#lines] == "" then
6666- -- table.remove(lines)
6767- -- end
6864 vim.api.nvim_put(lines, reg_type, true, true)
6965end
7066
+15-9
lua/yankbank/init.lua
···55local clipboard = require("yankbank.clipboard")
66local persistence = require("yankbank.persistence")
7788--- initialize yanks tables
99-local yanks = {}
1010-local reg_types = {}
88+-- initialize tables
99+YANKS = {}
1010+REG_TYPES = {}
11111212-- default plugin options
1313local default_opts = {
···1818 registers = {
1919 yank_register = "+",
2020 },
2121- persist_type = "memory",
2121+ persist_type = nil,
2222 keymaps = {},
2323}
24242525--- wrapper function for main plugin functionality
2626---@param opts table
2727local function show_yank_bank(opts)
2828- yanks = persistence.get_yanks(opts) or yanks
2828+ YANKS = persistence.get_yanks(opts) or YANKS
29293030 -- initialize buffer and populate bank
3131 local bufnr, display_lines, line_yank_map =
3232- menu.create_and_fill_buffer(yanks, reg_types, opts)
3232+ menu.create_and_fill_buffer(opts)
33333434 -- handle empty bank case
3535 if not bufnr or not display_lines or not line_yank_map then
···38383939 -- open window and set keybinds
4040 local win_id = menu.open_window(bufnr, display_lines)
4141- menu.set_keymaps(win_id, bufnr, yanks, reg_types, line_yank_map, opts)
4141+ menu.set_keymaps(win_id, bufnr, line_yank_map, opts)
4242end
43434444-- plugin setup
···4848 opts = vim.tbl_deep_extend("keep", opts or {}, default_opts)
49495050 -- enable persistence based on opts (needs to be called before autocmd setup)
5151- yanks, reg_types = persistence.setup(opts)
5151+ YANKS, REG_TYPES = persistence.setup(opts)
52525353 -- create clipboard autocmds
5454- clipboard.setup_yank_autocmd(yanks, reg_types, opts)
5454+ clipboard.setup_yank_autocmd(opts)
55555656 -- create user command
5757 vim.api.nvim_create_user_command("YankBank", function()
5858 show_yank_bank(opts)
5959 end, { desc = "Show Recent Yanks" })
6060+6161+ -- TODO: remove
6262+ local api = require("yankbank.api")
6363+ vim.api.nvim_create_user_command("YankBankApi", function()
6464+ print(vim.inspect(api.get_all()))
6565+ end, {})
6066end
61676268return M
+9-23
lua/yankbank/menu.lua
···11local M = {}
2233--- import clipboard functions
44--- local clipboard = require("yankbank.clipboard")
53local data = require("yankbank.data")
64local helpers = require("yankbank.helpers")
7586---create new buffer and reformat yank table for ui
99----@param yanks table
1010----@param reg_types table
117---@param opts table
128---@return integer?
139---@return table?
1410---@return table?
1515-function M.create_and_fill_buffer(yanks, reg_types, opts)
1616- -- check the content of the system clipboard register
1717- -- TODO: this could be replaced with some sort of polling of the + register
1818- -- local text = vim.fn.getreg("+")
1919- -- local most_recent_yank = yanks[1] or ""
2020- -- local reg_type = vim.fn.getregtype("+")
2121- -- clipboard.add_yank(yanks, reg_types, text, reg_type, opts)
2222-2323- -- stop if yank table is empty
2424- if #yanks == 0 and #reg_types then
1111+function M.create_and_fill_buffer(opts)
1212+ -- stop if yanks or register types table is empty
1313+ if #YANKS == 0 or #REG_TYPES == 0 then
2514 print("No yanks to show.")
2615 return nil, nil, nil
2716 end
···3322 local current_filetype = vim.bo.filetype
3423 vim.api.nvim_set_option_value("filetype", current_filetype, { buf = bufnr })
35243636- -- TODO: need to update yanks from bank file before get_display_lines
3737- local display_lines, line_yank_map = data.get_display_lines(yanks, opts.sep)
2525+ local display_lines, line_yank_map = data.get_display_lines(opts)
38263927 -- replace current buffer contents with updated table
4028 vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, display_lines)
···8876 return win_id
8977end
90789191----Set key mappings for the popup window
7979+--- Set key mappings for the popup window
9280---@param win_id integer
9381---@param bufnr integer
9494----@param yanks table
9595----@param reg_types table
9682---@param line_yank_map table
9783---@param opts table
9898-function M.set_keymaps(win_id, bufnr, yanks, reg_types, line_yank_map, opts)
8484+function M.set_keymaps(win_id, bufnr, line_yank_map, opts)
9985 -- Key mappings for selection and closing the popup
10086 local map_opts = { noremap = true, silent = true, buffer = bufnr }
10187···177163 local yankIndex = line_yank_map[cursor]
178164 if yankIndex then
179165 -- retrieve the full yank, including all lines
180180- local text = yanks[yankIndex]
166166+ local text = YANKS[yankIndex]
181167182168 -- close window upon selection
183169 vim.api.nvim_win_close(win_id, true)
184184- helpers.smart_paste(text, reg_types[yankIndex])
170170+ helpers.smart_paste(text, REG_TYPES[yankIndex])
185171 else
186172 print("Error: Invalid selection")
187173 end
···192178 local cursor = vim.api.nvim_win_get_cursor(win_id)[1]
193179 local yankIndex = line_yank_map[cursor]
194180 if yankIndex then
195195- local text = yanks[yankIndex]
181181+ local text = YANKS[yankIndex]
196182 -- NOTE: possibly change this to '"' if not using system clipboard
197183 -- - make this an option
198184 vim.fn.setreg(opts.registers.yank_register, text)