Snippets

The snippet engine provides the ability to type shortcuts for boilerplate text. For example, gobject could expand into a fully working GObject implementation or header.

Status

  • {o} Needs design

    {o} Design in progress

    {o} Needs implementation

    {o} Implementation in progress

    {*} Stable

Animations

We can play with this a little bit to give visual feedback to the user when a snippet is inserted. A small "explosion" animation has been added to make it clear that something has happened.

Language Support

Each language will need to have it's own set of snippets. We should ship license snippets for a broad range of languages. At minimum C, Python, JavaScript, and Vala.

Adding Snippets

Snippets should be defined in a per-language file in the users config directory .config/gnome-builder/snippets/c.snippets for example.

We should also have UI for the developer to configure their own snippets.

Expanding a Snippet

Just start typing the snippet name and hit TAB. The snippet will show up in the auto-completion window when it is activatable.

Snippet Language

The following snippet definition shows how to use a couple of features in the snippet engine. It contains a snippet with two tab stops (${1} and ${2}) each with a default value. The default value for $2 is dependent on the value of $1 and will be updated each time $1 is modified (unless $2 has also been modified). $2 also contains a filter to modify the value from $1 to upper case.

$0 denotes the location the cursor should end up on after all tab stops have been exhausted.

snippet foo
        FooWidget ${1:name} = ${2:$1|upper};
        $1 $2
        $0

You can also have multiple dynamic values in a tab stop. See the following.

snippet foo
        ${1:abc} ${2:def} ${3:`$1`_TYPE_`$2`}
        $0

Apps/Builder/Planning/Snippets (last edited 2015-08-29 23:24:53 by sebastienlafargue)