Subject: Re: bug#20202: Considered Harmful 73d213: 'Comint, term, and compile new set Emacs'

From: [email-masked] (Phillip Lord)
Date: Thu, 07 Apr 2016 20:55:02 +0100

Paul Eggert <[email-masked]> writes:

> On 04/07/2016 09:07 AM, Phillip Lord wrote:
>> Well, I need to scope this. If the issue is tcsh and bash, then I will
>> look at both. I cannot, of course, look at any arbitrary program which
>> might be affected.
>
> I think we'd be OK if we work with the "common" shells. But that would include
> zsh, whose current FAQ says the following:
>
>   Probably the most reliable way of dealing with this is to look for
>     the environment variable `$EMACS', which is set to `t' in
>     Emacs' shell mode.  Putting
>
>       [[ $EMACS = t ]] && unsetopt zle
>
>     in your .zshrc should be sufficient.
>
> So here it's not merely a matter of fixing zsh, it's also fixing all the
> users' .zshrc files that are following this (obsolescent) advice.
>
> So far we've looked at three shells (bash, tcsh, zsh), and found compatibility
> issues with all three. This is not a good sign.

So, bash has a command line option to achieve the same thing as EMACS=t.

I've checked tcsh and as far as I can tell, here, there is no clear
solution. EMACS=t is used, and it's deep in the init code. In my hands,
directory tracking in tcsh does not work in ansi-term either way.

Zsh does not, AFAICT, use EMACS=t (it's hard to be sure searching
through the code, since most instances of "emacs" refer to zsh's
emulation of Emacs). In fact, though, as the FAQ entry you found shows,
zsh actually does this...

    /* unset zle if using zsh under emacs */
    if (!strcmp(term, "emacs"))
	opts[USEZLE] = 0;

which, according to the faq is behaviour from < Emacs-19.29.

So, zsh users already explicitly tell their zsh what to do.

Possible solutions:

1) For bash, launch with -o emacs, or call set -o emacs after launch.
2) zsh, launch and call unsetopt zle.
3) For tcsh, EMACS=t only needs to be correct during init. So, EMACS=t,
launch tcsh, set EMACS=what-ever-it-was-before.
4) Everything else -- move the "call-process" call to a single function
which people can advice as they choose.

Phil