From a62375e4cf7c5058a98d4f0d7abc0732d8c48722 Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Tue, 9 Nov 2021 17:07:13 +0900 Subject: [PATCH] Improve regex handling --- lua/cmp/context.lua | 2 +- plugin/cmp.lua | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lua/cmp/context.lua b/lua/cmp/context.lua index 2d53abc..bb6801a 100644 --- a/lua/cmp/context.lua +++ b/lua/cmp/context.lua @@ -68,7 +68,7 @@ end ---@return number|nil context.get_offset = function(self, keyword_pattern) return self.cache:ensure({ 'get_offset', keyword_pattern, self.cursor_before_line }, function() - return pattern.offset(keyword_pattern .. '$', self.cursor_before_line) or self.cursor.col + return pattern.offset(keyword_pattern .. '\\m$', self.cursor_before_line) or self.cursor.col end) end diff --git a/plugin/cmp.lua b/plugin/cmp.lua index 268bd04..e0db0cc 100644 --- a/plugin/cmp.lua +++ b/plugin/cmp.lua @@ -20,7 +20,6 @@ vim.cmd [[ autocmd CompleteDone * lua require'cmp.utils.autocmd'.emit('CompleteDone') autocmd ColorScheme * call v:lua.cmp.plugin.colorscheme() autocmd CmdlineEnter * call v:lua.cmp.plugin.cmdline.enter() - autocmd CmdlineLeave * call v:lua.cmp.plugin.cmdline.leave() augroup END ]] @@ -28,26 +27,24 @@ misc.set(_G, { 'cmp', 'plugin', 'cmdline', 'enter' }, function() if config.get().experimental.native_menu then return end - local cmdtype = vim.fn.expand('') - if cmdtype ~= '=' then - if api.is_cmdline_mode() then - vim.cmd [[ - augroup cmp-cmdline - autocmd! - autocmd CmdlineChanged * lua require'cmp.utils.autocmd'.emit('TextChanged') - augroup END - ]] - require('cmp.utils.autocmd').emit('CmdlineEnter') - end + if vim.fn.expand('')~= '=' then + vim.schedule(function() + if api.is_cmdline_mode() then + vim.cmd [[ + augroup cmp-cmdline + autocmd! + autocmd CmdlineChanged * lua require'cmp.utils.autocmd'.emit('TextChanged') + autocmd CmdlineLeave * call v:lua.cmp.plugin.cmdline.leave() + augroup END + ]] + require('cmp.utils.autocmd').emit('CmdlineEnter') + end + end) end end) misc.set(_G, { 'cmp', 'plugin', 'cmdline', 'leave' }, function() - if config.get().experimental.native_menu then - return - end - local cmdtype = vim.fn.expand('') - if cmdtype ~= '=' then + if vim.fn.expand('') ~= '=' then vim.cmd [[ augroup cmp-cmdline autocmd!