Buffer

open class Buffer(pointer: <Error class: unknown class><<Error class: unknown class>>)

Subclass of class@Gtk.TextBuffer.

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

To create a GtkSourceBuffer use ctor@GtkSource.Buffer.new or ctor@GtkSource.Buffer.new_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 method@Gtk.TextView.get_buffer.

The highlighting is enabled by default, but you can disable it with method@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 method@Buffer.iter_has_context_class take a string parameter as the context class.

GtkSourceBuffer provides an API to access the context classes: method@Buffer.iter_has_context_class, method@Buffer.get_context_classes_at_iter, method@Buffer.iter_forward_to_context_class_toggle and method@Buffer.iter_backward_to_context_class_toggle.

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

Each context class has also an associated class@Gtk.TextTag with the name gtksourceview:context-classes:<name>. For example to retrieve the class@Gtk.TextTag 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 class@Gtk.TextTag is less convenient than the GtkSourceBuffer API, because:

  • The tag doesn't always exist, you need to listen to the signal@Gtk.TextTagTable::tag-added and signal@Gtk.TextTagTable::tag-removed signals.

  • Instead of the signal@GtkSource.Buffer::highlight-updated signal, you can listen to the signal@Gtk.TextBuffer::apply-tag and signal@Gtk.TextBuffer::remove-tag signals.

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

Skipped during bindings generation

  • method backward_iter_to_source_mark: In/Out parameter is not supported

  • method forward_iter_to_source_mark: In/Out parameter is not supported

  • method iter_backward_to_context_class_toggle: In/Out parameter is not supported

  • method iter_forward_to_context_class_toggle: In/Out parameter is not supported

Constructors

Link copied to clipboard
constructor(table: <Error class: unknown class>? = null)

Creates a new source buffer.

constructor(language: Language)

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

constructor(pointer: <Error class: unknown class><<Error class: unknown class>>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val gtksourceBufferPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard

Whether to highlight matching brackets in the buffer.

Link copied to clipboard

Whether to highlight syntax in the buffer.

Link copied to clipboard

Whether the buffer has an implicit trailing newline. See method@Buffer.set_implicit_trailing_newline.

Link copied to clipboard
open var language: Language?
Link copied to clipboard
open val loading: Boolean

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

Link copied to clipboard

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

Functions

Link copied to clipboard
open fun changeCase(caseType: ChangeCaseType, start: <Error class: unknown class>, end: <Error class: unknown class>)

Changes the case of the text between the specified iterators.

Link copied to clipboard
fun connectBracketMatched(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (<Error class: unknown class>?, state: BracketMatchType) -> Unit): <Error class: unknown class>
Link copied to clipboard
fun connectCursorMoved(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: () -> Unit): <Error class: unknown class>

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

Link copied to clipboard
fun connectHighlightUpdated(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (<Error class: unknown class>, <Error class: unknown class>) -> Unit): <Error class: unknown class>

The ::highlight-updated signal is emitted when the syntax highlighting and ./class.Buffer.html#context-classes are updated in a certain region of the @buffer.

Link copied to clipboard
fun connectSourceMarkUpdated(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (<Error class: unknown class>) -> Unit): <Error class: unknown class>

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

Link copied to clipboard
open fun createSourceMark(name: String? = null, category: String, where: <Error class: unknown class>): Mark

Creates a source mark in the buffer of category category.

Link copied to clipboard
open fun ensureHighlight(start: <Error class: unknown class>, end: <Error class: unknown class>)

Forces buffer to analyze and highlight the given area synchronously.

Link copied to clipboard
open fun getContextClassesAtIter(iter: <Error class: unknown class>): List<String>

Get all defined context classes at @iter.

Link copied to clipboard

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

Link copied to clipboard

Determines whether syntax highlighting is activated in the source buffer.

Link copied to clipboard
Link copied to clipboard
open fun getLanguage(): Language?

Returns the class@Language associated with the buffer, see method@Buffer.set_language.

Link copied to clipboard
open fun getLoading(): Boolean
Link copied to clipboard
open fun getSourceMarksAtIter(iter: <Error class: unknown class>, category: String? = null): <Error class: unknown class>

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

Link copied to clipboard
open fun getSourceMarksAtLine(line: Int, category: String? = null): <Error class: unknown class>

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

Link copied to clipboard

Returns the class@StyleScheme associated with the buffer, see method@Buffer.set_style_scheme.

Link copied to clipboard
open fun iterHasContextClass(iter: <Error class: unknown class>, contextClass: String): Boolean

Check if the class @context_class is set on @iter.

Link copied to clipboard
open fun joinLines(start: <Error class: unknown class>, end: <Error class: unknown class>)

Joins the lines of text between the specified iterators.

Link copied to clipboard
open fun removeSourceMarks(start: <Error class: unknown class>, end: <Error class: unknown class>, category: String? = null)

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

Link copied to clipboard

Controls the bracket match highlighting function in the buffer.

Link copied to clipboard
open fun setHighlightSyntax(highlight: Boolean)

Controls whether syntax is highlighted in the buffer.

Link copied to clipboard
open fun setImplicitTrailingNewline(implicitTrailingNewline: Boolean)

Sets whether the @buffer has an implicit trailing newline.

Link copied to clipboard
open fun setLanguage(language: Language? = null)

Associates a class@Language with the buffer.

Link copied to clipboard
open fun setStyleScheme(scheme: StyleScheme? = null)

Sets a class@StyleScheme to be used by the buffer and the view.

Link copied to clipboard
open fun sortLines(start: <Error class: unknown class>, end: <Error class: unknown class>, flags: SortFlags, column: Int)

Sort the lines of text between the specified iterators.