Un-indents selected text

        :param cursor: QTextCursor

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
        _logger().debug('unindent selection: %d lines', nb_lines)
        while i < nb_lines:
            txt = block.text()[self.min_column:]
            _logger().debug('line to unindent: %s', txt)
            _logger().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', ''))
            _logger().debug('unindent line %d: %d spaces (min indent=%d)', i, indentation, self.min_column)
            if indentation > 0:
                c = QtGui.QTextCursor(block)
                c.movePosition(c.StartOfLine, cursor.MoveAnchor)
                c.movePosition(c.Right, cursor.MoveAnchor, indentation + self.min_column)
                max_spaces = indentation % tab_len
                if max_spaces == 0:
                    max_spaces = tab_len
                spaces = self.count_deletable_spaces(c, max_spaces)
                for _ in range(spaces):
                    c.deletePreviousChar()
            block = block.next()
            i += 1
        return cursor