import re


def reformat(before, after):
    """
    Formats new line from old line format. Keeps track of spaces near "=" and new lines. Also adds spaces at the
    beginning of the line.

    :param before: old line
    :param after: new line
    :return: new line with format of old one
    """

    search = re.search('^\\s+', before)
    if search:
        after = search.group() + after

    search = re.search('(?<!^)\\s+=', before)
    if search:
        after = after.replace('=', search.group())

    search = re.search('=\\s+(?!$)', before)
    if search:
        after = after.replace('=', search.group())

    if before == '\n':
        after = before

    return after