Subject: Re: bug#31605: 25.3; tramp-terminal-type too obscure

From: Michael Albinus <[email-masked]>
Date: Tue, 29 May 2018 13:19:03 +0200

Eli Barzilay <[email-masked]> writes:

Hi Eli,

> This is mostly a documentation issue for tramp's info file.  The
> problem is that `tramp-terminal-type` is described almost as an
> afterthought in a section that talks about `tset` of all things...
>
> It would be good to describe it better, and also mention it in the
> section about zsh, since it's probably a very common problem there
> with sophisticated prompts.

I have added the following in the Tramp manual, section "5.16 Remote
shell setup hints":

--8<---------------cut here---------------start------------->8---

‘tramp-terminal-type’

     TRAMP uses the user option ‘tramp-terminal-type’ to set the remote
     environment variable ‘TERM’ for the shells it runs.  Per default,
     it is ‘"dumb"’, but this could be changed.  A dumb terminal is best
     suited to run the background sessions of TRAMP.  However, running
     interactive remote shells might require a different setting.  This
     could be achieved by tweaking the ‘TERM’ environment variable in
     ‘process-environment’.

          (let ((process-environment
                 (cons "TERM=xterm-256color" process-environment)))
            (shell))

Determining a TRAMP session

     Sometimes, it is needed to identify whether a shell runs under
     TRAMP control.  The setting of environment variable ‘TERM’ will
     help:

          if test "$TERM" = "dumb"; then
             ...
          fi

     Another possibility is to check the environment variable
     ‘INSIDE_EMACS’.  Like for all subprocesses of Emacs, this is set to
     the version of the parent Emacs process, *Note (emacs)Interactive
     Shell::.  TRAMP adds its own package version to this string, which
     could be used for further tests in an inferior shell.  The string
     of that environment variable loooks always like

          echo $INSIDE_EMACS
          ⇒ 26.2,tramp:2.3.4

--8<---------------cut here---------------end--------------->8---

> ----
>
> Using it, a much better solution is to (setq tramp-terminal-type
> "tramp"), and in my .zshrc:
>
>     [[ $TERM == "tramp" ]] && unsetopt zle && PS1='$ ' && return

Since I'm not an zsh user, I'm dependent on recommendations. So I have
taken over your example, except still using "dumb" as default.

> In fact, I'd argue that the *default* value is better set as "tramp".
> "dumb" is very overuse to provide some kind of interactivity that
> tramp doesn't need anyway, so having a terminfo-unknown name like
> "tramp" could only improve things for tramp uses.  But that will
> likely break too many existing configurations (like ones that do the
> above recommended zsh hack...), so maybe recommend it instead.

This setting is not used only for interactive shells, but also for the
background processes. "dumb" has the advantage to own an entry in
terminfo:

--8<---------------cut here---------------start------------->8---
$ infocmp dumb
#	Reconstructed via infocmp from file: /lib/terminfo/d/dumb
dumb|80-column dumb tty,
	am,
	cols#80,
	bel=^G, cr=\r, cud1=\n, ind=\n,
--8<---------------cut here---------------end--------------->8---

This makes it much better suited to run background shells, than a TERM
set to "tramp", or alike.

Best regards, Michael.