nvim-config

Log | Files | Refs | Submodules | README

commit 1dd64f16dabfb8e2cf42c37025e056c913fb92e4
parent 5e7b3da344768598c7cf2800fddefe2fdf5fe107
Author: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
Date:   Wed,  8 Dec 2021 14:45:41 +0100

fix(complete): move all completions to new style

Use feedkeys everywhere for a more fine-grained control over the
behavior of tab.

Diffstat:
Mafter/plugin/mappings.vim | 4++--
Mlua/mappings.lua | 34+++++++++++++++++++++-------------
2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/after/plugin/mappings.vim b/after/plugin/mappings.vim @@ -9,8 +9,8 @@ nnoremap <silent> yQ :cclose<CR> inoremap <silent> <CR> <Cmd>lua cr_confirm()<CR> -imap <expr> <Tab> v:lua.tab_complete() -smap <expr> <Tab> v:lua.tab_complete() +imap <silent> <Tab> <CMD>lua tab_complete()<CR> +smap <silent> <Tab> <CMD>lua tab_complete()<CR> smap <silent> <C-l> <Plug>luasnip-jump-next diff --git a/lua/mappings.lua b/lua/mappings.lua @@ -1,5 +1,6 @@ -- Completion and so on require"completree-config" +local complementree = require'complementree' local luasnip = require'luasnip' local rt = function(codes) return vim.api.nvim_replace_termcodes(codes, true, true, true) @@ -7,29 +8,36 @@ end local call = vim.api.nvim_call_function +local function feed(codes) + local keys = rt(codes) + vim.api.nvim_feedkeys(keys, 'n', true) +end + +local function sjump() + vim.schedule(function () + if luasnip.jumpable(1) then + luasnip.jump(1) + end + end) +end + function tab_complete() if vim.fn.pumvisible() == 1 then - return rt '<C-N>' + return feed '<C-N>' elseif vim.api.nvim_get_current_line():match("^%s*$") then - return rt '<Tab>' - else - return rt '<Plug>(complementree-complete)' + return feed '<Tab>' end -end -local function feed(codes) - local keys = rt(codes) - vim.api.nvim_feedkeys(keys, 'n', true) + if not complementree.complete() then + -- Maybe we did not complete, and I actually wanted to jump + sjump() + end end function cr_confirm() if vim.fn.pumvisible() == 1 then feed '<C-Y>' - if luasnip.expand_or_locally_jumpable() then - vim.schedule(function() - luasnip.expand_or_jump() - end) - end + -- sjump() else feed '<CR>' end