def unindent_selection(self, cursor):
        """
        Un-indents selected text

        :param cursor: QTextCursor
        """
        doc = self.editor.document()
        tab_len = self.editor.tab_length
        nb_lines = len(cursor.selection().toPlainText().splitlines())
        if nb_lines == 0:
            nb_lines = 1
        block = doc.findBlock(cursor.selectionStart())
        assert isinstance(block, QtGui.QTextBlock)
        i = 0
        debug('unindent selection: %d lines', nb_lines)
        while i < nb_lines:
            txt = block.text()
            debug('line to unindent: %s', txt)
            debug('self.editor.use_spaces_instead_of_tabs: %r',
                  self.editor.use_spaces_instead_of_tabs)
            if self.editor.use_spaces_instead_of_tabs:
                indentation = (len(txt) - len(txt.lstrip()))
            else:
                indentation = len(txt) - len(txt.replace('\t', ''))
            debug('unindent line %d: %d spaces', i, indentation)
            if indentation > 0:
                c = QtGui.QTextCursor(block)
                c.movePosition(c.StartOfLine, cursor.MoveAnchor)
                for _ in range(tab_len):
                    txt = block.text()
                    if len(txt) and txt[0] == ' ':
                        c.deleteChar()
            block = block.next()
            i += 1
        return cursor