:right-sidebar: True Snippet =================================================================== .. currentmodule:: gi.repository.GtkSource .. class:: Snippet(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Quick insertion code snippets. The ``GtkSourceSnippet`` represents a series of chunks that can quickly be inserted into the :obj:`~gi.repository.GtkSource.View`\. Snippets are defined in XML files which are loaded by the :obj:`~gi.repository.GtkSource.SnippetManager`\. Alternatively, applications can create snippets on demand and insert them into the :obj:`~gi.repository.GtkSource.View` using :obj:`~gi.repository.View.push_snippet`\. Snippet chunks can reference other snippet chunks as well as post-process the values from other chunks such as capitalization. Constructors ------------ .. rst-class:: interim-class .. class:: Snippet :no-index: .. classmethod:: new(trigger: str | None = None, language_id: str | None = None) -> ~gi.repository.GtkSource.Snippet Creates a new :obj:`~gi.repository.GtkSource.Snippet` :param trigger: the trigger word :param language_id: the source language .. classmethod:: new_parsed(text: str) -> ~gi.repository.GtkSource.Snippet Parses the snippet formatted ``text`` into a series of chunks and adds them to a new :obj:`~gi.repository.GtkSource.Snippet`\. .. versionadded:: 5.6 :param text: the formatted snippet text to parse Methods ------- .. rst-class:: interim-class .. class:: Snippet :no-index: .. method:: add_chunk(chunk: ~gi.repository.GtkSource.SnippetChunk) -> None Appends ``chunk`` to the ``snippet``\. This may only be called before the snippet has been expanded. :param chunk: a :obj:`~gi.repository.GtkSource.SnippetChunk` .. method:: get_context() -> ~gi.repository.GtkSource.SnippetContext | None Gets the context used for expanding the snippet. .. method:: get_description() -> str Gets the description for the snippet. .. method:: get_focus_position() -> int Gets the current focus for the snippet. This is changed as the user tabs through focus locations. .. method:: get_language_id() -> str Gets the language-id used for the source snippet. The language identifier should be one that matches a source language :obj:`~gi.repository.GtkSource.Language.props.id` property. .. method:: get_n_chunks() -> int Gets the number of chunks in the snippet. Note that not all chunks are editable. .. method:: get_name() -> str Gets the name for the snippet. .. method:: get_nth_chunk(nth: int) -> ~gi.repository.GtkSource.SnippetChunk Gets the chunk at ``nth``\. :param nth: the nth chunk to get .. method:: 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. .. method:: set_description(description: str) -> None Sets the description for the snippet. :param description: the snippet description .. method:: set_language_id(language_id: str) -> None Sets the language identifier for the snippet. This should match the :obj:`~gi.repository.GtkSource.Language.props.id` identifier. :param language_id: the language identifier for the snippet .. method:: set_name(name: str) -> None Sets the name for the snippet. :param name: the snippet name .. method:: set_trigger(trigger: str) -> None Sets the trigger for the snippet. :param trigger: the trigger word Properties ---------- .. rst-class:: interim-class .. class:: Snippet :no-index: .. attribute:: props.buffer :type: ~gi.repository.Gtk.TextBuffer The type of the None singleton. .. attribute:: props.description :type: str The type of the None singleton. .. attribute:: props.focus_position :type: int The type of the None singleton. .. attribute:: props.language_id :type: str The type of the None singleton. .. attribute:: props.name :type: str The type of the None singleton. .. attribute:: props.trigger :type: str The type of the None singleton.