Subject: bug#51426: 29.0.50; [PATCH] Should 'comint-term-environment' be connection-aware?

From: Jim Porter <[email-masked]>
Date: Fri, 29 Oct 2021 09:39:15 -0700

On 10/29/2021 1:21 AM, Michael Albinus wrote:
> Jim Porter <[email-masked]> writes:
> 
>> Sure, that seems like a good idea. I expanded the example in the
>> section on "Per-Connection Local Variables" to show setting
>> `system-uses-terminfo'. Hopefully this will point people in the right
>> direction, and make it more apparent that
>> `connection-local-set-profiles' lets you set multiple profiles for a
>> connection, not just one. (That's documented in the Emacs Lisp manual,
>> but I think it would be helpful to show it in the Emacs manual as
>> well.)
> 
> Thanks. However, you don't show the second setting,
> comint-terminfo-terminal. Is it obvious to the reader that this shall be
> changed as well?

I didn't change it initially because I wasn't sure it's a value that 
people are likely to change connection-locally. `system-uses-terminfo' 
is definitely important to be able to set connection-locally: while many 
systems support terminfo, some don't (e.g. FreeBSD and MS Windows). 
`comint-terminfo-terminal' seemed less consequential.

However, after doing a bit of archaeology, I think it might make sense 
to `comint-terminfo-terminal' connection-locally in the example, so I've 
attached an updated patch. `comint-terminfo-terminal' was only added in 
Emacs 26.1, and I believe the "dumb-emacs-ansi" terminfo file was added 
to Debian's ncurses after that, so it makes sense that someone would 
want to set this differently when connecting to a newer host vs an older 
host. (I think TERM=dumb-emacs-ansi is the best setting to use if your 
terminfo database has it, since it reflects comint's capabilities more 
accurately than TERM=dumb.)

I didn't explain the above reasoning in the manual though, since it 
won't be so relevant as time goes on. Once people see that you can do 
this, it should hopefully be reasonably obvious why. If we need more 
explanation beyond this, it probably makes sense to expand the docstring 
for `comint-terminfo-terminal'.
From be23aebfd9c2e349ef73f4516520d0745e44e11e Mon Sep 17 00:00:00 2001
From: Jim Porter <[email-masked]>
Date: Thu, 28 Oct 2021 22:14:07 -0700
Subject: [PATCH] Expand the documentation for connection local variables

* doc/emacs/custom.texi (Per-Connection Local Variables): Expand the
example to include setting 'system-uses-terminfo'.
---
 doc/emacs/custom.texi | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index eb30a6acc5..bc70ae61c9 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -1474,9 +1474,10 @@ Connection Variables
 
   Most of the variables reflect the situation on the local machine.
 Often, they must use a different value when you operate in buffers
-with a remote default directory.  Think about the shell to be applied
-when calling @code{shell} -- it might be @file{/bin/bash} on your
-local machine, and @file{/bin/ksh} on a remote machine.
+with a remote default directory.  Think about the behavior when
+calling @code{shell} -- on your local machine, you might use
+@file{/bin/bash} and rely on termcap, but on a remote machine, it may
+be @file{/bin/ksh} and terminfo.
 
   This can be accomplished with @dfn{connection-local variables}.
 Directory and file local variables override connection-local
@@ -1492,6 +1493,10 @@ Connection Variables
 criteria, identifying a remote machine:
 
 @example
+(connection-local-set-profile-variables 'remote-terminfo
+   '((system-uses-terminfo . t)
+     (comint-terminfo-terminal . "dumb-emacs-ansi")))
+
 (connection-local-set-profile-variables 'remote-ksh
    '((shell-file-name . "/bin/ksh")
      (shell-command-switch . "-c")))
@@ -1501,13 +1506,15 @@ Connection Variables
      (shell-command-switch . "-c")))
 
 (connection-local-set-profiles
-   '(:application tramp :machine "remotemachine") 'remote-ksh)
+   '(:application tramp :machine "remotemachine")
+   'remote-terminfo 'remote-ksh)
 @end example
 
-  This code declares two different profiles, @code{remote-ksh} and
-@code{remote-bash}. The profile @code{remote-ksh} is applied to all
+  This code declares three different profiles, @code{remote-terminfo},
+@code{remote-ksh}, and @code{remote-bash}. The profiles
+@code{remote-terminfo} and @code{remote-ksh} are applied to all
 buffers which have a remote default directory matching the regexp
-@code{"remotemachine} as host name.  Such a criteria can also
+@code{"remotemachine"} as host name.  Such a criteria can also
 discriminate for the properties @code{:protocol} (this is the Tramp
 method) or @code{:user} (a remote user name).  The @code{nil} criteria
 matches all buffers with a remote default directory.
-- 
2.25.1