Buffer

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

class Buffer : TextBuffer {}

Constructors

this
this(gtk.text_tag_table.TextTagTable table)

Creates a new source buffer.

Members

Functions

backwardIterToSourceMark
bool backwardIterToSourceMark(gtk.text_iter.TextIter iter, string category)

Moves iter to the position of the previous classMark of the given category.

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

connectBracketMatched
ulong connectBracketMatched(T callback, Flag!"After" after)

Connect to BracketMatched signal.

connectCursorMoved
ulong connectCursorMoved(T callback, Flag!"After" after)

Connect to CursorMoved signal.

connectHighlightUpdated
ulong connectHighlightUpdated(T callback, Flag!"After" after)

Connect to HighlightUpdated signal.

connectSourceMarkUpdated
ulong connectSourceMarkUpdated(T callback, Flag!"After" after)

Connect to SourceMarkUpdated signal.

createSourceMark
gtksource.mark.Mark createSourceMark(string name, string category, gtk.text_iter.TextIter where)

Creates a source mark in the buffer of category category.

ensureHighlight
void ensureHighlight(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Forces buffer to analyze and highlight the given area synchronously.

forwardIterToSourceMark
bool forwardIterToSourceMark(gtk.text_iter.TextIter iter, string category)

Moves iter to the position of the next classMark of the given category.

getContextClassesAtIter
string[] getContextClassesAtIter(gtk.text_iter.TextIter iter)

Get all defined context classes at iter.

getHighlightMatchingBrackets
bool getHighlightMatchingBrackets()

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

getHighlightSyntax
bool getHighlightSyntax()

Determines whether syntax highlighting is activated in the source buffer.

getImplicitTrailingNewline
bool getImplicitTrailingNewline()
getLanguage
gtksource.language.Language getLanguage()

Returns the classLanguage associated with the buffer, see gtksource.buffer.Buffer.setLanguage.

getLoading
bool getLoading()
getSourceMarksAtIter
gtksource.mark.Mark[] getSourceMarksAtIter(gtk.text_iter.TextIter iter, string category)

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

getSourceMarksAtLine
gtksource.mark.Mark[] getSourceMarksAtLine(int line, string category)

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

getStyleScheme
gtksource.style_scheme.StyleScheme getStyleScheme()

Returns the classStyleScheme associated with the buffer, see gtksource.buffer.Buffer.setStyleScheme.

iterBackwardToContextClassToggle
bool iterBackwardToContextClassToggle(gtk.text_iter.TextIter iter, string contextClass)

Moves backward to the next toggle (on or off) of the context class.

iterForwardToContextClassToggle
bool iterForwardToContextClassToggle(gtk.text_iter.TextIter iter, string contextClass)

Moves forward to the next toggle (on or off) of the context class.

iterHasContextClass
bool iterHasContextClass(gtk.text_iter.TextIter iter, string contextClass)

Check if the class context_class is set on iter.

joinLines
void joinLines(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Joins the lines of text between the specified iterators.

removeSourceMarks
void removeSourceMarks(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end, string category)

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

setHighlightMatchingBrackets
void setHighlightMatchingBrackets(bool highlight)

Controls the bracket match highlighting function in the buffer.

setHighlightSyntax
void setHighlightSyntax(bool highlight)

Controls whether syntax is highlighted in the buffer.

setImplicitTrailingNewline
void setImplicitTrailingNewline(bool implicitTrailingNewline)

Sets whether the buffer has an implicit trailing newline.

setLanguage
void setLanguage(gtksource.language.Language language)

Associates a classLanguage with the buffer.

setStyleScheme
void setStyleScheme(gtksource.style_scheme.StyleScheme scheme)

Sets a classStyleScheme to be used by the buffer and the view.

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

Static functions

newWithLanguage
gtksource.buffer.Buffer newWithLanguage(gtksource.language.Language language)

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

Inherited Members

From TextBuffer

addMark
void addMark(gtk.text_mark.TextMark mark, gtk.text_iter.TextIter where)

Adds the mark at position where.

addSelectionClipboard
void addSelectionClipboard(gdk.clipboard.Clipboard clipboard)

Adds clipboard to the list of clipboards in which the selection contents of buffer are available.

applyTag
void applyTag(gtk.text_tag.TextTag tag, gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Emits the “apply-tag” signal on buffer.

applyTagByName
void applyTagByName(string name, gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Emits the “apply-tag” signal on buffer.

backspace
bool backspace(gtk.text_iter.TextIter iter, bool interactive, bool defaultEditable)

Performs the appropriate action as if the user hit the delete key with the cursor at the position specified by iter.

beginIrreversibleAction
void beginIrreversibleAction()

Denotes the beginning of an action that may not be undone.

beginUserAction
void beginUserAction()

Called to indicate that the buffer operations between here and a call to gtk.text_buffer.TextBuffer.endUserAction are part of a single user-visible operation.

copyClipboard
void copyClipboard(gdk.clipboard.Clipboard clipboard)

Copies the currently-selected text to a clipboard.

createChildAnchor
gtk.text_child_anchor.TextChildAnchor createChildAnchor(gtk.text_iter.TextIter iter)

Creates and inserts a child anchor.

createMark
gtk.text_mark.TextMark createMark(string markName, gtk.text_iter.TextIter where, bool leftGravity)

Creates a mark at position where.

cutClipboard
void cutClipboard(gdk.clipboard.Clipboard clipboard, bool defaultEditable)

Copies the currently-selected text to a clipboard, then deletes said text if it’s editable.

delete_
void delete_(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Deletes text between start and end.

deleteInteractive
bool deleteInteractive(gtk.text_iter.TextIter startIter, gtk.text_iter.TextIter endIter, bool defaultEditable)

Deletes all editable text in the given range.

deleteMark
void deleteMark(gtk.text_mark.TextMark mark)

Deletes mark, so that it’s no longer located anywhere in the buffer.

deleteMarkByName
void deleteMarkByName(string name)

Deletes the mark named name; the mark must exist.

deleteSelection
bool deleteSelection(bool interactive, bool defaultEditable)

Deletes the range between the “insert” and “selection_bound” marks, that is, the currently-selected text.

endIrreversibleAction
void endIrreversibleAction()

Denotes the end of an action that may not be undone.

endUserAction
void endUserAction()

Ends a user-visible operation.

getBounds
void getBounds(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Retrieves the first and last iterators in the buffer, i.e. the entire buffer lies within the range [start,end).

getCanRedo
bool getCanRedo()

Gets whether there is a redoable action in the history.

getCanUndo
bool getCanUndo()

Gets whether there is an undoable action in the history.

getCharCount
int getCharCount()

Gets the number of characters in the buffer.

getEnableUndo
bool getEnableUndo()

Gets whether the buffer is saving modifications to the buffer to allow for undo and redo actions.

getEndIter
void getEndIter(gtk.text_iter.TextIter iter)

Initializes iter with the “end iterator,” one past the last valid character in the text buffer.

getHasSelection
bool getHasSelection()

Indicates whether the buffer has some text currently selected.

getInsert
gtk.text_mark.TextMark getInsert()

Returns the mark that represents the cursor (insertion point).

getIterAtChildAnchor
void getIterAtChildAnchor(gtk.text_iter.TextIter iter, gtk.text_child_anchor.TextChildAnchor anchor)

Obtains the location of anchor within buffer.

getIterAtLine
bool getIterAtLine(gtk.text_iter.TextIter iter, int lineNumber)

Initializes iter to the start of the given line.

getIterAtLineIndex
bool getIterAtLineIndex(gtk.text_iter.TextIter iter, int lineNumber, int byteIndex)

Obtains an iterator pointing to byte_index within the given line.

getIterAtLineOffset
bool getIterAtLineOffset(gtk.text_iter.TextIter iter, int lineNumber, int charOffset)

Obtains an iterator pointing to char_offset within the given line.

getIterAtMark
void getIterAtMark(gtk.text_iter.TextIter iter, gtk.text_mark.TextMark mark)

Initializes iter with the current position of mark.

getIterAtOffset
void getIterAtOffset(gtk.text_iter.TextIter iter, int charOffset)

Initializes iter to a position char_offset chars from the start of the entire buffer.

getLineCount
int getLineCount()

Obtains the number of lines in the buffer.

getMark
gtk.text_mark.TextMark getMark(string name)

Returns the mark named name in buffer buffer, or null if no such mark exists in the buffer.

getMaxUndoLevels
uint getMaxUndoLevels()

Gets the maximum number of undo levels to perform.

getModified
bool getModified()

Indicates whether the buffer has been modified since the last call to gtk.text_buffer.TextBuffer.setModified set the modification flag to false.

getSelectionBound
gtk.text_mark.TextMark getSelectionBound()

Returns the mark that represents the selection bound.

getSelectionBounds
bool getSelectionBounds(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Returns true if some text is selected; places the bounds of the selection in start and end.

getSelectionContent
gdk.content_provider.ContentProvider getSelectionContent()

Get a content provider for this buffer.

getSlice
string getSlice(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end, bool includeHiddenChars)

Returns the text in the range [start,end).

getStartIter
void getStartIter(gtk.text_iter.TextIter iter)

Initialized iter with the first position in the text buffer.

getTagTable
gtk.text_tag_table.TextTagTable getTagTable()

Get the gtk.text_tag_table.TextTagTable associated with this buffer.

getText
string getText(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end, bool includeHiddenChars)

Returns the text in the range [start,end).

insert
void insert(gtk.text_iter.TextIter iter, string text)

Inserts len bytes of text at position iter.

insertAtCursor
void insertAtCursor(string text)

Inserts text in buffer.

insertChildAnchor
void insertChildAnchor(gtk.text_iter.TextIter iter, gtk.text_child_anchor.TextChildAnchor anchor)

Inserts a child widget anchor into the text buffer at iter.

insertInteractive
bool insertInteractive(gtk.text_iter.TextIter iter, string text, bool defaultEditable)

Inserts text in buffer.

insertInteractiveAtCursor
bool insertInteractiveAtCursor(string text, bool defaultEditable)

Inserts text in buffer.

insertMarkup
void insertMarkup(gtk.text_iter.TextIter iter, string markup)

Inserts the text in markup at position iter.

insertPaintable
void insertPaintable(gtk.text_iter.TextIter iter, gdk.paintable.Paintable paintable)

Inserts an image into the text buffer at iter.

insertRange
void insertRange(gtk.text_iter.TextIter iter, gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Copies text, tags, and paintables between start and end and inserts the copy at iter.

insertRangeInteractive
bool insertRangeInteractive(gtk.text_iter.TextIter iter, gtk.text_iter.TextIter start, gtk.text_iter.TextIter end, bool defaultEditable)

Copies text, tags, and paintables between start and end and inserts the copy at iter.

moveMark
void moveMark(gtk.text_mark.TextMark mark, gtk.text_iter.TextIter where)

Moves mark to the new location where.

moveMarkByName
void moveMarkByName(string name, gtk.text_iter.TextIter where)

Moves the mark named name (which must exist) to location where.

pasteClipboard
void pasteClipboard(gdk.clipboard.Clipboard clipboard, gtk.text_iter.TextIter overrideLocation, bool defaultEditable)

Pastes the contents of a clipboard.

placeCursor
void placeCursor(gtk.text_iter.TextIter where)

This function moves the “insert” and “selection_bound” marks simultaneously.

redo
void redo()

Redoes the next redoable action on the buffer, if there is one.

removeAllTags
void removeAllTags(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Removes all tags in the range between start and end.

removeSelectionClipboard
void removeSelectionClipboard(gdk.clipboard.Clipboard clipboard)

Removes a gdk.clipboard.Clipboard added with gtk.text_buffer.TextBuffer.addSelectionClipboard

removeTag
void removeTag(gtk.text_tag.TextTag tag, gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Emits the “remove-tag” signal.

removeTagByName
void removeTagByName(string name, gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Emits the “remove-tag” signal.

selectRange
void selectRange(gtk.text_iter.TextIter ins, gtk.text_iter.TextIter bound)

This function moves the “insert” and “selection_bound” marks simultaneously.

setEnableUndo
void setEnableUndo(bool enableUndo)

Sets whether or not to enable undoable actions in the text buffer.

setMaxUndoLevels
void setMaxUndoLevels(uint maxUndoLevels)

Sets the maximum number of undo levels to perform.

setModified
void setModified(bool setting)

Used to keep track of whether the buffer has been modified since the last time it was saved.

setText
void setText(string text)

Deletes current contents of buffer, and inserts text instead. This is automatically marked as an irreversible action in the undo stack. If you wish to mark this action as part of a larger undo operation, call gtk.text_buffer.TextBuffer.delete_ and gtk.text_buffer.TextBuffer.insert directly instead.

undo
void undo()

Undoes the last undoable action on the buffer, if there is one.

connectApplyTag
ulong connectApplyTag(T callback, Flag!"After" after)

Connect to ApplyTag signal.

connectBeginUserAction
ulong connectBeginUserAction(T callback, Flag!"After" after)

Connect to BeginUserAction signal.

connectChanged
ulong connectChanged(T callback, Flag!"After" after)

Connect to Changed signal.

connectDeleteRange
ulong connectDeleteRange(T callback, Flag!"After" after)

Connect to DeleteRange signal.

connectEndUserAction
ulong connectEndUserAction(T callback, Flag!"After" after)

Connect to EndUserAction signal.

connectInsertChildAnchor
ulong connectInsertChildAnchor(T callback, Flag!"After" after)

Connect to InsertChildAnchor signal.

connectInsertPaintable
ulong connectInsertPaintable(T callback, Flag!"After" after)

Connect to InsertPaintable signal.

connectInsertText
ulong connectInsertText(T callback, Flag!"After" after)

Connect to InsertText signal.

connectMarkDeleted
ulong connectMarkDeleted(T callback, Flag!"After" after)

Connect to MarkDeleted signal.

connectMarkSet
ulong connectMarkSet(T callback, Flag!"After" after)

Connect to MarkSet signal.

connectModifiedChanged
ulong connectModifiedChanged(T callback, Flag!"After" after)

Connect to ModifiedChanged signal.

connectPasteDone
ulong connectPasteDone(T callback, Flag!"After" after)

Connect to PasteDone signal.

connectRedo
ulong connectRedo(T callback, Flag!"After" after)

Connect to Redo signal.

connectRemoveTag
ulong connectRemoveTag(T callback, Flag!"After" after)

Connect to RemoveTag signal.

connectUndo
ulong connectUndo(T callback, Flag!"After" after)

Connect to Undo signal.