Class

GtkSourceBuffer

Description [src]

class GtkSource.Buffer : Gtk.TextBuffer {
  parent_instance: GtkTextBuffer
}

Subclass of GtkTextBuffer.

A GtkSourceBuffer object is the model for GtkSourceView widgets. It extends the GtkTextBuffer class by adding features useful to display and edit source code such as syntax highlighting and bracket matching.

To create a GtkSourceBuffer use gtk_source_buffer_new() or gtk_source_buffer_new_with_language(). The second form is just a convenience function which allows you to initially set a GtkSourceLanguage. You can also directly create a GtkSourceView and get its GtkSourceBuffer with gtk_text_view_get_buffer().

The highlighting is enabled by default, but you can disable it with gtk_source_buffer_set_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 gtk_source_buffer_iter_has_context_class() take a string parameter as the context class.

GtkSourceBuffer provides an API to access the context classes: gtk_source_buffer_iter_has_context_class(), gtk_source_buffer_get_context_classes_at_iter(), gtk_source_buffer_iter_forward_to_context_class_toggle() and gtk_source_buffer_iter_backward_to_context_class_toggle().

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

Each context class has also an associated GtkTextTag with the name gtksourceview:context-classes:<name>. For example to retrieve the GtkTextTag for the string context class, one can write:

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 GtkTextTag is less convenient than the GtkSourceBuffer API, because:

A possible use-case for accessing a context class via the associated GtkTextTag 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).

Constructors

gtk_source_buffer_new

Creates a new source buffer.

gtk_source_buffer_new_with_language

Creates a new source buffer using the highlighting patterns in language.

Instance methods

gtk_source_buffer_backward_iter_to_source_mark

Moves iter to the position of the previous GtkSourceMark of the given category.

gtk_source_buffer_change_case

Changes the case of the text between the specified iterators.

gtk_source_buffer_create_source_mark

Creates a source mark in the buffer of category category.

gtk_source_buffer_create_source_tag

In short, this is the same function as gtk_text_buffer_create_tag() but instead of creating a GtkTextTag, this function creates a GtkSourceTag.

gtk_source_buffer_ensure_highlight

Forces buffer to analyze and highlight the given area synchronously.

gtk_source_buffer_forward_iter_to_source_mark

Moves iter to the position of the next GtkSourceMark of the given category.

gtk_source_buffer_get_context_classes_at_iter

Get all defined context classes at iter.

gtk_source_buffer_get_highlight_matching_brackets

Determines whether bracket match highlighting is activated for the source buffer.

gtk_source_buffer_get_highlight_syntax

Determines whether syntax highlighting is activated in the source buffer.

gtk_source_buffer_get_language

Returns the GtkSourceLanguage associated with the buffer, see gtk_source_buffer_set_language().

gtk_source_buffer_get_loading
No description available.

gtk_source_buffer_get_source_marks_at_iter

Returns the list of marks of the given category at iter.

gtk_source_buffer_get_source_marks_at_line

Returns the list of marks of the given category at line.

gtk_source_buffer_get_style_scheme

Returns the GtkSourceStyleScheme associated with the buffer, see gtk_source_buffer_set_style_scheme().

gtk_source_buffer_iter_backward_to_context_class_toggle

Moves backward to the next toggle (on or off) of the context class.

gtk_source_buffer_iter_forward_to_context_class_toggle

Moves forward to the next toggle (on or off) of the context class.

gtk_source_buffer_iter_has_context_class

Check if the class context_class is set on iter.

gtk_source_buffer_join_lines

Joins the lines of text between the specified iterators.

gtk_source_buffer_remove_source_marks

Remove all marks of category between start and end from the buffer.

gtk_source_buffer_set_highlight_matching_brackets

Controls the bracket match highlighting function in the buffer.

gtk_source_buffer_set_highlight_syntax

Controls whether syntax is highlighted in the buffer.

gtk_source_buffer_set_implicit_trailing_newline

Sets whether the buffer has an implicit trailing newline.

gtk_source_buffer_set_language

Associates a GtkSourceLanguage with the buffer.

gtk_source_buffer_set_style_scheme

Sets a GtkSourceStyleScheme to be used by the buffer and the view.

gtk_source_buffer_sort_lines

Sort the lines of text between the specified iterators.

Methods inherited from GtkTextBuffer (70)

Please see GtkTextBuffer for a full list of methods.

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Properties

GtkSource.Buffer:highlight-matching-brackets

Whether to highlight matching brackets in the buffer.

GtkSource.Buffer:highlight-syntax

Whether to highlight syntax in the buffer.

GtkSource.Buffer:implicit-trailing-newline

Whether the buffer has an implicit trailing newline. See gtk_source_buffer_set_implicit_trailing_newline().

GtkSource.Buffer:language
No description available.

GtkSource.Buffer:loading

The “loading” property denotes that a GtkSourceFileLoader is currently loading the buffer.

since: 5.10

GtkSource.Buffer:style-scheme

Style scheme. It contains styles for syntax highlighting, optionally foreground, background, cursor color, current line color, and matching brackets style.

Properties inherited from GtkTextBuffer (7)
Gtk.TextBuffer:can-redo

Denotes that the buffer can reapply the last undone action.

Gtk.TextBuffer:can-undo

Denotes that the buffer can undo the last applied action.

Gtk.TextBuffer:cursor-position

The position of the insert mark.

Gtk.TextBuffer:enable-undo

Denotes if support for undoing and redoing changes to the buffer is allowed.

Gtk.TextBuffer:has-selection

Whether the buffer has some text currently selected.

Gtk.TextBuffer:tag-table

The GtkTextTagTable for the buffer.

Gtk.TextBuffer:text

The text content of the buffer.

Signals

GtkSource.Buffer::bracket-matched

iter is set to a valid iterator pointing to the matching bracket if state is GTK_SOURCE_BRACKET_MATCH_FOUND. Otherwise iter is meaningless.

GtkSource.Buffer::cursor-moved

The “cursor-moved” signal is emitted when then insertion mark has moved.

GtkSource.Buffer::highlight-updated

The ::highlight-updated signal is emitted when the syntax highlighting and context classes are updated in a certain region of the buffer.

GtkSource.Buffer::source-mark-updated

The ::source-mark-updated signal is emitted each time a mark is added to, moved or removed from the buffer.

Signals inherited from GtkTextBuffer (15)
GtkTextBuffer::apply-tag

Emitted to apply a tag to a range of text in a GtkTextBuffer.

GtkTextBuffer::begin-user-action

Emitted at the beginning of a single user-visible operation on a GtkTextBuffer.

GtkTextBuffer::changed

Emitted when the content of a GtkTextBuffer has changed.

GtkTextBuffer::delete-range

Emitted to delete a range from a GtkTextBuffer.

GtkTextBuffer::end-user-action

Emitted at the end of a single user-visible operation on the GtkTextBuffer.

GtkTextBuffer::insert-child-anchor

Emitted to insert a GtkTextChildAnchor in a GtkTextBuffer.

GtkTextBuffer::insert-paintable

Emitted to insert a GdkPaintable in a GtkTextBuffer.

GtkTextBuffer::insert-text

Emitted to insert text in a GtkTextBuffer.

GtkTextBuffer::mark-deleted

Emitted as notification after a GtkTextMark is deleted.

GtkTextBuffer::mark-set

Emitted as notification after a GtkTextMark is set.

GtkTextBuffer::modified-changed

Emitted when the modified bit of a GtkTextBuffer flips.

GtkTextBuffer::paste-done

Emitted after paste operation has been completed.

GtkTextBuffer::redo

Emitted when a request has been made to redo the previously undone operation.

GtkTextBuffer::remove-tag

Emitted to remove all occurrences of tag from a range of text in a GtkTextBuffer.

GtkTextBuffer::undo

Emitted when a request has been made to undo the previous operation or set of operations that have been grouped together.

Signals inherited from GObject (1)
GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

Class structure

struct GtkSourceBufferClass {
  GtkTextBufferClass parent_class;
  void (* bracket_matched) (
    GtkSourceBuffer* buffer,
    GtkTextIter* iter,
    GtkSourceBracketMatchType state
  );
  
}
No description available.
Class members
parent_class: GtkTextBufferClass
No description available.
bracket_matched: void (* bracket_matched) ( GtkSourceBuffer* buffer, GtkTextIter* iter, GtkSourceBracketMatchType state )
No description available.

Virtual methods

GtkSource.BufferClass.bracket_matched
No description available.