def correctIndent(result):
    origIndent = result['x']
    newIndent = origIndent
    minIndent = 0
    maxIndent = result['maxIndent']

    opener = peek(result['parenStack'])
    if opener is not None:
        minIndent = opener['x'] + 1
        newIndent = newIndent + opener['indentDelta']

    newIndent = clamp(newIndent, minIndent, maxIndent)

    if newIndent != origIndent:
        indentStr = repeatString(BLANK_SPACE, newIndent)
        replaceWithinLine(result, result['lineNo'], 0, origIndent, indentStr)
        result['x'] = newIndent
        result['indentDelta'] = result['indentDelta'] + newIndent - origIndent
dataset/ETHPy150Open oakmac/sublime-text-parinfer/parinfer.py/correctIndent/original