gtksource.buffer

Module for [Buffer] class

Types 3

Subclass of gtk.text_buffer.TextBuffer.

A gtksource.buffer.Buffer object is the model for gtksource.view.View widgets. It extends the gtk.text_buffer.TextBuffer class by adding features useful to display and edit source code such as syntax highlighting and bracket matching.

To create a gtksource.buffer.Buffer use gtksource.buffer.Buffer.new_ or gtksource.buffer.Buffer.newWithLanguage. The second form is just a convenience function which allows you to initially set a gtksource.language.Language. You can also directly create a gtksource.view.View and get its gtksource.buffer.Buffer with gtk.text_view.TextView.getBuffer.

The highlighting is enabled by default, but you can disable it with gtksource.buffer.Buffer.setHighlightSyntax.

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 gtksource.buffer.Buffer:

  • 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 gtksource.buffer.Buffer.iterHasContextClass take a string parameter as the context class.

gtksource.buffer.Buffer provides an API to access the context classes: gtksource.buffer.Buffer.iterHasContextClass, gtksource.buffer.Buffer.getContextClassesAtIter, gtksource.buffer.Buffer.iterForwardToContextClassToggle and gtksource.buffer.Buffer.iterBackwardToContextClassToggle.

And the gtksource.buffer.Buffer.highlightUpdated signal permits to be notified when a context class region changes.

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

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

Methods
GType _getGType() static nothrow
GType _gType() @property nothrow
Buffer self() nothrowReturns `this`, for use in `with` statements.
BufferGidBuilder builder() static nothrowGet builder for [gtksource.buffer.Buffer] Returns: New builder object
bool highlightMatchingBrackets() @property nothrowGet `highlightMatchingBrackets` property. Returns: Whether to highlight matching brackets in the buffer.
void highlightMatchingBrackets(bool propval) @property nothrowSet `highlightMatchingBrackets` property. Params: propval = Whether to highlight matching brackets in the buffer.
bool highlightSyntax() @property nothrowGet `highlightSyntax` property. Returns: Whether to highlight syntax in the buffer.
void highlightSyntax(bool propval) @property nothrowSet `highlightSyntax` property. Params: propval = Whether to highlight syntax in the buffer.
bool implicitTrailingNewline() @property nothrowGet `implicitTrailingNewline` property. Returns: Whether the buffer has an implicit trailing newline. See [gtksource.buffer.Buffer.setImplicitTrailingNewline].
void implicitTrailingNewline(bool propval) @property nothrowSet `implicitTrailingNewline` property. Params: propval = Whether the buffer has an implicit trailing newline. See [gtksource.buffer.Buffer.setImplicitTrailingNewline].
void language(gtksource.language.Language propval) @property nothrow
bool loading() @property nothrowGet `loading` property. Returns: The "loading" property denotes that a [gtksource.file_loader.FileLoader] is currently loading the buffer.
gtksource.style_scheme.StyleScheme styleScheme() @property nothrowGet `styleScheme` property. Returns: Style scheme. It contains styles for syntax highlighting, optionally foreground, background, cursor color, current line color, and matching brackets style.
void styleScheme(gtksource.style_scheme.StyleScheme propval) @property nothrowSet `styleScheme` property. Params: propval = Style scheme. It contains styles for syntax highlighting, optionally foreground, background, cursor color, current line color, and matching brackets st...
gtksource.buffer.Buffer newWithLanguage(gtksource.language.Language language) static nothrowCreates a new source buffer using the highlighting patterns in `language`.
bool backwardIterToSourceMark(gtk.text_iter.TextIter iter, string category = null) nothrowMoves `iter` to the position of the previous [gtksource.mark.Mark] of the given category.
void changeCase(gtksource.types.ChangeCaseType caseType, gtk.text_iter.TextIter start, gtk.text_iter.TextIter end) nothrowChanges the case of the text between the specified iterators.
gtksource.mark.Mark createSourceMark(string name, string category, gtk.text_iter.TextIter where) nothrowCreates a source mark in the `buffer` of category `category`.
void ensureHighlight(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end) nothrowForces buffer to analyze and highlight the given area synchronously.
bool forwardIterToSourceMark(gtk.text_iter.TextIter iter, string category = null) nothrowMoves `iter` to the position of the next [gtksource.mark.Mark] of the given `category`.
string[] getContextClassesAtIter(gtk.text_iter.TextIter iter) nothrowGet all defined context classes at iter.
bool getHighlightMatchingBrackets() nothrowDetermines whether bracket match highlighting is activated for the source buffer. Returns: true if the source buffer will highlight matching brackets.
bool getHighlightSyntax() nothrowDetermines whether syntax highlighting is activated in the source buffer. Returns: true if syntax highlighting is enabled, false otherwise.
gtksource.language.Language getLanguage() nothrowReturns the [gtksource.language.Language] associated with the buffer, see [gtksource.buffer.Buffer.setLanguage].
bool getLoading() nothrow
gtksource.mark.Mark[] getSourceMarksAtIter(gtk.text_iter.TextIter iter, string category = null) nothrowReturns the list of marks of the given category at iter.
gtksource.mark.Mark[] getSourceMarksAtLine(int line, string category = null) nothrowReturns the list of marks of the given category at line.
gtksource.style_scheme.StyleScheme getStyleScheme() nothrowReturns the [gtksource.style_scheme.StyleScheme] associated with the buffer, see [gtksource.buffer.Buffer.setStyleScheme].
bool iterBackwardToContextClassToggle(gtk.text_iter.TextIter iter, string contextClass) nothrowMoves backward to the next toggle (on or off) of the context class.
bool iterForwardToContextClassToggle(gtk.text_iter.TextIter iter, string contextClass) nothrowMoves forward to the next toggle (on or off) of the context class.
bool iterHasContextClass(gtk.text_iter.TextIter iter, string contextClass) nothrowCheck if the class context_class is set on iter.
void joinLines(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end) nothrowJoins the lines of text between the specified iterators.
void removeSourceMarks(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end, string category = null) nothrowRemove all marks of category between start and end from the buffer.
void setHighlightMatchingBrackets(bool highlight) nothrowControls the bracket match highlighting function in the buffer.
void setHighlightSyntax(bool highlight) nothrowControls whether syntax is highlighted in the buffer.
void setImplicitTrailingNewline(bool implicitTrailingNewline) nothrowSets whether the buffer has an implicit trailing newline.
void setLanguage(gtksource.language.Language language = null) nothrowAssociates a [gtksource.language.Language] with the buffer.
void setStyleScheme(gtksource.style_scheme.StyleScheme scheme = null) nothrowSets a [gtksource.style_scheme.StyleScheme] to be used by the buffer and the view.
void sortLines(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end, gtksource.types.SortFlags flags, int column) nothrowSort the lines of text between the specified iterators.
gulong connectBracketMatched(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.text_iter.TextIter))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == gtksource.types.BracketMatchType))) && (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtksource.buffer.Buffer))) && Parameters!T.length < 4) nothrowConnect to `BracketMatched` signal.
gulong connectCursorMoved(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtksource.buffer.Buffer))) && Parameters!T.length < 2) nothrowConnect to `CursorMoved` signal.
gulong connectHighlightUpdated(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.text_iter.TextIter))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == gtk.text_iter.TextIter))) && (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtksource.buffer.Buffer))) && Parameters!T.length < 4) nothrowConnect to `HighlightUpdated` signal.
gulong connectSourceMarkUpdated(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.text_mark.TextMark))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtksource.buffer.Buffer))) && Parameters!T.length < 3) nothrowConnect to `SourceMarkUpdated` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this(gtk.text_tag_table.TextTagTable table = null)Creates a new source buffer.

Fluent builder implementation template for gtksource.buffer.Buffer

Methods
T highlightMatchingBrackets(bool propval) nothrowSet `highlightMatchingBrackets` property. Params: propval = Whether to highlight matching brackets in the buffer. Returns: Builder instance for fluent chaining
T highlightSyntax(bool propval) nothrowSet `highlightSyntax` property. Params: propval = Whether to highlight syntax in the buffer. Returns: Builder instance for fluent chaining
T implicitTrailingNewline(bool propval) nothrowSet `implicitTrailingNewline` property. Params: propval = Whether the buffer has an implicit trailing newline. See [gtksource.buffer.Buffer.setImplicitTrailingNewline]. Returns: Builder instance fo...
T styleScheme(gtksource.style_scheme.StyleScheme propval) nothrowSet `styleScheme` property. Params: propval = Style scheme. It contains styles for syntax highlighting, optionally foreground, background, cursor color, current line color, and matching brackets st...

Fluent builder for gtksource.buffer.Buffer

Methods
Buffer build() nothrowCreate object from builder. Returns: New object