Skip to content

Commit

Permalink
fix: avoid global variable usage (#426)
Browse files Browse the repository at this point in the history
* fix: avoid global variable usage

* fix: replaced last occurence of `MPairs` global
  • Loading branch information
JosefLitos committed Feb 17, 2024
1 parent 00def01 commit 2e8a10c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
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

3 comments on commit 2e8a10c

@richin13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit somehow broke my setup. Neovim completely crashes when I type:

Word(|)

The end parenthesis gets inserted but the program freezes completely. Reverting back to 096d0ba fixes the issue

@stancl
Copy link

@stancl stancl commented on 2e8a10c Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, doing:

public function foo()
{<ENTER>

leads to neovim fully freezing.

@richin13
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened a bug report πŸ‘πŸΌ

Please sign in to comment.