Reduce use of VimL (#168)
* perf(context): reduce use of `cmd` and `fn` * perf(float): reduce use of `cmd` and `fn` * perf(init): reduce use of `cmd` and `fn` * perf(menu): reduce use of `cmd` and `fn` * perf(plugin): reduce use of `cmd` and `fn` * docs(README): reduce use of `cmd` and `fn`
This commit is contained in:
18
README.md
18
README.md
@@ -174,18 +174,18 @@ You can specify your own custom mapping function.
|
|||||||
|
|
||||||
```lua
|
```lua
|
||||||
local check_back_space = function()
|
local check_back_space = function()
|
||||||
local col = vim.fn.col('.') - 1
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s')
|
return col == 0 or vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
mapping = {
|
mapping = {
|
||||||
['<Tab>'] = function(fallback)
|
['<Tab>'] = function(fallback)
|
||||||
if vim.fn.pumvisible() == 1 then
|
if vim.fn.pumvisible() == 1 then
|
||||||
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n')
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n', true)
|
||||||
elseif check_back_space() then
|
elseif check_back_space() then
|
||||||
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Tab>', true, true, true), 'n')
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Tab>', true, true, true), 'n', true)
|
||||||
elseif vim.fn['vsnip#available']() == 1 then
|
elseif vim.fn['vsnip#available']() == 1 then
|
||||||
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>(vsnip-expand-or-jump)', true, true, true), '')
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Plug>(vsnip-expand-or-jump)', true, true, true), '', true)
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
@@ -496,9 +496,9 @@ end
|
|||||||
mapping = {
|
mapping = {
|
||||||
["<Tab>"] = cmp.mapping(function(fallback)
|
["<Tab>"] = cmp.mapping(function(fallback)
|
||||||
if vim.fn.pumvisible() == 1 then
|
if vim.fn.pumvisible() == 1 then
|
||||||
vim.fn.feedkeys(t("<C-n>"), "n")
|
vim.api.nvim_feedkeys(t("<C-n>"), "n", true)
|
||||||
elseif luasnip.expand_or_jumpable() then
|
elseif luasnip.expand_or_jumpable() then
|
||||||
vim.fn.feedkeys(t("<Plug>luasnip-expand-or-jump"), "")
|
vim.api.nvim_feedkeys(t("<Plug>luasnip-expand-or-jump"), "", true)
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
@@ -508,9 +508,9 @@ mapping = {
|
|||||||
}),
|
}),
|
||||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
if vim.fn.pumvisible() == 1 then
|
if vim.fn.pumvisible() == 1 then
|
||||||
vim.fn.feedkeys(t("<C-p>"), "n")
|
vim.api.nvim_feedkeys(t("<C-p>"), "n", true)
|
||||||
elseif luasnip.jumpable(-1) then
|
elseif luasnip.jumpable(-1) then
|
||||||
vim.fn.feedkeys(t("<Plug>luasnip-jump-prev"), "")
|
vim.api.nvim_feedkeys(t("<Plug>luasnip-jump-prev"), "", true)
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -55,8 +55,9 @@ context.new = function(prev_context, option)
|
|||||||
self.cursor_line = vim.api.nvim_get_current_line()
|
self.cursor_line = vim.api.nvim_get_current_line()
|
||||||
self.virtcol = vim.fn.virtcol('.')
|
self.virtcol = vim.fn.virtcol('.')
|
||||||
self.cursor = {}
|
self.cursor = {}
|
||||||
self.cursor.row = vim.api.nvim_win_get_cursor(0)[1]
|
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||||
self.cursor.col = vim.api.nvim_win_get_cursor(0)[2] + 1
|
self.cursor.row = cursor[1]
|
||||||
|
self.cursor.col = cursor[2] + 1
|
||||||
self.cursor.line = self.cursor.row - 1
|
self.cursor.line = self.cursor.row - 1
|
||||||
self.cursor.character = misc.to_utfindex(self.cursor_line, self.cursor.col)
|
self.cursor.character = misc.to_utfindex(self.cursor_line, self.cursor.col)
|
||||||
self.cursor_before_line = string.sub(self.cursor_line, 1, self.cursor.col - 1)
|
self.cursor_before_line = string.sub(self.cursor_line, 1, self.cursor.col - 1)
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ float.scroll = function(self, delta)
|
|||||||
|
|
||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
vim.api.nvim_buf_call(buf, function()
|
vim.api.nvim_buf_call(buf, function()
|
||||||
vim.cmd('normal! ' .. top .. 'zt')
|
vim.api.nvim_command('normal! ' .. top .. 'zt')
|
||||||
end)
|
end)
|
||||||
end, 0)
|
end, 0)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ end
|
|||||||
---Select next item if possible
|
---Select next item if possible
|
||||||
cmp.select_next_item = function()
|
cmp.select_next_item = function()
|
||||||
if vim.fn.pumvisible() == 1 then
|
if vim.fn.pumvisible() == 1 then
|
||||||
vim.fn.feedkeys(keymap.t('<C-n>'), 'n')
|
vim.api.nvim_feedkeys(keymap.t('<C-n>'), 'n', true)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
@@ -73,7 +73,7 @@ end
|
|||||||
---Select prev item if possible
|
---Select prev item if possible
|
||||||
cmp.select_prev_item = function()
|
cmp.select_prev_item = function()
|
||||||
if vim.fn.pumvisible() == 1 then
|
if vim.fn.pumvisible() == 1 then
|
||||||
vim.fn.feedkeys(keymap.t('<C-p>'), 'n')
|
vim.api.nvim_feedkeys(keymap.t('<C-p>'), 'n', true)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ menu.close = function(self)
|
|||||||
debug.log('menu.close', vim.fn.pumvisible())
|
debug.log('menu.close', vim.fn.pumvisible())
|
||||||
if vim.fn.pumvisible() == 1 then
|
if vim.fn.pumvisible() == 1 then
|
||||||
-- TODO: Is it safe to call...?
|
-- TODO: Is it safe to call...?
|
||||||
vim.fn.complete(#vim.fn.getline('.') + 1, {})
|
local line = vim.api.nvim_win_get_cursor(0)[1]
|
||||||
|
vim.fn.complete(#vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1] + 1, {})
|
||||||
end
|
end
|
||||||
self:unselect()
|
self:unselect()
|
||||||
end)
|
end)
|
||||||
@@ -162,15 +163,15 @@ menu.show = function(self)
|
|||||||
|
|
||||||
local completeopt = vim.o.completeopt
|
local completeopt = vim.o.completeopt
|
||||||
if self.preselect == 1 then
|
if self.preselect == 1 then
|
||||||
vim.cmd('set completeopt=menuone,noinsert')
|
vim.opt.completeopt = {'menuone', 'noinsert'}
|
||||||
else
|
else
|
||||||
vim.cmd('set completeopt=' .. config.get().completion.completeopt)
|
vim.opt.completeopt = config.get().completion.completeopt
|
||||||
end
|
end
|
||||||
vim.fn.complete(self.offset, self.items)
|
vim.fn.complete(self.offset, self.items)
|
||||||
if self.preselect > 1 then
|
if self.preselect > 1 then
|
||||||
vim.api.nvim_select_popupmenu_item(self.preselect - 1, false, false, {})
|
vim.api.nvim_select_popupmenu_item(self.preselect - 1, false, false, {})
|
||||||
end
|
end
|
||||||
vim.cmd('set completeopt=' .. completeopt)
|
vim.opt.completeopt = completeopt
|
||||||
end
|
end
|
||||||
|
|
||||||
---Select current item
|
---Select current item
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ vim.cmd [[
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
if vim.fn.hlexists('CmpDocumentation') == 0 then
|
if vim.fn.hlexists('CmpDocumentation') == 0 then
|
||||||
vim.cmd [[highlight link CmpDocumentation NormalFloat]]
|
vim.api.nvim_command [[highlight link CmpDocumentation NormalFloat]]
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.fn.hlexists('CmpDocumentationBorder') == 0 then
|
if vim.fn.hlexists('CmpDocumentationBorder') == 0 then
|
||||||
vim.cmd [[highlight link CmpDocumentationBorder NormalFloat]]
|
vim.api.nvim_command [[highlight link CmpDocumentationBorder NormalFloat]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user