Neovim plugin improving access to clipboard history (mirror)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: move init code to plugin/yankbank.lua

+32 -36
+2 -28
lua/yankbank/clipboard.lua
··· 78 78 require("yankbank.persistence").add_entry(text, reg_type, pin) 79 79 end 80 80 81 - --- autocommand to listen for yank events 82 - function M.setup_yank_autocmd() 83 - vim.api.nvim_create_autocmd("TextYankPost", { 84 - callback = function() 85 - -- get register information 86 - local rn = vim.v.event.regname 87 - 88 - -- check changes were made to default register 89 - if rn == "" or rn == "+" then 90 - local reg_type = vim.fn.getregtype(rn) 91 - local yank_text = vim.fn.getreg(rn) 92 - 93 - if not yank_text or type(yank_text) ~= "string" then 94 - return 95 - end 96 - 97 - if #yank_text <= 1 then 98 - return 99 - end 100 - 101 - -- lazy load initialization when first yank happens 102 - require("yankbank").ensure_initialized() 103 - M.add_yank(yank_text, reg_type) 104 - end 105 - end, 106 - }) 107 - 108 - -- poll registers when vim is focused (check for new clipboard activity) 81 + --- poll registers when vim is focused (check for new clipboard activity) 82 + function M.setup_focus_autocmd() 109 83 local opts = state.get_opts() 110 84 if opts.focus_gain_poll == true then 111 85 vim.api.nvim_create_autocmd("FocusGained", {
+3 -8
lua/yankbank/init.lua
··· 17 17 end 18 18 19 19 --- wrapper function for main plugin functionality 20 - local function show_yank_bank() 20 + function M.show() 21 21 M.ensure_initialized() 22 22 23 23 local state = require("yankbank.state") ··· 69 69 local state = require("yankbank.state") 70 70 state.set_opts(merged_opts) 71 71 72 - -- create user command 73 - vim.api.nvim_create_user_command("YankBank", function() 74 - show_yank_bank() 75 - end, { desc = "Show Recent Yanks" }) 76 - 77 - -- create clipboard autocmds 78 - require("yankbank.clipboard").setup_yank_autocmd() 72 + -- focus-gain polling autocmd (TextYankPost is registered in plugin/yankbank.lua) 73 + require("yankbank.clipboard").setup_focus_autocmd() 79 74 80 75 -- Bind 1-n if `bind_indices` is set to a string 81 76 if merged_opts.bind_indices then
+27
plugin/yankbank.lua
··· 1 + if vim.g.loaded_yankbank then 2 + return 3 + end 4 + vim.g.loaded_yankbank = 1 5 + 6 + vim.api.nvim_create_user_command("YankBank", function() 7 + require("yankbank").show() 8 + end, { desc = "Show Recent Yanks" }) 9 + 10 + vim.api.nvim_create_autocmd("TextYankPost", { 11 + group = vim.api.nvim_create_augroup("YankBank", { clear = true }), 12 + callback = function() 13 + local rn = vim.v.event.regname 14 + if rn ~= "" and rn ~= "+" then 15 + return 16 + end 17 + 18 + local yank_text = vim.fn.getreg(rn) 19 + if type(yank_text) ~= "string" or #yank_text <= 1 then 20 + return 21 + end 22 + 23 + local reg_type = vim.fn.getregtype(rn) 24 + require("yankbank").ensure_initialized() 25 + require("yankbank.clipboard").add_yank(yank_text, reg_type) 26 + end, 27 + })