'Return current word, i.e. word at cursor position'

def get_current_word(self):

    cursor = self.textCursor()
    if cursor.hasSelection():
        cursor.setPosition(min([cursor.selectionStart(), cursor.selectionEnd()]))
    else:
        def is_space(move):
            curs = self.textCursor()
            curs.movePosition(move, QTextCursor.KeepAnchor)
            return (not to_text_string(curs.selectedText()).strip())
        if is_space(QTextCursor.NextCharacter):
            if is_space(QTextCursor.PreviousCharacter):
                return
            cursor.movePosition(QTextCursor.WordLeft)
    cursor.select(QTextCursor.WordUnderCursor)
    text = to_text_string(cursor.selectedText())
    match = re.findall('([a-zA-Z\\_]+[0-9a-zA-Z\\_]*)', text)
    if match:
        return match[0]
