fix: fix use of opts

This commit is contained in:
swaits committed 2024-12-23 20:35:22 -07:00
1 parent c80c7e1851
commit d680fd17d0
1 file changed
+9 -7
+9 -7
View File
@@ -62,7 +62,7 @@ local function warn(msg)
end end
-- Pick copy/paste commands from the list in opts.tools -- Pick copy/paste commands from the list in opts.tools
local function pick_copy_paste_tool(opts) local function pick_copy_paste_tool()
info("[universal-clipboard.nvim] looking for copy/paste tool ...") info("[universal-clipboard.nvim] looking for copy/paste tool ...")
local function check_detect(tool) local function check_detect(tool)
@@ -80,7 +80,7 @@ local function pick_copy_paste_tool(opts)
return false return false
end end
for _, tool in ipairs(opts.tools) do for _, tool in ipairs(M.opts.tools) do
if check_detect(tool) then if check_detect(tool) then
info("[universal-clipboard.nvim] found " .. tool.name) info("[universal-clipboard.nvim] found " .. tool.name)
return tool return tool
@@ -92,12 +92,12 @@ local function pick_copy_paste_tool(opts)
end end
-- Configure Neovim's clipboard usage -- Configure Neovim's clipboard usage
local function configure_clipboard(opts) local function configure_clipboard()
-- Unify normal yanks/pastes to systepm clipboard -- Unify normal yanks/pastes to systepm clipboard
vim.opt.clipboard = "unnamedplus" vim.opt.clipboard = "unnamedplus"
-- Search for custom clipboard provider -- Search for custom clipboard provider
local tool = pick_copy_paste_tool(opts) local tool = pick_copy_paste_tool()
if tool then if tool then
vim.g.clipboard = { vim.g.clipboard = {
name = "UniversalClipboard(" .. tool.name .. ")", name = "UniversalClipboard(" .. tool.name .. ")",
@@ -125,7 +125,7 @@ function M.setup(opts)
M.opts = vim.tbl_deep_extend("force", M.opts, opts or {}) M.opts = vim.tbl_deep_extend("force", M.opts, opts or {})
-- Set the clipboard up -- Set the clipboard up
local tool_name = configure_clipboard(M.opts) local tool_name = configure_clipboard()
info(("[universal-clipboard.nvim] Clipboard tool: %s"):format(tool_name)) info(("[universal-clipboard.nvim] Clipboard tool: %s"):format(tool_name))
-- Command for viewing results -- Command for viewing results
@@ -139,10 +139,12 @@ function M.setup(opts)
-- Command for re-running checks -- Command for re-running checks
vim.api.nvim_create_user_command("UniversalClipboardReinit", function() vim.api.nvim_create_user_command("UniversalClipboardReinit", function()
print("=== UniversalClipboardReinit ===") print("=== UniversalClipboardReinit ===")
local verbose_opts = vim.tbl_deep_extend("force", M.opts, { verbose = true }) local original_verbose = M.opts.verbose
local new_tool_name = configure_clipboard(verbose_opts) M.opts.verbose = true
local new_tool_name = configure_clipboard()
print("Reinitialized external clipboard tool: " .. new_tool_name) print("Reinitialized external clipboard tool: " .. new_tool_name)
vim.cmd("UniversalClipboardCheck") vim.cmd("UniversalClipboardCheck")
M.opts.verbose = original_verbose
end, {}) end, {})
end end