Snippet#

class Snippet(**properties: Any)#

Superclasses: Object

Quick insertion code snippets.

The GtkSourceSnippet represents a series of chunks that can quickly be inserted into the View.

Snippets are defined in XML files which are loaded by the SnippetManager. Alternatively, applications can create snippets on demand and insert them into the View using push_snippet.

Snippet chunks can reference other snippet chunks as well as post-process the values from other chunks such as capitalization.

Constructors#

class Snippet
classmethod new(trigger: str | None = None, language_id: str | None = None) Snippet#

Creates a new Snippet

Parameters:
  • trigger – the trigger word

  • language_id – the source language

classmethod new_parsed(text: str) Snippet#

Parses the snippet formatted text into a series of chunks and adds them to a new Snippet.

Added in version 5.6.

Parameters:

text – the formatted snippet text to parse

Methods#

class Snippet
add_chunk(chunk: SnippetChunk) None#

Appends chunk to the snippet.

This may only be called before the snippet has been expanded.

Parameters:

chunk – a SnippetChunk

get_context() SnippetContext | None#

Gets the context used for expanding the snippet.

get_description() str#

Gets the description for the snippet.

get_focus_position() int#

Gets the current focus for the snippet.

This is changed as the user tabs through focus locations.

get_language_id() str#

Gets the language-id used for the source snippet.

The language identifier should be one that matches a source language id property.

get_n_chunks() int#

Gets the number of chunks in the snippet.

Note that not all chunks are editable.

get_name() str#

Gets the name for the snippet.

get_nth_chunk(nth: int) SnippetChunk#

Gets the chunk at nth.

Parameters:

nth – the nth chunk to get

get_trigger() str | None#

Gets the trigger for the source snippet.

A trigger is a word that can be expanded into the full snippet when the user presses Tab.

set_description(description: str) None#

Sets the description for the snippet.

Parameters:

description – the snippet description

set_language_id(language_id: str) None#

Sets the language identifier for the snippet.

This should match the id identifier.

Parameters:

language_id – the language identifier for the snippet

set_name(name: str) None#

Sets the name for the snippet.

Parameters:

name – the snippet name

set_trigger(trigger: str) None#

Sets the trigger for the snippet.

Parameters:

trigger – the trigger word

Properties#

class Snippet
props.buffer: TextBuffer#

The type of the None singleton.

props.description: str#

The type of the None singleton.

props.focus_position: int#

The type of the None singleton.

props.language_id: str#

The type of the None singleton.

props.name: str#

The type of the None singleton.

props.trigger: str#

The type of the None singleton.