gtksource.buffer
Module for [Buffer] class
Types 3
Subclass of [gtk.text_buffer.TextBuffer].
A [gtksource.buffer.Buffer] object is the model for class@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 class@Language. You can also directly create a class@View and get its class@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 signal@GtkSource.Buffer::highlight-updated 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:
- 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-updatedsignal, 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 [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).
BufferGidBuilder builder()Get builder for [gtksource.buffer.Buffer] Returns: New builder objectbool highlightMatchingBrackets() @propertyGet `highlightMatchingBrackets` property. Returns: Whether to highlight matching brackets in the buffer.void highlightMatchingBrackets(bool propval) @propertySet `highlightMatchingBrackets` property. Params: propval = Whether to highlight matching brackets in the buffer.bool highlightSyntax() @propertyGet `highlightSyntax` property. Returns: Whether to highlight syntax in the buffer.void highlightSyntax(bool propval) @propertySet `highlightSyntax` property. Params: propval = Whether to highlight syntax in the buffer.bool implicitTrailingNewline() @propertyGet `implicitTrailingNewline` property. Returns: Whether the buffer has an implicit trailing newline. See [gtksource.buffer.Buffer.setImplicitTrailingNewline].void implicitTrailingNewline(bool propval) @propertySet `implicitTrailingNewline` property. Params: propval = Whether the buffer has an implicit trailing newline. See [gtksource.buffer.Buffer.setImplicitTrailingNewline].gtksource.language.Language language() @propertyvoid language(gtksource.language.Language propval) @propertybool loading() @propertyGet `loading` property. Returns: The "loading" property denotes that a [gtksource.file_loader.FileLoader] is currently loading the buffer.gtksource.style_scheme.StyleScheme styleScheme() @propertyGet `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) @propertySet `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)Creates a new source buffer using the highlighting patterns in `language`.bool backwardIterToSourceMark(gtk.text_iter.TextIter iter, string category = null)Moves `iter` to the position of the previous `classMark` of the given category.void changeCase(gtksource.types.ChangeCaseType caseType, gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)Changes the case of the text between the specified iterators.gtksource.mark.Mark createSourceMark(string name, string category, gtk.text_iter.TextIter where)Creates a source mark in the `buffer` of category `category`.void ensureHighlight(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)Forces buffer to analyze and highlight the given area synchronously.bool forwardIterToSourceMark(gtk.text_iter.TextIter iter, string category = null)Moves `iter` to the position of the next `classMark` of the given `category`.string[] getContextClassesAtIter(gtk.text_iter.TextIter iter)Get all defined context classes at iter.bool getHighlightMatchingBrackets()Determines whether bracket match highlighting is activated for the source buffer. Returns: true if the source buffer will highlight matching brackets.bool getHighlightSyntax()Determines whether syntax highlighting is activated in the source buffer. Returns: true if syntax highlighting is enabled, false otherwise.bool getImplicitTrailingNewline()gtksource.language.Language getLanguage()Returns the `classLanguage` associated with the buffer, see [gtksource.buffer.Buffer.setLanguage].bool getLoading()gtksource.mark.Mark[] getSourceMarksAtIter(gtk.text_iter.TextIter iter, string category = null)Returns the list of marks of the given category at iter.gtksource.mark.Mark[] getSourceMarksAtLine(int line, string category = null)Returns the list of marks of the given category at line.gtksource.style_scheme.StyleScheme getStyleScheme()Returns the `classStyleScheme` associated with the buffer, see [gtksource.buffer.Buffer.setStyleScheme].bool iterBackwardToContextClassToggle(gtk.text_iter.TextIter iter, string contextClass)Moves backward to the next toggle (on or off) of the context class.bool iterForwardToContextClassToggle(gtk.text_iter.TextIter iter, string contextClass)Moves forward to the next toggle (on or off) of the context class.bool iterHasContextClass(gtk.text_iter.TextIter iter, string contextClass)Check if the class context_class is set on iter.void joinLines(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)Joins the lines of text between the specified iterators.void removeSourceMarks(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end, string category = null)Remove all marks of category between start and end from the buffer.void setHighlightMatchingBrackets(bool highlight)Controls the bracket match highlighting function in the buffer.void setHighlightSyntax(bool highlight)Controls whether syntax is highlighted in the buffer.void setImplicitTrailingNewline(bool implicitTrailingNewline)Sets whether the buffer has an implicit trailing newline.void setLanguage(gtksource.language.Language language = null)Associates a `classLanguage` with the buffer.void setStyleScheme(gtksource.style_scheme.StyleScheme scheme = null)Sets a `classStyleScheme` 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)Sort 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)Connect 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)Connect 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)Connect 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)Connect to `SourceMarkUpdated` signal.this(gtk.text_tag_table.TextTagTable table = null)Creates a new source buffer.T highlightMatchingBrackets(bool propval)Set `highlightMatchingBrackets` property. Params: propval = Whether to highlight matching brackets in the buffer. Returns: Builder instance for fluent chainingT highlightSyntax(bool propval)Set `highlightSyntax` property. Params: propval = Whether to highlight syntax in the buffer. Returns: Builder instance for fluent chainingT implicitTrailingNewline(bool propval)Set `implicitTrailingNewline` property. Params: propval = Whether the buffer has an implicit trailing newline. See [gtksource.buffer.Buffer.setImplicitTrailingNewline]. Returns: Builder instance fo...T language(gtksource.language.Language propval)T styleScheme(gtksource.style_scheme.StyleScheme propval)Set `styleScheme` property. Params: propval = Style scheme. It contains styles for syntax highlighting, optionally foreground, background, cursor color, current line color, and matching brackets st...