Documentation
¶
Overview ¶
Package snippet implements Qt Creator / TextMate / LSP style snippet expansion. A snippet body is a template string containing tab-stop placeholders; Expand turns it into the final text plus a list of stops recording where the editor caret should land.
Placeholder syntax:
$N a bare tab stop with index N and no default (empty)
${N:default} a tab stop with index N and a default value
${N} a tab stop with index N and an empty default
$0 / ${0:..} the final caret position; always sorted last
\$ an escaped literal dollar sign (not a placeholder)
\\ an escaped literal backslash
\} a literal brace, useful inside a ${N:default}
Offsets in Stop are BYTE offsets into Expansion.Text. Byte offsets keep slicing (Text[Start:End]) correct for multibyte UTF-8 defaults without any rune/byte conversion at the call site.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Expansion ¶
Expansion is the result of expanding a template: the final Text and the Stops sorted by Index ascending with every index-0 stop ($0, the final caret) placed last. Stops sharing an index keep their appearance order.
func Expand ¶
Expand parses template, replacing each placeholder with its default (empty for a bare $N) and recording a Stop for every placeholder. It returns an error for a malformed ${...} group: one with no closing brace, a non-numeric index, an out-of-range index, or a stray character where ':' or '}' was expected. A bare '$' not followed by a digit or '{' is a literal dollar, as is an escaped \$.
type Stop ¶
Stop is a single tab stop landed in the expanded text. Start and End are byte offsets into Expansion.Text delimiting the region occupied by the placeholder's default (Start == End when the default is empty). A snippet may contain several stops with the same Index (mirrors); each is recorded separately.