Skip to content

Commit 08511f9

Browse files
L3MON4D3github-actions[bot]
authored andcommitted
Auto generate docs
1 parent 4b8d678 commit 08511f9

File tree

1 file changed

+125
-85
lines changed

1 file changed

+125
-85
lines changed

doc/luasnip.txt

Lines changed: 125 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,18 @@ are used there.
266266

267267
SNIPPET-DATA ~
268268

269-
Snippets contain some interesting tables during runtime: - `snippet.env`:
270-
Contains variables used in the LSP-protocol, for example `TM_CURRENT_LINE` or
271-
`TM_FILENAME`. It’s possible to add customized variables here too, check
272-
|luasnip-environment-namespaces| - `snippet.captures`: If the snippet was
273-
triggered by a pattern (`regTrig`), and the pattern contained capture-groups,
274-
they can be retrieved here. - `snippet.trigger`: The string that triggered this
275-
snippet. Again, only interesting if the snippet was triggered through
276-
`regTrig`, for getting the full match.
269+
Snippets contain some interesting tables during runtime:
270+
271+
272+
- `snippet.env`: Contains variables used in the LSP-protocol, for example
273+
`TM_CURRENT_LINE` or `TM_FILENAME`. It’s possible to add customized variables
274+
here too, check |luasnip-environment-namespaces|
275+
- `snippet.captures`: If the snippet was triggered by a pattern (`regTrig`), and
276+
the pattern contained capture-groups, they can be retrieved here.
277+
- `snippet.trigger`: The string that triggered this snippet. Again, only
278+
interesting if the snippet was triggered through `regTrig`, for getting the
279+
full match.
280+
277281

278282
These variables/tables primarily come in handy in `dynamic/functionNodes`,
279283
where the snippet can be accessed through the immediate parent
@@ -318,8 +322,12 @@ lines rather than a string:
318322
<
319323

320324

321-
`t(text, node_opts)`: - `text`: `string` or `string[]` - `node_opts`: `table`,
322-
see |luasnip-here|
325+
`t(text, node_opts)`:
326+
327+
328+
- `text`: `string` or `string[]`
329+
- `node_opts`: `table`, see |luasnip-here|
330+
323331

324332
==============================================================================
325333
5. INSERTNODE *luasnip-insertnode*
@@ -553,20 +561,25 @@ ChoiceNodes allow choosing between multiple nodes.
553561
<
554562

555563

556-
`c(jump_index, choices, node_opts)` - |luasnip-`jump_index`|: `number`, since
557-
choiceNodes can be jumped to, they need their jump-indx. - `choices`:
558-
`node[]|node`, the choices. The first will be initialliy active. A list of
559-
nodes will be turned into a `snippetNode`. - `node_opts`: `table`. `choiceNode`
560-
supports the keys common to all nodes described |luasnip-here|, and one
561-
additional key: - `restore_cursor`: `false` by default. If it is set, and the
562-
node that was being edited also appears in the switched-to choice (can be the
563-
case if a `restoreNode` is present in both choice) the cursor is restored
564-
relative to that node. The default is `false` as enabling might lead to
565-
decreased performance. It’s possible to override the default by wrapping the
566-
`choiceNode`-constructor in another function that sets `opts.restore_cursor` to
567-
`true` and then using that to construct `choiceNode`s: `lua local function
568-
restore_cursor_choice(pos, choices, opts) if opts then opts.restore_cursor =
569-
true else opts = {restore_cursor = true} end return c(pos, choices, opts) end`
564+
`c(jump_index, choices, node_opts)`
565+
566+
567+
- |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+
570583

571584
Jumpable nodes that normally expect an index as their first parameter don’t
572585
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]`.
956969
LAMBDA *luasnip-lambda*
957970

958971
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+
966986

967987
There are many examples for `lamda` in `Examples/snippets.lua`
968988

@@ -971,44 +991,50 @@ MATCH *luasnip-match*
971991
`match` can insert text based on a predicate (again, a shorthand for
972992
`functionNode`).
973993

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.
9861009
- `then` is inserted if the condition matches,
9871010
- `else` if it does not.
9881011

9891012

9901013
Both `then` and `else` can be either text, lambda or function (with the same
9911014
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
997-
the lambda.
1015+
`condition`:
9981016

999-
Examples: * `match(n, "^ABC$", "A")`. * `match(n,
1000-
lambda._1:match(lambda._1:reverse()), "PALINDROME")`
10011017

1002-
>
1003-
s("trig", {
1004-
i(1), t":",
1005-
i(2), t"::",
1006-
m({1, 2}, l._1:match("^"..l._2.."$"), l._1:gsub("a", "e"))
1007-
})
1008-
<
1018+
- `pattern`: Simply the return value from the `match`, e.g. the entire match,
1019+
or, if there were capture groups, the first capture group.
1020+
- `function`: the return value of the function if it is either a string, or a
1021+
table (if there is no `then`, the function cannot return a table containing
1022+
something other than strings).
1023+
- `lambda`: Simply the first value returned by the lambda.
1024+
10091025

1026+
Examples:
10101027

10111028

1029+
- `match(n, "^ABC$", "A")`.
1030+
- `match(n, lambda._1:match(lambda._1:reverse()), "PALINDROME")`
1031+
>
1032+
s("trig", {
1033+
i(1), t":",
1034+
i(2), t"::",
1035+
m({1, 2}, l._1:match("^"..l._2.."$"), l._1:gsub("a", "e"))
1036+
})
1037+
<
10121038
- >
10131039
s("extras1", {
10141040
i(1), t { "", "" }, m(1, "^ABC$", "A")
@@ -1217,11 +1243,15 @@ expanded, with as little disruption as possible.
12171243

12181244
Since they should mainly fast to write, and don’t necessarily need all bells
12191245
and whistles, they don’t make use of lsp/textmate-syntax, but a more
1220-
simplistic one: * `$anytext` denotes a placeholder (`insertNode`) with text
1221-
"anytext". The text also serves as a unique key: if there are multiple
1222-
placeholders with the same key, only the first will be editable, the others
1223-
will just mirror it. * … That’s it. `$` can be escaped by preceding it with
1224-
a second `$`, all other symbols will be interpreted literally.
1246+
simplistic one:
1247+
1248+
1249+
- `$anytext` denotes a placeholder (`insertNode`) with text "anytext". The text
1250+
also serves as a unique key: if there are multiple placeholders with the same
1251+
key, only the first will be editable, the others will just mirror it.
1252+
- … That’s it. `$` can be escaped by preceding it with a second `$`, all other
1253+
symbols will be interpreted literally.
1254+
12251255

12261256
There is currently only one way to expand On The Fly-snippets:
12271257
`require('luasnip.extras.otf').on_the_fly("<some-register>")` will interpret
@@ -1444,19 +1474,29 @@ via `extend_decorator.register`. (This is not limited to luasnip’s
14441474
functions!) (although, for usage outside of luasnip, best copy the source-file
14451475
`/lua/luasnip/util/extend_decorator.lua`).
14461476

1447-
`register(fn, ...)`: * `fn`: the function. * `...`: any number of tables. Each
1448-
specifies how to extend an argument of `fn`. The tables accept: * arg_indx,
1449-
`number` (required): the position of the parameter to override. * extend,
1450-
`fn(arg, extend_value) -> effective_arg` (optional): this function is used to
1451-
extend the args passed to the decorated function. It defaults to a function
1452-
which just extends the the arg-table with the extend-table (accepts `nil`).
1453-
This extend-behaviour is adaptable to accomodate `s`, where the first argument
1454-
may be string or table.
1477+
`register(fn, ...)`:
1478+
1479+
1480+
- `fn`: the function.
1481+
- `...`: any number of tables. Each specifies how to extend an argument of `fn`.
1482+
The tables accept:
1483+
- arg_indx, `number` (required): the position of the parameter to override.
1484+
- extend, `fn(arg, extend_value) -> effective_arg` (optional): this function
1485+
is used to extend the args passed to the decorated function.
1486+
It defaults to a function which just extends the the arg-table with the
1487+
extend-table (accepts `nil`).
1488+
This extend-behaviour is adaptable to accomodate `s`, where the first
1489+
argument may be string or table.
1490+
1491+
1492+
`apply(fn, ...) -> decorated_fn`:
1493+
1494+
1495+
- `fn`: the function to decorate.
1496+
- `...`: The values to extend with. These should match the descriptions passed
1497+
in `register` (the argument first passed to `register` will be extended with
1498+
the first value passed here).
14551499

1456-
`apply(fn, ...) -> decorated_fn`: * `fn`: the function to decorate. * `...`:
1457-
The values to extend with. These should match the descriptions passed in
1458-
`register` (the argument first passed to `register` will be extended with the
1459-
first value passed here).
14601500

14611501
One more example for registering a new function:
14621502

@@ -1986,10 +2026,6 @@ there are multiple) the associated file to edit.
19862026
end
19872027
}
19882028
<
1989-
<div class="figure">
1990-
<img src="https://user-images.githubusercontent.com/25300418/184359420-3bc22d67-1f90-49d9-ac4e-3ea2524bcf0d.gif" title="fig:"/>
1991-
<p class="caption">edit-select-format</p>
1992-
</div>
19932029
- `edit`: `fn(file:string)` This function is supposed to open the file for
19942030
editing. The default is a simple `vim.cmd("edit " .. file)` (replace the
19952031
current buffer), but one could open the file in a split, a tab, or a floating
@@ -2027,12 +2063,16 @@ This will parse the snippet on startup…
20272063
<
20282064

20292065

2030-
`sp(context, body, opts) -> snippetProxy` - `context`: exactly the same as the
2031-
first argument passed to `ls.s`. - `body`: the snippet-body. - `opts`: accepts
2032-
the same `opts` as `ls.s`, with some additions: - `parse_fn`: the function for
2033-
parsing the snippet. Defaults to `ls.parser.parse_snippet` (the parser for
2034-
lsp-snippets), an alternative is the parser for snipmate-snippets
2035-
(`ls.parser.parse_snipmate`).
2066+
`sp(context, body, opts) -> snippetProxy`
2067+
2068+
2069+
- `context`: exactly the same as the first argument passed to `ls.s`.
2070+
- `body`: the snippet-body.
2071+
- `opts`: accepts the same `opts` as `ls.s`, with some additions:
2072+
- `parse_fn`: the function for parsing the snippet. Defaults to
2073+
`ls.parser.parse_snippet` (the parser for lsp-snippets), an alternative is
2074+
the parser for snipmate-snippets (`ls.parser.parse_snipmate`).
2075+
20362076

20372077
==============================================================================
20382078
19. EXT_OPTS *luasnip-ext_opts*

0 commit comments

Comments
 (0)