Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid global variable usage #426

Merged
merged 2 commits into from Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 9 additions & 10 deletions lua/nvim-autopairs.lua
Expand Up @@ -311,8 +311,8 @@ M.on_attach = function(bufnr)
bufnr,
'i',
'<bs>',
'v:lua.MPairs.autopairs_bs()',
{ expr = true, noremap = true }
'',
{ callback = M.autopairs_bs, expr = true, noremap = true }
)
end

Expand All @@ -321,8 +321,8 @@ M.on_attach = function(bufnr)
bufnr,
"i",
utils.key.c_h,
'v:lua.MPairs.autopairs_c_h()',
{ expr = true, noremap = true }
'',
{ callback = M.autopairs_c_h, expr = true, noremap = true }
)
end

Expand All @@ -331,8 +331,8 @@ M.on_attach = function(bufnr)
bufnr,
'i',
'<c-w>',
'v:lua.MPairs.autopairs_c_w()',
{ expr = true, noremap = true }
'',
{ callback = M.autopairs_c_w, expr = true, noremap = true }
)
end
api.nvim_buf_set_var(bufnr, 'nvim-autopairs', 1)
Expand Down Expand Up @@ -624,7 +624,7 @@ M.autopairs_afterquote = function(line, key_char)
append = 'la'
end
return utils.esc(
'<esc><cmd>lua MPairs.autopairs_closequote_expr()<cr>' .. append
"<esc><cmd>lua require'nvim-autopairs'.autopairs_closequote_expr()<cr>" .. append
)
end
end
Expand Down Expand Up @@ -654,11 +654,10 @@ M.map_cr = function()
api.nvim_set_keymap(
'i',
'<CR>',
'v:lua.MPairs.completion_confirm()',
{ expr = true, noremap = true }
'',
{ callback = M.completion_confirm, expr = true, noremap = true }
)
end

M.esc = utils.esc
_G.MPairs = M
return M
2 changes: 1 addition & 1 deletion lua/nvim-autopairs/completion/cmp.lua
Expand Up @@ -60,7 +60,7 @@ M.on_confirm_done = function(opts)
if evt.commit_character then
return
end

local entry = evt.entry
local commit_character = entry:get_commit_characters()
local bufnr = vim.api.nvim_get_current_buf()
Expand Down
14 changes: 7 additions & 7 deletions lua/nvim-autopairs/completion/compe.lua
Expand Up @@ -7,7 +7,8 @@ local function_kind = nil

local options = {}

_G.MPairs.completion_done = function()
local M = {}
M.completion_done = function()
local line = utils.text_get_current_line(0)
local _, col = utils.get_cursor()
local prev_char, next_char = utils.text_cusor_line(line, col, 1, 1, false)
Expand Down Expand Up @@ -40,7 +41,6 @@ _G.MPairs.completion_done = function()
end
end

local M = {}
M.setup = function(opt)
opt = opt or { map_cr = true, map_complete = true, auto_select = false, map_char = {all = '('}}
if not opt.map_char then opt.map_char = {} end
Expand All @@ -52,20 +52,20 @@ M.setup = function(opt)
vim.api.nvim_set_keymap(
'i',
'<CR>',
'v:lua.MPairs.completion_confirm()',
{ expr = true, noremap = true }
'',
{ callback = M.completion_confirm, expr = true, noremap = true }
)
end
if opt.auto_select then
_G.MPairs.completion_confirm = function()
M.completion_confirm = function()
if vim.fn.pumvisible() ~= 0 then
return vim.fn['compe#confirm']({ keys = '<CR>', select = true })
else
return npairs.autopairs_cr()
end
end
else
_G.MPairs.completion_confirm = function()
M.completion_confirm = function()
if vim.fn.pumvisible() ~= 0 and vim.fn.complete_info()['selected'] ~= -1 then
return vim.fn['compe#confirm'](npairs.esc('<cr>'))
else
Expand All @@ -78,7 +78,7 @@ M.setup = function(opt)
vim.cmd([[
augroup autopairs_compe
autocmd!
autocmd User CompeConfirmDone call v:lua.MPairs.completion_done()
autocmd User CompeConfirmDone lua require'nvim-autopairs.completion.compe'.completion_done()
augroup end
]])
end
Expand Down