diff --git a/DOC.md b/DOC.md index 8b1471fdf..bb054159a 100644 --- a/DOC.md +++ b/DOC.md @@ -67,12 +67,10 @@ The second argument to `s` is a table containing all nodes that belong to the snippet. If the table only has a single node, it can be passed directly without wrapping it in a table. -The third argument is the condition-function. The snippet will be expanded only -if it returns true (default is a function that just returns true) (the function -is called before the text is modified in any way). - -The fourth and following args are passed to the condition-function(allows -reusing condition-functions). +The third argument is a table with the following valid keys: +- `cond`: the condition-function. The snippet will be expanded only + if it returns true (default is a function that just returns true) + (the function is called before the text is modified in any way). Snippets contain some interesting tables, eg. `snippet.env` contains variables used in the LSP-protocol like `TM_CURRENT_LINE` or `TM_FILENAME` or diff --git a/lua/luasnip/nodes/snippet.lua b/lua/luasnip/nodes/snippet.lua index e94f21abd..af3673477 100644 --- a/lua/luasnip/nodes/snippet.lua +++ b/lua/luasnip/nodes/snippet.lua @@ -87,12 +87,8 @@ local function wrap_nodes(nodes) end end -local function S(context, nodes, condition, ...) - if not condition then - condition = function() - return true - end - end +local function S(context, nodes, opts) + opts = opts or {} if type(context) == "string" then context = { trig = context } @@ -123,8 +119,7 @@ local function S(context, nodes, condition, ...) nodes = nodes, insert_nodes = {}, current_insert = 0, - condition = condition, - user_args = { ... }, + condition = opts.condition or function() return true end, mark = nil, dependents = {}, active = false, @@ -362,7 +357,7 @@ function Snippet:matches(line_to_cursor) return nil end - if not self.condition(unpack(self.user_args)) then + if not self.condition() then return nil end