GtkSource.Snippet

g GObject.Object GObject.Object GtkSource.Snippet GtkSource.Snippet GObject.Object->GtkSource.Snippet

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new (trigger, language_id)

class

new_parsed (text)

add_chunk (chunk)

copy ()

get_context ()

get_description ()

get_focus_position ()

get_language_id ()

get_n_chunks ()

get_name ()

get_nth_chunk (nth)

get_trigger ()

set_description (description)

set_language_id (language_id)

set_name (name)

set_trigger (trigger)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

buffer

Gtk.TextBuffer

r/en

The Gtk.TextBuffer for the snippet

description

str

r/w/en

The description for the snippet

focus-position

int

r

The currently focused chunk

language-id

str

r/w/en

The language-id for the snippet

name

str

r/w/en

The name for the snippet

trigger

str

r/w/en

The trigger for the snippet

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class GtkSource.Snippet(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

GtkSource.SnippetClass

Quick insertion code snippets.

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

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

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

classmethod new(trigger, language_id)
Parameters:
  • trigger (str or None) – the trigger word

  • language_id (str or None) – the source language

Returns:

A new GtkSource.Snippet

Return type:

GtkSource.Snippet

Creates a new GtkSource.Snippet

classmethod new_parsed(text)
Parameters:

text (str) – the formatted snippet text to parse

Raises:

GLib.Error

Returns:

the newly parsed GtkSource.Snippet, or None upon failure and error is set.

Return type:

GtkSource.Snippet

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

New in version 5.6.

add_chunk(chunk)
Parameters:

chunk (GtkSource.SnippetChunk) – a GtkSource.SnippetChunk

Appends chunk to the self.

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

copy()
Returns:

A new GtkSource.Snippet

Return type:

GtkSource.Snippet

Does a deep copy of the snippet.

get_context()
Returns:

an GtkSource.SnippetContext

Return type:

GtkSource.SnippetContext or None

Gets the context used for expanding the snippet.

get_description()
Return type:

str

Gets the description for the snippet.

get_focus_position()
Returns:

The focus position, or -1 if unset.

Return type:

int

Gets the current focus for the snippet.

This is changed as the user tabs through focus locations.

get_language_id()
Returns:

the language identifier

Return type:

str

Gets the language-id used for the source snippet.

The language identifier should be one that matches a source language [property`Language`:py:data::id<GtkSource.Snippet.props.id>] property.

get_n_chunks()
Returns:

The number of chunks.

Return type:

int

Gets the number of chunks in the snippet.

Note that not all chunks are editable.

get_name()
Return type:

str

Gets the name for the snippet.

get_nth_chunk(nth)
Parameters:

nth (int) – the nth chunk to get

Returns:

an GtkSource.SnippetChunk

Return type:

GtkSource.SnippetChunk

Gets the chunk at nth.

get_trigger()
Returns:

A string or None

Return type:

str or 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)
Parameters:

description (str) – the snippet description

Sets the description for the snippet.

set_language_id(language_id)
Parameters:

language_id (str) – the language identifier for the snippet

Sets the language identifier for the snippet.

This should match the [property`Language`:py:data::id<GtkSource.Snippet.props.id>] identifier.

set_name(name)
Parameters:

name (str) – the snippet name

Sets the name for the snippet.

set_trigger(trigger)
Parameters:

trigger (str) – the trigger word

Sets the trigger for the snippet.

Property Details

GtkSource.Snippet.props.buffer
Name:

buffer

Type:

Gtk.TextBuffer

Default Value:

None

Flags:

READABLE, EXPLICIT_NOTIFY

The Gtk.TextBuffer for the snippet

GtkSource.Snippet.props.description
Name:

description

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The description for the snippet

GtkSource.Snippet.props.focus_position
Name:

focus-position

Type:

int

Default Value:

-1

Flags:

READABLE

The currently focused chunk

GtkSource.Snippet.props.language_id
Name:

language-id

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The language-id for the snippet

GtkSource.Snippet.props.name
Name:

name

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The name for the snippet

GtkSource.Snippet.props.trigger
Name:

trigger

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The trigger for the snippet