'Reimplement QTextDocument\'s find method
Add support for *multiline* regular expressions'

def find_multiline_pattern(self, regexp, cursor, findflag):

    pattern = to_text_string(regexp.pattern())
    text = to_text_string(self.toPlainText())
    try:
        regobj = re.compile(pattern)
    except sre_constants.error:
        return
    if (findflag & QTextDocument.FindBackward):
        offset = min([cursor.selectionEnd(), cursor.selectionStart()])
        text = text[:offset]
        matches = [_m for _m in regobj.finditer(text, 0, offset)]
        if matches:
            match = matches[(-1)]
        else:
            return
    else:
        offset = max([cursor.selectionEnd(), cursor.selectionStart()])
        match = regobj.search(text, offset)
    if match:
        (pos1, pos2) = match.span()
        fcursor = self.textCursor()
        fcursor.setPosition(pos1)
        fcursor.setPosition(pos2, QTextCursor.KeepAnchor)
        return fcursor
