'Copy specified lines from the syntax highlighted buffer into the
destination cursor, preserving all formatting created by the syntax
highlighter.'

def copy_lines(self, lo, hi, cursor):

    self.highlighter.join()
    num = (hi - lo)
    if (num > 0):
        block = self.findBlockByNumber(lo)
        while (num > 0):
            num -= 1
            cursor.insertText(block.text())
            dest_block = cursor.block()
            c = QTextCursor(dest_block)
            try:
                afs = block.layout().additionalFormats()
            except AttributeError:
                afs = ()
            for af in afs:
                start = (dest_block.position() + af.start)
                (c.setPosition(start), c.setPosition((start + af.length), c.KeepAnchor))
                c.setCharFormat(af.format)
            cursor.insertBlock()
            cursor.setCharFormat(NULL_FMT)
            block = block.next()
