kifield/common.py
def sexp_indent(s, tab="    "):
    """Indent an S-expression string.

    Args:
        s (string): S-expression string.
        tab (string, optional): Indentation string. Defaults to "    ".

    Returns:
        string: Indented S-expression.
    """

    out_s = ""
    indent = ""
    nl = ""  # First '(' will not be preceded by a newline.
    in_quote = False
    backslash = False

    for c in s:
        if c == "(" and not in_quote:
            out_s += nl + indent
            nl = "\n"  # Every '(' from now on gets preceded by a newline.
            indent += tab
        elif c == ")" and not in_quote:
            indent = indent[len(tab) :]
        elif c == '"' and not backslash:
            in_quote = not in_quote

        if c == "\\":
            backslash = True
        else:
            backslash = False

        out_s += c

    return out_s
Indent an S-expression string.

    Args:
        s (string): S-expression string.
        tab (string, optional): Indentation string. Defaults to "    ".

    Returns:
        string: Indented S-expression.
    
Indent an S-expression string.
Indent an S - expression string .
def sexp_indent(s, tab="    "):
    out_s = ""
    indent = ""
    nl = ""  
    in_quote = False
    backslash = False
    for c in s:
        if c == "(" and not in_quote:
            out_s += nl + indent
            nl = "\n"  
            indent += tab
        elif c == ")" and not in_quote:
            indent = indent[len(tab) :]
        elif c == '"' and not backslash:
            in_quote = not in_quote
        if c == "\\":
            backslash = True
        else:
            backslash = False
        out_s += c
    return out_s
def sexp_indent ( s , tab = "    " ) : out_s = "" indent = "" nl = "" in_quote = False backslash = False for c in s : if c == "(" and not in_quote : out_s += nl + indent nl = "\n" indent += tab elif c == ")" and not in_quote : indent = indent [ len ( tab ) : ] elif c == '"' and not backslash : in_quote = not in_quote if c == "\\" : backslash = True else : backslash = False out_s += c return out_s
Indent an S-expression string.
Indent an S - expression string .
"""Indent an S-expression string.

    Args:
        s (string): S-expression string.
        tab (string, optional): Indentation string. Defaults to "    ".

    Returns:
        string: Indented S-expression.
    """ # First '(' will not be preceded by a newline. # Every '(' from now on gets preceded by a newline.
None
string
s
None
tab
Indentation string. Defaults to "    ".
Indentation string . Defaults to " " .
"    "