Class
GtkSourceBuffer
Description
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:
- The tag doesn’t always exist, you need to listen to the
GtkTextTagTable::tag-added
andGtkTextTagTable::tag-removed
signals. - Instead of the
GtkSourceBuffer::highlight-updated
signal, you can listen to theGtkTextBuffer::apply-tag
andGtkTextBuffer::remove-tag
signals.
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_implicit_trailing_newline
gtk_source_buffer_get_language
Returns the GtkSourceLanguage
associated with the buffer,
see gtk_source_buffer_set_language()
.
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.
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
GtkSource.Buffer:style-scheme
Style scheme. It contains styles for syntax highlighting, optionally foreground, background, cursor color, current line color, and matching brackets style.
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
.
Class structure
struct GtkSourceBufferClass {
GtkTextBufferClass parent_class;
void (* bracket_matched) (
GtkSourceBuffer* buffer,
GtkTextIter* iter,
GtkSourceBracketMatchType state
);
}
Class members
parent_class |
|
No description available. | |
bracket_matched |
|
No description available. |