IdeSourceSnippetsManager: Builder SDK Reference

## IdeSourceSnippetsManager IdeSourceSnippetsManager — Manage snippets for the source code editor |

## Functions

void | ide_source_snippets_manager_load_async ()
gboolean | ide_source_snippets_manager_load_finish ()
IdeSourceSnippets * | ide_source_snippets_manager_get_for_language ()
IdeSourceSnippets * | ide_source_snippets_manager_get_for_language_id ()

## Types and Values

#define | IDE_TYPE_SOURCE_SNIPPETS_MANAGER
| IdeSourceSnippetsManager

## Object Hierarchy

        GObject
        ╰── IdeSourceSnippetsManager

## Description

The IdeSourceSnippetsManager is responsible for locating and parsing snippets that are bundled with Builder and user defined snippets.

The snippets manager will search various paths and resources for snippets when loading. Snippets are collected per-language so that the editor will only see relevant snippets for the given language.

The snippet language is similar to other snippet engines, but with some additional features to make it easier to write snippets for multiple languages at once.

Files containing snippets should have a filename suffix of ".snippets".

The following makes a snippet called "class" for Python2 and Python3 which allows you to tab through edit points. The "$0" contains the final position of the snippet.

Each line of the snippet should start with a Tab. When expanding the snippet, tabs will be converted to spaces if the users language settings specify that spaces should be used.

    1
    2
    3
    4
    5
    snippet class
    - scope python, python3
    - desc Create a Python class
        class ${1:MyClass}(${2:object}):
            $0

The default class name would be "MyClass" and inherit from "object". Upon expanding the snippet, "MyClass" will be focused and "object" will focus once the user hits Tab. A second Tab will exhaust the edit points and therefore place the insertion cursor at "$0".

You may reference other edit points as which can help in complex scenarios. In the following example, there will be a single edit point, repeated three times.

    1
    2
    3
    4
    snippet test
    - scope c
    - desc An example snippet
        ${1:test} $1 $1 $1 $0

You may also reference other edit points in the default value for an edit point. This allows you to set a value by default, but allow the user to Tab into that position and modify it.

    1
    2
    3
    4
    snippet test
    - scope c
    - desc An example snippet
        ${1:foo} ${2:`$1`}

If you want to add additional data to the edit point, you can use multiple backticks to include additional text.

    1
    2
    3
    4
    snippet test
    - scope c
    - desc An example snippet
        ${1:foo} ${2:`$1`_with_`$1`}

You can post-process the output text for an edit point by specifying a pipe "|" and then a post-processing function.

Currently, the following post-processing functions are supported.

- capitalize: make the input into "Captital Text"

- decapitalize: make the input into "decaptital text"

- html: replaces input "<>" into &lt; and &gt;

- functify: converts input into something that looks like a c_function_name

- namespace: guesses a proper code namespace from the input text

- upper: converts to uppercase

- lower: converts to lowercase

- space: converts the input text into whitespace of the same length

- camelize: converts the input text into CamelCase

- stripsuffix: removes a filename suffix, such as ".txt" from the input

- class: guess the class name from the input text

- instance: guess the instance name from the input text

You may chain multiple post-processing functions together.

    1
    2
    snippet test
        ${1:some-file} ${2:$1|functify|upper}

## Functions

### ide_source_snippets_manager_load_async ()

    void
    ide_source_snippets_manager_load_async
                                   (IdeSourceSnippetsManager *self,
                                    GCancellable *cancellable,
                                    GAsyncReadyCallback callback,
                                    gpointer user_data);

Asynchronously locates and parses snippet definitions.

Call `ide_source_snippets_manager_load_finish()` to get the result of this asynchronous operation.

#### Parameters

self | a IdeSourceSnippetsManager |
cancellable | a GCancellable or `NULL`. | [nullable]
callback | A GAsyncReadyCallback or `NULL`. | [nullable]
user_data | closure data for `callback` |

Since: 3.18

### ide_source_snippets_manager_load_finish ()

    gboolean
    ide_source_snippets_manager_load_finish
                                   (IdeSourceSnippetsManager *self,
                                    GAsyncResult *result,
                                    GError **error);

Completes an asynchronous call to `ide_source_snippets_manager_load_async()`.

#### Parameters

self | a IdeSourceSnippetsManager |
result | a GAsyncResult provided to the async callback |
error | a location for a GError or `NULL` |

#### Returns

`TRUE` if successful; otherwise `FALSE` and `error` is set.

Since: 3.18

### ide_source_snippets_manager_get_for_language ()

    IdeSourceSnippets *
    ide_source_snippets_manager_get_for_language
                                   (IdeSourceSnippetsManager *self,
                                    GtkSourceLanguage *language);

Gets the snippets for a given source language.

#### Parameters

self | An IdeSourceSnippetsManager |
language | a GtkSourceLanguage. | [not nullable]

#### Returns

An IdeSourceSnippets or `NULL`.

[transfer none][nullable]

Since: 3.18

### ide_source_snippets_manager_get_for_language_id ()

    IdeSourceSnippets *
    ide_source_snippets_manager_get_for_language_id
                                   (IdeSourceSnippetsManager *self,
                                    const gchar *language_id);

Gets the snippets for a given source language.

#### Parameters

self | an IdeSourceSnippetsManager |
language_id | the identifier for the language. | [not nullable]

#### Returns

An IdeSourceSnippets or `NULL`.

[transfer none][nullable]

Since: 3.18

## Types and Values

### IDE_TYPE_SOURCE_SNIPPETS_MANAGER

    #define IDE_TYPE_SOURCE_SNIPPETS_MANAGER (ide_source_snippets_manager_get_type())

### IdeSourceSnippetsManager

    typedef struct _IdeSourceSnippetsManager IdeSourceSnippetsManager;