SnippetContext

class SnippetContext(**properties: Any)

Superclasses: Object

Context for expanding SnippetChunk.

This class is currently used primary as a hashtable. However, the longer term goal is to have it hold onto a GjsContext as well as other languages so that SnippetChunk can expand themselves by executing script within the context.

The Snippet will build the context and then expand each of the chunks during the insertion/edit phase.

Constructors

class SnippetContext
classmethod new() SnippetContext

Creates a new SnippetContext.

Generally, this isn’t needed unless you are controlling the expansion of snippets manually.

Methods

class SnippetContext
clear_variables() None

Removes all variables from the context.

expand(input: str) str
Parameters:

input

get_variable(key: str) str | None

Gets the current value for a variable named key.

Parameters:

key – the name of the variable

set_constant(key: str, value: str) None

Sets a constatnt within the context.

This is similar to a variable set with set_variable but is expected to not change during use of the snippet.

Examples would be the date or users name.

Parameters:
  • key – the constant name

  • value – the value of the constant

set_line_prefix(line_prefix: str) None
Parameters:

line_prefix

set_tab_width(tab_width: int) None
Parameters:

tab_width

set_use_spaces(use_spaces: bool) None
Parameters:

use_spaces

set_variable(key: str, value: str) None

Sets a variable within the context.

This variable may be overridden by future updates to the context.

Parameters:
  • key – the variable name

  • value – the value for the variable

Signals

class SnippetContext.signals
changed() None

The signal is emitted when a change has been discovered in one of the chunks of the snippet which has caused a variable or other dynamic data within the context to have changed.