CtkTextBuffer: CTK+ 3 Reference Manual

## CtkTextBuffer CtkTextBuffer — Stores attributed text for display in a CtkTextView |

## Functions

CtkTextBuffer * | ctk_text_buffer_new ()
gint | ctk_text_buffer_get_line_count ()
gint | ctk_text_buffer_get_char_count ()
CtkTextTagTable * | ctk_text_buffer_get_tag_table ()
void | ctk_text_buffer_insert ()
void | ctk_text_buffer_insert_at_cursor ()
gboolean | ctk_text_buffer_insert_interactive ()
gboolean | ctk_text_buffer_insert_interactive_at_cursor ()
void | ctk_text_buffer_insert_range ()
gboolean | ctk_text_buffer_insert_range_interactive ()
void | ctk_text_buffer_insert_with_tags ()
void | ctk_text_buffer_insert_with_tags_by_name ()
void | ctk_text_buffer_insert_markup ()
void | ctk_text_buffer_delete ()
gboolean | ctk_text_buffer_delete_interactive ()
gboolean | ctk_text_buffer_backspace ()
void | ctk_text_buffer_set_text ()
gchar * | ctk_text_buffer_get_text ()
gchar * | ctk_text_buffer_get_slice ()
void | ctk_text_buffer_insert_pixbuf ()
void | ctk_text_buffer_insert_child_anchor ()
CtkTextChildAnchor * | ctk_text_buffer_create_child_anchor ()
CtkTextMark * | ctk_text_buffer_create_mark ()
void | ctk_text_buffer_move_mark ()
void | ctk_text_buffer_move_mark_by_name ()
void | ctk_text_buffer_add_mark ()
void | ctk_text_buffer_delete_mark ()
void | ctk_text_buffer_delete_mark_by_name ()
CtkTextMark * | ctk_text_buffer_get_mark ()
CtkTextMark * | ctk_text_buffer_get_insert ()
CtkTextMark * | ctk_text_buffer_get_selection_bound ()
gboolean | ctk_text_buffer_get_has_selection ()
void | ctk_text_buffer_place_cursor ()
void | ctk_text_buffer_select_range ()
void | ctk_text_buffer_apply_tag ()
void | ctk_text_buffer_remove_tag ()
void | ctk_text_buffer_apply_tag_by_name ()
void | ctk_text_buffer_remove_tag_by_name ()
void | ctk_text_buffer_remove_all_tags ()
CtkTextTag * | ctk_text_buffer_create_tag ()
void | ctk_text_buffer_get_iter_at_line_offset ()
void | ctk_text_buffer_get_iter_at_offset ()
void | ctk_text_buffer_get_iter_at_line ()
void | ctk_text_buffer_get_iter_at_line_index ()
void | ctk_text_buffer_get_iter_at_mark ()
void | ctk_text_buffer_get_iter_at_child_anchor ()
void | ctk_text_buffer_get_start_iter ()
void | ctk_text_buffer_get_end_iter ()
void | ctk_text_buffer_get_bounds ()
gboolean | ctk_text_buffer_get_modified ()
void | ctk_text_buffer_set_modified ()
gboolean | ctk_text_buffer_delete_selection ()
void | ctk_text_buffer_paste_clipboard ()
void | ctk_text_buffer_copy_clipboard ()
void | ctk_text_buffer_cut_clipboard ()
gboolean | ctk_text_buffer_get_selection_bounds ()
void | ctk_text_buffer_begin_user_action ()
void | ctk_text_buffer_end_user_action ()
void | ctk_text_buffer_add_selection_clipboard ()
void | ctk_text_buffer_remove_selection_clipboard ()
gboolean | (*CtkTextBufferDeserializeFunc) ()
gboolean | ctk_text_buffer_deserialize ()
gboolean | ctk_text_buffer_deserialize_get_can_create_tags ()
void | ctk_text_buffer_deserialize_set_can_create_tags ()
CtkTargetList * | ctk_text_buffer_get_copy_target_list ()
CdkAtom * | ctk_text_buffer_get_deserialize_formats ()
CtkTargetList * | ctk_text_buffer_get_paste_target_list ()
CdkAtom * | ctk_text_buffer_get_serialize_formats ()
CdkAtom | ctk_text_buffer_register_deserialize_format ()
CdkAtom | ctk_text_buffer_register_deserialize_tagset ()
CdkAtom | ctk_text_buffer_register_serialize_format ()
CdkAtom | ctk_text_buffer_register_serialize_tagset ()
guint8 * | (*CtkTextBufferSerializeFunc) ()
guint8 * | ctk_text_buffer_serialize ()
void | ctk_text_buffer_unregister_deserialize_format ()
void | ctk_text_buffer_unregister_serialize_format ()

## Properties

CtkTargetList * | copy-target-list | Read
int | cursor-position | Read
gboolean | has-selection | Read
CtkTargetList * | paste-target-list | Read
CtkTextTagTable * | tag-table | Read / Write / Construct Only
char * | text | Read / Write

## Signals

void | apply-tag | Run Last
void | begin-user-action | Run Last
void | changed | Run Last
void | delete-range | Run Last
void | end-user-action | Run Last
void | insert-child-anchor | Run Last
void | insert-pixbuf | Run Last
void | insert-text | Run Last
void | mark-deleted | Run Last
void | mark-set | Run Last
void | modified-changed | Run Last
void | paste-done | Run Last
void | remove-tag | Run Last

## Types and Values

| CtkTextBuffer
struct | CtkTextBufferClass
enum | CtkTextBufferTargetInfo

## Object Hierarchy

        GObject
        ╰── CtkTextBuffer

## Includes

    #include <ctk/ctk.h>

## Description

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.

## Functions

### ctk_text_buffer_new ()

    CtkTextBuffer *
    ctk_text_buffer_new (CtkTextTagTable *table);

Creates a new text buffer.

#### Parameters

table | a tag table, or `NULL` to create a new one. | [allow-none]

#### Returns

a new text buffer

### ctk_text_buffer_get_line_count ()

    gint
    ctk_text_buffer_get_line_count (CtkTextBuffer *buffer);

Obtains the number of lines in the buffer. This value is cached, so the function is very fast.

#### Parameters

buffer | a CtkTextBuffer |

#### Returns

number of lines in the buffer

### ctk_text_buffer_get_char_count ()

    gint
    ctk_text_buffer_get_char_count (CtkTextBuffer *buffer);

Gets the number of characters in the buffer; note that characters and bytes are not the same, you can’t e.g. expect the contents of the buffer in string form to be this many bytes long. The character count is cached, so this function is very fast.

#### Parameters

buffer | a CtkTextBuffer |

#### Returns

number of characters in the buffer

### ctk_text_buffer_get_tag_table ()

    CtkTextTagTable *
    ctk_text_buffer_get_tag_table (CtkTextBuffer *buffer);

Get the CtkTextTagTable associated with this buffer.

#### Parameters

buffer | a CtkTextBuffer |

#### Returns

the buffer’s tag table.

[transfer none]

### ctk_text_buffer_insert ()

    void
    ctk_text_buffer_insert (CtkTextBuffer *buffer,
                            CtkTextIter *iter,
                            const gchar *text,
                            gint len);

Inserts `len` bytes of `text` at position `iter` . If `len` is -1, `text` must be nul-terminated and will be inserted in its entirety. Emits the “insert-text” signal; insertion actually occurs in the default handler for the signal. `iter` is invalidated when insertion occurs (because the buffer contents change), but the default signal handler revalidates it to point to the end of the inserted text.

#### Parameters

buffer | a CtkTextBuffer |
iter | a position in the buffer |
text | text in UTF-8 format |
len | length of text in bytes, or -1 |

### ctk_text_buffer_insert_at_cursor ()

    void
    ctk_text_buffer_insert_at_cursor (CtkTextBuffer *buffer,
                                      const gchar *text,
                                      gint len);

Simply calls `ctk_text_buffer_insert()`, using the current cursor position as the insertion point.

#### Parameters

buffer | a CtkTextBuffer |
text | text in UTF-8 format |
len | length of text, in bytes |

### ctk_text_buffer_insert_interactive ()

    gboolean
    ctk_text_buffer_insert_interactive (CtkTextBuffer *buffer,
                                        CtkTextIter *iter,
                                        const gchar *text,
                                        gint len,
                                        gboolean default_editable);

Like `ctk_text_buffer_insert()`, but the insertion will not occur if `iter` is at a non-editable location in the buffer. Usually you want to prevent insertions at ineditable locations if the insertion results from a user action (is interactive).

`default_editable` indicates the editability of text that doesn't have a tag affecting editability applied to it. Typically the result of `ctk_text_view_get_editable()` is appropriate here.

#### Parameters

buffer | a CtkTextBuffer |
iter | a position in `buffer` |
text | some UTF-8 text |
len | length of text in bytes, or -1 |
default_editable | default editability of buffer |

#### Returns

whether text was actually inserted

### ctk_text_buffer_insert_interactive_at_cursor ()

    gboolean
    ctk_text_buffer_insert_interactive_at_cursor
                                   (CtkTextBuffer *buffer,
                                    const gchar *text,
                                    gint len,
                                    gboolean default_editable);

Calls `ctk_text_buffer_insert_interactive()` at the cursor position.

`default_editable` indicates the editability of text that doesn't have a tag affecting editability applied to it. Typically the result of `ctk_text_view_get_editable()` is appropriate here.

#### Parameters

buffer | a CtkTextBuffer |
text | text in UTF-8 format |
len | length of text in bytes, or -1 |
default_editable | default editability of buffer |

#### Returns

whether text was actually inserted

### ctk_text_buffer_insert_range ()

    void
    ctk_text_buffer_insert_range (CtkTextBuffer *buffer,
                                  CtkTextIter *iter,
                                  const CtkTextIter *start,
                                  const CtkTextIter *end);

Copies text, tags, and pixbufs between `start` and `end` (the order of `start` and `end` doesn’t matter) and inserts the copy at `iter` . Used instead of simply getting/inserting text because it preserves images and tags. If `start` and `end` are in a different buffer from `buffer` , the two buffers must share the same tag table.

Implemented via emissions of the insert_text and apply_tag signals, so expect those.

#### Parameters

buffer | a CtkTextBuffer |
iter | a position in `buffer` |
start | a position in a CtkTextBuffer |
end | another position in the same buffer as `start` |

### ctk_text_buffer_insert_range_interactive ()

    gboolean
    ctk_text_buffer_insert_range_interactive
                                   (CtkTextBuffer *buffer,
                                    CtkTextIter *iter,
                                    const CtkTextIter *start,
                                    const CtkTextIter *end,
                                    gboolean default_editable);

Same as `ctk_text_buffer_insert_range()`, but does nothing if the insertion point isn’t editable. The `default_editable` parameter indicates whether the text is editable at `iter` if no tags enclosing `iter` affect editability. Typically the result of `ctk_text_view_get_editable()` is appropriate here.

#### Parameters

buffer | a CtkTextBuffer |
iter | a position in `buffer` |
start | a position in a CtkTextBuffer |
end | another position in the same buffer as `start` |
default_editable | default editability of the buffer |

#### Returns

whether an insertion was possible at `iter`

### ctk_text_buffer_insert_with_tags ()

    void
    ctk_text_buffer_insert_with_tags (CtkTextBuffer *buffer,
                                      CtkTextIter *iter,
                                      const gchar *text,
                                      gint len,
                                      CtkTextTag *first_tag,
                                      ...);

Inserts `text` into `buffer` at `iter` , applying the list of tags to the newly-inserted text. The last tag specified must be `NULL` to terminate the list. Equivalent to calling `ctk_text_buffer_insert()`, then `ctk_text_buffer_apply_tag()` on the inserted text; `ctk_text_buffer_insert_with_tags()` is just a convenience function.

#### Parameters

buffer | a CtkTextBuffer |
iter | an iterator in `buffer` |
text | UTF-8 text |
len | length of `text` , or -1 |
first_tag | first tag to apply to `text` |
... | `NULL`-terminated list of tags to apply |

### ctk_text_buffer_insert_with_tags_by_name ()

    void
    ctk_text_buffer_insert_with_tags_by_name
                                   (CtkTextBuffer *buffer,
                                    CtkTextIter *iter,
                                    const gchar *text,
                                    gint len,
                                    const gchar *first_tag_name,
                                    ...);

Same as `ctk_text_buffer_insert_with_tags()`, but allows you to pass in tag names instead of tag objects.

#### Parameters

buffer | a CtkTextBuffer |
iter | position in `buffer` |
text | UTF-8 text |
len | length of `text` , or -1 |
first_tag_name | name of a tag to apply to `text` |
... | more tag names |

### ctk_text_buffer_insert_markup ()

    void
    ctk_text_buffer_insert_markup (CtkTextBuffer *buffer,
                                   CtkTextIter *iter,
                                   const gchar *markup,
                                   gint len);

Inserts the text in `markup` at position `iter` . `markup` will be inserted in its entirety and must be nul-terminated and valid UTF-8. Emits the “insert-text” signal, possibly multiple times; insertion actually occurs in the default handler for the signal. `iter` will point to the end of the inserted text on return.

#### Parameters

buffer | a CtkTextBuffer |
iter | location to insert the markup |
markup | a nul-terminated UTF-8 string containing Pango markup |
len | length of `markup` in bytes, or -1 |

Since: 3.16

### ctk_text_buffer_delete ()

    void
    ctk_text_buffer_delete (CtkTextBuffer *buffer,
                            CtkTextIter *start,
                            CtkTextIter *end);

Deletes text between `start` and `end` . The order of `start` and `end` is not actually relevant; `ctk_text_buffer_delete()` will reorder them. This function actually emits the “delete-range” signal, and the default handler of that signal deletes the text. Because the buffer is modified, all outstanding iterators become invalid after calling this function; however, the `start` and `end` will be re-initialized to point to the location where text was deleted.

#### Parameters

buffer | a CtkTextBuffer |
start | a position in `buffer` |
end | another position in `buffer` |

### ctk_text_buffer_delete_interactive ()

    gboolean
    ctk_text_buffer_delete_interactive (CtkTextBuffer *buffer,
                                        CtkTextIter *start_iter,
                                        CtkTextIter *end_iter,
                                        gboolean default_editable);

Deletes all editable text in the given range. Calls `ctk_text_buffer_delete()` for each editable sub-range of [`start` ,`end` ). `start` and `end` are revalidated to point to the location of the last deleted range, or left untouched if no text was deleted.

#### Parameters

buffer | a CtkTextBuffer |
start_iter | start of range to delete |
end_iter | end of range |
default_editable | whether the buffer is editable by default |

#### Returns

whether some text was actually deleted

### ctk_text_buffer_backspace ()

    gboolean
    ctk_text_buffer_backspace (CtkTextBuffer *buffer,
                               CtkTextIter *iter,
                               gboolean interactive,
                               gboolean default_editable);

Performs the appropriate action as if the user hit the delete key with the cursor at the position specified by `iter` . In the normal case a single character will be deleted, but when combining accents are involved, more than one character can be deleted, and when precomposed character and accent combinations are involved, less than one character will be deleted.

Because the buffer is modified, all outstanding iterators become invalid after calling this function; however, the `iter` will be re-initialized to point to the location where text was deleted.

#### Parameters

buffer | a CtkTextBuffer |
iter | a position in `buffer` |
interactive | whether the deletion is caused by user interaction |
default_editable | whether the buffer is editable by default |

#### Returns

`TRUE` if the buffer was modified

Since: 2.6

### ctk_text_buffer_set_text ()

    void
    ctk_text_buffer_set_text (CtkTextBuffer *buffer,
                              const gchar *text,
                              gint len);

Deletes current contents of `buffer` , and inserts `text` instead. If `len` is -1, `text` must be nul-terminated. `text` must be valid UTF-8.

#### Parameters

buffer | a CtkTextBuffer |
text | UTF-8 text to insert |
len | length of `text` in bytes |

### ctk_text_buffer_get_text ()

    gchar *
    ctk_text_buffer_get_text (CtkTextBuffer *buffer,
                              const CtkTextIter *start,
                              const CtkTextIter *end,
                              gboolean include_hidden_chars);

Returns the text in the range [`start` ,`end` ). Excludes undisplayed text (text marked with tags that set the invisibility attribute) if `include_hidden_chars` is `FALSE`. Does not include characters representing embedded images, so byte and character indexes into the returned string do not correspond to byte and character indexes into the buffer. Contrast with `ctk_text_buffer_get_slice()`.

#### Parameters

buffer | a CtkTextBuffer |
start | start of a range |
end | end of a range |
include_hidden_chars | whether to include invisible text |

#### Returns

an allocated UTF-8 string.

[transfer full]

### ctk_text_buffer_get_slice ()

    gchar *
    ctk_text_buffer_get_slice (CtkTextBuffer *buffer,
                               const CtkTextIter *start,
                               const CtkTextIter *end,
                               gboolean include_hidden_chars);

Returns the text in the range [`start` ,`end` ). Excludes undisplayed text (text marked with tags that set the invisibility attribute) if `include_hidden_chars` is `FALSE`. The returned string includes a 0xFFFC character whenever the buffer contains embedded images, so byte and character indexes into the returned string do correspond to byte and character indexes into the buffer. Contrast with `ctk_text_buffer_get_text()`. Note that 0xFFFC can occur in normal text as well, so it is not a reliable indicator that a pixbuf or widget is in the buffer.

#### Parameters

buffer | a CtkTextBuffer |
start | start of a range |
end | end of a range |
include_hidden_chars | whether to include invisible text |

#### Returns

an allocated UTF-8 string.

[transfer full]

### ctk_text_buffer_insert_pixbuf ()

    void
    ctk_text_buffer_insert_pixbuf (CtkTextBuffer *buffer,
                                   CtkTextIter *iter,
                                   GdkPixbuf *pixbuf);

Inserts an image into the text buffer at `iter` . The image will be counted as one character in character counts, and when obtaining the buffer contents as a string, will be represented by the Unicode “object replacement character” 0xFFFC. Note that the “slice” variants for obtaining portions of the buffer as a string include this character for pixbufs, but the “text” variants do not. e.g. see `ctk_text_buffer_get_slice()` and `ctk_text_buffer_get_text()`.

#### Parameters

buffer | a CtkTextBuffer |
iter | location to insert the pixbuf |
pixbuf | a GdkPixbuf |

### ctk_text_buffer_insert_child_anchor ()

    void
    ctk_text_buffer_insert_child_anchor (CtkTextBuffer *buffer,
                                         CtkTextIter *iter,
                                         CtkTextChildAnchor *anchor);

Inserts a child widget anchor into the text buffer at `iter` . The anchor will be counted as one character in character counts, and when obtaining the buffer contents as a string, will be represented by the Unicode “object replacement character” 0xFFFC. Note that the “slice” variants for obtaining portions of the buffer as a string include this character for child anchors, but the “text” variants do not. E.g. see `ctk_text_buffer_get_slice()` and `ctk_text_buffer_get_text()`. Consider `ctk_text_buffer_create_child_anchor()` as a more convenient alternative to this function. The buffer will add a reference to the anchor, so you can unref it after insertion.

#### Parameters

buffer | a CtkTextBuffer |
iter | location to insert the anchor |
anchor | a CtkTextChildAnchor |

### ctk_text_buffer_create_child_anchor ()

    CtkTextChildAnchor *
    ctk_text_buffer_create_child_anchor (CtkTextBuffer *buffer,
                                         CtkTextIter *iter);

This is a convenience function which simply creates a child anchor with `ctk_text_child_anchor_new()` and inserts it into the buffer with `ctk_text_buffer_insert_child_anchor()`. The new anchor is owned by the buffer; no reference count is returned to the caller of `ctk_text_buffer_create_child_anchor()`.

#### Parameters

buffer | a CtkTextBuffer |
iter | location in the buffer |

#### Returns

the created child anchor.

[transfer none]

### ctk_text_buffer_create_mark ()

    CtkTextMark *
    ctk_text_buffer_create_mark (CtkTextBuffer *buffer,
                                 const gchar *mark_name,
                                 const CtkTextIter *where,
                                 gboolean left_gravity);

Creates a mark at position `where` . If `mark_name` is `NULL`, the mark is anonymous; otherwise, the mark can be retrieved by name using `ctk_text_buffer_get_mark()`. If a mark has left gravity, and text is inserted at the mark’s current location, the mark will be moved to the left of the newly-inserted text. If the mark has right gravity (`left_gravity` = `FALSE`), the mark will end up on the right of newly-inserted text. The standard left-to-right cursor is a mark with right gravity (when you type, the cursor stays on the right side of the text you’re typing).

The caller of this function does not own a reference to the returned CtkTextMark, so you can ignore the return value if you like. Marks are owned by the buffer and go away when the buffer does.

Emits the “mark-set” signal as notification of the mark's initial placement.

#### Parameters

buffer | a CtkTextBuffer |
mark_name | name for mark, or `NULL`. | [allow-none]
where | location to place mark |
left_gravity | whether the mark has left gravity |

#### Returns

the new CtkTextMark object.

[transfer none]

### ctk_text_buffer_move_mark ()

    void
    ctk_text_buffer_move_mark (CtkTextBuffer *buffer,
                               CtkTextMark *mark,
                               const CtkTextIter *where);

Moves `mark` to the new location `where` . Emits the “mark-set” signal as notification of the move.

#### Parameters

buffer | a CtkTextBuffer |
mark | a CtkTextMark |
where | new location for `mark` in `buffer` |

### ctk_text_buffer_move_mark_by_name ()

    void
    ctk_text_buffer_move_mark_by_name (CtkTextBuffer *buffer,
                                       const gchar *name,
                                       const CtkTextIter *where);

Moves the mark named `name` (which must exist) to location `where` . See `ctk_text_buffer_move_mark()` for details.

#### Parameters

buffer | a CtkTextBuffer |
name | name of a mark |
where | new location for mark |

### ctk_text_buffer_add_mark ()

    void
    ctk_text_buffer_add_mark (CtkTextBuffer *buffer,
                              CtkTextMark *mark,
                              const CtkTextIter *where);

Adds the mark at position `where` . The mark must not be added to another buffer, and if its name is not `NULL` then there must not be another mark in the buffer with the same name.

Emits the “mark-set” signal as notification of the mark's initial placement.

#### Parameters

buffer | a CtkTextBuffer |
mark | the mark to add |
where | location to place mark |

Since: 2.12

### ctk_text_buffer_delete_mark ()

    void
    ctk_text_buffer_delete_mark (CtkTextBuffer *buffer,
                                 CtkTextMark *mark);

Deletes `mark` , so that it’s no longer located anywhere in the buffer. Removes the reference the buffer holds to the mark, so if you haven’t called `g_object_ref()` on the mark, it will be freed. Even if the mark isn’t freed, most operations on `mark` become invalid, until it gets added to a buffer again with `ctk_text_buffer_add_mark()`. Use `ctk_text_mark_get_deleted()` to find out if a mark has been removed from its buffer. The “mark-deleted” signal will be emitted as notification after the mark is deleted.

#### Parameters

buffer | a CtkTextBuffer |
mark | a CtkTextMark in `buffer` |

### ctk_text_buffer_delete_mark_by_name ()

    void
    ctk_text_buffer_delete_mark_by_name (CtkTextBuffer *buffer,
                                         const gchar *name);

Deletes the mark named `name` ; the mark must exist. See `ctk_text_buffer_delete_mark()` for details.

#### Parameters

buffer | a CtkTextBuffer |
name | name of a mark in `buffer` |

### ctk_text_buffer_get_mark ()

    CtkTextMark *
    ctk_text_buffer_get_mark (CtkTextBuffer *buffer,
                              const gchar *name);

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

#### Parameters

buffer | a CtkTextBuffer |
name | a mark name |

#### Returns

a CtkTextMark, or `NULL`.

[nullable][transfer none]

### ctk_text_buffer_get_insert ()

    CtkTextMark *
    ctk_text_buffer_get_insert (CtkTextBuffer *buffer);

Returns the mark that represents the cursor (insertion point). Equivalent to calling `ctk_text_buffer_get_mark()` to get the mark named “insert”, but very slightly more efficient, and involves less typing.

#### Parameters

buffer | a CtkTextBuffer |

#### Returns

insertion point mark.

[transfer none]

### ctk_text_buffer_get_selection_bound ()

    CtkTextMark *
    ctk_text_buffer_get_selection_bound (CtkTextBuffer *buffer);

Returns the mark that represents the selection bound. Equivalent to calling `ctk_text_buffer_get_mark()` to get the mark named “selection_bound”, but very slightly more efficient, and involves less typing.

The currently-selected text in `buffer` is the region between the “selection_bound” and “insert” marks. If “selection_bound” and “insert” are in the same place, then there is no current selection. `ctk_text_buffer_get_selection_bounds()` is another convenient function for handling the selection, if you just want to know whether there’s a selection and what its bounds are.

#### Parameters

buffer | a CtkTextBuffer |

#### Returns

selection bound mark.

[transfer none]

### ctk_text_buffer_get_has_selection ()

    gboolean
    ctk_text_buffer_get_has_selection (CtkTextBuffer *buffer);

Indicates whether the buffer has some text currently selected.

#### Parameters

buffer | a CtkTextBuffer |

#### Returns

`TRUE` if the there is text selected

Since: 2.10

### ctk_text_buffer_place_cursor ()

    void
    ctk_text_buffer_place_cursor (CtkTextBuffer *buffer,
                                  const CtkTextIter *where);

This function moves the “insert” and “selection_bound” marks simultaneously. If you move them to the same place in two steps with `ctk_text_buffer_move_mark()`, you will temporarily select a region in between their old and new locations, which can be pretty inefficient since the temporarily-selected region will force stuff to be recalculated. This function moves them as a unit, which can be optimized.

#### Parameters

buffer | a CtkTextBuffer |
where | where to put the cursor |

### ctk_text_buffer_select_range ()

    void
    ctk_text_buffer_select_range (CtkTextBuffer *buffer,
                                  const CtkTextIter *ins,
                                  const CtkTextIter *bound);

This function moves the “insert” and “selection_bound” marks simultaneously. If you move them in two steps with `ctk_text_buffer_move_mark()`, you will temporarily select a region in between their old and new locations, which can be pretty inefficient since the temporarily-selected region will force stuff to be recalculated. This function moves them as a unit, which can be optimized.

#### Parameters

buffer | a CtkTextBuffer |
ins | where to put the “insert” mark |
bound | where to put the “selection_bound” mark |

Since: 2.4

### ctk_text_buffer_apply_tag ()

    void
    ctk_text_buffer_apply_tag (CtkTextBuffer *buffer,
                               CtkTextTag *tag,
                               const CtkTextIter *start,
                               const CtkTextIter *end);

Emits the “apply-tag” signal on `buffer` . The default handler for the signal applies `tag` to the given range. `start` and `end` do not have to be in order.

#### Parameters

buffer | a CtkTextBuffer |
tag | a CtkTextTag |
start | one bound of range to be tagged |
end | other bound of range to be tagged |

### ctk_text_buffer_remove_tag ()

    void
    ctk_text_buffer_remove_tag (CtkTextBuffer *buffer,
                                CtkTextTag *tag,
                                const CtkTextIter *start,
                                const CtkTextIter *end);

Emits the “remove-tag” signal. The default handler for the signal removes all occurrences of `tag` from the given range. `start` and `end` don’t have to be in order.

#### Parameters

buffer | a CtkTextBuffer |
tag | a CtkTextTag |
start | one bound of range to be untagged |
end | other bound of range to be untagged |

### ctk_text_buffer_apply_tag_by_name ()

    void
    ctk_text_buffer_apply_tag_by_name (CtkTextBuffer *buffer,
                                       const gchar *name,
                                       const CtkTextIter *start,
                                       const CtkTextIter *end);

Calls `ctk_text_tag_table_lookup()` on the buffer’s tag table to get a CtkTextTag, then calls `ctk_text_buffer_apply_tag()`.

#### Parameters

buffer | a CtkTextBuffer |
name | name of a named CtkTextTag |
start | one bound of range to be tagged |
end | other bound of range to be tagged |

### ctk_text_buffer_remove_tag_by_name ()

    void
    ctk_text_buffer_remove_tag_by_name (CtkTextBuffer *buffer,
                                        const gchar *name,
                                        const CtkTextIter *start,
                                        const CtkTextIter *end);

Calls `ctk_text_tag_table_lookup()` on the buffer’s tag table to get a CtkTextTag, then calls `ctk_text_buffer_remove_tag()`.

#### Parameters

buffer | a CtkTextBuffer |
name | name of a CtkTextTag |
start | one bound of range to be untagged |
end | other bound of range to be untagged |

### ctk_text_buffer_remove_all_tags ()

    void
    ctk_text_buffer_remove_all_tags (CtkTextBuffer *buffer,
                                     const CtkTextIter *start,
                                     const CtkTextIter *end);

Removes all tags in the range between `start` and `end` . Be careful with this function; it could remove tags added in code unrelated to the code you’re currently writing. That is, using this function is probably a bad idea if you have two or more unrelated code sections that add tags.

#### Parameters

buffer | a CtkTextBuffer |
start | one bound of range to be untagged |
end | other bound of range to be untagged |

### ctk_text_buffer_create_tag ()

    CtkTextTag *
    ctk_text_buffer_create_tag (CtkTextBuffer *buffer,
                                const gchar *tag_name,
                                const gchar *first_property_name,
                                ...);

Creates a tag and adds it to the tag table for `buffer` . Equivalent to calling `ctk_text_tag_new()` and then adding the tag to the buffer’s tag table. The returned tag is owned by the buffer’s tag table, so the ref count will be equal to one.

If `tag_name` is `NULL`, the tag is anonymous.

If `tag_name` is non-`NULL`, a tag called `tag_name` must not already exist in the tag table for this buffer.

The `first_property_name` argument and subsequent arguments are a list of properties to set on the tag, as with `g_object_set()`.

#### Parameters

buffer | a CtkTextBuffer |
tag_name | name of the new tag, or `NULL`. | [allow-none]
first_property_name | name of first property to set, or `NULL`. | [allow-none]
... | `NULL`-terminated list of property names and values |

#### Returns

a new tag.

[transfer none]

### ctk_text_buffer_get_iter_at_line_offset ()

    void
    ctk_text_buffer_get_iter_at_line_offset
                                   (CtkTextBuffer *buffer,
                                    CtkTextIter *iter,
                                    gint line_number,
                                    gint char_offset);

Obtains an iterator pointing to `char_offset` within the given line. Note characters, not bytes; UTF-8 may encode one character as multiple bytes.

Before the 3.20 version, it was not allowed to pass an invalid location.

Since the 3.20 version, if `line_number` is greater than the number of lines in the `buffer` , the end iterator is returned. And if `char_offset` is off the end of the line, the iterator at the end of the line is returned.

#### Parameters

buffer | a CtkTextBuffer |
iter | iterator to initialize. | [out]
line_number | line number counting from 0 |
char_offset | char offset from start of line |

### ctk_text_buffer_get_iter_at_offset ()

    void
    ctk_text_buffer_get_iter_at_offset (CtkTextBuffer *buffer,
                                        CtkTextIter *iter,
                                        gint char_offset);

Initializes `iter` to a position `char_offset` chars from the start of the entire buffer. If `char_offset` is -1 or greater than the number of characters in the buffer, `iter` is initialized to the end iterator, the iterator one past the last valid character in the buffer.

#### Parameters

buffer | a CtkTextBuffer |
iter | iterator to initialize. | [out]
char_offset | char offset from start of buffer, counting from 0, or -1 |

### ctk_text_buffer_get_iter_at_line ()

    void
    ctk_text_buffer_get_iter_at_line (CtkTextBuffer *buffer,
                                      CtkTextIter *iter,
                                      gint line_number);

Initializes `iter` to the start of the given line. If `line_number` is greater than the number of lines in the `buffer` , the end iterator is returned.

#### Parameters

buffer | a CtkTextBuffer |
iter | iterator to initialize. | [out]
line_number | line number counting from 0 |

### ctk_text_buffer_get_iter_at_line_index ()

    void
    ctk_text_buffer_get_iter_at_line_index
                                   (CtkTextBuffer *buffer,
                                    CtkTextIter *iter,
                                    gint line_number,
                                    gint byte_index);

Obtains an iterator pointing to `byte_index` within the given line. `byte_index` must be the start of a UTF-8 character. Note bytes, not characters; UTF-8 may encode one character as multiple bytes.

Before the 3.20 version, it was not allowed to pass an invalid location.

Since the 3.20 version, if `line_number` is greater than the number of lines in the `buffer` , the end iterator is returned. And if `byte_index` is off the end of the line, the iterator at the end of the line is returned.

#### Parameters

buffer | a CtkTextBuffer |
iter | iterator to initialize. | [out]
line_number | line number counting from 0 |
byte_index | byte index from start of line |

### ctk_text_buffer_get_iter_at_mark ()

    void
    ctk_text_buffer_get_iter_at_mark (CtkTextBuffer *buffer,
                                      CtkTextIter *iter,
                                      CtkTextMark *mark);

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

#### Parameters

buffer | a CtkTextBuffer |
iter | iterator to initialize. | [out]
mark | a CtkTextMark in `buffer` |

### ctk_text_buffer_get_iter_at_child_anchor ()

    void
    ctk_text_buffer_get_iter_at_child_anchor
                                   (CtkTextBuffer *buffer,
                                    CtkTextIter *iter,
                                    CtkTextChildAnchor *anchor);

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

#### Parameters

buffer | a CtkTextBuffer |
iter | an iterator to be initialized. | [out]
anchor | a child anchor that appears in `buffer` |

### ctk_text_buffer_get_start_iter ()

    void
    ctk_text_buffer_get_start_iter (CtkTextBuffer *buffer,
                                    CtkTextIter *iter);

Initialized `iter` with the first position in the text buffer. This is the same as using `ctk_text_buffer_get_iter_at_offset()` to get the iter at character offset 0.

#### Parameters

buffer | a CtkTextBuffer |
iter | iterator to initialize. | [out]

### ctk_text_buffer_get_end_iter ()

    void
    ctk_text_buffer_get_end_iter (CtkTextBuffer *buffer,
                                  CtkTextIter *iter);

Initializes `iter` with the “end iterator,” one past the last valid character in the text buffer. If dereferenced with `ctk_text_iter_get_char()`, the end iterator has a character value of 0. The entire buffer lies in the range from the first position in the buffer (call `ctk_text_buffer_get_start_iter()` to get character position 0) to the end iterator.

#### Parameters

buffer | a CtkTextBuffer |
iter | iterator to initialize. | [out]

### ctk_text_buffer_get_bounds ()

    void
    ctk_text_buffer_get_bounds (CtkTextBuffer *buffer,
                                CtkTextIter *start,
                                CtkTextIter *end);

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

#### Parameters

buffer | a CtkTextBuffer |
start | iterator to initialize with first position in the buffer. | [out]
end | iterator to initialize with the end iterator. | [out]

### ctk_text_buffer_get_modified ()

    gboolean
    ctk_text_buffer_get_modified (CtkTextBuffer *buffer);

Indicates whether the buffer has been modified since the last call to `ctk_text_buffer_set_modified()` set the modification flag to `FALSE`. Used for example to enable a “save” function in a text editor.

#### Parameters

buffer | a CtkTextBuffer |

#### Returns

`TRUE` if the buffer has been modified

### ctk_text_buffer_set_modified ()

    void
    ctk_text_buffer_set_modified (CtkTextBuffer *buffer,
                                  gboolean setting);

Used to keep track of whether the buffer has been modified since the last time it was saved. Whenever the buffer is saved to disk, call ctk_text_buffer_set_modified (`buffer` , FALSE). When the buffer is modified, it will automatically toggled on the modified bit again. When the modified bit flips, the buffer emits the “modified-changed” signal.

#### Parameters

buffer | a CtkTextBuffer |
setting | modification flag setting |

### ctk_text_buffer_delete_selection ()

    gboolean
    ctk_text_buffer_delete_selection (CtkTextBuffer *buffer,
                                      gboolean interactive,
                                      gboolean default_editable);

Deletes the range between the “insert” and “selection_bound” marks, that is, the currently-selected text. If `interactive` is `TRUE`, the editability of the selection will be considered (users can’t delete uneditable text).

#### Parameters

buffer | a CtkTextBuffer |
interactive | whether the deletion is caused by user interaction |
default_editable | whether the buffer is editable by default |

#### Returns

whether there was a non-empty selection to delete

### ctk_text_buffer_paste_clipboard ()

    void
    ctk_text_buffer_paste_clipboard (CtkTextBuffer *buffer,
                                     CtkClipboard *clipboard,
                                     CtkTextIter *override_location,
                                     gboolean default_editable);

Pastes the contents of a clipboard. If `override_location` is `NULL`, the pasted text will be inserted at the cursor position, or the buffer selection will be replaced if the selection is non-empty.

Note: pasting is asynchronous, that is, we’ll ask for the paste data and return, and at some point later after the main loop runs, the paste data will be inserted.

#### Parameters

buffer | a CtkTextBuffer |
clipboard | the CtkClipboard to paste from |
override_location | location to insert pasted text, or `NULL`. | [allow-none]
default_editable | whether the buffer is editable by default |

### ctk_text_buffer_copy_clipboard ()

    void
    ctk_text_buffer_copy_clipboard (CtkTextBuffer *buffer,
                                    CtkClipboard *clipboard);

Copies the currently-selected text to a clipboard.

#### Parameters

buffer | a CtkTextBuffer |
clipboard | the CtkClipboard object to copy to |

### ctk_text_buffer_cut_clipboard ()

    void
    ctk_text_buffer_cut_clipboard (CtkTextBuffer *buffer,
                                   CtkClipboard *clipboard,
                                   gboolean default_editable);

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

#### Parameters

buffer | a CtkTextBuffer |
clipboard | the CtkClipboard object to cut to |
default_editable | default editability of the buffer |

### ctk_text_buffer_get_selection_bounds ()

    gboolean
    ctk_text_buffer_get_selection_bounds (CtkTextBuffer *buffer,
                                          CtkTextIter *start,
                                          CtkTextIter *end);

Returns `TRUE` if some text is selected; places the bounds of the selection in `start` and `end` (if the selection has length 0, then `start` and `end` are filled in with the same value). `start` and `end` will be in ascending order. If `start` and `end` are NULL, then they are not filled in, but the return value still indicates whether text is selected.

#### Parameters

buffer | a CtkTextBuffer a CtkTextBuffer |
start | iterator to initialize with selection start. | [out]
end | iterator to initialize with selection end. | [out]

#### Returns

whether the selection has nonzero length

### ctk_text_buffer_begin_user_action ()

    void
    ctk_text_buffer_begin_user_action (CtkTextBuffer *buffer);

Called to indicate that the buffer operations between here and a call to `ctk_text_buffer_end_user_action()` are part of a single user-visible operation. The operations between `ctk_text_buffer_begin_user_action()` and `ctk_text_buffer_end_user_action()` can then be grouped when creating an undo stack. CtkTextBuffer maintains a count of calls to `ctk_text_buffer_begin_user_action()` that have not been closed with a call to `ctk_text_buffer_end_user_action()`, and emits the “begin-user-action” and “end-user-action” signals only for the outermost pair of calls. This allows you to build user actions from other user actions.

The “interactive” buffer mutation functions, such as `ctk_text_buffer_insert_interactive()`, automatically call begin/end user action around the buffer operations they perform, so there's no need to add extra calls if you user action consists solely of a single call to one of those functions.

#### Parameters

buffer | a CtkTextBuffer |

### ctk_text_buffer_end_user_action ()

    void
    ctk_text_buffer_end_user_action (CtkTextBuffer *buffer);

Should be paired with a call to `ctk_text_buffer_begin_user_action()`. See that function for a full explanation.

#### Parameters

buffer | a CtkTextBuffer |

### ctk_text_buffer_add_selection_clipboard ()

    void
    ctk_text_buffer_add_selection_clipboard
                                   (CtkTextBuffer *buffer,
                                    CtkClipboard *clipboard);

Adds `clipboard` to the list of clipboards in which the selection contents of `buffer` are available. In most cases, `clipboard` will be the CtkClipboard of type `CDK_SELECTION_PRIMARY` for a view of `buffer` .

#### Parameters

buffer | a CtkTextBuffer |
clipboard | a CtkClipboard |

### ctk_text_buffer_remove_selection_clipboard ()

    void
    ctk_text_buffer_remove_selection_clipboard
                                   (CtkTextBuffer *buffer,
                                    CtkClipboard *clipboard);

Removes a CtkClipboard added with `ctk_text_buffer_add_selection_clipboard()`.

#### Parameters

buffer | a CtkTextBuffer |
clipboard | a CtkClipboard added to `buffer` by `ctk_text_buffer_add_selection_clipboard()` |

### CtkTextBufferDeserializeFunc ()

    gboolean
    (*CtkTextBufferDeserializeFunc) (CtkTextBuffer *register_buffer,
                                     CtkTextBuffer *content_buffer,
                                     CtkTextIter *iter,
                                     const guint8 *data,
                                     gsize length,
                                     gboolean create_tags,
                                     gpointer user_data,
                                     GError **error);

A function that is called to deserialize rich text that has been serialized with `ctk_text_buffer_serialize()`, and insert it at `iter` .

#### Parameters

register_buffer | the CtkTextBuffer the format is registered with |
content_buffer | the CtkTextBuffer to deserialize into |
iter | insertion point for the deserialized text |
data | data to deserialize. | [array length=length]
length | length of `data` |
create_tags | `TRUE` if deserializing may create tags |
user_data | user data that was specified when registering the format |
error | return location for a GError |

#### Returns

`TRUE` on success, `FALSE` otherwise

### ctk_text_buffer_deserialize ()

    gboolean
    ctk_text_buffer_deserialize (CtkTextBuffer *register_buffer,
                                 CtkTextBuffer *content_buffer,
                                 CdkAtom format,
                                 CtkTextIter *iter,
                                 const guint8 *data,
                                 gsize length,
                                 GError **error);

This function deserializes rich text in format `format` and inserts it at `iter` .

`formats` to be used must be registered using `ctk_text_buffer_register_deserialize_format()` or `ctk_text_buffer_register_deserialize_tagset()` beforehand.

#### Parameters

register_buffer | the CtkTextBuffer `format` is registered with |
content_buffer | the CtkTextBuffer to deserialize into |
format | the rich text format to use for deserializing |
iter | insertion point for the deserialized text |
data | data to deserialize. | [array length=length]
length | length of `data` |
error | return location for a GError |

#### Returns

`TRUE` on success, `FALSE` otherwise.

Since: 2.10

### ctk_text_buffer_deserialize_get_can_create_tags ()

    gboolean
    ctk_text_buffer_deserialize_get_can_create_tags
                                   (CtkTextBuffer *buffer,
                                    CdkAtom format);

This functions returns the value set with `ctk_text_buffer_deserialize_set_can_create_tags()`

#### Parameters

buffer | a CtkTextBuffer |
format | a CdkAtom representing a registered rich text format |

#### Returns

whether deserializing this format may create tags

Since: 2.10

### ctk_text_buffer_deserialize_set_can_create_tags ()

    void
    ctk_text_buffer_deserialize_set_can_create_tags
                                   (CtkTextBuffer *buffer,
                                    CdkAtom format,
                                    gboolean can_create_tags);

Use this function to allow a rich text deserialization function to create new tags in the receiving buffer. Note that using this function is almost always a bad idea, because the rich text functions you register should know how to map the rich text format they handler to your text buffers set of tags.

The ability of creating new (arbitrary!) tags in the receiving buffer is meant for special rich text formats like the internal one that is registered using `ctk_text_buffer_register_deserialize_tagset()`, because that format is essentially a dump of the internal structure of the source buffer, including its tag names.

You should allow creation of tags only if you know what you are doing, e.g. if you defined a tagset name for your application suite’s text buffers and you know that it’s fine to receive new tags from these buffers, because you know that your application can handle the newly created tags.

#### Parameters

buffer | a CtkTextBuffer |
format | a CdkAtom representing a registered rich text format |
can_create_tags | whether deserializing this format may create tags |

Since: 2.10

### ctk_text_buffer_get_copy_target_list ()

    CtkTargetList *
    ctk_text_buffer_get_copy_target_list (CtkTextBuffer *buffer);

This function returns the list of targets this text buffer can provide for copying and as DND source. The targets in the list are added with `info` values from the CtkTextBufferTargetInfo enum, using `ctk_target_list_add_rich_text_targets()` and `ctk_target_list_add_text_targets()`.

#### Parameters

buffer | a CtkTextBuffer |

#### Returns

the CtkTargetList.

[transfer none]

Since: 2.10

### ctk_text_buffer_get_deserialize_formats ()

    CdkAtom *
    ctk_text_buffer_get_deserialize_formats
                                   (CtkTextBuffer *buffer,
                                    gint *n_formats);

This function returns the rich text deserialize formats registered with `buffer` using `ctk_text_buffer_register_deserialize_format()` or `ctk_text_buffer_register_deserialize_tagset()`

#### Parameters

buffer | a CtkTextBuffer |
n_formats | return location for the number of formats. | [out]

#### Returns

an array of CdkAtoms representing the registered formats.

[array length=n_formats][transfer container]

Since: 2.10

### ctk_text_buffer_get_paste_target_list ()

    CtkTargetList *
    ctk_text_buffer_get_paste_target_list (CtkTextBuffer *buffer);

This function returns the list of targets this text buffer supports for pasting and as DND destination. The targets in the list are added with `info` values from the CtkTextBufferTargetInfo enum, using `ctk_target_list_add_rich_text_targets()` and `ctk_target_list_add_text_targets()`.

#### Parameters

buffer | a CtkTextBuffer |

#### Returns

the CtkTargetList.

[transfer none]

Since: 2.10

### ctk_text_buffer_get_serialize_formats ()

    CdkAtom *
    ctk_text_buffer_get_serialize_formats (CtkTextBuffer *buffer,
                                           gint *n_formats);

This function returns the rich text serialize formats registered with `buffer` using `ctk_text_buffer_register_serialize_format()` or `ctk_text_buffer_register_serialize_tagset()`

#### Parameters

buffer | a CtkTextBuffer |
n_formats | return location for the number of formats. | [out]

#### Returns

an array of CdkAtoms representing the registered formats.

[array length=n_formats][transfer container]

Since: 2.10

### ctk_text_buffer_register_deserialize_format ()

    CdkAtom
    ctk_text_buffer_register_deserialize_format
                                   (CtkTextBuffer *buffer,
                                    const gchar *mime_type,
                                    CtkTextBufferDeserializeFunc function,
                                    gpointer user_data,
                                    GDestroyNotify user_data_destroy);

This function registers a rich text deserialization `function` along with its `mime_type` with the passed `buffer` .

#### Parameters

buffer | a CtkTextBuffer |
mime_type | the format’s mime-type |
function | the deserialize function to register |
user_data | `function` ’s user_data |
user_data_destroy | a function to call when `user_data` is no longer needed |

#### Returns

the CdkAtom that corresponds to the newly registered format’s mime-type.

[transfer none]

Since: 2.10

### ctk_text_buffer_register_deserialize_tagset ()

    CdkAtom
    ctk_text_buffer_register_deserialize_tagset
                                   (CtkTextBuffer *buffer,
                                    const gchar *tagset_name);

This function registers CTK+’s internal rich text serialization format with the passed `buffer` . See `ctk_text_buffer_register_serialize_tagset()` for details.

#### Parameters

buffer | a CtkTextBuffer |
tagset_name | an optional tagset name, on `NULL`. | [allow-none]

#### Returns

the CdkAtom that corresponds to the newly registered format’s mime-type.

[transfer none]

Since: 2.10

### ctk_text_buffer_register_serialize_format ()

    CdkAtom
    ctk_text_buffer_register_serialize_format
                                   (CtkTextBuffer *buffer,
                                    const gchar *mime_type,
                                    CtkTextBufferSerializeFunc function,
                                    gpointer user_data,
                                    GDestroyNotify user_data_destroy);

This function registers a rich text serialization `function` along with its `mime_type` with the passed `buffer` .

#### Parameters

buffer | a CtkTextBuffer |
mime_type | the format’s mime-type |
function | the serialize function to register |
user_data | `function` ’s user_data |
user_data_destroy | a function to call when `user_data` is no longer needed |

#### Returns

the CdkAtom that corresponds to the newly registered format’s mime-type.

[transfer none]

Since: 2.10

### ctk_text_buffer_register_serialize_tagset ()

    CdkAtom
    ctk_text_buffer_register_serialize_tagset
                                   (CtkTextBuffer *buffer,
                                    const gchar *tagset_name);

This function registers CTK+’s internal rich text serialization format with the passed `buffer` . The internal format does not comply to any standard rich text format and only works between CtkTextBuffer instances. It is capable of serializing all of a text buffer’s tags and embedded pixbufs.

This function is just a wrapper around `ctk_text_buffer_register_serialize_format()`. The mime type used for registering is “application/x-ctk-text-buffer-rich-text”, or “application/x-ctk-text-buffer-rich-text;format=`tagset_name` ” if a `tagset_name` was passed.

The `tagset_name` can be used to restrict the transfer of rich text to buffers with compatible sets of tags, in order to avoid unknown tags from being pasted. It is probably the common case to pass an identifier != `NULL` here, since the `NULL` tagset requires the receiving buffer to deal with with pasting of arbitrary tags.

#### Parameters

buffer | a CtkTextBuffer |
tagset_name | an optional tagset name, on `NULL`. | [allow-none]

#### Returns

the CdkAtom that corresponds to the newly registered format’s mime-type.

[transfer none]

Since: 2.10

### CtkTextBufferSerializeFunc ()

    guint8 *
    (*CtkTextBufferSerializeFunc) (CtkTextBuffer *register_buffer,
                                   CtkTextBuffer *content_buffer,
                                   const CtkTextIter *start,
                                   const CtkTextIter *end,
                                   gsize *length,
                                   gpointer user_data);

A function that is called to serialize the content of a text buffer. It must return the serialized form of the content.

#### Parameters

register_buffer | the CtkTextBuffer for which the format is registered |
content_buffer | the CtkTextBuffer to serialize |
start | start of the block of text to serialize |
end | end of the block of text to serialize |
length | Return location for the length of the serialized data |
user_data | user data that was specified when registering the format |

#### Returns

a newly-allocated array of guint8 which contains the serialized data, or `NULL` if an error occurred.

[nullable]

### ctk_text_buffer_serialize ()

    guint8 *
    ctk_text_buffer_serialize (CtkTextBuffer *register_buffer,
                               CtkTextBuffer *content_buffer,
                               CdkAtom format,
                               const CtkTextIter *start,
                               const CtkTextIter *end,
                               gsize *length);

This function serializes the portion of text between `start` and `end` in the rich text format represented by `format` .

`formats` to be used must be registered using `ctk_text_buffer_register_serialize_format()` or `ctk_text_buffer_register_serialize_tagset()` beforehand.

#### Parameters

register_buffer | the CtkTextBuffer `format` is registered with |
content_buffer | the CtkTextBuffer to serialize |
format | the rich text format to use for serializing |
start | start of block of text to serialize |
end | end of block of test to serialize |
length | return location for the length of the serialized data. | [out]

#### Returns

the serialized data, encoded as `format` .

[array length=length][transfer full]

Since: 2.10

### ctk_text_buffer_unregister_deserialize_format ()

    void
    ctk_text_buffer_unregister_deserialize_format
                                   (CtkTextBuffer *buffer,
                                    CdkAtom format);

This function unregisters a rich text format that was previously registered using `ctk_text_buffer_register_deserialize_format()` or `ctk_text_buffer_register_deserialize_tagset()`.

#### Parameters

buffer | a CtkTextBuffer |
format | a CdkAtom representing a registered rich text format. |

Since: 2.10

### ctk_text_buffer_unregister_serialize_format ()

    void
    ctk_text_buffer_unregister_serialize_format
                                   (CtkTextBuffer *buffer,
                                    CdkAtom format);

This function unregisters a rich text format that was previously registered using `ctk_text_buffer_register_serialize_format()` or `ctk_text_buffer_register_serialize_tagset()`

#### Parameters

buffer | a CtkTextBuffer |
format | a CdkAtom representing a registered rich text format. |

Since: 2.10

## Types and Values

### CtkTextBuffer

    typedef struct _CtkTextBuffer CtkTextBuffer;

### struct CtkTextBufferClass

    struct CtkTextBufferClass {
      GObjectClass parent_class;

      void (* insert_text)            (CtkTextBuffer      *buffer,
                                       CtkTextIter        *pos,
                                       const gchar        *new_text,
                                       gint                new_text_length);

      void (* insert_pixbuf)          (CtkTextBuffer      *buffer,
                                       CtkTextIter        *iter,
                                       GdkPixbuf          *pixbuf);

      void (* insert_child_anchor)    (CtkTextBuffer      *buffer,
                                       CtkTextIter        *iter,
                                       CtkTextChildAnchor *anchor);

      void (* delete_range)           (CtkTextBuffer      *buffer,
                                       CtkTextIter        *start,
                                       CtkTextIter        *end);

      void (* changed)                (CtkTextBuffer      *buffer);

      void (* modified_changed)       (CtkTextBuffer      *buffer);

      void (* mark_set)               (CtkTextBuffer      *buffer,
                                       const CtkTextIter  *location,
                                       CtkTextMark        *mark);

      void (* mark_deleted)           (CtkTextBuffer      *buffer,
                                       CtkTextMark        *mark);

      void (* apply_tag)              (CtkTextBuffer      *buffer,
                                       CtkTextTag         *tag,
                                       const CtkTextIter  *start,
                                       const CtkTextIter  *end);

      void (* remove_tag)             (CtkTextBuffer      *buffer,
                                       CtkTextTag         *tag,
                                       const CtkTextIter  *start,
                                       const CtkTextIter  *end);

      void (* begin_user_action)      (CtkTextBuffer      *buffer);

      void (* end_user_action)        (CtkTextBuffer      *buffer);

      void (* paste_done)             (CtkTextBuffer      *buffer,
                                       CtkClipboard       *clipboard);
    };

#### Members

`insert_text` () | The class handler for the “insert-text” signal. |
`insert_pixbuf` () | The class handler for the “insert-pixbuf” signal. |
`insert_child_anchor` () | The class handler for the “insert-child-anchor” signal. |
`delete_range` () | The class handler for the “delete-range” signal. |
`changed` () | The class handler for the “changed” signal. |
`modified_changed` () | The class handler for the “modified-changed” signal. |
`mark_set` () | The class handler for the “mark-set” signal. |
`mark_deleted` () | The class handler for the “mark-deleted” signal. |
`apply_tag` () | The class handler for the “apply-tag” signal. |
`remove_tag` () | The class handler for the “remove-tag” signal. |
`begin_user_action` () | The class handler for the “begin-user-action” signal. |
`end_user_action` () | The class handler for the “end-user-action” signal. |
`paste_done` () | The class handler for the “paste-done” signal. |

### enum CtkTextBufferTargetInfo

These values are used as “info” for the targets contained in the lists returned by `ctk_text_buffer_get_copy_target_list()` and `ctk_text_buffer_get_paste_target_list()`.

The values counts down from `-1` to avoid clashes with application added drag destinations which usually start at 0.

#### Members

CTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS | Buffer contents |
CTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT | Rich text |
CTK_TEXT_BUFFER_TARGET_INFO_TEXT | Text |

## Property Details

### The `“copy-target-list”` property

      “copy-target-list”         CtkTargetList *

The list of targets this buffer supports for clipboard copying and as DND source.

Owner: CtkTextBuffer

Flags: Read

Since: 2.10

### The `“cursor-position”` property

      “cursor-position”          int

The position of the insert mark (as offset from the beginning of the buffer). It is useful for getting notified when the cursor moves.

Owner: CtkTextBuffer

Flags: Read

Allowed values: >= 0

Default value: 0

Since: 2.10

### The `“has-selection”` property

      “has-selection”            gboolean

Whether the buffer has some text currently selected.

Owner: CtkTextBuffer

Flags: Read

Default value: FALSE

Since: 2.10

### The `“paste-target-list”` property

      “paste-target-list”        CtkTargetList *

The list of targets this buffer supports for clipboard pasting and as DND destination.

Owner: CtkTextBuffer

Flags: Read

Since: 2.10

### The `“tag-table”` property

      “tag-table”                CtkTextTagTable *

Text Tag Table.

Owner: CtkTextBuffer

Flags: Read / Write / Construct Only

### The `“text”` property

      “text”                     char *

The text content of the buffer. Without child widgets and images, see `ctk_text_buffer_get_text()` for more information.

Owner: CtkTextBuffer

Flags: Read / Write

Default value: ""

Since: 2.8

## Signal Details

### The `“apply-tag”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   CtkTextTag    *tag,
                   CtkTextIter   *start,
                   CtkTextIter   *end,
                   gpointer       user_data)

The ::apply-tag signal is emitted to apply a tag to a range of text in a CtkTextBuffer. Applying actually occurs in the default handler.

Note that if your handler runs before the default handler it must not invalidate the `start` and `end` iters (or has to revalidate them).

See also: `ctk_text_buffer_apply_tag()`, `ctk_text_buffer_insert_with_tags()`, `ctk_text_buffer_insert_range()`.

#### Parameters

textbuffer | the object which received the signal |
tag | the applied tag |
start | the start of the range the tag is applied to |
end | the end of the range the tag is applied to |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“begin-user-action”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   gpointer       user_data)

The ::begin-user-action signal is emitted at the beginning of a single user-visible operation on a CtkTextBuffer.

See also: `ctk_text_buffer_begin_user_action()`, `ctk_text_buffer_insert_interactive()`, `ctk_text_buffer_insert_range_interactive()`, `ctk_text_buffer_delete_interactive()`, `ctk_text_buffer_backspace()`, `ctk_text_buffer_delete_selection()`.

#### Parameters

textbuffer | the object which received the signal |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“changed”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   gpointer       user_data)

The ::changed signal is emitted when the content of a CtkTextBuffer has changed.

#### Parameters

textbuffer | the object which received the signal |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“delete-range”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   CtkTextIter   *start,
                   CtkTextIter   *end,
                   gpointer       user_data)

The ::delete-range signal is emitted to delete a range from a CtkTextBuffer.

Note that if your handler runs before the default handler it must not invalidate the `start` and `end` iters (or has to revalidate them). The default signal handler revalidates the `start` and `end` iters to both point to the location where text was deleted. Handlers which run after the default handler (see `g_signal_connect_after()`) do not have access to the deleted text.

See also: `ctk_text_buffer_delete()`.

#### Parameters

textbuffer | the object which received the signal |
start | the start of the range to be deleted |
end | the end of the range to be deleted |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“end-user-action”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   gpointer       user_data)

The ::end-user-action signal is emitted at the end of a single user-visible operation on the CtkTextBuffer.

See also: `ctk_text_buffer_end_user_action()`, `ctk_text_buffer_insert_interactive()`, `ctk_text_buffer_insert_range_interactive()`, `ctk_text_buffer_delete_interactive()`, `ctk_text_buffer_backspace()`, `ctk_text_buffer_delete_selection()`, `ctk_text_buffer_backspace()`.

#### Parameters

textbuffer | the object which received the signal |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“insert-child-anchor”` signal

    void
    user_function (CtkTextBuffer      *textbuffer,
                   CtkTextIter        *location,
                   CtkTextChildAnchor *anchor,
                   gpointer            user_data)

The ::insert-child-anchor signal is emitted to insert a CtkTextChildAnchor in a CtkTextBuffer. Insertion actually occurs in the default handler.

Note that if your handler runs before the default handler it must not invalidate the `location` iter (or has to revalidate it). The default signal handler revalidates it to be placed after the inserted `anchor` .

See also: `ctk_text_buffer_insert_child_anchor()`.

#### Parameters

textbuffer | the object which received the signal |
location | position to insert `anchor` in `textbuffer` |
anchor | the CtkTextChildAnchor to be inserted |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“insert-pixbuf”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   CtkTextIter   *location,
                   GdkPixbuf     *pixbuf,
                   gpointer       user_data)

The ::insert-pixbuf signal is emitted to insert a GdkPixbuf in a CtkTextBuffer. Insertion actually occurs in the default handler.

Note that if your handler runs before the default handler it must not invalidate the `location` iter (or has to revalidate it). The default signal handler revalidates it to be placed after the inserted `pixbuf` .

See also: `ctk_text_buffer_insert_pixbuf()`.

#### Parameters

textbuffer | the object which received the signal |
location | position to insert `pixbuf` in `textbuffer` |
pixbuf | the GdkPixbuf to be inserted |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“insert-text”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   CtkTextIter   *location,
                   char          *text,
                   int            len,
                   gpointer       user_data)

The ::insert-text signal is emitted to insert text in a CtkTextBuffer. Insertion actually occurs in the default handler.

Note that if your handler runs before the default handler it must not invalidate the `location` iter (or has to revalidate it). The default signal handler revalidates it to point to the end of the inserted text.

See also: `ctk_text_buffer_insert()`, `ctk_text_buffer_insert_range()`.

#### Parameters

textbuffer | the object which received the signal |
location | position to insert `text` in `textbuffer` |
text | the UTF-8 text to be inserted |
len | length of the inserted text in bytes |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“mark-deleted”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   CtkTextMark   *mark,
                   gpointer       user_data)

The ::mark-deleted signal is emitted as notification after a CtkTextMark is deleted.

See also: `ctk_text_buffer_delete_mark()`.

#### Parameters

textbuffer | the object which received the signal |
mark | The mark that was deleted |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“mark-set”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   CtkTextIter   *location,
                   CtkTextMark   *mark,
                   gpointer       user_data)

The ::mark-set signal is emitted as notification after a CtkTextMark is set.

See also: `ctk_text_buffer_create_mark()`, `ctk_text_buffer_move_mark()`.

#### Parameters

textbuffer | the object which received the signal |
location | The location of `mark` in `textbuffer` |
mark | The mark that is set |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“modified-changed”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   gpointer       user_data)

The ::modified-changed signal is emitted when the modified bit of a CtkTextBuffer flips.

See also: `ctk_text_buffer_set_modified()`.

#### Parameters

textbuffer | the object which received the signal |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“paste-done”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   CtkClipboard  *clipboard,
                   gpointer       user_data)

The paste-done signal is emitted after paste operation has been completed. This is useful to properly scroll the view to the end of the pasted text. See `ctk_text_buffer_paste_clipboard()` for more details.

#### Parameters

textbuffer | the object which received the signal |
clipboard | the CtkClipboard pasted from |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

Since: 2.16

### The `“remove-tag”` signal

    void
    user_function (CtkTextBuffer *textbuffer,
                   CtkTextTag    *tag,
                   CtkTextIter   *start,
                   CtkTextIter   *end,
                   gpointer       user_data)

The ::remove-tag signal is emitted to remove all occurrences of `tag` from a range of text in a CtkTextBuffer. Removal actually occurs in the default handler.

Note that if your handler runs before the default handler it must not invalidate the `start` and `end` iters (or has to revalidate them).

See also: `ctk_text_buffer_remove_tag()`.

#### Parameters

textbuffer | the object which received the signal |
tag | the tag to be removed |
start | the start of the range the tag is removed from |
end | the end of the range the tag is removed from |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

## See Also

CtkTextView, CtkTextIter, CtkTextMark