···35}
36```
370000000000000000038## Usage
3940The popup menu can be opened with the command:`:YankBank`, an entry is pasted at the current cursor position by hitting enter, and the menu can be closed by hitting escape, ctrl-c, or q.
···35}
36```
3738+The setup function also supports taking in a table of options:
39+| Option | Type | Default |
40+|-------------|--------------------------------------------|----------------|
41+| max_entries | integer number of entries to show in popup | 10 |
42+| sep | string separator to show between table entries | "-----" |
43+44+45+If no separator is desired, pass in an empty string for sep:
46+```lua
47+ config = function()
48+ require('yankbank').setup({
49+ max_entries = 12,
50+ sep = "",
51+ })
52+ end,
53+```
54+55## Usage
5657The popup menu can be opened with the command:`:YankBank`, an entry is pasted at the current cursor position by hitting enter, and the menu can be closed by hitting escape, ctrl-c, or q.
+5-4
lua/yankbank/data.lua
···2local M = {}
34-- reformat yanks table for popup
5-function M.get_display_lines(yanks)
6 local display_lines = {}
7 local line_yank_map = {}
8 local yank_num = 0
···39 table.insert(line_yank_map, i)
40 end
4142- -- Add a visual separator between yanks, aligned with the yank content
43- -- TODO: allow turning off/on in plugin setup
44 if i < #yanks then
45- table.insert(display_lines, string.rep(" ", max_digits + 2) .. "------")
00046 table.insert(line_yank_map, false)
47 end
48 end
···2local M = {}
34-- reformat yanks table for popup
5+function M.get_display_lines(yanks, sep)
6 local display_lines = {}
7 local line_yank_map = {}
8 local yank_num = 0
···39 table.insert(line_yank_map, i)
40 end
410042 if i < #yanks then
43+ -- Add a visual separator between yanks, aligned with the yank content
44+ if sep ~= "" then
45+ table.insert(display_lines, string.rep(" ", max_digits + 2) .. sep)
46+ end
47 table.insert(line_yank_map, false)
48 end
49 end
+25-12
lua/yankbank/init.lua
···8-- initialize yanks tables
9local yanks = {}
10local max_entries = 10
01112-- wrapper function for main plugin functionality
13-local function show_yank_bank()
14- -- TODO: update max entries with passed in options
15- local bufnr, display_lines, line_yank_map = menu.create_and_fill_buffer(yanks, max_entries)
0000000000000016 local win_id = menu.open_window(bufnr, display_lines)
17 menu.set_keymaps(win_id, bufnr, yanks, line_yank_map)
18end
1920-- plugin setup
21function M.setup(opts)
22- local o = {}
2324 -- parse opts
25- if opts ~= nil then
26- o.max_entries = opts.max_entries or max_entries
27- else
28- o.max_entries = max_entries
29- end
3031 -- create clipboard autocmds
32- clipboard.setup_yank_autocmd(yanks, o.max_entries)
3334 -- Create user command
35 -- TODO: allow params (i.e. keymaps/max_entries/separator)
36- vim.api.nvim_create_user_command("YankBank", show_yank_bank,
37- { desc = "Show Recent Yanks" })
038end
3940return M
···8-- initialize yanks tables
9local yanks = {}
10local max_entries = 10
11+local sep = "-----"
1213-- wrapper function for main plugin functionality
14+local function show_yank_bank(args)
15+ -- Parse command arguments directly if args are provided as a string
16+ local opts = {}
17+ if type(args) == "string" and args ~= "" then
18+ local parts = vim.split(args, "%s+", {true})
19+ opts.max_entries = tonumber(parts[1])
20+ opts.sep = parts[2]
21+ elseif type(args) == "table" then
22+ -- If opts is already a table, use it directly (for programmatic calls)
23+ opts = args
24+ end
25+26+ -- Fallback to defaults if necessary
27+ local max_entries_opt = opts.max_entries or max_entries
28+ local sep_opt = opts.sep or sep
29+30+ local bufnr, display_lines, line_yank_map = menu.create_and_fill_buffer(yanks, max_entries_opt, sep_opt)
31 local win_id = menu.open_window(bufnr, display_lines)
32 menu.set_keymaps(win_id, bufnr, yanks, line_yank_map)
33end
3435-- plugin setup
36function M.setup(opts)
37+ opts = opts or {}
3839 -- parse opts
40+ max_entries = opts.max_entries or max_entries
41+ sep = opts.sep or sep
0004243 -- create clipboard autocmds
44+ clipboard.setup_yank_autocmd(yanks, max_entries)
4546 -- Create user command
47 -- TODO: allow params (i.e. keymaps/max_entries/separator)
48+ vim.api.nvim_create_user_command("YankBank", function(args)
49+ show_yank_bank(args.args)
50+ end, { desc = "Show Recent Yanks", nargs = "*" })
51end
5253return M
+6-6
lua/yankbank/menu.lua
···7local helpers = require("yankbank.helpers")
89-- create new buffer and reformat yank table for ui
10-function M.create_and_fill_buffer(yanks, max_entries)
11 -- check the content of the system clipboard register
12 -- TODO: this could be replaced with some sort of polling of the + register
13 local text = vim.fn.getreg('+')
···29 local current_filetype = vim.bo.filetype
30 vim.api.nvim_buf_set_option(bufnr, 'filetype', current_filetype)
3132- local display_lines, line_yank_map = data.get_display_lines(yanks)
3334 -- replace current buffer contents with updated table
35 vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, display_lines)
···46 end
4748 -- define buffer window width and height based on number of columns
49- local width = math.min(max_width + 4, vim.api.nvim_get_option("columns") - 50)
50- local height = math.min(#display_lines, vim.api.nvim_get_option("lines") - 4)
5152 -- open window
53 local win_id = vim.api.nvim_open_win(bufnr, true, {
54 relative = "editor",
55 width = width,
56 height = height,
57- col = math.floor((vim.api.nvim_get_option("columns") - width) / 2 - 1),
58- row = math.floor((vim.api.nvim_get_option("lines") - height) / 2 - 1),
59 border = "rounded",
60 style = "minimal",
61 })
···7local helpers = require("yankbank.helpers")
89-- create new buffer and reformat yank table for ui
10+function M.create_and_fill_buffer(yanks, max_entries, sep)
11 -- check the content of the system clipboard register
12 -- TODO: this could be replaced with some sort of polling of the + register
13 local text = vim.fn.getreg('+')
···29 local current_filetype = vim.bo.filetype
30 vim.api.nvim_buf_set_option(bufnr, 'filetype', current_filetype)
3132+ local display_lines, line_yank_map = data.get_display_lines(yanks, sep)
3334 -- replace current buffer contents with updated table
35 vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, display_lines)
···46 end
4748 -- define buffer window width and height based on number of columns
49+ local width = math.min(max_width + 4, vim.api.nvim_get_option("columns"))
50+ local height = math.min(#display_lines, vim.api.nvim_get_option("lines"))
5152 -- open window
53 local win_id = vim.api.nvim_open_win(bufnr, true, {
54 relative = "editor",
55 width = width,
56 height = height,
57+ col = math.floor((vim.api.nvim_get_option("columns") - width) / 2),
58+ row = math.floor((vim.api.nvim_get_option("lines") - height) / 2),
59 border = "rounded",
60 style = "minimal",
61 })