Something went wrong. Try again.
Neovim plugin improving access to clipboard history (mirror)
Something went wrong. Try again.
2.9 kB · 106 lines
Lua
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107local M = {}
local state = require("yankbank.state")
--- get a table containg a single yankbank entry by index---@param i integer---@return tablefunction M.get_entry(i) require("yankbank").ensure_initialized() return { yank_text = state.get_yanks()[i], reg_type = state.get_reg_types()[i], }end
--- get a table containing all yankbank entries---@return tablefunction M.get_all() require("yankbank").ensure_initialized() local out = {} local yanks = state.get_yanks() local reg_types = state.get_reg_types() for i, v in ipairs(yanks) do table.insert(out, { yank_text = v, reg_type = reg_types[i], }) end return outend
--- add an entry to yankbank---@param yank_text string yank text to add to YANKS table---@param reg_type string register type "v", "V", or "^V" (visual, v-line, v-block respectively)---@param pin integer|boolean?function M.add_entry(yank_text, reg_type, pin) require("yankbank").ensure_initialized() require("yankbank.clipboard").add_yank(yank_text, reg_type, pin)end
--- remove entry from yankbank by index---@param i integer index to removefunction M.remove_entry(i) require("yankbank").ensure_initialized() local yanks = state.get_yanks() local reg_types = state.get_reg_types() local yank_text = table.remove(yanks, i) local reg_type = table.remove(reg_types, i) state.set_yanks(yanks) state.set_reg_types(reg_types)
local opts = state.get_opts() if opts.persist_type == "sqlite" then require("yankbank.persistence.sql") .data() .remove_match(yank_text, reg_type) endend
--- pin entry to yankbank so that it won't be removed when its position exceeds the max number of entries------@param i integer index to pinfunction M.pin_entry(i) require("yankbank").ensure_initialized() local pins = state.get_pins() if i > #pins then return end
-- TODO: show pins differently in popup (could use different hl_groups for pinned entries?) pins[i] = 1 state.set_pins(pins)
local opts = state.get_opts() if opts.persist_type == "sqlite" then return require("yankbank.persistence.sql") .data() .pin(state.get_yanks()[i], state.get_reg_types()[i]) endend
--- unpin bank entry------@param i integer index to unpinfunction M.unpin_entry(i) require("yankbank").ensure_initialized() local pins = state.get_pins() if i > #pins then return end
-- TODO: update popup pin highlight pins[i] = 0 state.set_pins(pins)
local opts = state.get_opts() if opts.persist_type == "sqlite" then return require("yankbank.persistence.sql") .data() .unpin(state.get_yanks()[i], state.get_reg_types()[i]) endend
-- TODO: individual popup keymap setting functions
return M