From 098182e2c23a1728c975474f7217eb067f5696f5 Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Sat, 15 Jan 2022 18:56:29 +0900 Subject: [PATCH] Fix #734 --- lua/cmp/core.lua | 4 ++-- lua/cmp/utils/keymap.lua | 7 +++++++ lua/cmp/view/custom_entries_view.lua | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index bcfaf0a..0132cef 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -318,7 +318,7 @@ core.confirm = function(self, e, option, callback) -- Close menus. self.view:close() - feedkeys.call(keymap.t('set indentkeys='), 'n') + feedkeys.call(keymap.indentkeys(), 'n') feedkeys.call('', 'n', function() local ctx = context.new() local keys = {} @@ -424,7 +424,7 @@ core.confirm = function(self, e, option, callback) feedkeys.call(table.concat(keys, ''), 'int') end end) - feedkeys.call(keymap.t('set indentkeys=%s'):format(vim.fn.escape(vim.bo.indentkeys, ' "|\\')), 'n') + feedkeys.call(keymap.indentkeys(vim.bo.indentkeys), 'n') feedkeys.call('', 'n', function() e:execute(vim.schedule_wrap(function() release() diff --git a/lua/cmp/utils/keymap.lua b/lua/cmp/utils/keymap.lua index d8a1587..ab25ae4 100644 --- a/lua/cmp/utils/keymap.lua +++ b/lua/cmp/utils/keymap.lua @@ -75,6 +75,13 @@ keymap.backspace = function(count) return table.concat(keys, '') end +---Update indentkeys. +---@param expr string +---@return string +keymap.indentkeys = function(expr) + return string.format(keymap.t('set indentkeys=%s'), expr and vim.fn.escape(expr, '| \t\\') or '') +end + ---Return two key sequence are equal or not. ---@param a string ---@param b string diff --git a/lua/cmp/view/custom_entries_view.lua b/lua/cmp/view/custom_entries_view.lua index d84baee..a6b60c8 100644 --- a/lua/cmp/view/custom_entries_view.lua +++ b/lua/cmp/view/custom_entries_view.lua @@ -314,10 +314,10 @@ custom_entries_view._insert = setmetatable({ local cursor = api.get_cursor() local length = vim.fn.strchars(string.sub(api.get_current_line(), self.offset, cursor[2]), true) local keys = {} - table.insert(keys, keymap.t('set indentkeys=')) + table.insert(keys, keymap.indentkeys()) table.insert(keys, keymap.backspace(length)) table.insert(keys, word) - table.insert(keys, keymap.t('set indentkeys=%s'):format(vim.fn.escape(vim.bo.indentkeys, ' "|\\'))) + table.insert(keys, keymap.indentkeys(vim.bo.indentkeys)) feedkeys.call( table.concat(keys, ''), 'int',