Class: Gtk::TextBuffer

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#add_mark(mark, where) ⇒ nil

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

Emits the Gtk::TextBuffer::mark-set signal as notification of the mark’s initial placement.

Parameters:

  • mark (Gtk::TextMark)

    the mark to add

  • where (Gtk::TextIter)

    location to place mark

Returns:

  • (nil)

#add_selection_clipboard(clipboard) ⇒ nil

Adds clipboard to the list of clipboards in which the selection contents of buffer are available. In most cases, clipboard will be the Gtk::Clipboard of type %GDK_SELECTION_PRIMARY for a view of buffer.

Parameters:

Returns:

  • (nil)

#apply_tag(tag, start, end) ⇒ nil

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:

  • tag (Gtk::TextTag)

    a Gtk::TextTag

  • start (Gtk::TextIter)

    one bound of range to be tagged

  • end (Gtk::TextIter)

    other bound of range to be tagged

Returns:

  • (nil)

#apply_tag_by_name(name, start, end) ⇒ nil

Calls gtk_text_tag_table_lookup() on the buffer’s tag table to get a Gtk::TextTag, then calls gtk_text_buffer_apply_tag().

Parameters:

  • name (String)

    name of a named Gtk::TextTag

  • start (Gtk::TextIter)

    one bound of range to be tagged

  • end (Gtk::TextIter)

    other bound of range to be tagged

Returns:

  • (nil)

#backspace(iter, interactive, default_editable) ⇒ TrueClass

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:

  • iter (Gtk::TextIter)

    a position in buffer

  • interactive (TrueClass)

    whether the deletion is caused by user interaction

  • default_editable (TrueClass)

    whether the buffer is editable by default

Returns:

  • (TrueClass)

    true if the buffer was modified

#begin_user_actionnil

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. The operations between gtk_text_buffer_begin_user_action() and gtk_text_buffer_end_user_action() can then be grouped when creating an undo stack. Gtk::TextBuffer maintains a count of calls to gtk_text_buffer_begin_user_action() that have not been closed with a call to gtk_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 gtk_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.

Returns:

  • (nil)

#char_countInteger

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.

Returns:

  • (Integer)

    number of characters in the buffer

#copy_clipboard(clipboard) ⇒ nil

Copies the currently-selected text to a clipboard.

Parameters:

Returns:

  • (nil)

#copy_target_listGtk::TargetList

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

Returns:

  • (Gtk::TargetList)

    copy-target-list

#copy_target_list=(copy_target_list) ⇒ Gtk::TargetList

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

Parameters:

  • copy_target_list (Gtk::TargetList)

Returns:

  • (Gtk::TargetList)

    copy-target-list

  • (Gtk::TargetList)

    copy-target-list

#create_child_anchor(iter) ⇒ Gtk::TextChildAnchor

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

Parameters:

  • iter (Gtk::TextIter)

    location in the buffer

Returns:

#create_mark(mark_name, where, left_gravity) ⇒ Gtk::TextMark

Creates a mark at position where. If mark_name is nil, the mark is anonymous; otherwise, the mark can be retrieved by name using gtk_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 Gtk::TextMark, 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 Gtk::TextBuffer::mark-set signal as notification of the mark’s initial placement.

Parameters:

  • mark_name (String)

    name for mark, or nil

  • where (Gtk::TextIter)

    location to place mark

  • left_gravity (TrueClass)

    whether the mark has left gravity

Returns:

#create_tag(tag_name, first_property_name, array) ⇒ Gtk::TextTag

Creates a tag and adds it to the tag table for buffer. Equivalent to calling gtk_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 nil, the tag is anonymous.

If tag_name is non-nil, 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:

  • tag_name (String)

    name of the new tag, or nil

  • first_property_name (String)

    name of first property to set, or nil

  • array (Array)

    nil-terminated list of property names and values

Returns:

#cursor_positionInteger

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

Returns:

  • (Integer)

    cursor-position

#cursor_position=(cursor_position) ⇒ Integer

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

Parameters:

  • cursor_position (Integer)

Returns:

  • (Integer)

    cursor-position

  • (Integer)

    cursor-position

#cut_clipboard(clipboard, default_editable) ⇒ nil

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

Parameters:

  • clipboard (Gtk::Clipboard)

    the Gtk::Clipboard object to cut to

  • default_editable (TrueClass)

    default editability of the buffer

Returns:

  • (nil)

#delete(start, end) ⇒ nil

Deletes text between start and end. The order of start and end is not actually relevant; gtk_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:

  • start (Gtk::TextIter)

    a position in buffer

  • end (Gtk::TextIter)

    another position in buffer

Returns:

  • (nil)

#delete_interactive(start_iter, end_iter, default_editable) ⇒ TrueClass

Deletes all editable text in the given range. Calls gtk_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:

  • start_iter (Gtk::TextIter)

    start of range to delete

  • end_iter (Gtk::TextIter)

    end of range

  • default_editable (TrueClass)

    whether the buffer is editable by default

Returns:

  • (TrueClass)

    whether some text was actually deleted

#delete_mark(mark) ⇒ nil

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 gtk_text_buffer_add_mark(). Use gtk_text_mark_get_deleted() to find out if a mark has been removed from its buffer. The Gtk::TextBuffer::mark-deleted signal will be emitted as notification after the mark is deleted.

Parameters:

Returns:

  • (nil)

#delete_mark_by_name(name) ⇒ nil

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

Parameters:

  • name (String)

    name of a mark in buffer

Returns:

  • (nil)

#delete_selection(interactive, default_editable) ⇒ TrueClass

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:

  • interactive (TrueClass)

    whether the deletion is caused by user interaction

  • default_editable (TrueClass)

    whether the buffer is editable by default

Returns:

  • (TrueClass)

    whether there was a non-empty selection to delete

#deserialize(content_buffer, format, iter, data, length) ⇒ TrueClass

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

formats to be used must be registered using gtk_text_buffer_register_deserialize_format() or gtk_text_buffer_register_deserialize_tagset() beforehand.

Parameters:

  • content_buffer (Gtk::TextBuffer)

    the Gtk::TextBuffer to deserialize into

  • format (Gdk::Atom)

    the rich text format to use for deserializing

  • iter (Gtk::TextIter)

    insertion point for the deserialized text

  • data (Array<Integer>)

    data to deserialize

  • length (Integer)

    length of data

Returns:

  • (TrueClass)

    true on success, false otherwise.

#deserialize_get_can_create_tags(format) ⇒ TrueClass

This functions returns the value set with gtk_text_buffer_deserialize_set_can_create_tags()

Parameters:

  • format (Gdk::Atom)

    a Gdk::Atom representing a registered rich text format

Returns:

  • (TrueClass)

    whether deserializing this format may create tags

#deserialize_set_can_create_tags(format, can_create_tags) ⇒ nil

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 gtk_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:

  • format (Gdk::Atom)

    a Gdk::Atom representing a registered rich text format

  • can_create_tags (TrueClass)

    whether deserializing this format may create tags

Returns:

  • (nil)

#end_user_actionnil

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

Returns:

  • (nil)

#get_bounds(start, end) ⇒ nil

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

Parameters:

  • start (Gtk::TextIter)

    iterator to initialize with first position in the buffer

  • end (Gtk::TextIter)

    iterator to initialize with the end iterator

Returns:

  • (nil)

#get_deserialize_formats(n_formats) ⇒ Array<Gdk::Atom>

This function returns the rich text deserialize formats registered with buffer using gtk_text_buffer_register_deserialize_format() or gtk_text_buffer_register_deserialize_tagset()

Parameters:

  • n_formats (Integer)

    return location for the number of formats

Returns:

  • (Array<Gdk::Atom>)

    an array of Gdk::Atoms representing the registered formats.

#get_end_iter(iter) ⇒ nil

Initializes iter with the “end iterator,” one past the last valid character in the text buffer. If dereferenced with gtk_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 gtk_text_buffer_get_start_iter() to get character position 0) to the end iterator.

Parameters:

  • iter (Gtk::TextIter)

    iterator to initialize

Returns:

  • (nil)

#get_iter_at_child_anchor(iter, anchor) ⇒ nil

Obtains the location of anchor within buffer.

Parameters:

  • iter (Gtk::TextIter)

    an iterator to be initialized

  • anchor (Gtk::TextChildAnchor)

    a child anchor that appears in buffer

Returns:

  • (nil)

#get_iter_at_line(iter, line_number) ⇒ nil

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:

  • iter (Gtk::TextIter)

    iterator to initialize

  • line_number (Integer)

    line number counting from 0

Returns:

  • (nil)

#get_iter_at_line_index(iter, line_number, byte_index) ⇒ nil

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:

  • iter (Gtk::TextIter)

    iterator to initialize

  • line_number (Integer)

    line number counting from 0

  • byte_index (Integer)

    byte index from start of line

Returns:

  • (nil)

#get_iter_at_line_offset(iter, line_number, char_offset) ⇒ nil

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:

  • iter (Gtk::TextIter)

    iterator to initialize

  • line_number (Integer)

    line number counting from 0

  • char_offset (Integer)

    char offset from start of line

Returns:

  • (nil)

#get_iter_at_mark(iter, mark) ⇒ nil

Initializes iter with the current position of mark.

Parameters:

  • iter (Gtk::TextIter)

    iterator to initialize

  • mark (Gtk::TextMark)

    a Gtk::TextMark in buffer

Returns:

  • (nil)

#get_iter_at_offset(iter, char_offset) ⇒ nil

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:

  • iter (Gtk::TextIter)

    iterator to initialize

  • char_offset (Integer)

    char offset from start of buffer, counting from 0, or -1

Returns:

  • (nil)

#get_mark(name) ⇒ Gtk::TextMark

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

Parameters:

  • name (String)

    a mark name

Returns:

#get_selection_bounds(start, end) ⇒ TrueClass

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:

  • start (Gtk::TextIter)

    iterator to initialize with selection start

  • end (Gtk::TextIter)

    iterator to initialize with selection end

Returns:

  • (TrueClass)

    whether the selection has nonzero length

#get_serialize_formats(n_formats) ⇒ Array<Gdk::Atom>

This function returns the rich text serialize formats registered with buffer using gtk_text_buffer_register_serialize_format() or gtk_text_buffer_register_serialize_tagset()

Parameters:

  • n_formats (Integer)

    return location for the number of formats

Returns:

  • (Array<Gdk::Atom>)

    an array of Gdk::Atoms representing the registered formats.

#get_slice(start, end, include_hidden_chars) ⇒ String

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 gtk_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:

  • start (Gtk::TextIter)

    start of a range

  • end (Gtk::TextIter)

    end of a range

  • include_hidden_chars (TrueClass)

    whether to include invisible text

Returns:

  • (String)

    an allocated UTF-8 string

#get_start_iter(iter) ⇒ nil

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

Parameters:

  • iter (Gtk::TextIter)

    iterator to initialize

Returns:

  • (nil)

#get_text(start, end, include_hidden_chars) ⇒ String

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

Parameters:

  • start (Gtk::TextIter)

    start of a range

  • end (Gtk::TextIter)

    end of a range

  • include_hidden_chars (TrueClass)

    whether to include invisible text

Returns:

  • (String)

    an allocated UTF-8 string

#has_selectionTrueClass

Indicates whether the buffer has some text currently selected.

Returns:

  • (TrueClass)

    true if the there is text selected

#has_selection=(has_selection) ⇒ TrueClass

Whether the buffer has some text currently selected.

Parameters:

  • has_selection (TrueClass)

Returns:

  • (TrueClass)

    has-selection

  • (TrueClass)

    has-selection

#has_selection?TrueClass

Whether the buffer has some text currently selected.

Returns:

  • (TrueClass)

    has-selection

#insert(iter, text, len) ⇒ nil

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:

  • iter (Gtk::TextIter)

    a position in the buffer

  • text (String)

    text in UTF-8 format

  • len (Integer)

    length of text in bytes, or -1

Returns:

  • (nil)

#insert_at_cursor(text, len) ⇒ nil

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

Parameters:

  • text (String)

    text in UTF-8 format

  • len (Integer)

    length of text, in bytes

Returns:

  • (nil)

#insert_child_anchor(iter, anchor) ⇒ nil

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 gtk_text_buffer_get_slice() and gtk_text_buffer_get_text(). Consider gtk_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:

  • iter (Gtk::TextIter)

    location to insert the anchor

  • anchor (Gtk::TextChildAnchor)

    a Gtk::TextChildAnchor

Returns:

  • (nil)

#insert_interactive(iter, text, len, default_editable) ⇒ TrueClass

Like gtk_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 gtk_text_view_get_editable() is appropriate here.

Parameters:

  • iter (Gtk::TextIter)

    a position in buffer

  • text (String)

    some UTF-8 text

  • len (Integer)

    length of text in bytes, or -1

  • default_editable (TrueClass)

    default editability of buffer

Returns:

  • (TrueClass)

    whether text was actually inserted

#insert_interactive_at_cursor(text, len, default_editable) ⇒ TrueClass

Calls gtk_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 gtk_text_view_get_editable() is appropriate here.

Parameters:

  • text (String)

    text in UTF-8 format

  • len (Integer)

    length of text in bytes, or -1

  • default_editable (TrueClass)

    default editability of buffer

Returns:

  • (TrueClass)

    whether text was actually inserted

#insert_markup(iter, markup, len) ⇒ nil

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 Gtk::TextBuffer::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:

  • iter (Gtk::TextIter)

    location to insert the markup

  • markup (String)

    a nul-terminated UTF-8 string containing [Pango markup]

  • len (Integer)

    length of markup in bytes, or -1

Returns:

  • (nil)

#insert_pixbuf(iter, pixbuf) ⇒ nil

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 gtk_text_buffer_get_slice() and gtk_text_buffer_get_text().

Parameters:

  • iter (Gtk::TextIter)

    location to insert the pixbuf

  • pixbuf (GdkPixbuf::Pixbuf)

    a Gdk::Pixbuf

Returns:

  • (nil)

#insert_range(iter, start, end) ⇒ nil

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:

  • iter (Gtk::TextIter)

    a position in buffer

  • start (Gtk::TextIter)

    a position in a Gtk::TextBuffer

  • end (Gtk::TextIter)

    another position in the same buffer as start

Returns:

  • (nil)

#insert_range_interactive(iter, start, end, default_editable) ⇒ TrueClass

Same as gtk_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 gtk_text_view_get_editable() is appropriate here.

Parameters:

  • iter (Gtk::TextIter)

    a position in buffer

  • start (Gtk::TextIter)

    a position in a Gtk::TextBuffer

  • end (Gtk::TextIter)

    another position in the same buffer as start

  • default_editable (TrueClass)

    default editability of the buffer

Returns:

  • (TrueClass)

    whether an insertion was possible at iter

#insert_with_tags(iter, text, len, first_tag, array) ⇒ nil

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

Parameters:

  • iter (Gtk::TextIter)

    an iterator in buffer

  • text (String)

    UTF-8 text

  • len (Integer)

    length of text, or -1

  • first_tag (Gtk::TextTag)

    first tag to apply to text

  • array (Array)

    nil-terminated list of tags to apply

Returns:

  • (nil)

#insert_with_tags_by_name(iter, text, len, first_tag_name, array) ⇒ nil

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

Parameters:

  • iter (Gtk::TextIter)

    position in buffer

  • text (String)

    UTF-8 text

  • len (Integer)

    length of text, or -1

  • first_tag_name (String)

    name of a tag to apply to text

  • array (Array)

    more tag names

Returns:

  • (nil)

#line_countInteger

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

Returns:

  • (Integer)

    number of lines in the buffer

#modifiedTrueClass

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

Returns:

  • (TrueClass)

    true if the buffer has been modified

#modified=(setting) ⇒ nil

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 gtk_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 Gtk::TextBuffer::modified-changed signal.

Parameters:

  • setting (TrueClass)

    modification flag setting

Returns:

  • (nil)

#move_mark(mark, where) ⇒ nil

Moves mark to the new location where. Emits the Gtk::TextBuffer::mark-set signal as notification of the move.

Parameters:

  • mark (Gtk::TextMark)

    a Gtk::TextMark

  • where (Gtk::TextIter)

    new location for mark in buffer

Returns:

  • (nil)

#move_mark_by_name(name, where) ⇒ nil

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

Parameters:

  • name (String)

    name of a mark

  • where (Gtk::TextIter)

    new location for mark

Returns:

  • (nil)

#new(table) ⇒ Gtk::TextBuffer

Creates a new text buffer.

Parameters:

Returns:

#paste_clipboard(clipboard, override_location, default_editable) ⇒ nil

Pastes the contents of a clipboard. If override_location is nil, 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:

  • clipboard (Gtk::Clipboard)

    the Gtk::Clipboard to paste from

  • override_location (Gtk::TextIter)

    location to insert pasted text, or nil

  • default_editable (TrueClass)

    whether the buffer is editable by default

Returns:

  • (nil)

#paste_target_listGtk::TargetList

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

Returns:

  • (Gtk::TargetList)

    paste-target-list

#paste_target_list=(paste_target_list) ⇒ Gtk::TargetList

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

Parameters:

  • paste_target_list (Gtk::TargetList)

Returns:

  • (Gtk::TargetList)

    paste-target-list

  • (Gtk::TargetList)

    paste-target-list

#place_cursor(where) ⇒ nil

This function moves the “insert” and “selection_bound” marks simultaneously. If you move them to the same place in two steps with gtk_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:

  • where (Gtk::TextIter)

    where to put the cursor

Returns:

  • (nil)

#register_deserialize_format(mime_type, function, user_data, user_data_destroy) ⇒ Gdk::Atom

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

Parameters:

  • mime_type (String)

    the format’s mime-type

  • function (Gtk::TextBufferDeserializeFunc)

    the deserialize function to register

  • user_data (GObject)

    function’s user_data

  • user_data_destroy (GLib::DestroyNotify)

    a function to call when user_data is no longer needed

Returns:

  • (Gdk::Atom)

    the Gdk::Atom that corresponds to the newly registered format’s mime-type.

#register_deserialize_tagset(tagset_name) ⇒ Gdk::Atom

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

Parameters:

  • tagset_name (String)

    an optional tagset name, on nil

Returns:

  • (Gdk::Atom)

    the Gdk::Atom that corresponds to the newly registered format’s mime-type.

#register_serialize_format(mime_type, function, user_data, user_data_destroy) ⇒ Gdk::Atom

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

Parameters:

  • mime_type (String)

    the format’s mime-type

  • function (Gtk::TextBufferSerializeFunc)

    the serialize function to register

  • user_data (GObject)

    function’s user_data

  • user_data_destroy (GLib::DestroyNotify)

    a function to call when user_data is no longer needed

Returns:

  • (Gdk::Atom)

    the Gdk::Atom that corresponds to the newly registered format’s mime-type.

#register_serialize_tagset(tagset_name) ⇒ Gdk::Atom

This function registers GTK+’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 Gtk::TextBuffer instances. It is capable of serializing all of a text buffer’s tags and embedded pixbufs.

This function is just a wrapper around gtk_text_buffer_register_serialize_format(). The mime type used for registering is “application/x-gtk-text-buffer-rich-text”, or “application/x-gtk-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 != nil here, since the nil tagset requires the receiving buffer to deal with with pasting of arbitrary tags.

Parameters:

  • tagset_name (String)

    an optional tagset name, on nil

Returns:

  • (Gdk::Atom)

    the Gdk::Atom that corresponds to the newly registered format’s mime-type.

#remove_all_tags(start, end) ⇒ nil

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:

  • start (Gtk::TextIter)

    one bound of range to be untagged

  • end (Gtk::TextIter)

    other bound of range to be untagged

Returns:

  • (nil)

#remove_selection_clipboard(clipboard) ⇒ nil

Removes a Gtk::Clipboard added with gtk_text_buffer_add_selection_clipboard().

Parameters:

  • clipboard (Gtk::Clipboard)

    a Gtk::Clipboard added to buffer by gtk_text_buffer_add_selection_clipboard()

Returns:

  • (nil)

#remove_tag(tag, start, end) ⇒ nil

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:

  • tag (Gtk::TextTag)

    a Gtk::TextTag

  • start (Gtk::TextIter)

    one bound of range to be untagged

  • end (Gtk::TextIter)

    other bound of range to be untagged

Returns:

  • (nil)

#remove_tag_by_name(name, start, end) ⇒ nil

Calls gtk_text_tag_table_lookup() on the buffer’s tag table to get a Gtk::TextTag, then calls gtk_text_buffer_remove_tag().

Parameters:

  • name (String)

    name of a Gtk::TextTag

  • start (Gtk::TextIter)

    one bound of range to be untagged

  • end (Gtk::TextIter)

    other bound of range to be untagged

Returns:

  • (nil)

#select_range(ins, bound) ⇒ nil

This function moves the “insert” and “selection_bound” marks simultaneously. If you move them in two steps with gtk_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:

  • ins (Gtk::TextIter)

    where to put the “insert” mark

  • bound (Gtk::TextIter)

    where to put the “selection_bound” mark

Returns:

  • (nil)

#selection_boundGtk::TextMark

Returns the mark that represents the selection bound. Equivalent to calling gtk_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. gtk_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.

Returns:

#serialize(content_buffer, format, start, end, length) ⇒ Array<Integer>

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 gtk_text_buffer_register_serialize_format() or gtk_text_buffer_register_serialize_tagset() beforehand.

Parameters:

  • content_buffer (Gtk::TextBuffer)

    the Gtk::TextBuffer to serialize

  • format (Gdk::Atom)

    the rich text format to use for serializing

  • start (Gtk::TextIter)

    start of block of text to serialize

  • end (Gtk::TextIter)

    end of block of test to serialize

  • length (Integer)

    return location for the length of the serialized data

Returns:

  • (Array<Integer>)

    the serialized data, encoded as format

#set_text(text, len) ⇒ nil

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:

  • text (String)

    UTF-8 text to insert

  • len (Integer)

    length of text in bytes

Returns:

  • (nil)

#tag_tableGtk::TextTagTable

Returns tag-table.

Returns:

#tag_table=(tag_table) ⇒ Gtk::TextTagTable

Parameters:

Returns:

#textString

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

Returns:

  • (String)

    text

#text=(text) ⇒ String

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

Parameters:

  • text (String)

Returns:

  • (String)

    text

  • (String)

    text

#unregister_deserialize_format(format) ⇒ nil

This function unregisters a rich text format that was previously registered using gtk_text_buffer_register_deserialize_format() or gtk_text_buffer_register_deserialize_tagset().

Parameters:

  • format (Gdk::Atom)

    a Gdk::Atom representing a registered rich text format.

Returns:

  • (nil)

#unregister_serialize_format(format) ⇒ nil

This function unregisters a rich text format that was previously registered using gtk_text_buffer_register_serialize_format() or gtk_text_buffer_register_serialize_tagset()

Parameters:

  • format (Gdk::Atom)

    a Gdk::Atom representing a registered rich text format.

Returns:

  • (nil)