···11local M = {}
2233--- import persistence module
44-local persistence = require("yankbank.persistence")
55-local utils = require("yankbank.utils")
66-73--- Function to add yanked text to table
84---@param text string
95---@param reg_type string
···39354036 -- trim table size if necessary
4137 if #YB_YANKS > YB_OPTS.max_entries then
4242- local i = utils.last_zero_entry(YB_PINS)
3838+ local i = require("yankbank.utils").last_zero_entry(YB_PINS)
43394440 if not i or i == 1 then
4541 -- WARN: undefined behavior
···5551 end
56525753 -- add entry to persistent store
5858- persistence.add_entry(text, reg_type, pin)
5454+ require("yankbank.persistence").add_entry(text, reg_type, pin)
5955end
60566157--- autocommand to listen for yank events
···6561 -- get register information
6662 local rn = vim.v.event.regname
67636868- -- check changes wwere made to default register
6464+ -- check changes were made to default register
6965 if rn == "" or rn == "+" then
7066 local reg_type = vim.fn.getregtype(rn)
7167 local yank_text = vim.fn.getreg(rn)
+48-44
lua/yankbank/init.lua
···11local M = {}
2233--- define global variables
44-YB_YANKS = {}
55-YB_REG_TYPES = {}
66-YB_PINS = {}
77-YB_OPTS = {}
33+-- plugin setup
44+---@param opts? table
55+function M.setup(opts)
66+ -- define global variables
77+ YB_YANKS = {}
88+ YB_REG_TYPES = {}
99+ YB_PINS = {}
1010+ YB_OPTS = {}
81199--- local imports
1010-local menu = require("yankbank.menu")
1111-local clipboard = require("yankbank.clipboard")
1212-local persistence = require("yankbank.persistence")
1313-local helpers = require("yankbank.helpers")
1212+ -- local imports
1313+ local clipboard = require("yankbank.clipboard")
1414+ local persistence = require("yankbank.persistence")
14151515--- default plugin options
1616-local default_opts = {
1717- max_entries = 10,
1818- sep = "-----",
1919- focus_gain_poll = false,
2020- num_behavior = "prefix",
2121- registers = {
2222- yank_register = "+",
2323- },
2424- keymaps = {},
2525- persist_type = nil,
2626- db_path = nil,
2727- bind_indices = nil,
2828-}
1616+ -- default plugin options
1717+ local default_opts = {
1818+ max_entries = 10,
1919+ sep = "-----",
2020+ focus_gain_poll = false,
2121+ num_behavior = "prefix",
2222+ registers = {
2323+ yank_register = "+",
2424+ },
2525+ keymaps = {},
2626+ persist_type = nil,
2727+ db_path = nil,
2828+ bind_indices = nil,
2929+ }
29303030---- wrapper function for main plugin functionality
3131-local function show_yank_bank()
3232- YB_YANKS = persistence.get_yanks() or YB_YANKS
3131+ --- wrapper function for main plugin functionality
3232+ local function show_yank_bank()
3333+ local menu = require("yankbank.menu")
33343434- -- initialize buffer and populate bank
3535- local buf_data = menu.create_and_fill_buffer()
3636- if not buf_data then
3737- return
3838- end
3535+ -- set up menu keybinds from defaults and YB_OPTS.keymaps
3636+ menu.setup()
39374040- -- open popup window
4141- buf_data.win_id = menu.open_window(buf_data)
3838+ YB_YANKS = persistence.get_yanks() or YB_YANKS
42394343- -- set popup keybinds
4444- menu.set_keymaps(buf_data)
4545-end
4040+ -- initialize buffer and populate bank
4141+ local buf_data = menu.create_and_fill_buffer()
4242+ if not buf_data then
4343+ return
4444+ end
46454747--- plugin setup
4848----@param opts? table
4949-function M.setup(opts)
4646+ -- open popup window
4747+ buf_data.win_id = menu.open_window(buf_data)
4848+4949+ -- set popup keybinds
5050+ menu.set_keymaps(buf_data)
5151+ end
5252+5053 -- merge opts with default options table
5154 YB_OPTS = vim.tbl_deep_extend("keep", opts or {}, default_opts)
5252-5353- -- set up menu keybinds from defafaults and YB_OPTS.keymaps
5454- menu.setup()
55555656 -- enable persistence based on opts (needs to be called before autocmd setup)
5757 YB_YANKS, YB_REG_TYPES, YB_PINS = persistence.setup()
···6868 if YB_OPTS.bind_indices then
6969 for i = 1, YB_OPTS.max_entries do
7070 vim.keymap.set("n", YB_OPTS.bind_indices .. i, function()
7171- helpers.smart_paste(YB_YANKS[i], YB_REG_TYPES[i], true)
7171+ require("yankbank.helpers").smart_paste(
7272+ YB_YANKS[i],
7373+ YB_REG_TYPES[i],
7474+ true
7575+ )
7276 end, {
7377 noremap = true,
7478 silent = true,