EtiamNullam / deferred-clipboard.nvim

Keep clipboard in sync with Neovim without the peformance hit.
77 stars 2 forks source link

[ Question ] Can we simply use `let @"=@+` to do this? #4

Closed NEX-S closed 1 year ago

NEX-S commented 1 year ago

hi, after reading your code, i got a idea:

api.nvim_create_autocmd( "FocusLost", {
    command = 'let @+=@"'
    -- callback = function ()
    --     vim.defer_fn(function ()
    --         api.nvim_command 'let @+=@"'
    --     end, 20)
    -- end
})

api.nvim_create_autocmd( "FocusGained", {
    command = 'let @"=@+'
    -- callback = function ()
    --     vim.defer_fn(function ()
    --         api.nvim_command 'let @"=@+'
    --     end, 20)
    -- end
})

this works fine for me, but it seems you are using vim.o.clipboard=unnamedplus to sync the clipboard, so I'm wondering if we can just sync the register but vim.o.clipboard?

is there any benefit from setting the vim.o.clipboard?

appreciate for your reply sir :)

EtiamNullam commented 1 year ago

vim.o.clipboard is only used as a fallback (if specified) when focus change events (FocusGained and FocusLost) are not supported. Otherwise I'm currently using getreg and setreg functions to copy content between the system clipboard and the unnamed register.

Anyway if I understand you correctly: You're proposing using let @"=@+ and let @+=@" instead of the current implementation (vim.fn.setreg('"', vim.fn.getreg('+')) and vim.fn.setreg('+', vim.fn.getreg('"'))), but I don't see any benefit. Okay, it's less characters but from my tests the performance is basically the same and using lua gives more flexibility.

Why do you think your solution would be better? Unless using command in autocommand is faster than using callback, but it's hard to reliably test that, and I'm not sure if it's worth it.

The real performance bottleneck is most likely the call to clipboard integration provider (like win32yank on Windows). I believe removal of redundant calls to it, as this plugin aims to do, is enough. Of course I'm open to critique and suggestions, also those regarding performance.

NEX-S commented 1 year ago

got it :)