This commit is contained in:
hrsh7th
2021-09-29 21:20:35 +09:00
parent f56e6b5ee4
commit a63a1a23e9
3 changed files with 21 additions and 14 deletions

View File

@@ -226,12 +226,23 @@ end
---@param callback function
core.autoindent = function(event, callback)
if event == types.cmp.TriggerEvent.TextChanged then
local ctx = context.new()
local prefix = pattern.matchstr('[^[:blank:]]\\+$', ctx.cursor_before_line)
local cursor_before_line = misc.get_cursor_before_line()
local prefix = pattern.matchstr('[^[:blank:]]\\+$', cursor_before_line)
if prefix then
for _, key in ipairs(vim.split(vim.bo.indentkeys, ',')) do
if vim.tbl_contains({ '=' .. prefix, '0=' .. prefix }, key) then
return keymap.feedkeys(keymap.t('<Plug>(cmp-autoindent)'), '', callback)
return vim.schedule(function()
if cursor_before_line == misc.get_cursor_before_line() then
local indentkeys = vim.bo.indentkeys
vim.bo.indentkeys = indentkeys .. ',!^F'
keymap.feedkeys(keymap.t('<C-f>'), 'n', function()
vim.bo.indentkeys = indentkeys
callback()
end)
else
callback()
end
end)
end
end
end