Buffer


Object Hierarchy:

GtkSource.Buffer GtkSource.Buffer GtkSource.Buffer Gtk.TextBuffer Gtk.TextBuffer Gtk.TextBuffer->GtkSource.Buffer GLib.Object GLib.Object GLib.Object->Gtk.TextBuffer

Description:

[ CCode ( type_id = "gtk_source_buffer_get_type ()" ) ]
public class Buffer : TextBuffer

Subclass of [class@Gtk.

TextBuffer].

A `GtkSourceBuffer` object is the model for [class@View] widgets. It extends the [[email protected]] class by adding features useful to display and edit source code such as syntax highlighting and bracket matching.

To create a `GtkSourceBuffer` use [[email protected]] or [[email protected]_with_language]. The second form is just a convenience function which allows you to initially set a [class@Language]. You can also directly create a [class@View] and get its [ class@Buffer] with [[email protected]_buffer].

The highlighting is enabled by default, but you can disable it with [[email protected]_highlight_syntax].

Context Classes:

It is possible to retrieve some information from the syntax highlighting engine. The default context classes that are applied to regions of a `GtkSourceBuffer`:

  • **comment**: the region delimits a comment;
  • **no-spell-check**: the region should not be spell checked;
  • **path**: the region delimits a path to a file;
  • **string**: the region delimits a string.

Custom language definition files can create their own context classes, since the functions like [[email protected]_has_context_class] take a string parameter as the context class.

`GtkSourceBuffer` provides an API to access the context classes: [[email protected]_has_context_class], [ [email protected]_context_classes_at_iter], [[email protected]_forward_to_context_class_toggle] and [ [email protected]_backward_to_context_class_toggle].

And the [[email protected]:GtkSourceBuffer:highlight-updated] signal permits to be notified when a context class region changes.

Each context class has also an associated [[email protected]] with the name `gtksourceview:context-classes:<name>`. For example to retrieve the [[email protected]] for the string context class, one can write: ```c GtkTextTagTable *tag_table; GtkTextTag *tag;

tag_table = gtk_text_buffer_get_tag_table (buffer); tag = gtk_text_tag_table_lookup (tag_table, "gtksourceview:context-classes:string"); ```

The tag must be used for read-only purposes.

Accessing a context class via the associated [[email protected]] is less convenient than the `GtkSourceBuffer` API, because:

A possible use-case for accessing a context class via the associated [[email protected]] is to read the region but without adding a hard dependency on the GtkSourceView library (for example for a spell-checking library that wants to read the no-spell-check region).


Namespace: GtkSource
Package: gtksourceview-5

Content:

Properties:

Creation methods:

Methods:

Signals:

Inherited Members:

All known members inherited from class Gtk.TextBuffer
All known members inherited from class GLib.Object



2022 vala-language.org