Subject: Re: bug#28139: 25.2; TRAMP vs bash 4.4 / readline 7.0 "bracketed paste" mode

From: Daniel Pittman <[email-masked]>
Date: Mon, 13 Nov 2017 14:41:30 -0500

Michael, you are completely right that my previous change was not
necessary.  I blame my prehistoric knowledge of Emacs here, as I wasn't
aware of the change to use INSIDE_EMACS.  On testing, it seems that EMACS=t
just happened to work in bash (for legacy reasons, probably other dinosaurs
like me), and INSIDE_EMACS also disables editing, and fixes my problem.

You are also quite correct that INSIDE_EMACS was being set by tramp.  The
problem was that it was set at the wrong time: we need it set *before* we
start the shell, to disable readline bracketed paste (and other advanced
features) before we start, for example, interrogating the remote system for
the running version with `uname` during `tramp-open-shell`.

I have attached a patch that moves two variables, TERM and INSIDE_EMACS,
out of `tramp-remote-process-environment`, and instead, handles setting
them prior to shell execution.

This has two advantages:

First, INSIDE_EMACS is visible to the shell we are about to probe for
usability, which fixes my own problem with bracketed paste support in
libreadline / bash breaking, and which makes it uniformly available on the
remote host.

Second, changes to `tramp-terminal-type` (and the TRAMP version) are now
handled correctly without having to recompute the value of
`tramp-remote-process-environment`; previously this was not done, and a
restart or user intervention would be required to correct them.

Hopefully this meets with approval, so I append both the patch, and what I
think is the appropriate changelog entry for this, to be manually added:

2017-11-13  Daniel Pittman  <[email-masked]>

* tramp-sh.el: Set TERM and INSIDE_EMACS environment earlier.
(tramp-remote-process-environment): Remove TERM and INSIDE_EMACS.
(tramp-remote-process-environment): Document their special handling.
(tramp-open-shell): Set TERM and INSIDE_EMACS prior to starting the
initial remote shell, so that it is also aware of the environment
in which it is operating.