You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- |luasnip-`jump_index`|: `number`, since choiceNodes can be jumped to, they need their
568
+
jump-indx.
569
+
- `choices`: `node[]|node`, the choices. The first will be initialliy active.
570
+
A list of nodes will be turned into a `snippetNode`.
571
+
- `node_opts`: `table`. `choiceNode` supports the keys common to all nodes
572
+
described |luasnip-here|, and one additional key:
573
+
- `restore_cursor`: `false` by default. If it is set, and the node that was
574
+
being edited also appears in the switched-to choice (can be the case if a
575
+
`restoreNode` is present in both choice) the cursor is restored relative to
576
+
that node.
577
+
The default is `false` as enabling might lead to decreased performance. It’s
578
+
possible to override the default by wrapping the `choiceNode`-constructor
579
+
in another function that sets `opts.restore_cursor` to `true` and then using
580
+
that to construct `choiceNode`s:
581
+
`lua local function restore_cursor_choice(pos, choices, opts) if opts then opts.restore_cursor = true else opts = {restore_cursor = true} end return c(pos, choices, opts) end`
582
+
570
583
571
584
Jumpable nodes that normally expect an index as their first parameter don’t
572
585
need one inside a choiceNode; their jump-index is the same as the
@@ -956,13 +969,20 @@ to be accessed as `ai[restoreNodeIndx][0][1]`.
956
969
LAMBDA *luasnip-lambda*
957
970
958
971
A shortcut for `functionNode`s that only do very basic string- manipulation.
959
-
`l(lambda, argnodes)`: - `lambda`: An object created by applying
960
-
string-operations to `l._n`, objects representing the `n`th argnode. For
961
-
example: - `l._1:gsub("a", "e")` replaces all occurences of "a" in the text of
962
-
the first argnode with "e", or - `l._1 .. l._2` concats text of the first and
963
-
second argnode. If an argnode contains multiple lines of text, they are
964
-
concatenated with `"\n"` prior to any operation. - `argnodes`,
965
-
|luasnip-`node-references`|, just like in function- and dynamicNode.
972
+
`l(lambda, argnodes)`:
973
+
974
+
975
+
- `lambda`: An object created by applying string-operations to `l._n`, objects
976
+
representing the `n`th argnode.
977
+
For example:
978
+
- `l._1:gsub("a", "e")` replaces all occurences of "a" in the text of the
979
+
first argnode with "e", or
980
+
- `l._1 .. l._2` concats text of the first and second argnode.
981
+
If an argnode contains multiple lines of text, they are concatenated with
982
+
`"\n"` prior to any operation.
983
+
- `argnodes`, |luasnip-`node-references`|, just like in function- and
984
+
dynamicNode.
985
+
966
986
967
987
There are many examples for `lamda` in `Examples/snippets.lua`
968
988
@@ -971,44 +991,50 @@ MATCH *luasnip-match*
971
991
`match` can insert text based on a predicate (again, a shorthand for
972
992
`functionNode`).
973
993
974
-
`match(argnodes, condition, then, else)`, where * `argnode`: A single
975
-
|luasnip-`node-reference`|. May not be nil, or a table. * `condition` may be
976
-
either of * `string`: interpreted as a lua-pattern. Matched on the `\n`-joined
977
-
(in case it’s multiline) text of the first argnode
978
-
(`args[1]:match(condition)`). * `function`: `fn(args, snip) -> bool`: takes the
979
-
same parameters as the `functionNode`-function, any value other than nil or
980
-
false is interpreted as a match. * `lambda`: `l._n` is the `\n`-joined text of
981
-
the nth argnode. Useful if string-manipulations have to be performed before the
982
-
string is matched. Should end with `match`, but any other truthy result will be
983
-
interpreted as matching.
984
-
985
-
994
+
`match(argnodes, condition, then, else)`, where
995
+
996
+
997
+
- `argnode`: A single |luasnip-`node-reference`|. May not be nil, or
998
+
a table.
999
+
- `condition` may be either of
1000
+
- `string`: interpreted as a lua-pattern. Matched on the `\n`-joined (in case
1001
+
it’s multiline) text of the first argnode (`args[1]:match(condition)`).
1002
+
- `function`: `fn(args, snip) -> bool`: takes the same parameters as the
1003
+
`functionNode`-function, any value other than nil or false is interpreted
1004
+
as a match.
1005
+
- `lambda`: `l._n` is the `\n`-joined text of the nth argnode.
1006
+
Useful if string-manipulations have to be performed before the string is matched.
1007
+
Should end with `match`, but any other truthy result will be interpreted
1008
+
as matching.
986
1009
- `then` is inserted if the condition matches,
987
1010
- `else` if it does not.
988
1011
989
1012
990
1013
Both `then` and `else` can be either text, lambda or function (with the same
991
1014
parameters as specified above). `then`’s default-value depends on the
992
-
`condition`: * `pattern`: Simply the return value from the `match`, e.g. the
993
-
entire match, or, if there were capture groups, the first capture group. *
994
-
`function`: the return value of the function if it is either a string, or a
995
-
table (if there is no `then`, the function cannot return a table containing
996
-
something other than strings). * `lambda`: Simply the first value returned by
0 commit comments