def _format_msg(text, width, indent=0, prefix=""):
    r"""
    Format exception message.

    Replace newline characters \n with ``\n``, ` with \` and then wrap text as
    needed
    """
    text = repr(text).replace("`", "\\`").replace("\\n", " ``\\n`` ")
    sindent = " " * indent if not prefix else prefix
    wrapped_text = textwrap.wrap(text, width, subsequent_indent=sindent)
    # [1:-1] eliminates quotes generated by repr in first line
    return ("\n".join(wrapped_text))[1:-1].rstrip()
r"""
    Format exception message.

    Replace newline characters \n with ``\n``, ` with \` and then wrap text as
    needed