Skip to content

Commit

Permalink
Document indent_snippet_node and some usages for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
L3MON4D3 committed Aug 23, 2021
1 parent b322d51 commit 3e4ea5d
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All code-snippets in this help assume that
local ls = require"luasnip"
local s = ls.snippet
local sn = ls.snippet_node
local isn = ls.indent_snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
Expand Down Expand Up @@ -234,6 +235,42 @@ Note that snippetNodes don't expect an `i(0)`.



# INDENTSNIPPETNODE

By default, all nodes are indented at least as deep as the trigger. With these
nodes it's possible to override that behaviour:

```lua
s("isn", {
isn(1, {
t({"This is indented as deep as the trigger",
"and this is at the beginning of the next line"})
}, "")
})
```

(Note the empty string passed to isn).

Indent is only applied after linebreaks, so it's not possible to remove indent
on the line where the snippet was triggered using `ISN` (That is possible via
regex-triggers where the entire line before the trigger is matched).

Another nice usecase for `ISN` is inserting text, eg. `//` or some other comment-
string before the nodes of the snippet:

```lua
s("isn2", {
isn(1, t({"//This is", "A multiline", "comment"}), "$PARENT_INDENT//")
})
```

Here the `//` before `This is` is important, once again, because indent is only
applied after linebreaks.
To enable such usage, `$PARENT_INDENT` in the indentstring is replaced by the
parents' indent (duh).



# DYNAMICNODE

Very similar to functionNode: returns a snippetNode instead of just text,
Expand Down Expand Up @@ -311,6 +348,8 @@ eg. 3, it would change to "3\nSample Text\nSample Text\nSample Text". Text
that was inserted into any of the dynamicNodes insertNodes is kept when
changing to a bigger number.



# LSP-SNIPPETS

Luasnip is capable of parsing lsp-style snippets using
Expand All @@ -324,6 +363,8 @@ choiceNode's with:
- the given snippet(`"this is ${1:nested}"`) and
- an empty insertNode



# VARIABLES

All `TM_something`-variables are supported with two additions:
Expand All @@ -347,6 +388,8 @@ To use any `*SELECT*` variable, the `store_selection_keys` must be set via
hitting `<Tab>` while in Visualmode will populate the `*SELECT*`-vars for the next
snippet and then clear them.



# VSCODE SNIPPETS LOADER

As luasnip is capable of loading the same format of plugins as vscode, it also
Expand Down Expand Up @@ -384,6 +427,8 @@ In this case `opts` only accepts paths (`runtimepath` if any). That will load
the general snippets (the ones of filetype 'all') and those of the filetype
of the buffers, you open every time you open a new one (but it won't reload them).



# EXT\_OPTS

`ext_opts` are probably best explained with a short example:
Expand Down Expand Up @@ -427,6 +472,8 @@ As a shortcut for setting `hl_group`, the highlight-groups
values defined in `ext_opts` directly, but otherwise behave the same (active is
extended by passive).



# DOCSTRING

Snippet-docstrings can be queried using `snippet:get_docstring()`. The function
Expand Down Expand Up @@ -475,6 +522,8 @@ s({trig = "(%d)", regTrig = true, docstring = "repeatmerepeatmerepeatme"}, {
}),
```



# DOCSTRING-CACHE

Although generation of docstrings is pretty fast, it's preferable to not
Expand Down

0 comments on commit 3e4ea5d

Please sign in to comment.