diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua index 19799ac6c..41c516513 100644 --- a/lua/luasnip/init.lua +++ b/lua/luasnip/init.lua @@ -73,13 +73,16 @@ local function jumpable(dir) return (node ~= nil and node:jumpable(dir)) end -local function expand_or_jumpable() +local function expandable() next_expand = match_snippet(util.get_current_line_to_cursor()) - return (next_expand ~= nil) or jumpable(1) + return next_expand ~= nil end --- return true and expand snippet if expandable, return false if not. -local function expand_or_jump() +local function expand_or_jumpable() + return expandable() or jumpable(1) +end + +local function expand() if next_expand ~= nil then next_expand:trigger_expand( Luasnip_current_nodes[vim.api.nvim_get_current_buf()] @@ -95,6 +98,14 @@ local function expand_or_jump() return true end end + return false +end + +-- return true and expand snippet if expandable, return false if not. +local function expand_or_jump() + if expand() then + return true + end if jump(1) then return true end @@ -166,6 +177,8 @@ end ls = { expand_or_jumpable = expand_or_jumpable, jumpable = jumpable, + expandable = expandable, + expand = expand, expand_or_jump = expand_or_jump, jump = jump, get_active_snip = get_active_snip, diff --git a/plugin/luasnip.vim b/plugin/luasnip.vim index 1209b5ba5..eebed26d4 100644 --- a/plugin/luasnip.vim +++ b/plugin/luasnip.vim @@ -1,9 +1,11 @@ inoremap luasnip-expand-or-jump lua require'luasnip'.expand_or_jump() +inoremap luasnip-expand-snippet lua require'luasnip'.expand() inoremap luasnip-next-choice lua require'luasnip'.change_choice(1) inoremap luasnip-jump-next lua require'luasnip'.jump(1) inoremap luasnip-jump-prev lua require'luasnip'.jump(-1) snoremap luasnip-expand-or-jump lua require'luasnip'.expand_or_jump() +inoremap luasnip-expand-snippet lua require'luasnip'.expand() snoremap luasnip-next-choice lua require'luasnip'.change_choice(1) snoremap luasnip-jump-next lua require'luasnip'.jump(1) snoremap luasnip-jump-prev lua require'luasnip'.jump(-1) @@ -11,6 +13,10 @@ snoremap luasnip-jump-prev lua require'luasnip'.jump(-1) command! LuaSnipUnlinkCurrent lua require'luasnip'.unlink_current() command! LuaSnipListAvailable lua print(vim.inspect(require'luasnip'.available())) +function! luasnip#expandable() + return luaeval('require("luasnip").expandable()') +endfunction + function! luasnip#expand_or_jumpable() return luaeval('require("luasnip").expand_or_jumpable()') endfunction @@ -23,4 +29,4 @@ function! luasnip#choice_active() return luaeval('require("luasnip").choice_active()') endfunction -lua require('luasnip.config')._setup() \ No newline at end of file +lua require('luasnip.config')._setup()