### Class

# Gtk TextBuffer

since: 4.0

#### Description [src]

    class Gtk.TextBuffer : GObject.Object
    {
      priv: GtkTextBufferPrivate*
    }

Stores text and attributes for display in a `GtkTextView`.

You may wish to begin by reading the text widget conceptual overview, which gives an overview of all the objects and data types related to the text widget and how they work together.

GtkTextBuffer can support undoing changes to the buffer content, see `gtk_text_buffer_set_enable_undo()`.

Available since: 4.0

#### Ancestors

- GObject

#### Constructors

###### gtk_text_buffer_new

Creates a new text buffer.

since: 4.0

#### Instance methods

###### gtk_text_buffer_add_mark

Adds the mark at position `where`.

since: 4.0

###### gtk_text_buffer_add_selection_clipboard

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

since: 4.0

###### gtk_text_buffer_apply_tag

Emits the “apply-tag” signal on `buffer`.

since: 4.0

###### gtk_text_buffer_apply_tag_by_name

Emits the “apply-tag” signal on `buffer`.

since: 4.0

###### gtk_text_buffer_backspace

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

since: 4.0

###### gtk_text_buffer_begin_irreversible_action

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

since: 4.0

###### gtk_text_buffer_begin_user_action

Called to indicate that the buffer operations between here and a call to `gtk_text_buffer_end_user_action()` are part of a single user-visible operation.

since: 4.0

###### gtk_text_buffer_copy_clipboard

Copies the currently-selected text to a clipboard.

since: 4.0

###### gtk_text_buffer_create_child_anchor

Creates and inserts a child anchor.

since: 4.0

###### gtk_text_buffer_create_mark

Creates a mark at position `where`.

since: 4.0

###### gtk_text_buffer_create_tag

Creates a tag and adds it to the tag table for `buffer`.

since: 4.0

###### gtk_text_buffer_cut_clipboard

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

since: 4.0

###### gtk_text_buffer_delete

Deletes text between `start` and `end`.

since: 4.0

###### gtk_text_buffer_delete_interactive

Deletes all editable text in the given range.

since: 4.0

###### gtk_text_buffer_delete_mark

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

since: 4.0

###### gtk_text_buffer_delete_mark_by_name

Deletes the mark named `name`; the mark must exist.

since: 4.0

###### gtk_text_buffer_delete_selection

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

since: 4.0

###### gtk_text_buffer_end_irreversible_action

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

since: 4.0

###### gtk_text_buffer_end_user_action

Ends a user-visible operation.

since: 4.0

###### gtk_text_buffer_get_bounds

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

since: 4.0

###### gtk_text_buffer_get_can_redo

Gets whether there is a redoable action in the history.

since: 4.0

###### gtk_text_buffer_get_can_undo

Gets whether there is an undoable action in the history.

since: 4.0

###### gtk_text_buffer_get_char_count

Gets the number of characters in the buffer.

since: 4.0

###### gtk_text_buffer_get_enable_undo

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

since: 4.0

###### gtk_text_buffer_get_end_iter

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

since: 4.0

###### gtk_text_buffer_get_has_selection

Indicates whether the buffer has some text currently selected.

since: 4.0

###### gtk_text_buffer_get_insert

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

since: 4.0

###### gtk_text_buffer_get_iter_at_child_anchor

Obtains the location of `anchor` within `buffer`.

since: 4.0

###### gtk_text_buffer_get_iter_at_line

Initializes `iter` to the start of the given line.

since: 4.0

###### gtk_text_buffer_get_iter_at_line_index

Obtains an iterator pointing to `byte_index` within the given line.

since: 4.0

###### gtk_text_buffer_get_iter_at_line_offset

Obtains an iterator pointing to `char_offset` within the given line.

since: 4.0

###### gtk_text_buffer_get_iter_at_mark

Initializes `iter` with the current position of `mark`.

since: 4.0

###### gtk_text_buffer_get_iter_at_offset

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

since: 4.0

###### gtk_text_buffer_get_line_count

Obtains the number of lines in the buffer.

since: 4.0

###### gtk_text_buffer_get_mark

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

since: 4.0

###### gtk_text_buffer_get_max_undo_levels

Gets the maximum number of undo levels to perform.

since: 4.0

###### gtk_text_buffer_get_modified

Indicates whether the buffer has been modified since the last call to `gtk_text_buffer_set_modified()` set the modification flag to `FALSE`.

since: 4.0

###### gtk_text_buffer_get_selection_bound

Returns the mark that represents the selection bound.

since: 4.0

###### gtk_text_buffer_get_selection_bounds

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

since: 4.0

###### gtk_text_buffer_get_selection_content

Get a content provider for this buffer.

since: 4.0

###### gtk_text_buffer_get_slice

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

since: 4.0

###### gtk_text_buffer_get_start_iter

Initialized `iter` with the first position in the text buffer.

since: 4.0

###### gtk_text_buffer_get_tag_table

Get the `GtkTextTagTable` associated with this buffer.

since: 4.0

###### gtk_text_buffer_get_text

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

since: 4.0

###### gtk_text_buffer_insert

Inserts `len` bytes of `text` at position `iter`.

since: 4.0

###### gtk_text_buffer_insert_at_cursor

Inserts `text` in `buffer`.

since: 4.0

###### gtk_text_buffer_insert_child_anchor

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

since: 4.0

###### gtk_text_buffer_insert_interactive

Inserts `text` in `buffer`.

since: 4.0

###### gtk_text_buffer_insert_interactive_at_cursor

Inserts `text` in `buffer`.

since: 4.0

###### gtk_text_buffer_insert_markup

Inserts the text in `markup` at position `iter`.

since: 4.0

###### gtk_text_buffer_insert_paintable

Inserts an image into the text buffer at `iter`.

since: 4.0

###### gtk_text_buffer_insert_range

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

since: 4.0

###### gtk_text_buffer_insert_range_interactive

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

since: 4.0

###### gtk_text_buffer_insert_with_tags

Inserts `text` into `buffer` at `iter`, applying the list of tags to the newly-inserted text.

since: 4.0

###### gtk_text_buffer_insert_with_tags_by_name

Inserts `text` into `buffer` at `iter`, applying the list of tags to the newly-inserted text.

since: 4.0

###### gtk_text_buffer_move_mark

Moves `mark` to the new location `where`.

since: 4.0

###### gtk_text_buffer_move_mark_by_name

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

since: 4.0

###### gtk_text_buffer_paste_clipboard

Pastes the contents of a clipboard.

since: 4.0

###### gtk_text_buffer_place_cursor

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

since: 4.0

###### gtk_text_buffer_redo

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

since: 4.0

###### gtk_text_buffer_remove_all_tags

Removes all tags in the range between `start` and `end`.

since: 4.0

###### gtk_text_buffer_remove_selection_clipboard

Removes a `GdkClipboard` added with `gtk_text_buffer_add_selection_clipboard()`

since: 4.0

###### gtk_text_buffer_remove_tag

Emits the “remove-tag” signal.

since: 4.0

###### gtk_text_buffer_remove_tag_by_name

Emits the “remove-tag” signal.

since: 4.0

###### gtk_text_buffer_select_range

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

since: 4.0

###### gtk_text_buffer_set_enable_undo

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

since: 4.0

###### gtk_text_buffer_set_max_undo_levels

Sets the maximum number of undo levels to perform.

since: 4.0

###### gtk_text_buffer_set_modified

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

since: 4.0

###### gtk_text_buffer_set_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_delete()` and `gtk_text_buffer_insert()` directly instead.

since: 4.0

###### gtk_text_buffer_undo

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

since: 4.0

##### Methods inherited from GObject (43)

Please see GObject for a full list of methods.

#### Properties

###### Gtk.TextBuffer:can-redo

Denotes that the buffer can reapply the last undone action.

since: 4.0

###### Gtk.TextBuffer:can-undo

Denotes that the buffer can undo the last applied action.

since: 4.0

###### Gtk.TextBuffer:cursor-position

The position of the insert mark.

since: 4.0

###### Gtk.TextBuffer:enable-undo

Denotes if support for undoing and redoing changes to the buffer is allowed.

since: 4.0

###### Gtk.TextBuffer:has-selection

Whether the buffer has some text currently selected.

since: 4.0

###### Gtk.TextBuffer:tag-table

The GtkTextTagTable for the buffer.

since: 4.0

###### Gtk.TextBuffer:text

The text content of the buffer.

since: 4.0

#### Signals

###### Gtk.TextBuffer::apply-tag

Emitted to apply a tag to a range of text in a `GtkTextBuffer`.

since: 4.0

###### Gtk.TextBuffer::begin-user-action

Emitted at the beginning of a single user-visible operation on a `GtkTextBuffer`.

since: 4.0

###### Gtk.TextBuffer::changed

Emitted when the content of a `GtkTextBuffer` has changed.

since: 4.0

###### Gtk.TextBuffer::delete-range

Emitted to delete a range from a `GtkTextBuffer`.

since: 4.0

###### Gtk.TextBuffer::end-user-action

Emitted at the end of a single user-visible operation on the `GtkTextBuffer`.

since: 4.0

###### Gtk.TextBuffer::insert-child-anchor

Emitted to insert a `GtkTextChildAnchor` in a `GtkTextBuffer`.

since: 4.0

###### Gtk.TextBuffer::insert-paintable

Emitted to insert a `GdkPaintable` in a `GtkTextBuffer`.

since: 4.0

###### Gtk.TextBuffer::insert-text

Emitted to insert text in a `GtkTextBuffer`.

since: 4.0

###### Gtk.TextBuffer::mark-deleted

Emitted as notification after a `GtkTextMark` is deleted.

since: 4.0

###### Gtk.TextBuffer::mark-set

Emitted as notification after a `GtkTextMark` is set.

since: 4.0

###### Gtk.TextBuffer::modified-changed

Emitted when the modified bit of a `GtkTextBuffer` flips.

since: 4.0

###### Gtk.TextBuffer::paste-done

Emitted after paste operation has been completed.

since: 4.0

###### Gtk.TextBuffer::redo

Emitted when a request has been made to redo the previously undone operation.

since: 4.0

###### Gtk.TextBuffer::remove-tag

Emitted to remove all occurrences of `tag` from a range of text in a `GtkTextBuffer`.

since: 4.0

###### Gtk.TextBuffer::undo

Emitted when a request has been made to undo the previous operation or set of operations that have been grouped together.

since: 4.0

##### Signals inherited from GObject (1)

###### GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

since: 2.0

#### Class structure

    struct GtkTextBufferClass {
      GObjectClass parent_class;
      void (* insert_text) (
        GtkTextBuffer* buffer,
        GtkTextIter* pos,
        const char* new_text,
        int new_text_length
      );
      void (* insert_paintable) (
        GtkTextBuffer* buffer,
        GtkTextIter* iter,
        GdkPaintable* paintable
      );
      void (* insert_child_anchor) (
        GtkTextBuffer* buffer,
        GtkTextIter* iter,
        GtkTextChildAnchor* anchor
      );
      void (* delete_range) (
        GtkTextBuffer* buffer,
        GtkTextIter* start,
        GtkTextIter* end
      );
      void (* changed) (
        GtkTextBuffer* buffer
      );
      void (* modified_changed) (
        GtkTextBuffer* buffer
      );
      void (* mark_set) (
        GtkTextBuffer* buffer,
        const GtkTextIter* location,
        GtkTextMark* mark
      );
      void (* mark_deleted) (
        GtkTextBuffer* buffer,
        GtkTextMark* mark
      );
      void (* apply_tag) (
        GtkTextBuffer* buffer,
        GtkTextTag* tag,
        const GtkTextIter* start,
        const GtkTextIter* end
      );
      void (* remove_tag) (
        GtkTextBuffer* buffer,
        GtkTextTag* tag,
        const GtkTextIter* start,
        const GtkTextIter* end
      );
      void (* begin_user_action) (
        GtkTextBuffer* buffer
      );
      void (* end_user_action) (
        GtkTextBuffer* buffer
      );
      void (* paste_done) (
        GtkTextBuffer* buffer,
        GdkClipboard* clipboard
      );
      void (* undo) (
        GtkTextBuffer* buffer
      );
      void (* redo) (
        GtkTextBuffer* buffer
      );
      void (* _gtk_reserved1) (
    void
      );
      void (* _gtk_reserved2) (
    void
      );
      void (* _gtk_reserved3) (
    void
      );
      void (* _gtk_reserved4) (
    void
      );

    }

The class structure for `GtkTextBuffer`.

###### Class members

`parent_class: GObjectClass`

  The object class structure needs to be the first.

`insert_text: void (* insert_text) ( GtkTextBuffer* buffer, GtkTextIter* pos, const char* new_text, int new_text_length )`

  The class handler for the `GtkTextBuffer::insert-text` signal.

`insert_paintable: void (* insert_paintable) ( GtkTextBuffer* buffer, GtkTextIter* iter, GdkPaintable* paintable )`

  The class handler for the `GtkTextBuffer::insert-paintable` signal.

`insert_child_anchor: void (* insert_child_anchor) ( GtkTextBuffer* buffer, GtkTextIter* iter, GtkTextChildAnchor* anchor )`

  The class handler for the `GtkTextBuffer::insert-child-anchor` signal.

`delete_range: void (* delete_range) ( GtkTextBuffer* buffer, GtkTextIter* start, GtkTextIter* end )`

  The class handler for the `GtkTextBuffer::delete-range` signal.

`changed: void (* changed) ( GtkTextBuffer* buffer )`

  The class handler for the `GtkTextBuffer::changed` signal.

`modified_changed: void (* modified_changed) ( GtkTextBuffer* buffer )`

  The class handler for the `GtkTextBuffer::modified-changed` signal.

`mark_set: void (* mark_set) ( GtkTextBuffer* buffer, const GtkTextIter* location, GtkTextMark* mark )`

  The class handler for the `GtkTextBuffer::mark-set` signal.

`mark_deleted: void (* mark_deleted) ( GtkTextBuffer* buffer, GtkTextMark* mark )`

  The class handler for the `GtkTextBuffer::mark-deleted` signal.

`apply_tag: void (* apply_tag) ( GtkTextBuffer* buffer, GtkTextTag* tag, const GtkTextIter* start, const GtkTextIter* end )`

  The class handler for the `GtkTextBuffer::apply-tag` signal.

`remove_tag: void (* remove_tag) ( GtkTextBuffer* buffer, GtkTextTag* tag, const GtkTextIter* start, const GtkTextIter* end )`

  The class handler for the `GtkTextBuffer::remove-tag` signal.

`begin_user_action: void (* begin_user_action) ( GtkTextBuffer* buffer )`

  The class handler for the `GtkTextBuffer::begin-user-action` signal.

`end_user_action: void (* end_user_action) ( GtkTextBuffer* buffer )`

  The class handler for the `GtkTextBuffer::end-user-action` signal.

`paste_done: void (* paste_done) ( GtkTextBuffer* buffer, GdkClipboard* clipboard )`

  The class handler for the `GtkTextBuffer::paste-done` signal.

`undo: void (* undo) ( GtkTextBuffer* buffer )`

  The class handler for the `GtkTextBuffer::undo` signal.

`redo: void (* redo) ( GtkTextBuffer* buffer )`

  The class handler for the `GtkTextBuffer::redo` signal.

`_gtk_reserved1: void (* _gtk_reserved1) ( void )`
  No description available.
`_gtk_reserved2: void (* _gtk_reserved2) ( void )`
  No description available.
`_gtk_reserved3: void (* _gtk_reserved3) ( void )`
  No description available.
`_gtk_reserved4: void (* _gtk_reserved4) ( void )`
  No description available.

#### Virtual methods

###### Gtk.TextBufferClass.apply_tag

Emits the “apply-tag” signal on `buffer`.

since: 4.0

###### Gtk.TextBufferClass.begin_user_action

Called to indicate that the buffer operations between here and a call to `gtk_text_buffer_end_user_action()` are part of a single user-visible operation.

since: 4.0

###### Gtk.TextBufferClass.changed

The class handler for the `GtkTextBuffer::changed` signal.

since: 4.0

###### Gtk.TextBufferClass.delete_range

The class handler for the `GtkTextBuffer::delete-range` signal.

since: 4.0

###### Gtk.TextBufferClass.end_user_action

Ends a user-visible operation.

since: 4.0

###### Gtk.TextBufferClass.insert_child_anchor

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

since: 4.0

###### Gtk.TextBufferClass.insert_paintable

Inserts an image into the text buffer at `iter`.

since: 4.0

###### Gtk.TextBufferClass.insert_text

The class handler for the `GtkTextBuffer::insert-text` signal.

since: 4.0

###### Gtk.TextBufferClass.mark_deleted

The class handler for the `GtkTextBuffer::mark-deleted` signal.

since: 4.0

###### Gtk.TextBufferClass.mark_set

The class handler for the `GtkTextBuffer::mark-set` signal.

since: 4.0

###### Gtk.TextBufferClass.modified_changed

The class handler for the `GtkTextBuffer::modified-changed` signal.

since: 4.0

###### Gtk.TextBufferClass.paste_done

The class handler for the `GtkTextBuffer::paste-done` signal.

since: 4.0

###### Gtk.TextBufferClass.redo

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

since: 4.0

###### Gtk.TextBufferClass.remove_tag

Emits the “remove-tag” signal.

since: 4.0

###### Gtk.TextBufferClass.undo

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

since: 4.0