moo.Edit - document object
Prev | Chapter 3. medit Python API | Next

## moo.Edit - document object

Object which represents a document. It has methods for file operations and manipulating document text.

    gobject.Object
      |
      +-- moo.Edit

### signal after-save

    after-save()

This signal is emitted after the document has been successfully saved on disk.

### signal before-save

    before-save(file)

This signal is emitted when the document is going to be saved on disk. Callbacks should return `SAVE_RESPONSE_CANCEL` if document should not be saved, and `SAVE_RESPONSE_CONTINUE` otherwise. For example, if before saving the file must be checked out from a version control system, a callback can do that and return `SAVE_RESPONSE_CANCEL` if checkout failed. Callbacks should not modify document content. If you need to modify it before saving, use `will-save` signal instead.

`file` : | the `gio.File` object which represents saved file

`Returns:` `SAVE_RESPONSE_CANCEL` to cancel saving, `SAVE_RESPONSE_CONTINUE` otherwise.

### signal will-close

    will-close()

This signal is emitted before the document is closed.

### signal will-save

    will-save(file)

This signal is emitted when the document is going to be saved on disk, after `before-save` signal. Callbacks may modify document content at this point.

`file` : | the `gio.File` object which represents saved file

### append_text()

    doc.append_text(text)

Append text to the end of document.

`text` : | `str`

### begin_non_undoable_action()

    doc.begin_non_undoable_action()

### begin_user_action()

    doc.begin_user_action()

### can_redo()

    doc.can_redo()

`Returns:` `bool`

### can_undo()

    doc.can_undo()

`Returns:` `bool`

### clear()

    doc.clear()

Remove all text from document.

### close()

    doc.close()

`Returns:` whether document was closed

### comment_selection()

    doc.comment_selection()

### copy()

    doc.copy()

Copy selection to clipboard.

### cut()

    doc.cut()

Cut selection to clipboard.

### delete_selected_lines()

    doc.delete_selected_lines()

Delete selected lines. Similar to `delete_selected_text()` but selection is extended to include whole lines. If no text is selected then line at cursor is deleted.

### delete_selected_text()

    doc.delete_selected_text()

### delete_text()

    doc.delete_text(start, end)

`start` : | `gtk.TextIter`
`end` : | `gtk.TextIter`

### end_non_undoable_action()

    doc.end_non_undoable_action()

### end_user_action()

    doc.end_user_action()

### get_buffer()

    doc.get_buffer()

`Returns:` `gtk.TextBuffer`

### get_char_at_pos()

    doc.get_char_at_pos(pos)

`pos` : | `gtk.TextIter`

`Returns:` `str`

### get_char_count()

    doc.get_char_count()

`Returns:` `int`

### get_clean()

    doc.get_clean()

`Returns:` `bool`

### get_cursor_pos()

    doc.get_cursor_pos()

`Returns:` Iterator which points to the current cursor (insertion point) position. In the case when text selection is not empty, it points to one of the ends of the selection.

### get_display_basename()

    doc.get_display_basename()

`Returns:` `str`

### get_display_name()

    doc.get_display_name()

`Returns:` `str`

### get_editor()

    doc.get_editor()

`Returns:` `moo.Editor`

### get_encoding()

    doc.get_encoding()

`Returns:` `str`

### get_end_pos()

    doc.get_end_pos()

`Returns:` Iterator which points to the end of the document, i.e. the position past the last character in the document.

### get_file()

    doc.get_file()

`Returns:` `gio.File`

### get_filename()

    doc.get_filename()

`Returns:` `str`

### get_lang_id()

    doc.get_lang_id()

`Returns:` id of language currently used in the document. If no language is used, then string "none" is returned.

### get_line_at_cursor()

    doc.get_line_at_cursor()

`Returns:` ``0``-based number of the current cursor line.

### get_line_at_pos()

    doc.get_line_at_pos(pos)

`pos` : | `gtk.TextIter`

`Returns:` ``0``-based number of the line at the given position.

### get_line_count()

    doc.get_line_count()

`Returns:` `int`

### get_line_end_type()

    doc.get_line_end_type()

`Returns:` `moo.LineEndType`

### get_line_text()

    doc.get_line_text(line=-1)

`line` : | ``0``-based line number.

`Returns:` text at line `line`, not including line end characters. If `line` is missing, returns text at cursor line.

### get_line_text_at_pos()

    doc.get_line_text_at_pos(pos)

`pos` : | `gtk.TextIter`

`Returns:` text at line which contains position `pos`, not including the line end character(s).

### get_n_views()

    doc.get_n_views()

Get the number of views which belong to this document.

`Returns:` `int`

### get_pos_at_line()

    doc.get_pos_at_line(line)

`line` : | ``0``-based line number.

`Returns:` Iterator which points to the beginning of the given line.

### get_pos_at_line_end()

    doc.get_pos_at_line_end(line)

`line` : | ``0``-based line number.

`Returns:` Iterator which points to the end of the given line (i.e. the position before the line end character(s)).

### get_selected_lines()

    doc.get_selected_lines()

Returns selected lines as a list of strings, one string for each line, line terminator characters not included. If nothing is selected, then line at cursor is returned.

`Returns:` list of strings

### get_selected_text()

    doc.get_selected_text()

`Returns:` selected text.

### get_selection_end_pos()

    doc.get_selection_end_pos()

`Returns:` Iterator which points to the end of the current text selection. If the selection is empty, it returns the current cursor position.

### get_selection_start_pos()

    doc.get_selection_start_pos()

`Returns:` Iterator which points to the beginning of the current text selection. If the selection is empty, it returns the current cursor position.

### get_start_pos()

    doc.get_start_pos()

`Returns:` Iterator which points to the beginning of the document.

### get_status()

    doc.get_status()

`Returns:` `moo.EditStatus`

### get_tab()

    doc.get_tab()

`Returns:` `moo.EditTab`

### get_text()

    doc.get_text(start=None, end=None)

`start` : | `gtk.TextIter` or `None`
`end` : | `gtk.TextIter` or `None`

`Returns:` text between `start` and `end`. If `end` is missing then it returns text from `start` to the end of document; and if both `start` and `end` are missing then it returns whole document content.

### get_uri()

    doc.get_uri()

`Returns:` `str`

### get_view()

    doc.get_view()

Get the active view of this document.

`Returns:` `moo.EditView`

### get_views()

    doc.get_views()

Get the list of views which belong to this document.

`Returns:` list of `moo.EditView` objects

### get_window()

    doc.get_window()

`Returns:` `moo.EditWindow`

### has_selection()

    doc.has_selection()

`Returns:` `bool`

### insert_text()

    doc.insert_text(text, where=None)

Insert `text` at position `where` or at cursor position if `where` is ``None``.

`text` : | `str`
`where` : | `gtk.TextIter` or `None`

### is_empty()

    doc.is_empty()

This function returns whether the document is "empty", i.e. is not modified, is untitled, and contains no text.

`Returns:` `bool`

### is_modified()

    doc.is_modified()

`Returns:` `bool`

### is_untitled()

    doc.is_untitled()

`Returns:` `bool`

### paste()

    doc.paste()

Paste clipboard contents.

### redo()

    doc.redo()

`Returns:` `bool`

### reload()

    doc.reload(info=None)

Reload document from disk

`info` : | `moo.ReloadInfo` or `None`

`Returns:` whether document was successfully reloaded

### replace_selected_lines()

    doc.replace_selected_lines(replacement)

replace selected lines with `replacement`. Similar to `replace_selected_text()`, but selection is extended to include whole lines. If nothing is selected, then line at cursor is replaced.

`replacement` : | list of lines to replace selected lines with, maybe empty

### replace_selected_text()

    doc.replace_selected_text(replacement)

Replace selected text with string `replacement`. If nothing is selected, then `replacement` is inserted at cursor.

`replacement` : | `str`

### replace_text()

    doc.replace_text(start, end, text)

`start` : | `gtk.TextIter`
`end` : | `gtk.TextIter`
`text` : | `str`

### save()

    doc.save()

`Returns:` `bool`

### save_as()

    doc.save_as(info)

Save document with new filename and/or encoding. If `info` is missing or ``None`` then the user is asked for a new filename first.

`info` : | `moo.SaveInfo` or `None`

`Returns:` `bool`

### save_copy()

    doc.save_copy(info)

`info` : | `moo.SaveInfo`

`Returns:` `bool`

### select_all()

    doc.select_all()

### select_lines()

    doc.select_lines(start, end=-1)

`start` : | `integer index (0-based)`
`end` : | `integer index (0-based)`

### select_lines_at_pos()

    doc.select_lines_at_pos(start, end=None)

Select lines which span the range from `start` to `end` (including `end` position). If `end` is ``None``, then it selects single line which contains position `start`.

`start` : | `gtk.TextIter`
`end` : | `gtk.TextIter` or `None`

### select_range()

    doc.select_range(start, end)

Select text from `start` to `end`.

`start` : | `gtk.TextIter`
`end` : | `gtk.TextIter`

### set_clean()

    doc.set_clean(clean)

`clean` : | `bool`

### set_cursor_pos()

    doc.set_cursor_pos(pos)

Move the text cursor to the given position. No text is selected after this operation, use one of the select* methods if you need to select a range of text.

`pos` : | `gtk.TextIter`

### set_encoding()

    doc.set_encoding(encoding)

`encoding` : | `str`

### set_line_end_type()

    doc.set_line_end_type(le)

`le` : | `moo.LineEndType`

### set_modified()

    doc.set_modified(modified)

`modified` : | `bool`

### set_text()

    doc.set_text(text)

`text` : | `str`

### uncomment_selection()

    doc.uncomment_selection()

### undo()

    doc.undo()

`Returns:` `bool`

Prev | Up | Next
moo.CmdView | Home | moo.EditTab - document tab object