def METHOD_NAME(tab: tabs.FileTab, alt_pressed: bool) -> None:
    lineno = int(tab.textwidget.index("insert").split(".")[0])
    prevline = tab.textwidget.get(f"{lineno}.0 - 1 line", f"{lineno}.0")
    # we can't strip trailing whitespace before this because then
    # pressing enter twice would get rid of all indentation
    tab.textwidget.insert("insert", leading_whitespace(prevline))
    comment_prefix = tab.settings.get("comment_prefix", Optional[str])
    if comment_prefix is None:
        prevline = prevline.strip()
    else:
        # Not perfect, but should work fine
        prevline = prevline.split(comment_prefix)[0].strip()
    indent_regex, dedent_regex, dedent_prev_line = get_regexes(tab)
    if (
        prevline.endswith(("(", "[", "{")) or re.fullmatch(indent_regex, prevline)
    ) and not alt_pressed:
        tab.textwidget.indent("insert")
    elif re.fullmatch(dedent_regex, prevline):
        # must be end of a block
        tab.textwidget.dedent("insert")
        if dedent_prev_line:
            tab.textwidget.dedent("insert - 1 line")