![]() |
![]() |
![]() |
![]() |
Snippet Definition ReferenceSnippet Definition Reference — Reference to the GtkSourceView snippet definition file format |
This is an overview of the Snippet Definition XML format, describing the
meaning and usage of every element and attribute. The formal definition is
stored in the RelaxNG schema file snippets.rng
which
should be installed on your system in the directory
${PREFIX}/share/gtksourceview-5/
(where
${PREFIX}
can be /usr/
or
/usr/local/
if you have installed from source).
The toplevel tag in a snippet file is <snippets>
.
It has the following attributes:
|
The group for the snippet. This is purely used to group snippets together in user-interfaces. |
Within the snippets tag is one or more <snippets>
elements.
It has the following attributes:
|
The name of the snippet. This may be displayed in the user interface such as in a snippet editor or completion providers. An attempt will be made to translate it by GtkSourceView. |
|
The word trigger of the snippet. If the user types this word and hits Tab, the snippet will be inserted. |
|
The description of the snippet. This may be displayed in the user interface such as in a snippet editor or completion providers. An attempt will be made to translate it by GtkSourceView. |
Within the snippet tag is one or more <text>
elements.
It has the following attributes:
|
A semicolon separated list of GtkSourceView language identifiers for which this
text should be used when inserting the snippet. Defining this on the
|
|
Within the |
GtkSourceView's snippet text format is largely based upon other snippet implementations that have gained popularity. Since there are so many, it likely differs in some small ways from what you may have used previously.
Focus positions allow the user to move through chunks within the snippet that are meant to be edited by the user. Each subsequent "Tab" by the user will advance them to the next focus position until all have been exhausted.
To set a focus position in your snippet, use a dollar sign followed by
curly braces with the focus position number inside like ${1}
or
${2}
. The user can also use Shift+Tab to move to a previous tab
stop.
The special $0
tab stop is used to place the cursor after
all focus positions have been exhausted. If no focus position was provided, the
cursor will be placed there automatically.
You can also set a default value for a focus position by appending a colon
and the initial value such as ${2:default_value}
. You can even
reference other chunks such as ${3:$2_$1}
to join the contents of
$2
, an underbar _
, and $1
.
When a snippet is expanded into the #GtkSourceView, chunks may reference a number of built-in or application provided variables. Applications may add additional variables with either gtk_source_snippet_context_set_constant() (for things that do not change) or gtk_source_snippet_context_set_variable() for values that may change.
Snippet chunks can reference a variable anywhere by using a dollar sign
followed by the variable name such as $variable
.
You can also reference another focus position's value by using their focus
position number as the variable such as $1
.
To post-process a variables value, enclose the variable in curly-brackets
and use the pipe operator to denote the post-processing function such as
${$1|capitalize}
.
A number of predefined variables are provided by GtkSourceView which can be extended by applications.
|
The current 4-digit year |
|
The last 2 digits of the current year |
|
The current month as a number from 01-12 |
|
The full month name such as "August" in the current locale |
|
The short month name such as "Aug" in the current locale |
|
The current day of the month from 1-31 |
|
The current day such as "Friday" in the current locale |
|
The current day using the shortened name such as "Fri" in the current locale |
|
The current hour in 24-hour format |
|
The current minute within the hour |
|
The current second within the minute |
|
The number of seconds since the UNIX epoch |
|
The users login user name (See g_get_user_name()) |
|
The users full name, if known (See g_get_full_name()) |
|
The contents of the current line |
|
The zero-index based line number |
|
The one-index based line number |
By appending a pipe to a variable within curly braces, you can post-process
the variable. A number of built-in functions are available for processing.
For example ${$1|stripsuffix|functify}
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|