'Indent or replace by 4 spaces depending on selection and tab mode'

def indent_or_replace(self):

    if ((self.tab_indents and self.tab_mode) or (not self.has_selected_text())):
        self.indent()
    else:
        cursor = self.textCursor()
        if (self.get_selected_text() == to_text_string(cursor.block().text())):
            self.indent()
        else:
            cursor1 = self.textCursor()
            cursor1.setPosition(cursor.selectionStart())
            cursor2 = self.textCursor()
            cursor2.setPosition(cursor.selectionEnd())
            if (cursor1.blockNumber() != cursor2.blockNumber()):
                self.indent()
            else:
                self.replace(self.indent_chars)
