gtksource.c.types

C types for gtksource5 library

struct GtkSourceBuffer GtkSourceBufferClass GtkSourceCompletion GtkSourceCompletionCell GtkSourceCompletionCellClass GtkSourceCompletionClass GtkSourceCompletionContext GtkSourceCompletionContextClass GtkSourceCompletionProposal GtkSourceCompletionProposalInterface GtkSourceCompletionProvider GtkSourceCompletionProviderInterface GtkSourceCompletionSnippets GtkSourceCompletionSnippetsClass GtkSourceCompletionWords GtkSourceCompletionWordsClass GtkSourceEncoding GtkSourceFile GtkSourceFileClass GtkSourceFileLoader GtkSourceFileLoaderClass GtkSourceFileSaver GtkSourceFileSaverClass GtkSourceGutter GtkSourceGutterClass GtkSourceGutterLines GtkSourceGutterLinesClass GtkSourceGutterRenderer GtkSourceGutterRendererClass GtkSourceGutterRendererPixbuf GtkSourceGutterRendererPixbufClass GtkSourceGutterRendererText GtkSourceGutterRendererTextClass GtkSourceHover GtkSourceHoverClass GtkSourceHoverContext GtkSourceHoverContextClass GtkSourceHoverDisplay GtkSourceHoverDisplayClass GtkSourceHoverProvider GtkSourceHoverProviderInterface GtkSourceIndenter GtkSourceIndenterInterface GtkSourceLanguage GtkSourceLanguageClass GtkSourceLanguageManager GtkSourceLanguageManagerClass GtkSourceMap GtkSourceMapClass GtkSourceMark GtkSourceMarkAttributes GtkSourceMarkAttributesClass GtkSourceMarkClass GtkSourcePrintCompositor GtkSourcePrintCompositorClass GtkSourceRegion GtkSourceRegionClass GtkSourceRegionIter GtkSourceSearchContext GtkSourceSearchContextClass GtkSourceSearchSettings GtkSourceSearchSettingsClass GtkSourceSnippet GtkSourceSnippetChunk GtkSourceSnippetChunkClass GtkSourceSnippetClass GtkSourceSnippetContext GtkSourceSnippetContextClass GtkSourceSnippetManager GtkSourceSnippetManagerClass GtkSourceSpaceDrawer GtkSourceSpaceDrawerClass GtkSourceStyle GtkSourceStyleClass GtkSourceStyleScheme GtkSourceStyleSchemeChooser GtkSourceStyleSchemeChooserButton GtkSourceStyleSchemeChooserButtonClass GtkSourceStyleSchemeChooserInterface GtkSourceStyleSchemeChooserWidget GtkSourceStyleSchemeChooserWidgetClass GtkSourceStyleSchemeClass GtkSourceStyleSchemeManager GtkSourceStyleSchemeManagerClass GtkSourceStyleSchemePreview GtkSourceStyleSchemePreviewClass GtkSourceTag GtkSourceTagClass GtkSourceView GtkSourceViewClass GtkSourceVimIMContext GtkSourceVimIMContextClass

Types 110

None = 0no pattern
Grid = 1grid pattern
None = 0there is no bracket to match.
OutOfRange = 1matching a bracket failed because the maximum range was reached.
NotFound = 2a matching bracket was not found.
Found = 3a matching bracket was found.
Lower = 0change case to lowercase.
Upper = 1change case to uppercase.
Toggle = 2toggle case of each character.
Title = 3capitalize each word.
None = 0
Interactive = 1
UserRequested = 2
Icon = 0
Before = 1
TypedText = 2
After = 3
Comment = 4
Details = 5
None = 0plain text.
Gzip = 1gzip compression.

An error code used with the GTK_SOURCE_FILE_LOADER_ERROR domain.

TooBig = 0The file is too big.
EncodingAutoDetectionFailed = 1It is not possible to detect the encoding automatically.
ConversionFallback = 2There was an encoding conversion error and it was needed to use a fallback character.

An error code used with the GTK_SOURCE_FILE_SAVER_ERROR domain.

InvalidChars = 0The buffer contains invalid characters.
ExternallyModified = 1The file is externally modified.

Flags to define the behavior of a gtksource.types.FileSaverFlags.

None = 0No flags.
IgnoreInvalidChars = 1Ignore invalid characters.
IgnoreModificationTime = 2Save file despite external modifications.
CreateBackup = 4Create a backup before saving the file.

The alignment mode of the renderer, when a cell spans multiple lines (due to text wrapping).

Cell = 0The full cell.
First = 1The first line.
Last = 2The last line.
Lf = 0line feed, used on UNIX.
Cr = 1carriage return, used on Mac.
CrLf = 2carriage return followed by a line feed, used on Windows.
Disabled = 0smart-home-end disabled.
Before = 1move to the first/last non-whitespace character on the first press of the HOME/END keys and to the beginning/end of the line on the second press.
After = 2move to the beginning/end of the line on the first press of the HOME/END keys and to the first/last non-whitespace character on the second press.
Always = 3always move to the first/last non-whitespace character when the HOME/END keys are pressed.
None = 0no flags specified
CaseSensitive = 1case sensitive sort
ReverseOrder = 2sort in reverse order
RemoveDuplicates = 4remove duplicates

#GtkSourceSpaceLocationFlags contains flags for white space locations.

If a line contains only white spaces (no text), the white spaces match both gtksource.types.SpaceLocationFlags.Leading and gtksource.types.SpaceLocationFlags.Trailing.

None = 0No flags.
Leading = 1Leading white spaces on a line, i.e. the indentation.
InsideText = 2White spaces inside a line of text.
Trailing = 4Trailing white spaces on a line.
All = 7White spaces anywhere.

#GtkSourceSpaceTypeFlags contains flags for white space types.

None = 0No flags.
Space = 1Space character.
Tab = 2Tab character.
Newline = 4Line break character. If the #GtkSourceBuffer:implicit-trailing-newline property is true, #GtkSourceSpaceDrawer also draws a line break at the end of the buffer.
Nbsp = 8Non-breaking space character.
All = 15All white spaces.
Lines = - 30the gutter position of the lines renderer
Marks = - 20the gutter position of the marks renderer

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).

Fields
GtkTextBuffer parentInstance
Fields
GtkTextBufferClass parentClass
void function(GtkSourceBuffer * buffer, GtkTextIter * iter, GtkSourceBracketMatchType state) bracketMatched
void *[20] Reserved

Main Completion Object.

The completion system helps the user when they writes some text, such as words, command names, functions, and suchlike. Proposals can be shown, to complete the text the user is writing. Each proposal can contain an additional piece of information (for example documentation), that is displayed when the "Details" button is clicked.

Proposals are created via a gtksource.completion_provider.CompletionProvider. There can be for example a provider to complete words (see gtksource.completion_words.CompletionWords), another provider for the completion of function names, etc. To add a provider, call gtksource.completion.Completion.addProvider.

The gtksource.completion_proposal.CompletionProposal interface represents a proposal.

If a proposal contains extra information (see gtksource.types.CompletionColumn.Details), it will be displayed in a supplemental details window, which appears when the "Details" button is clicked.

Each gtksource.view.View object is associated with a gtksource.completion.Completion instance. This instance can be obtained with gtksource.view.View.getCompletion. The gtksource.view.View class contains also the gtksource.view.View.showCompletion signal.

A same gtksource.completion_provider.CompletionProvider object can be used for several gtksource.completion.Completion's.

Widget for single cell of completion proposal.

The gtksource.completion_cell.CompletionCell widget provides a container to display various types of information with the completion display.

Each proposal may consist of multiple cells depending on the complexity of the proposal. For example, programming language proposals may contain a cell for the "left-hand-side" of an operation along with the "typed-text" for a function name and "parameters". They may also optionally set an icon to signify the kind of result.

A gtksource.completion_provider.CompletionProvider should implement the vfunc@CompletionProvider.display virtual function to control how to convert data from their gtksource.completion_proposal.CompletionProposal to content for the gtksource.completion_cell.CompletionCell.

Fields
GObjectClass parentClass

The context of a completion.

gtksource.completion_context.CompletionContext contains information about an attept to display completion proposals to the user based on typed text in the gtksource.view.View.

When typing, gtksource.completion.Completion may use registered gtksource.completion_provider.CompletionProvider to determine if there may be results which could be displayed. If so, a gtksource.completion_context.CompletionContext is created with information that is provided to the gtksource.completion_provider.CompletionProvider to populate results which might be useful to the user.

gtksource.completion_provider.CompletionProvider are expected to provide gio.list_model.ListModel with gtksource.completion_proposal.CompletionProposal which may be joined together in a list of results for the user. They are also responsible for how the contents are displayed using gtksource.completion_cell.CompletionCell which allows for some level of customization.

Interface for completion proposals.

This interface is used to denote that an object is capable of being a completion proposal for gtksource.completion.Completion.

Currently, no method or functions are required but additional methods may be added in the future. Proposals created by #GtkSourceCompletionProvider can use func@GObject.IMPLEMENT_INTERFACE to implement this with null for the interface init function.

Fields
GTypeInterface parentIface
char * function(GtkSourceCompletionProposal * proposal) getTypedText

Completion provider interface.

You must implement this interface to provide proposals to gtksource.completion.Completion.

In most cases, implementations of this interface will want to use vfunc@CompletionProvider.populate_async to asynchronously populate the results to avoid blocking the main loop.

Fields
GTypeInterface parentIface
char * function(GtkSourceCompletionProvider * self) getTitle
int function(GtkSourceCompletionProvider * self, GtkSourceCompletionContext * context) getPriority
gboolean function(GtkSourceCompletionProvider * self, const(GtkTextIter) * iter, dchar ch) isTrigger
gboolean function(GtkSourceCompletionProvider * self, GtkSourceCompletionContext * context, GtkSourceCompletionProposal * proposal, uint keyval, GdkModifierType state) keyActivates
GListModel * function(GtkSourceCompletionProvider * self, GtkSourceCompletionContext * context, GError * * _err) populate
void function(GtkSourceCompletionProvider * self, GtkSourceCompletionContext * context, GCancellable * cancellable, GAsyncReadyCallback callback, void * userData) populateAsync
GListModel * function(GtkSourceCompletionProvider * self, GAsyncResult * result, GError * * _err) populateFinish
void function(GtkSourceCompletionProvider * self, GtkSourceCompletionContext * context, GListModel * model) refilter
void function(GtkSourceCompletionProvider * self, GtkSourceCompletionContext * context, GtkSourceCompletionProposal * proposal) activate
GPtrArray * function(GtkSourceCompletionProvider * self, GtkSourceCompletionContext * context, GtkSourceCompletionProposal * proposal) listAlternates

A gtksource.completion_provider.CompletionProvider for the completion of snippets.

The gtksource.completion_snippets.CompletionSnippets is an example of an implementation of the gtksource.completion_provider.CompletionProvider interface. The proposals are snippets registered with the gtksource.snippet_manager.SnippetManager.

Fields
GObject parentInstance
Fields
GObjectClass parentClass
void *[10] Reserved

A gtksource.completion_provider.CompletionProvider for the completion of words.

The gtksource.completion_words.CompletionWords is an example of an implementation of the gtksource.completion_provider.CompletionProvider interface. The proposals are words appearing in the registered gtk.text_buffer.TextBuffers.

Fields
GObject parentInstance
Fields
GObjectClass parentClass
void *[10] Reserved

Character encoding.

The #GtkSourceEncoding boxed type represents a character encoding. It is used for example by #GtkSourceFile. Note that the text in GTK widgets is always encoded in UTF-8.

On-disk representation of a gtksource.buffer.Buffer.

A gtksource.file.File object is the on-disk representation of a gtksource.buffer.Buffer. With a gtksource.file.File, you can create and configure a gtksource.file_loader.FileLoader and gtksource.file_saver.FileSaver which take by default the values of the gtksource.file.File properties (except for the file loader which auto-detect some properties). On a successful load or save operation, the gtksource.file.File properties are updated. If an operation fails, the gtksource.file.File properties have still the previous valid values.

Fields
GObject parentInstance
Fields
GObjectClass parentClass
void *[10] Reserved

Load a file into a GtkSourceBuffer.

A gtksource.file_loader.FileLoader object permits to load the contents of a gio.file.File or a gio.input_stream.InputStream into a gtksource.buffer.Buffer.

A file loader should be used only for one load operation, including errors handling. If an error occurs, you can reconfigure the loader and relaunch the operation with gtksource.file_loader.FileLoader.loadAsync.

Running a gtksource.file_loader.FileLoader is an undoable action for the gtksource.buffer.Buffer.

After a file loading, the buffer is reset to the contents provided by the gio.file.File or gio.input_stream.InputStream, so the buffer is set as “unmodified”, that is, gtk.text_buffer.TextBuffer.setModified is called with false. If the contents isn't saved somewhere (for example if you load from stdin), then you should probably call gtk.text_buffer.TextBuffer.setModified with true after calling gtksource.file_loader.FileLoader.loadFinish.

Fields
GObjectClass parentClass

Save a gtksource.buffer.Buffer into a file.

A gtksource.file_saver.FileSaver object permits to save a gtksource.buffer.Buffer into a gio.file.File.

A file saver should be used only for one save operation, including errors handling. If an error occurs, you can reconfigure the saver and relaunch the operation with gtksource.file_saver.FileSaver.saveAsync.

Fields
GObjectClass parentClass

Gutter object for gtksource.view.View.

The gtksource.gutter.Gutter object represents the left or right gutter of the text view. It is used by gtksource.view.View to draw the line numbers and gtksource.mark.Marks that might be present on a line. By packing additional gtksource.gutter_renderer.GutterRenderer objects in the gutter, you can extend the gutter with your own custom drawings.

To get a gtksource.gutter.Gutter, use the gtksource.view.View.getGutter function.

The gutter works very much the same way as cells rendered in a gtk.tree_view.TreeView. The concept is similar, with the exception that the gutter does not have an underlying gtk.tree_model.TreeModel. The builtin line number renderer is at position gtksource.types.ViewGutterPosition.Lines (-30) and the marks renderer is at gtksource.types.ViewGutterPosition.Marks (-20). The gutter sorts the renderers in ascending order, from left to right. So the marks are displayed on the right of the line numbers.

Fields
GtkWidgetClass parentClass

Collected information about visible lines.

The gtksource.gutter_lines.GutterLines object is used to collect information about visible lines.

Use this from your gtksource.gutter_renderer.GutterRenderer.queryData to collect the necessary information on visible lines. Doing so reduces the number of passes through the text btree allowing GtkSourceView to reach more frames-per-second while performing kinetic scrolling.

Gutter cell renderer.

A gtksource.gutter_renderer.GutterRenderer represents a column in a gtksource.gutter.Gutter. The column contains one cell for each visible line of the gtk.text_buffer.TextBuffer. Due to text wrapping, a cell can thus span multiple lines of the gtk.text_view.TextView. In this case, gtksource.types.GutterRendererAlignmentMode controls the alignment of the cell.

The gutter renderer is a gtk.widget.Widget and is measured using the normal widget measurement facilities. The width of the gutter will be determined by the measurements of the gutter renderers.

The width of a gutter renderer generally takes into account the entire text buffer. For instance, to display the line numbers, if the buffer contains 100 lines, the gutter renderer will always set its width such as three digits can be printed, even if only the first 20 lines are shown. Another strategy is to take into account only the visible lines. In this case, only two digits are necessary to display the line numbers of the first 20 lines. To take another example, the gutter renderer for gtksource.mark.Marks doesn't need to take into account the text buffer to announce its width. It only depends on the icons size displayed in the gutter column.

When the available size to render a cell is greater than the required size to render the cell contents, the cell contents can be aligned horizontally and vertically with gtksource.gutter_renderer.GutterRenderer.setAlignmentMode.

The cells rendering occurs using vfunc@Gtk.Widget.snapshot. Implementations should use gtk_source_gutter_renderer_get_lines() to retrieve information about the lines to be rendered. To help with aligning content which takes into account the padding and alignment of a cell, implementations may call gtksource.gutter_renderer.GutterRenderer.alignCell for a given line number with the width and height measurement of the content they width to render.

Fields
GtkWidget parentInstance
Fields
GtkWidgetClass parentClass
void function(GtkSourceGutterRenderer * renderer, GtkSourceGutterLines * lines, uint line) queryData
void function(GtkSourceGutterRenderer * renderer, GtkSourceGutterLines * lines) begin
void function(GtkSourceGutterRenderer * renderer, GtkSnapshot * snapshot, GtkSourceGutterLines * lines, uint line) snapshotLine
void function(GtkSourceGutterRenderer * renderer) end
void function(GtkSourceGutterRenderer * renderer, GtkSourceView * oldView) changeView
void function(GtkSourceGutterRenderer * renderer, GtkSourceBuffer * oldBuffer) changeBuffer
gboolean function(GtkSourceGutterRenderer * renderer, GtkTextIter * iter, GdkRectangle * area) queryActivatable
void function(GtkSourceGutterRenderer * renderer, GtkTextIter * iter, GdkRectangle * area, uint button, GdkModifierType state, int nPresses) activate
void *[20] Reserved

Renders a pixbuf in the gutter.

A gtksource.gutter_renderer_pixbuf.GutterRendererPixbuf can be used to render an image in a cell of gtksource.gutter.Gutter.

Fields
Fields
void *[10] Reserved

Renders text in the gutter.

A gtksource.gutter_renderer_text.GutterRendererText can be used to render text in a cell of gtksource.gutter.Gutter.

Fields
Fields
void *[10] Reserved

Interactive tooltips.

gtksource.hover.Hover allows a gtksource.view.View to provide contextual information. When enabled, if the user hovers over a word in the text editor, a series of registered gtksource.hover_provider.HoverProvider can populate a gtksource.hover_display.HoverDisplay with useful information.

To enable call gtksource.view.View.getHover and add gtksource.hover_provider.HoverProvider using gtksource.hover.Hover.addProvider. To disable, remove all registered providers with gtksource.hover.Hover.removeProvider.

You can change how long to wait to display the interactive tooltip by setting the gtksource.hover.Hover.hoverDelay property in milliseconds.

Fields
GObjectClass parentClass

Context for populating gtksource.hover_display.HoverDisplay contents.

gtksource.hover_context.HoverContext contains information about the request to populate contents for a gtksource.hover_display.HoverDisplay.

It can be used to retrieve the gtksource.view.View, gtksource.buffer.Buffer, and gtk.text_iter.TextIter for the regions of text which are being displayed.

Use gtksource.hover_context.HoverContext.getBounds to get the word that was requested. gtksource.hover_context.HoverContext.getIter will get you the location of the pointer when the request was made.

Display for interactive tooltips.

gtksource.hover_display.HoverDisplay is a gtk.widget.Widget that may be populated with widgets to be displayed to the user in interactive tooltips. The children widgets are packed vertically using a gtk.box.Box.

Implement the gtksource.hover_provider.HoverProvider interface to be notified of when to populate a gtksource.hover_display.HoverDisplay on behalf of the user.

Interface to populate interactive tooltips.

gtksource.hover_provider.HoverProvider is an interface that should be implemented to extend the contents of a gtksource.hover_display.HoverDisplay. This is typical in editors that interact external tooling such as those utilizing Language Server Protocol.

If you can populate the gtksource.hover_display.HoverDisplay synchronously, use vfunc@HoverProvider.populate. Otherwise, interface implementations that may take additional time should use vfunc@HoverProvider.populate_async to avoid blocking the main loop.

Fields
GTypeInterface parentIface
gboolean function(GtkSourceHoverProvider * self, GtkSourceHoverContext * context, GtkSourceHoverDisplay * display, GError * * _err) populate
void function(GtkSourceHoverProvider * self, GtkSourceHoverContext * context, GtkSourceHoverDisplay * display, GCancellable * cancellable, GAsyncReadyCallback callback, void * userData) populateAsync
gboolean function(GtkSourceHoverProvider * self, GAsyncResult * result, GError * * _err) populateFinish

Auto-indentation interface.

By default, gtksource.view.View can auto-indent as you type when gtksource.view.View.autoIndent is enabled. The indentation simply copies the previous lines indentation.

This can be changed by implementing gtksource.indenter.Indenter and setting the gtksource.view.View.indenter property.

Implementors of this interface should implement both vfunc@Indenter.is_trigger and vfunc@Indenter.indent.

vfunc@Indenter.is_trigger is called upon key-press to determine of the key press should trigger an indentation. The default implementation of the interface checks to see if the key was gdk.types.KEY_Return or gdk.types.KEY_KP_Enter without gdk.types.ModifierType.ShiftMask set.

vfunc@Indenter.indent is called after text has been inserted into gtksource.buffer.Buffer when vfunc@Indenter.is_trigger returned true. The gtk.text_iter.TextIter is placed directly after the inserted character or characters.

It may be beneficial to move the insertion mark using gtk.text_buffer.TextBuffer.selectRange depending on how the indenter changes the indentation.

All changes are encapsulated within a single user action so that the user may undo them using standard undo/redo accelerators.

The virtual function table for #GtkSourceIndenter.

Fields
GTypeInterface parentIface
gboolean function(GtkSourceIndenter * self, GtkSourceView * view, const(GtkTextIter) * location, GdkModifierType state, uint keyval) isTriggerthe virtual function pointer for [gtksource.indenter.Indenter.isTrigger]
void function(GtkSourceIndenter * self, GtkSourceView * view, GtkTextIter * iter) indentthe virtual function pointer for [gtksource.indenter.Indenter.indent]

Represents a syntax highlighted language.

A gtksource.language.Language represents a programming or markup language, affecting syntax highlighting and context classes.

Use gtksource.language_manager.LanguageManager to obtain a gtksource.language.Language instance, and gtksource.buffer.Buffer.setLanguage to apply it to a gtksource.buffer.Buffer.

Fields
GObjectClass parentClass

Provides access to gtksource.language.Languages.

gtksource.language_manager.LanguageManager is an object which processes language description files and creates and stores gtksource.language.Language objects, and provides API to access them.

Use gtksource.language_manager.LanguageManager.getDefault to retrieve the default instance of gtksource.language_manager.LanguageManager, and gtksource.language_manager.LanguageManager.guessLanguage to get a gtksource.language.Language for given file name and content type.

Widget that displays a map for a specific gtksource.view.View.

gtksource.map.Map is a widget that maps the content of a gtksource.view.View into a smaller view so the user can have a quick overview of the whole document.

This works by connecting a gtksource.view.View to to the gtksource.map.Map using the gtksource.map.Map.view property or gtksource.map.Map.setView.

gtksource.map.Map is a gtksource.view.View object. This means that you can add a gtksource.gutter_renderer.GutterRenderer to a gutter in the same way you would for a gtksource.view.View. One example might be a gtksource.gutter_renderer.GutterRenderer that shows which lines have changed in the document.

Additionally, it is desirable to match the font of the gtksource.map.Map and the gtksource.view.View used for editing. Therefore, gtksource.map.Map.fontDesc should be used to set the target font. You will need to adjust this to the desired font size for the map. A 1pt font generally seems to be an appropriate font size. "Monospace 1" is the default. See pango.font_description.FontDescription.setSize for how to alter the size of an existing pango.font_description.FontDescription.

When FontConfig is available, gtksource.map.Map will try to use a bundled "block" font to make the map more legible.

Fields
GtkSourceView parentInstance
Fields
GtkSourceViewClass parentClass
void *[10] Reserved

Mark object for gtksource.buffer.Buffer.

A gtksource.mark.Mark marks a position in the text where you want to display additional info. It is based on gtk.text_mark.TextMark and thus is still valid after the text has changed though its position may change.

gtksource.mark.Marks are organized in categories which you have to set when you create the mark. Each category can have a priority, a pixbuf and other associated attributes. See gtksource.view.View.setMarkAttributes. The pixbuf will be displayed in the margin at the line where the mark residents if the gtksource.view.View.showLineMarks property is set to true. If there are multiple marks in the same line, the pixbufs will be drawn on top of each other. The mark with the highest priority will be drawn on top.

Fields
GtkTextMark parentInstance

The source mark attributes object.

gtksource.mark_attributes.MarkAttributes is an object specifying attributes used by a gtksource.view.View to visually show lines marked with gtksource.mark.Marks of a specific category. It allows you to define a background color of a line, an icon shown in gutter and tooltips.

The background color is used as a background of a line where a mark is placed and it can be set with gtksource.mark_attributes.MarkAttributes.setBackground. To check if any custom background color was defined and what color it is, use gtksource.mark_attributes.MarkAttributes.getBackground.

An icon is a graphic element which is shown in the gutter of a view. An example use is showing a red filled circle in a debugger to show that a breakpoint was set in certain line. To get an icon that will be placed in a gutter, first a base for it must be specified and then gtksource.mark_attributes.MarkAttributes.renderIcon must be called. There are several ways to specify a base for an icon:

Using any of the above functions overrides the one used earlier. But note that a getter counterpart of earlier used function can still return some value, but it is just not used when rendering the proper icon.

To provide meaningful tooltips for a given mark of a category, you should connect to gtksource.mark_attributes.MarkAttributes.queryTooltipText or gtksource.mark_attributes.MarkAttributes.queryTooltipMarkup where the latter takes precedence.

Fields
GtkTextMarkClass parentClass
void *[10] Reserved

Compose a gtksource.buffer.Buffer for printing.

The gtksource.print_compositor.PrintCompositor object is used to compose a gtksource.buffer.Buffer for printing. You can set various configuration options to customize the printed output. gtksource.print_compositor.PrintCompositor is designed to be used with the high-level printing API of gtk+, i.e. gtk.print_operation.PrintOperation.

The margins specified in this object are the layout margins: they define the blank space bordering the printed area of the pages. They must not be confused with the "print margins", i.e. the parts of the page that the printer cannot print on, defined in the gtk.page_setup.PageSetup objects. If the specified layout margins are smaller than the "print margins", the latter ones are used as a fallback by the gtksource.print_compositor.PrintCompositor object, so that the printed area is not clipped.

Fields
GObject parentInstance
Fields
GObjectClass parentClass
void *[10] Reserved

Region utility.

A gtksource.region.Region permits to store a group of subregions of a gtk.text_buffer.TextBuffer. gtksource.region.Region stores the subregions with pairs of gtk.text_mark.TextMark's, so the region is still valid after insertions and deletions in the gtk.text_buffer.TextBuffer.

The gtk.text_mark.TextMark for the start of a subregion has a left gravity, while the gtk.text_mark.TextMark for the end of a subregion has a right gravity.

The typical use-case of gtksource.region.Region is to scan a gtk.text_buffer.TextBuffer chunk by chunk, not the whole buffer at once to not block the user interface. The gtksource.region.Region represents in that case the remaining region to scan. You can listen to the gtk.text_buffer.TextBuffer.insertText and gtk.text_buffer.TextBuffer.deleteRange signals to update the gtksource.region.Region accordingly.

To iterate through the subregions, you need to use a gtksource.region_iter.RegionIter, for example:

GtkSourceRegion *region;
GtkSourceRegionIter region_iter;

gtk_source_region_get_start_region_iter (region, ®ion_iter);

while (!gtk_source_region_iter_is_end (&region_iter))
{
        GtkTextIter subregion_start;
        GtkTextIter subregion_end;

        if (!gtk_source_region_iter_get_subregion (&region_iter,
                                                   &subregion_start,
                                                   &subregion_end))
        {
                break;
        }

        // Do something useful with the subregion.

        gtk_source_region_iter_next (®ion_iter);
}

Fields
GObject parentInstance
Fields
GObjectClass parentClass
void *[10] Reserved

An opaque datatype.

Ignore all its fields and initialize the iter with gtksource.region.Region.getStartRegionIter.

Fields
void * dummy1
uint dummy2
void * dummy3

Search context.

A gtksource.search_context.SearchContext is used for the search and replace in a gtksource.buffer.Buffer. The search settings are represented by a gtksource.search_settings.SearchSettings object. There can be a many-to-many relationship between buffers and search settings, with the search contexts in-between: a search settings object can be shared between several search contexts; and a buffer can contain several search contexts at the same time.

The total number of search occurrences can be retrieved with gtksource.search_context.SearchContext.getOccurrencesCount. To know the position of a certain match, use gtksource.search_context.SearchContext.getOccurrencePosition.

The buffer is scanned asynchronously, so it doesn't block the user interface. For each search, the buffer is scanned at most once. After that, navigating through the occurrences doesn't require to re-scan the buffer entirely.

To search forward, use gtksource.search_context.SearchContext.forward or gtksource.search_context.SearchContext.forwardAsync for the asynchronous version. The backward search is done similarly. To replace a search match, or all matches, use gtksource.search_context.SearchContext.replace and gtksource.search_context.SearchContext.replaceAll.

The search occurrences are highlighted by default. To disable it, use gtksource.search_context.SearchContext.setHighlight. You can enable the search highlighting for several gtksource.search_context.SearchContexts attached to the same buffer. Moreover, each of those gtksource.search_context.SearchContexts can have a different text style associated. Use gtksource.search_context.SearchContext.setMatchStyle to specify the gtksource.style.Style to apply on search matches.

Note that the gtksource.search_context.SearchContext.highlight and gtksource.search_context.SearchContext.matchStyle properties are in the gtksource.search_context.SearchContext class, not gtksource.search_settings.SearchSettings. Appearance settings should be tied to one, and only one buffer, as different buffers can have different style scheme associated (a gtksource.search_settings.SearchSettings object can be bound indirectly to several buffers).

The concept of "current match" doesn't exist yet. A way to highlight differently the current match is to select it.

A search occurrence's position doesn't depend on the cursor position or other parameters. Take for instance the buffer "aaaa" with the search text "aa". The two occurrences are at positions 0:2 and 2:4. If you begin to search at position 1, you will get the occurrence 2:4, not 1:3. This is a prerequisite for regular expression searches. The pattern ".*" matches the entire line. If the cursor is at the middle of the line, you don't want the rest of the line as the occurrence, you want an entire line. (As a side note, regular expression searches can also match multiple lines.)

In the GtkSourceView source code, there is an example of how to use the search and replace API: see the tests/test-search.c file. It is a mini application for the search and replace, with a basic user interface.

Search settings.

A gtksource.search_settings.SearchSettings object represents the settings of a search. The search settings can be associated with one or several gtksource.search_context.SearchContexts.

Fields
GObject parentInstance
Fields
GObjectClass parentClass
void *[10] Reserved

Quick insertion code snippets.

The gtksource.snippet.Snippet represents a series of chunks that can quickly be inserted into the gtksource.view.View.

Snippets are defined in XML files which are loaded by the gtksource.snippet_manager.SnippetManager. Alternatively, applications can create snippets on demand and insert them into the gtksource.view.View using gtksource.view.View.pushSnippet.

Snippet chunks can reference other snippet chunks as well as post-process the values from other chunks such as capitalization.

A chunk of text within the source snippet.

The gtksource.snippet_chunk.SnippetChunk represents a single chunk of text that may or may not be an edit point within the snippet. Chunks that are an edit point (also called a tab stop) have the gtksource.snippet_chunk.SnippetChunk.focusPosition property set.

Fields
GObjectClass parentClass

Context for expanding gtksource.snippet_chunk.SnippetChunk.

This class is currently used primary as a hashtable. However, the longer term goal is to have it hold onto a GjsContext as well as other languages so that gtksource.snippet_chunk.SnippetChunk can expand themselves by executing script within the context.

The gtksource.snippet.Snippet will build the context and then expand each of the chunks during the insertion/edit phase.

Provides access to gtksource.snippet.Snippet.

gtksource.snippet_manager.SnippetManager is an object which processes snippet description files and creates gtksource.snippet.Snippet objects.

Use gtksource.snippet_manager.SnippetManager.getDefault to retrieve the default instance of gtksource.snippet_manager.SnippetManager.

Use gtksource.snippet_manager.SnippetManager.getSnippet to retrieve snippets for a given snippets.

Represent white space characters with symbols.

#GtkSourceSpaceDrawer provides a way to visualize white spaces, by drawing symbols.

Call gtksource.view.View.getSpaceDrawer to get the gtksource.space_drawer.SpaceDrawer instance of a certain gtksource.view.View.

By default, no white spaces are drawn because the gtksource.space_drawer.SpaceDrawer.enableMatrix is false.

To draw white spaces, gtksource.space_drawer.SpaceDrawer.setTypesForLocations can be called to set the gtksource.space_drawer.SpaceDrawer.matrix property (by default all space types are enabled at all locations). Then call gtksource.space_drawer.SpaceDrawer.setEnableMatrix.

For a finer-grained method, there is also the gtksource.tag.Tag's gtksource.tag.Tag.drawSpaces property.

Example

To draw non-breaking spaces everywhere and draw all types of trailing spaces except newlines:

gtk_source_space_drawer_set_types_for_locations (space_drawer,
                                                 GTK_SOURCE_SPACE_LOCATION_ALL,
                                                 GTK_SOURCE_SPACE_TYPE_NBSP);

gtk_source_space_drawer_set_types_for_locations (space_drawer,
                                                 GTK_SOURCE_SPACE_LOCATION_TRAILING,
                                                 GTK_SOURCE_SPACE_TYPE_ALL &
                                                 ~GTK_SOURCE_SPACE_TYPE_NEWLINE);

gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE);

Use-case: draw unwanted white spaces

A possible use-case is to draw only unwanted white spaces.

Examples

- Draw all trailing spaces.
  • If the indentation and alignment must be done with spaces, draw tabs.

And non-breaking spaces can always be drawn, everywhere, to distinguish them from normal spaces.

Represents a style.

The gtksource.style.Style structure is used to describe text attributes which are set when given style is used.

Fields
GObjectClass parentClass

Controls the appearance of gtksource.view.View.

#GtkSourceStyleScheme contains all the text styles to be used in gtksource.view.View and gtksource.buffer.Buffer. For instance, it contains text styles for syntax highlighting, it may contain foreground and background color for non-highlighted text, color for the line numbers, current line highlighting, bracket matching, etc.

Style schemes are stored in XML files. The format of a scheme file is documented in the style scheme reference.

The two style schemes with IDs "classic" and "tango" follow more closely the GTK theme (for example for the background color).

Interface implemented by widgets for choosing style schemes.

gtksource.style_scheme_chooser.StyleSchemeChooser is an interface that is implemented by widgets for choosing style schemes.

In GtkSourceView, the main widgets that implement this interface are gtksource.style_scheme_chooser_widget.StyleSchemeChooserWidget and gtksource.style_scheme_chooser_button.StyleSchemeChooserButton.

A button to launch a style scheme selection dialog.

The gtksource.style_scheme_chooser_button.StyleSchemeChooserButton is a button which displays the currently selected style scheme and allows to open a style scheme selection dialog to change the style scheme. It is suitable widget for selecting a style scheme in a preference dialog.

In gtksource.style_scheme_chooser_button.StyleSchemeChooserButton, a gtksource.style_scheme_chooser_widget.StyleSchemeChooserWidget is used to provide a dialog for selecting style schemes.

Fields
GtkButton parentInstance
Fields
void *[10] Reserved
Fields
GTypeInterface baseInterface
GtkSourceStyleScheme * function(GtkSourceStyleSchemeChooser * chooser) getStyleScheme
void function(GtkSourceStyleSchemeChooser * chooser, GtkSourceStyleScheme * scheme) setStyleScheme
void *[12] Reserved

A widget for choosing style schemes.

The gtksource.style_scheme_chooser_widget.StyleSchemeChooserWidget widget lets the user select a style scheme. By default, the chooser presents a predefined list of style schemes.

To change the initially selected style scheme, use gtksource.style_scheme_chooser.StyleSchemeChooser.setStyleScheme. To get the selected style scheme use gtksource.style_scheme_chooser.StyleSchemeChooser.getStyleScheme.

Fields
GtkWidget parentInstance
Fields
void *[10] Reserved

A preview widget for gtksource.style_scheme.StyleScheme.

This widget provides a convenient gtk.widget.Widget to preview a gtksource.style_scheme.StyleScheme.

The gtksource.style_scheme_preview.StyleSchemePreview.selected property can be used to manage the selection state of a single preview widget.

A tag that can be applied to text in a gtksource.buffer.Buffer.

gtksource.tag.Tag is a subclass of gtk.text_tag.TextTag that adds properties useful for the GtkSourceView library.

If, for a certain tag, gtk.text_tag.TextTag is sufficient, it's better that you create a gtk.text_tag.TextTag, not a gtksource.tag.Tag.

Fields
GtkTextTag parentInstance
Fields
GtkTextTagClass parentClass
void *[10] Reserved

Subclass of gtk.text_view.TextView.

gtksource.view.View is the main class of the GtkSourceView library. Use a gtksource.buffer.Buffer to display text with a gtksource.view.View.

This class provides:

  • Show the line numbers;
  • Show a right margin;
  • Highlight the current line;
  • Indentation settings;
  • Configuration for the Home and End keyboard keys;
  • Configure and show line marks;
  • And a few other things.

An easy way to test all these features is to use the test-widget mini-program provided in the GtkSourceView repository, in the tests/ directory.

GtkSourceView as GtkBuildable

The GtkSourceView implementation of the gtk.buildable.Buildable interface exposes the gtksource.view.View.completion object with the internal-child "completion".

An example of a UI definition fragment with GtkSourceView:

<object class="GtkSourceView" id="source_view">
  <property name="tab-width">4</property>
  <property name="auto-indent">True</property>
  <child internal-child="completion">
    <object class="GtkSourceCompletion">
      <property name="select-on-show">False</property>
    </object>
  </child>
</object>

Changing the Font

Gtk CSS provides the best way to change the font for a gtksource.view.View in a manner that allows for components like gtksource.map.Map to scale the desired font.

GtkCssProvider *provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,
                                 "textview { font-family: Monospace; font-size: 8pt; }",
                                 -1,
                                 NULL);
gtk_style_context_add_provider (gtk_widget_get_style_context (view),
                                GTK_STYLE_PROVIDER (provider),
                                GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);

If you need to adjust the font or size of font within a portion of the document only, you should use a gtk.text_tag.TextTag with the gtk.text_tag.TextTag.family or gtk.text_tag.TextTag.scale set so that the font size may be scaled relative to the default font set in CSS.

Fields
GtkTextView parentInstance
Fields
GtkTextViewClass parentClass
void function(GtkSourceView * view, const(GtkTextIter) * iter, uint button, GdkModifierType state, int nPresses) lineMarkActivated
void function(GtkSourceView * view) showCompletion
void function(GtkSourceView * view, gboolean down) moveLines
void function(GtkSourceView * view, int step) moveWords
void function(GtkSourceView * view, GtkSourceSnippet * snippet, GtkTextIter * location) pushSnippet
void *[20] Reserved

Vim emulation.

The gtksource.vim_imcontext.VimIMContext is a gtk.imcontext.IMContext implementation that can be used to provide Vim-like editing controls within a gtksource.view.View.

The GtkSourceViMIMContext will process incoming gdk.key_event.KeyEvent as the user types. It should be used in conjunction with a gtk.event_controller_key.EventControllerKey.

Various features supported by gtksource.vim_imcontext.VimIMContext include:

  • Normal, Insert, Replace, Visual, and Visual Line modes
  • Support for an integrated command bar and current command preview
  • Search and replace
  • Motions and Text Objects
  • History replay
  • Jumplists within the current file
  • Registers including the system and primary clipboards
  • Creation and motion to marks
  • Some commonly used Vim commands

It is recommended that applications display the contents of gtksource.vim_imcontext.VimIMContext.commandBarText and gtksource.vim_imcontext.VimIMContext.commandText to the user as they represent the command-bar and current command preview found in Vim.

gtksource.vim_imcontext.VimIMContext attempts to work with additional gtk.imcontext.IMContext implementations such as IBus by querying the gtk.text_view.TextView before processing the command in states which support it (notably Insert and Replace modes).

GtkEventController *key;
GtkIMContext *im_context;
GtkWidget *view;

view = gtk_source_view_new ();
im_context = gtk_source_vim_im_context_new ();
key = gtk_event_controller_key_new ();

gtk_event_controller_key_set_im_context (GTK_EVENT_CONTROLLER_KEY (key), im_context);
gtk_event_controller_set_propagation_phase (key, GTK_PHASE_CAPTURE);
gtk_widget_add_controller (view, key);
gtk_im_context_set_client_widget (im_context, view);

g_object_bind_property (im_context, "command-bar-text", command_bar_label, "label", 0);
g_object_bind_property (im_context, "command-text", command_label, "label", 0);

aliasGtkSourceMountOperationFactory = GMountOperation * function(GtkSourceFile * file, void * userdata)
aliasGtkSourceSchedulerCallback = gboolean function(long deadline, void * userData)