Subject: Re: bug#11919: 24.1; term-emulate-term does not process bash's Ctrl-Z signal of directory name when an AnSi message is present

From: "Michael Hoffman" <[email-masked]>
Date: Mon, 23 Jan 2017 12:54:10 -0500

On 07/11/2012 08:45 PM, Michael Hoffman wrote:

> 1) emacs -Q
> 2) M-x ansi-term RET /bin/bash RET
> 3) PS1='\033AnSiTu x\012$ ' RET
>
>  From then on, every prompt will be preceded by a Ctrl-Z character and
> the working directory. This is because recent versions of bash
> try to figure out whether they are running under emacs, and if they
> are, output Ctrl-Z and the working directory before the PS1 prompt.
> term-emulate-terminal normally eliminates such garbage, but not when
> it has also processed an AnSi message. The elimination only happens
> when the following conditions are true:
>
> (and (eq char ?\032)
>       (not handled-ansi-message))
>
> Suggested fix: eliminate the "(not handled-ansi-message)" form.

I have located the original commit that added the `handled-ansi-message` 
behavior: 
https://github.com/emacs-mirror/emacs/commit/59be5828de98814b8aa32718bf2b6196db085db1

Eli Zaretskii added it to "Let term-handle-ansi-terminal-messages 
override what Bash says about its current directory."

In order to keep this behavior but not print garbage to the buffer: I 
would suggest that perhaps the call to `term-command-hook` is what 
should be conditioned on `(not handled-ansi-message)` and not the rest 
of the code in this branch which seems to remove the garbage.

Michael Hoffman