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

View File

@@ -15,6 +15,13 @@ misc.concat = function(list1, list2)
return new_list
end
---Get cursor before line
---@return string
misc.get_cursor_before_line = function()
local cursor = vim.api.nvim_win_get_cursor(0)
return string.sub(vim.api.nvim_get_current_line(), 1, cursor[2])
end
---Merge two tables recursively
---@generic T
---@param v1 T

View File

@@ -17,17 +17,6 @@ vim.cmd [[
augroup END
]]
vim.cmd [[inoremap <silent> <Plug>(cmp-autoindent) <Cmd>call v:lua.cmp.autoindent()<CR>]]
misc.set(_G, { 'cmp', 'autoindent' }, function()
local startofline = vim.o.startofline
local virtualedit = vim.o.virtualedit
vim.o.startofline = false
vim.o.virtualedit = 'all'
vim.cmd [[normal! ==]]
vim.o.startofline = startofline
vim.o.virtualedit = virtualedit
end)
vim.cmd [[command! CmpStatus lua require('cmp').status()]]
vim.cmd [[doautocmd <nomodeline> User cmp#ready]]