Skip to main content

Module variables

Module variables 

Source
Expand description

Variable resolution for snippet expansion. The host fills in a VariableContext with file / cursor / clipboard info; the renderer asks the context for each $VAR it encounters.

v1 supports the TextMate / VS Code built-in variable set:

VariableResolves to
TM_SELECTED_TEXTlast visual selection
TM_CURRENT_LINEcurrent line text
TM_CURRENT_WORDword under cursor
TM_LINE_INDEX0-based current line
TM_LINE_NUMBER1-based current line
TM_FILENAMEcurrent filename (basename + ext)
TM_FILENAME_BASEfilename without extension
TM_DIRECTORYcontaining directory absolute path
TM_FILEPATHabsolute path to current file
WORKSPACE_NAMEworkspace folder basename
WORKSPACE_FOLDERworkspace folder absolute path
CLIPBOARDcurrent "+ register text
CURRENT_YEAR / CURRENT_MONTH / CURRENT_DATE / CURRENT_HOUR / CURRENT_MINUTE / CURRENT_SECONDtimestamp components (zero-padded where conventional)
CURRENT_DAY_NAME / CURRENT_DAY_NAME_SHORT / CURRENT_MONTH_NAME / CURRENT_MONTH_NAME_SHORTnamed timestamp parts
RANDOM6-digit random int
RANDOM_HEX6-char random hex
UUIDrandom UUID v4
LINE_COMMENT / BLOCK_COMMENT_START / BLOCK_COMMENT_ENDper-major-mode comment strings (Phase 8)

Unknown variables resolve to None (the renderer emits the variable’s default body or the empty string).

Structs§

TimestampParts
Decomposed timestamp – supplied by the host (typically derived from chrono / time if it’s already a dep) or computed at variable-resolve time. Tests use fixed_now to pin output.
VariableContext
Editor-supplied context the renderer consults to resolve variable references. The host fills in the file / cursor fields; timestamp + random / UUID values are computed at expansion time inside VariableContext::resolve.

Functions§

builtin_variables
Convenience: VariableContext populated with the builtin timestamp + random sources but no editor-supplied fields. Useful for “expand this snippet outside an editor” flows (tests, examples, snippet authoring tools).