def setText(text): """Set the document text.""" # Just setting d.text does work, but triggers a bug in the # Katepart syntax highlighting: the first part of the document # looses its highlighting when a user undoes the conversion # with Ctrl+Z d = kate.document() d.editingSequence.begin() for i in range(d.numberOfLines): d.removeLine(0) kate.document().text = text d.editingSequence.end()
def replaceSelectionWith(text, keepSelection = False): """ Replaces the selection in the current view with text, and reselects the newly inserted text if keepSelection == True """ d, v, s = kate.document(), kate.view(), kate.view().selection if s.exists: line, col = s.region[0] else: line, col = v.cursor.position lines = text.split('\n') endline, endcol = line + len(lines) - 1, len(lines[-1]) if len(lines) < 2: endcol += col d.editingSequence.begin() if s.exists: s.removeSelectedText() v.insertText(text) d.editingSequence.end() if keepSelection: s.region = ((line, col), (endline, endcol))
def interrupt(): from lilykde import runlily runlily.interrupt(kate.document())
def publish(): from lilykde import runlily runlily.runLilyPond(kate.document())
def preview(): from lilykde import runlily runlily.runLilyPond(kate.document(), preview=True)
def fragment(start, end): """Returns the text from start (line, col) to end (line, col)...""" return kate.document().fragment(start, end)
def search(text, start, caseSensitive=True, searchBackwards=False): """ Search through the document. Returns match, (line, column), length """ return kate.document().search(text, start, caseSensitive, searchBackwards)
def line(lineNum): """The text on the given line number.""" return kate.document().line(lineNum)
def clear(): """Clear the current editor buffer.""" # kate.document().clear() is broken in Pate 0.5.1 d = kate.document() for i in range(d.numberOfLines): d.removeLine(0)
def append(text): """Append text to document (starting in a new line).""" d = kate.document() d.insertLine(d.numberOfLines, text)
def insertLine(lineNum, text): """Insert text at the given line number.""" kate.document().insertLine(lineNum, text)
def text(): """The document text.""" return kate.document().text
def editEnd(): """End an editing sequence.""" kate.document().editingSequence.end()
def editBegin(): """Start an editing sequence.""" kate.document().editingSequence.begin()