'Try to deduce the level of indentation of the given line.'

def deduce_indent(self, line, buffer):

    keywords = {'elif    ': ['if    '], 'else:': ['if    ', 'try'], 'except': ['try:'], 'finally:': ['try:']}
    opening_tags = ('if    ', 'try:', 'for    ', 'while    ')
    indent = self._indent
    if any((line.startswith(kw) for kw in keywords.keys())):
        keyword = [kw for kw in keywords if line.startswith(kw)][0]
        begin_tags = keywords[keyword]
        for oline in reversed(buffer.splitlines()):
            if any((oline.lstrip('    ').startswith(tag) for tag in begin_tags)):
                indent = ((len(oline) - len(oline.lstrip('    '))) / 4)
                break
        self._indent = (indent + 1)
        if self._persistent:
            self._caller.attributes.add('_eveditor_indent', self._indent)
    elif any((line.startswith(kw) for kw in opening_tags)):
        self._indent = (indent + 1)
        if self._persistent:
            self._caller.attributes.add('_eveditor_indent', self._indent)
    line = ((('    ' * 4) * indent) + line)
    return line
