Skip to content

Commit

Permalink
BREAKING: make functions for match-nodes more in line with others.
Browse files Browse the repository at this point in the history
old: `function(node_text)`
new: `function(args)`, where `args[1]` is node_text (table!!) and
`args[2]` is the surrounding snippet.
  • Loading branch information
L3MON4D3 committed Sep 5, 2021
1 parent 30cc695 commit 8361b35
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lua/luasnip/extras/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ local function to_function(val, use_re)
end
end
if type(val) == "string" and use_re then
return function(arg)
return arg:match(val)
return function(args)
return _concat(args[1]):match(val)
end
end
if lambda.isPE(val) then
return lambda.instantiate(val)
local lmb = lambda.instantiate(val)
return function(args)
return lmb(make_lambda_args(args))
end
end
assert(false, "Can't convert argument to function")
end
Expand All @@ -92,13 +95,12 @@ local function match(index, _match, _then, _else)
end)
_else = to_function(_else or "")

local function func(arg)
local text = _concat(arg[1])
local function func(args)
local out = nil
if _match(text) then
out = _then(text)
if _match(args) then
out = _then(args)
else
out = _else(text)
out = _else(args)
end
return vim.split(out, "\n")
end
Expand Down

0 comments on commit 8361b35

Please sign in to comment.