KDE 4.9 PyKDE API Reference

- KDE's Python API

# Document Class Reference

`from PyKDE4.ktexteditor import *`

Inherits: KParts.ReadWritePart → KParts.ReadOnlyPart → KParts.Part → QObject
Namespace: KTextEditor

## Detailed Description

A KParts derived class representing a text document.

Topics: - doc_intro - doc_manipulation - doc_views - doc_extensions

Introduction

The Document class represents a pure text document providing methods to modify the content and create views. A document can have any number of views, each view representing the same content, i.e. all views are synchronized. Support for text selection is handled by a View and text format attributes by the Attribute class.

To load a document call KParts.ReadOnlyPart.openUrl(). To reload a document from a file call documentReload(), to save the document call documentSave() or documentSaveAs(). Whenever the modified state of the document changes the signal modifiedChanged() is emitted. Check the modified state with KParts.ReadWritePart.isModified(). Further signals are documentUrlChanged(). The encoding can be specified with setEncoding(), however this will only take effect on file reload and file save.

Text Manipulation

Get the whole content with text() and set new content with setText(). Call insertText() or insertLine() to insert new text or removeText() and removeLine() to remove content. Whenever the document's content changed the signal textChanged() is emitted. Additional signals are textInserted() and textRemoved(). Note, that the first line in the document is line 0.

If the editor part supports it, a document provides full undo/redo history. Text manipulation actions can be grouped together using startEditing() and endEditing(). All actions in between are grouped together to only one undo/redo action. Due to internal reference counting you can call startEditing() and endEditing() as often as you wish, but make sure you call endEditing() exactly as often as you call startEditing(), otherwise the reference counter gets confused.

Document Views

A View displays the document's content. As already mentioned, a document can have any number of views, all synchronized. Get a list of all views with views(). Only one of the views can be active (i.e. has focus), get it by using activeView(). Create a new view with createView(). Every time a new view is created the signal viewCreated() is emitted.

Document Extension Interfaces

A simple document represents text and provides text manipulation methods. However, a real text editor should support advanced concepts like session support, textsearch support, bookmark/general mark support etc. That is why the KTextEditor library provides several additional interfaces to extend a document's capabilities via multiple inheritance.

More information about interfaces for the document can be found in kte_group_doc_extensions.

See also:
  KParts.ReadWritePart, KTextEditor.Editor, KTextEditor.View, KTextEditor.MarkInterface, KTextEditor.ModificationInterface, KTextEditor.SearchInterface, KTextEditor.SessionConfigInterface, KTextEditor.SmartInterface, KTextEditor.VariableInterface

Author:
  Christoph Cullmann <cullmann@kde.org>

## Signals

| aboutToClose (KTextEditor.Document document)
| aboutToReload (KTextEditor.Document document)
| documentNameChanged (KTextEditor.Document document)
| documentSavedOrUploaded (KTextEditor.Document document, bool saveAs)
| documentUrlChanged (KTextEditor.Document document)
| exclusiveEditEnd (KTextEditor.Document document)
| exclusiveEditStart (KTextEditor.Document document)
| highlightingModeChanged (KTextEditor.Document document)
| modeChanged (KTextEditor.Document document)
| modifiedChanged (KTextEditor.Document document)
| reloaded (KTextEditor.Document document)
| textChanged (KTextEditor.Document document)
| textChanged (KTextEditor.Document document, KTextEditor.Range oldRange, KTextEditor.Range newRange)
| textChanged (KTextEditor.Document document, KTextEditor.Range oldRange, QString oldText, KTextEditor.Range newRange)
| textInserted (KTextEditor.Document document, KTextEditor.Range range)
| textRemoved (KTextEditor.Document document, KTextEditor.Range range)
| textRemoved (KTextEditor.Document document, KTextEditor.Range range, QString oldText)
| viewCreated (KTextEditor.Document document, KTextEditor.View view)

## Methods

| __init__ (self, QObject parent=0)
KTextEditor.View | activeView (self)
QChar | character (self, KTextEditor.Cursor position)
bool | clear (self)
KTextEditor.View | createView (self, QWidget parent)
bool | cursorInText (self, KTextEditor.Cursor cursor)
KTextEditor.Cursor | documentEnd (self)
QString | documentName (self)
KTextEditor.Range | documentRange (self)
bool | documentReload (self)
bool | documentSave (self)
bool | documentSaveAs (self)
KTextEditor.Editor | editor (self)
QString | encoding (self)
bool | endEditing (self)
KTextEditor.Cursor | endOfLine (self, int line)
QString | highlightingMode (self)
QString | highlightingModeSection (self, int index)
QStringList | highlightingModes (self)
bool | insertLine (self, int line, QString text)
bool | insertLines (self, int line, QStringList text)
bool | insertText (self, KTextEditor.Cursor position, QString text, bool block=0)
bool | insertText (self, KTextEditor.Cursor position, QStringList text, bool block=0)
bool | isEmpty (self)
QString | line (self, int line)
int | lineLength (self, int line)
int | lines (self)
QString | mimeType (self)
QString | mode (self)
QString | modeSection (self, int index)
QStringList | modes (self)
bool | openingError (self)
QString | openingErrorMessage (self)
bool | removeLine (self, int line)
bool | removeText (self, KTextEditor.Range range, bool block=0)
bool | replaceText (self, KTextEditor.Range range, QString text, bool block=0)
bool | replaceText (self, KTextEditor.Range range, QStringList text, bool block=0)
bool | setEncoding (self, QString encoding)
bool | setHighlightingMode (self, QString name)
bool | setMode (self, QString name)
| setOpeningError (self, bool errors)
| setOpeningErrorMessage (self, QString message)
| setSuppressOpeningErrorDialogs (self, bool suppress)
bool | setText (self, QString text)
bool | setText (self, QStringList text)
bool | startEditing (self)
bool | suppressOpeningErrorDialogs (self)
QString | text (self)
QString | text (self, KTextEditor.Range range, bool block=0)
QStringList | textLines (self, KTextEditor.Range range, bool block=0)
int | totalCharacters (self)
[KTextEditor.View] | views (self)

## Signal Documentation

aboutToClose | ( | KTextEditor.Document | document
| ) |  |  |

Warn anyone listening that the current document is about to close. At this point all of the information is still accessible, such as the text, cursors and ranges.

Any modifications made to the document at this point will be lost.

Parameters:

  | document | the document being closed

Signal syntax:
  `QObject.connect(source, SIGNAL("aboutToClose(KTextEditor::Document*)"), target_slot)`

aboutToReload | ( | KTextEditor.Document | document
| ) |  |  |

Warn anyone listening that the current document is about to reload. At this point all of the information is still accessible, such as the text, cursors and ranges.

Any modifications made to the document at this point will be lost.

Parameters:

  | document | the document being reloaded

Signal syntax:
  `QObject.connect(source, SIGNAL("aboutToReload(KTextEditor::Document*)"), target_slot)`

documentNameChanged | ( | KTextEditor.Document | document
| ) |  |  |

This signal is emitted whenever the document name changes.

Parameters:

  | document | document which changed its name

See also:
  documentName()

Signal syntax:
  `QObject.connect(source, SIGNAL("documentNameChanged(KTextEditor::Document*)"), target_slot)`

documentSavedOrUploaded | ( | KTextEditor.Document | document,
|  | bool | saveAs
| ) |  |  |

This signal should be emitted after a document has been saved to disk or for remote files uploaded. saveAs should be set to true, if the operation is a save as operation

Signal syntax:
  `QObject.connect(source, SIGNAL("documentSavedOrUploaded(KTextEditor::Document*, bool)"), target_slot)`

documentUrlChanged | ( | KTextEditor.Document | document
| ) |  |  |

This signal is emitted whenever the document URL changes.

Parameters:

  | document | document which changed its URL

See also:
  KParts.ReadOnlyPart.url()

Signal syntax:
  `QObject.connect(source, SIGNAL("documentUrlChanged(KTextEditor::Document*)"), target_slot)`

exclusiveEditEnd | ( | KTextEditor.Document | document
| ) |  |  |

In conjunction with exclusiveEditStart(), signals that the document's content may be changed again without restriction.

Since:
  4.5

Signal syntax:
  `QObject.connect(source, SIGNAL("exclusiveEditEnd(KTextEditor::Document*)"), target_slot)`

exclusiveEditStart | ( | KTextEditor.Document | document
| ) |  |  |

Upon emission, the document's content may only be changed by the initiator of this signal until exclusiveEditEnd() is signalled. It is, however, possible to listen to changes of the content.

Signalled e.g. on undo or redo.

Since:
  4.5

Signal syntax:
  `QObject.connect(source, SIGNAL("exclusiveEditStart(KTextEditor::Document*)"), target_slot)`

highlightingModeChanged | ( | KTextEditor.Document | document
| ) |  |  |

Warn anyone listening that the current document's highlighting mode has changed.

Parameters:

  | document | the document which's mode has changed

See also:
  setHighlightingMode()

Signal syntax:
  `QObject.connect(source, SIGNAL("highlightingModeChanged(KTextEditor::Document*)"), target_slot)`

modeChanged | ( | KTextEditor.Document | document
| ) |  |  |

Warn anyone listening that the current document's mode has changed.

Parameters:

  | document | the document whose mode has changed

See also:
  setMode()

Signal syntax:
  `QObject.connect(source, SIGNAL("modeChanged(KTextEditor::Document*)"), target_slot)`

modifiedChanged | ( | KTextEditor.Document | document
| ) |  |  |

This signal is emitted whenever the document's buffer changed from either state unmodified to modified or vice versa.

Parameters:

  | document | document which changed its modified state

See also:
  KParts.ReadWritePart.isModified().

See also:
  KParts.ReadWritePart.setModified()

Signal syntax:
  `QObject.connect(source, SIGNAL("modifiedChanged(KTextEditor::Document*)"), target_slot)`

reloaded | ( | KTextEditor.Document | document
| ) |  |  |

Emitted after the current document was reloaded. At this point, some information might have been invalidated, like for example the editing history.

Parameters:

  | document | the document that was reloaded.

Since:
  4.6

Signal syntax:
  `QObject.connect(source, SIGNAL("reloaded(KTextEditor::Document*)"), target_slot)`

textChanged | ( | KTextEditor.Document | document
| ) |  |  |

The document emits this signal whenever the text in range oldRange was removed and replaced with the text now in newRange, e.g. the user selects text and pastes new text to replace the selection.

Note:
  oldRange.start() is guaranteed to equal newRange.start().

Parameters:

  | document | document which emitted this signal

Parameters:

  | oldRange | range that the text previously occupied

Parameters:

  | oldText | old text that has been replaced

Parameters:

  | newRange | range that the changed text now occupies

See also:
  insertText(), insertLine(), removeText(), removeLine(), clear()

Signal syntax:
  `QObject.connect(source, SIGNAL("textChanged(KTextEditor::Document*)"), target_slot)`

textChanged | ( | KTextEditor.Document | document,
|  | KTextEditor.Range | oldRange,
|  | KTextEditor.Range | newRange
| ) |  |  |

The document emits this signal whenever the text in range oldRange was removed and replaced with the text now in newRange, e.g. the user selects text and pastes new text to replace the selection.

Note:
  oldRange.start() is guaranteed to equal newRange.start().

Parameters:

  | document | document which emitted this signal

Parameters:

  | oldRange | range that the text previously occupied

Parameters:

  | oldText | old text that has been replaced

Parameters:

  | newRange | range that the changed text now occupies

See also:
  insertText(), insertLine(), removeText(), removeLine(), clear()

Signal syntax:
  `QObject.connect(source, SIGNAL("textChanged(KTextEditor::Document*, const KTextEditor::Range&, const KTextEditor::Range&)"), target_slot)`

textChanged | ( | KTextEditor.Document | document,
|  | KTextEditor.Range | oldRange,
|  | QString | oldText,
|  | KTextEditor.Range | newRange
| ) |  |  |

The document emits this signal whenever the text in range oldRange was removed and replaced with the text now in newRange, e.g. the user selects text and pastes new text to replace the selection.

Note:
  oldRange.start() is guaranteed to equal newRange.start().

Parameters:

  | document | document which emitted this signal

Parameters:

  | oldRange | range that the text previously occupied

Parameters:

  | oldText | old text that has been replaced

Parameters:

  | newRange | range that the changed text now occupies

See also:
  insertText(), insertLine(), removeText(), removeLine(), clear()

Signal syntax:
  `QObject.connect(source, SIGNAL("textChanged(KTextEditor::Document*, const KTextEditor::Range&, const QString&, const KTextEditor::Range&)"), target_slot)`

textInserted | ( | KTextEditor.Document | document,
|  | KTextEditor.Range | range
| ) |  |  |

The document emits this signal whenever text was inserted. The insertion occurred at range.start(), and new text now occupies up to range.end().

Parameters:

  | document | document which emitted this signal

Parameters:

  | range | range that the newly inserted text occupies

See also:
  insertText(), insertLine()

Signal syntax:
  `QObject.connect(source, SIGNAL("textInserted(KTextEditor::Document*, const KTextEditor::Range&)"), target_slot)`

textRemoved | ( | KTextEditor.Document | document,
|  | KTextEditor.Range | range
| ) |  |  |

The document emits this signal whenever range was removed, i.e. text was removed.

Parameters:

  | document | document which emitted this signal

Parameters:

  | range | range that the removed text previously occupied

Parameters:

  | oldText | the text that has been removed

See also:
  removeText(), removeLine(), clear()

Signal syntax:
  `QObject.connect(source, SIGNAL("textRemoved(KTextEditor::Document*, const KTextEditor::Range&)"), target_slot)`

textRemoved | ( | KTextEditor.Document | document,
|  | KTextEditor.Range | range,
|  | QString | oldText
| ) |  |  |

The document emits this signal whenever range was removed, i.e. text was removed.

Parameters:

  | document | document which emitted this signal

Parameters:

  | range | range that the removed text previously occupied

Parameters:

  | oldText | the text that has been removed

See also:
  removeText(), removeLine(), clear()

Signal syntax:
  `QObject.connect(source, SIGNAL("textRemoved(KTextEditor::Document*, const KTextEditor::Range&, const QString&)"), target_slot)`

viewCreated | ( | KTextEditor.Document | document,
|  | KTextEditor.View | view
| ) |  |  |

This signal is emitted whenever the document creates a new view. It should be called for every view to help applications / plugins to attach to the view. \attention This signal should be emitted after the view constructor is completed, e.g. in the createView() method.

Parameters:

  | document | the document for which a new view is created

Parameters:

  | view | the new view

See also:
  createView()

Signal syntax:
  `QObject.connect(source, SIGNAL("viewCreated(KTextEditor::Document*, KTextEditor::View*)"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QObject | parent=0
| ) |  |  |

Constructor.

Create a new document with parent.

Parameters:

  | parent | parent object

See also:
  Editor.createDocument()

KTextEditor.View activeView | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Return the view which currently has user focus, if any.

QChar character | ( | self, |
|  | KTextEditor.Cursor | position
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get the character at cursor.

Parameters:

  | position | the location of the character to retrieve

Returns:
  the requested character, or QChar() for invalid cursors.

See also:
  setText()

bool clear | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Remove the whole content of the document.

Returns:
  true on success, otherwise false

See also:
  removeText(), removeLine()

KTextEditor.View createView | ( | self, |
|  | QWidget | parent
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Create a new view attached to parent.

Parameters:

  | parent | parent widget

Returns:
  the new view

bool cursorInText | ( | self, |
|  | KTextEditor.Cursor | cursor
| ) |  |  |

Checks whether the cursor specifies a valid position in a document. It can optionally be overridden by an implementation.

Parameters:

  | cursor | which should be checked

Returns:
  true, if the cursor is valid, otherwise false

See also:
  SmartCursor.isValid()

KTextEditor.Cursor documentEnd | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

End position of the document.

Returns:
  The last column on the last line of the document

See also:
  all()

QString documentName | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get this document's name. The editor part should provide some meaningful name, like some unique "Untitled XYZ" for the document - without URL or basename for documents with url.

Returns:
  readable document name

KTextEditor.Range documentRange | ( |  | self ) |

A Range which encompasses the whole document.

Returns:
  A range from the start to the end of the document

bool documentReload | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Reload the current file. The user will be prompted by the part on changes and more and can cancel this action if it can harm.

Returns:
  true if the reload has been done, otherwise false. If the document has no url set, it will just return false.

bool documentSave | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Save the current file. The user will be asked for a filename if needed and more.

Returns:
  true on success, i.e. the save has been done, otherwise

false

bool documentSaveAs | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Save the current file to another location. The user will be asked for a filename and more.

Returns:
  true on success, i.e. the save has been done, otherwise

false

KTextEditor.Editor editor | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get the global editor object. The editor part implementation must ensure that this object exists as long as any factory or document object exists.

Returns:
  global KTextEditor.Editor object

See also:
  KTextEditor.Editor

QString encoding | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get the current chosen encoding. The return value is an empty string, if the document uses the default encoding of the editor and no own special encoding.

Returns:
  current encoding of the document

See also:
  setEncoding()

bool endEditing | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

End an editing sequence.

Returns:
  true on success, otherwise false. Parts not supporting it should return false.

See also:
  startEditing() for more details

KTextEditor.Cursor endOfLine | ( | self, |
|  | int | line
| ) |  |  |

Get the end cursor position of line line.

Parameters:

  | line | line

See also:
  lineLength(), line()

QString highlightingMode | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Return the name of the currently used mode

Returns:
  name of the used mode

See also:
  highlightingModes(), setHighlightingMode()

QString highlightingModeSection | ( | self, |
|  | int | index
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Returns the name of the section for a highlight given its index in the highlight list (as returned by highlightModes()).

You can use this function to build a tree of the highlight names, organized in sections.

Parameters:

  | index | the index of the highlight in the list returned by modes()

QStringList highlightingModes | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Return a list of the names of all possible modes

Returns:
  list of mode names

See also:
  highlightingMode(), setHighlightingMode()

bool insertLine | ( | self, |
|  | int | line,
|  | QString | text
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Insert line(s) at the given line number. The newline character '\\n' is treated as line delimiter, so it is possible to insert multiple lines. To append lines at the end of the document, use

     insertLine( lines(), text )

Parameters:

  | line | line where to insert the text

Parameters:

  | text | text which should be inserted

Returns:
  true on success, otherwise false

See also:
  insertText()

bool insertLines | ( | self, |
|  | int | line,
|  | QStringList | text
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Insert line(s) at the given line number. The newline character '\\n' is treated as line delimiter, so it is possible to insert multiple lines. To append lines at the end of the document, use

     insertLine( lines(), text )

Parameters:

  | line | line where to insert the text

Parameters:

  | text | text which should be inserted

Returns:
  true on success, otherwise false

See also:
  insertText()

bool insertText | ( | self, |
|  | KTextEditor.Cursor | position,
|  | QString | text,
|  | bool | block=0
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Insert text at position.

Parameters:

  | position | position to insert the text

Parameters:

  | text | text to insert

Parameters:

  | block | insert this text as a visual block of text rather than a linear sequence

Returns:
  true on success, otherwise false

See also:
  setText(), removeText()

bool insertText | ( | self, |
|  | KTextEditor.Cursor | position,
|  | QStringList | text,
|  | bool | block=0
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Insert text at position.

Parameters:

  | position | position to insert the text

Parameters:

  | text | text to insert

Parameters:

  | block | insert this text as a visual block of text rather than a linear sequence

Returns:
  true on success, otherwise false

See also:
  setText(), removeText()

bool isEmpty | ( |  | self ) |

Returns if the document is empty.

QString line | ( | self, |
|  | int | line
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get a single text line.

Parameters:

  | line | the wanted line

Returns:
  the requested line, or "" for invalid line numbers

See also:
  text(), lineLength()

int lineLength | ( | self, |
|  | int | line
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get the length of a given line in characters.

Parameters:

  | line | line to get length from

Returns:
  the number of characters in the line or -1 if the line was invalid

See also:
  line()

int lines | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get the count of lines of the document.

Returns:
  the current number of lines in the document

See also:
  length()

QString mimeType | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get this document's mimetype.

Returns:
  mimetype

QString mode | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Return the name of the currently used mode

Returns:
  name of the used mode

See also:
  modes(), setMode()

QString modeSection | ( | self, |
|  | int | index
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Returns the name of the section for a mode given its index in the highlight list (as returned by modes()).

You can use this function to build a tree of the mode names, organized in sections.

Parameters:

  | index | the index of the highlight in the list returned by modes()

QStringList modes | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Return a list of the names of all possible modes

Returns:
  list of mode names

See also:
  mode(), setMode()

bool openingError | ( |  | self ) |

True, eg if the file for opening could not be read This doesn't have to handle the KPart job cancled cases

QString openingErrorMessage | ( |  | self ) |

bool removeLine | ( | self, |
|  | int | line
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Remove line from the document.

Parameters:

  | line | line to remove

Returns:
  true on success, otherwise false

See also:
  removeText(), clear()

bool removeText | ( | self, |
|  | KTextEditor.Range | range,
|  | bool | block=0
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Remove the text specified in range.

Parameters:

  | range | range of text to remove

Parameters:

  | block | set this to true to remove a text block on the basis of columns, rather than everything inside range

Returns:
  true on success, otherwise false

See also:
  setText(), insertText()

bool replaceText | ( | self, |
|  | KTextEditor.Range | range,
|  | QString | text,
|  | bool | block=0
| ) |  |  |

Replace text from range with specified text.

Parameters:

  | range | range of text to replace

Parameters:

  | text | text to replace with

Parameters:

  | block | replace text as a visual block of text rather than a linear sequence

Returns:
  true on success, otherwise false

See also:
  setText(), removeText(), insertText()

bool replaceText | ( | self, |
|  | KTextEditor.Range | range,
|  | QStringList | text,
|  | bool | block=0
| ) |  |  |

Replace text from range with specified text.

Parameters:

  | range | range of text to replace

Parameters:

  | text | text to replace with

Parameters:

  | block | replace text as a visual block of text rather than a linear sequence

Returns:
  true on success, otherwise false

See also:
  setText(), removeText(), insertText()

bool setEncoding | ( | self, |
|  | QString | encoding
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Set the encoding for this document. This encoding will be used while loading and saving files, it will not affect the already existing content of the document, e.g. if the file has already been opened without the correct encoding, this will not fix it, you would for example need to trigger a reload for this.

Parameters:

  | encoding | new encoding for the document, the name must be accepted by QTextCodec, if an empty encoding name is given, the part should fallback to its own default encoding, e.g. the system encoding or the global user settings

Returns:
  true on success, or false, if the encoding could not be set.

See also:
  encoding()

bool setHighlightingMode | ( | self, |
|  | QString | name
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Set the current mode of the document by giving its name

Parameters:

  | name | name of the mode to use for this document

Returns:
  true on success, otherwise false

See also:
  highlightingMode(), highlightingModes(), highlightingModeChanged()

bool setMode | ( | self, |
|  | QString | name
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Set the current mode of the document by giving its name

Parameters:

  | name | name of the mode to use for this document

Returns:
  true on success, otherwise false

See also:
  mode(), modes(), modeChanged()

setOpeningError | ( | self, |
|  | bool | errors
| ) |  |  |

setOpeningErrorMessage | ( | self, |
|  | QString | message
| ) |  |  |

setSuppressOpeningErrorDialogs | ( | self, |
|  | bool | suppress
| ) |  |  |

by default dialogs should be displayed. In any case (dialog shown or suppressed) openingErrors and openingErrorMessage should have meaningfull values

Parameters:

  | suppress | true/false value if dialogs should be displayed

bool setText | ( | self, |
|  | QString | text
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Set the given text as new document content.

Parameters:

  | text | new content for the document

Returns:
  true on success, otherwise false

See also:
  text()

bool setText | ( | self, |
|  | QStringList | text
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Set the given text as new document content.

Parameters:

  | text | new content for the document

Returns:
  true on success, otherwise false

See also:
  text()

bool startEditing | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Begin an editing sequence. Edit commands during this sequence will be bunched together so that they represent a single undo command in the editor, and so that repaint events do not occur inbetween.

Your application should not return control to the event loop while it has an unterminated (i.e. no matching endEditing() call) editing sequence (result undefined) - so do all of your work in one go!

This call stacks, like the endEditing() calls, this means you can safely call it three times in a row for example if you call endEditing() three times, too, it internaly just does counting the running editing sessions.

If the texteditor part does not support these transactions, both calls just do nothing.

Returns:
  true on success, otherwise false. Parts not supporting it should return false

See also:
  endEditing()

bool suppressOpeningErrorDialogs | ( |  | self ) |

QString text | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get the document content within the given range.

Parameters:

  | range | the range of text to retrieve

Parameters:

  | block | Set this to true to receive text in a visual block, rather than everything inside range.

Returns:
  the requested text part, or QString() for invalid ranges.

See also:
  setText()

QString text | ( | self, |
|  | KTextEditor.Range | range,
|  | bool | block=0
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get the document content within the given range.

Parameters:

  | range | the range of text to retrieve

Parameters:

  | block | Set this to true to receive text in a visual block, rather than everything inside range.

Returns:
  the requested text part, or QString() for invalid ranges.

See also:
  setText()

QStringList textLines | ( | self, |
|  | KTextEditor.Range | range,
|  | bool | block=0
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get the document content within the given range.

Parameters:

  | range | the range of text to retrieve

Parameters:

  | block | Set this to true to receive text in a visual block, rather than everything inside range.

Returns:
  the requested text lines, or QStringList() for invalid ranges. no end of line termination is included.

See also:
  setText()

int totalCharacters | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Get the count of characters in the document. A TAB character counts as only one character.

Returns:
  the number of characters in the document

See also:
  lines()

[KTextEditor.View] views | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Returns the views pre-casted to KTextEditor.View%s