GNU bug report logs - #51426
29.0.50; [PATCH] Should 'comint-term-environment' be connection-aware?

Previous Next

Package: emacs;

Reported by: Jim Porter <jporterbugs <at> gmail.com>

Date: Tue, 26 Oct 2021 22:55:02 UTC

Severity: wishlist

Tags: patch

Found in version 29.0.50

Fixed in version 29.1

Done: Michael Albinus <michael.albinus <at> gmx.de>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 51426 in the body.
You can then email your comments to 51426 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#51426; Package emacs. (Tue, 26 Oct 2021 22:55:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jim Porter <jporterbugs <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 26 Oct 2021 22:55:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; [PATCH] Should 'comint-term-environment' be connection-aware?
Date: Tue, 26 Oct 2021 15:54:03 -0700
[Message part 1 (text/plain, inline)]
`comint-term-environment' consults `system-uses-terminfo' to determine 
how to set environment variables to indicate comint's terminal 
capabilities. However, `system-uses-terminfo' describes whether the host 
system running Emacs uses terminfo, not whether the remote system uses 
it. Similarly for `comint-terminfo-terminal'.

If `comint-term-environment' were aware of connection-local variables, 
it would be possible to create a connection-local profile to configure 
this for remote hosts, e.g.:

  (connection-local-set-profile-variables
   'remote-terminfo
   '((system-uses-terminfo . t)
     (comint-terminfo-terminal . "dumb-emacs-ansi")))

  (connection-local-set-profiles
   '(:application tramp :machine "foo")
   'remote-terminfo))

(Note: "dumb-emacs-ansi" comes from the ncurses-term package[1] in 
Debian, and should be a good value to represent comint's capabilities.)

This lets the user pass a terminfo-friendly value for TERM to the remote 
system, even if the local system doesn't use terminfo. Then programs on 
the remote system can consult terminfo to their hearts' content.

I've attached a patch that does this, assuming the reasoning above makes 
sense. Perhaps it also warrants an entry in NEWS? I wasn't sure...

[1] https://packages.debian.org/buster/all/ncurses-term/filelist
[0001-lisp-comint.el-comint-term-environment-Make-it-conne.patch (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51426; Package emacs. (Wed, 27 Oct 2021 08:21:02 GMT) Full text and rfc822 format available.

Message #8 received at 51426 <at> debbugs.gnu.org (full text, mbox):

From: Michael Albinus <michael.albinus <at> gmx.de>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 51426 <at> debbugs.gnu.org
Subject: Re: bug#51426: 29.0.50; [PATCH] Should 'comint-term-environment' be
 connection-aware?
Date: Wed, 27 Oct 2021 10:20:27 +0200
Jim Porter <jporterbugs <at> gmail.com> writes:

Hi Jim,

> `comint-term-environment' consults `system-uses-terminfo' to determine
> how to set environment variables to indicate comint's terminal
> capabilities. However, `system-uses-terminfo' describes whether the
> host system running Emacs uses terminfo, not whether the remote system
> uses it. Similarly for `comint-terminfo-terminal'.
>
> If `comint-term-environment' were aware of connection-local variables,
> it would be possible to create a connection-local profile to configure
> this for remote hosts, e.g.:
>
>   (connection-local-set-profile-variables
>    'remote-terminfo
>    '((system-uses-terminfo . t)
>      (comint-terminfo-terminal . "dumb-emacs-ansi")))
>
>   (connection-local-set-profiles
>    '(:application tramp :machine "foo")
>    'remote-terminfo))
>
> (Note: "dumb-emacs-ansi" comes from the ncurses-term package[1] in
> Debian, and should be a good value to represent comint's
> capabilities.)
>
> This lets the user pass a terminfo-friendly value for TERM to the
> remote system, even if the local system doesn't use terminfo. Then
> programs on the remote system can consult terminfo to their hearts'
> content.

Looks good to me. However, this technique must be documented
anywhere. Likely in the Emacs manual, node "Shell Options"
(file doc/emacs/misc.texi).

> I've attached a patch that does this, assuming the reasoning above
> makes sense. Perhaps it also warrants an entry in NEWS? I wasn't
> sure...

Yes, it should be said in etc/NEWS.

> diff --git a/lisp/comint.el b/lisp/comint.el
> index e925b3a4b6..04e39edc42 100644
> --- a/lisp/comint.el
> +++ b/lisp/comint.el
> @@ -889,12 +889,13 @@ comint-term-environment
>    ;; and there is no way for us to define it here.
>    ;; Some programs that use terminfo get very confused
>    ;; if TERM is not a valid terminal type.
> -  (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
> -      (list (format "TERM=%s" comint-terminfo-terminal)
> -            "TERMCAP="
> -            (format "COLUMNS=%d" (window-width)))
> -    (list "TERM=emacs"
> -          (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width)))))
> +  (with-connection-local-variables
> +   (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)

According to git log, the variable system-uses-terminfo exists since

--8<---------------cut here---------------start------------->8---
commit 07c57952d8364663eb2abd979457cc880b7fd855
Author: Karl Heuer <kwzh <at> gnu.org>
Date:   Fri Apr 8 06:59:55 1994 +0000

    (system_uses_terminfo): New variable.
    (syms_of_term): New function, to initialize it.
--8<---------------cut here---------------end--------------->8---

I guess it is save to get rid of "(and (boundp 'system-uses-terminfo)".

Best regards, Michael.




Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Wed, 27 Oct 2021 21:29:04 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51426; Package emacs. (Thu, 28 Oct 2021 00:47:01 GMT) Full text and rfc822 format available.

Message #13 received at 51426 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Michael Albinus <michael.albinus <at> gmx.de>
Cc: 51426 <at> debbugs.gnu.org
Subject: Re: bug#51426: 29.0.50; [PATCH] Should 'comint-term-environment' be
 connection-aware?
Date: Wed, 27 Oct 2021 17:45:53 -0700
[Message part 1 (text/plain, inline)]
On 10/27/2021 1:20 AM, Michael Albinus wrote:
> Looks good to me. However, this technique must be documented
> anywhere. Likely in the Emacs manual, node "Shell Options"
> (file doc/emacs/misc.texi).

Thanks. I've expanded the section about `comint-terminfo-terminal' in 
the manual to include information about how `system-uses-terminfo' works 
as well as mentioning that these variables can be declared as 
connection-local.

> Yes, it should be said in etc/NEWS.

I added a new entry too.

>> +  (with-connection-local-variables
>> +   (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
> 
> According to git log, the variable system-uses-terminfo exists since [1994.]
> I guess it is save to get rid of "(and (boundp 'system-uses-terminfo)".

Removed this.

Thanks for taking a look.

- Jim
[0001-Support-setting-comint-terminal-connection-locally.patch (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51426; Package emacs. (Thu, 28 Oct 2021 08:03:01 GMT) Full text and rfc822 format available.

Message #16 received at 51426 <at> debbugs.gnu.org (full text, mbox):

From: Michael Albinus <michael.albinus <at> gmx.de>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 51426 <at> debbugs.gnu.org
Subject: Re: bug#51426: 29.0.50; [PATCH] Should 'comint-term-environment' be
 connection-aware?
Date: Thu, 28 Oct 2021 10:02:46 +0200
Jim Porter <jporterbugs <at> gmail.com> writes:

Hi Jim,

> Thanks. I've expanded the section about `comint-terminfo-terminal' in
> the manual to include information about how `system-uses-terminfo'
> works as well as mentioning that these variables can be declared as
> connection-local.

LGTM. Just one nit:

>  color is supported.  Therefore, Emacs provides an option
> -@code{comint-terminfo-terminal}, which you can set to a terminal that
> -is present in your system's terminfo database, in order to take
> -advantage of advanced features of that terminal.
> +@code{comint-terminfo-terminal} to let you choose a terminal with more
> +advanced features, as defined in your system's terminfo database.
> +When @code{system-uses-terminfo} is non-nil, Emacs will use this
> +option as the value for @env{TERM}.

"this option" sounds like Emacs uses system-uses-terminfo for TERM, at
least in my ears. Could you pls rephrase it a little bit?

Otherwise, it is OK. If nobody else objects, I would push it in your
name to the master branch, when you have reworded it.

> Thanks for taking a look.
>
> - Jim

Best regards, Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51426; Package emacs. (Thu, 28 Oct 2021 15:50:02 GMT) Full text and rfc822 format available.

Message #19 received at 51426 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Michael Albinus <michael.albinus <at> gmx.de>
Cc: 51426 <at> debbugs.gnu.org
Subject: Re: bug#51426: 29.0.50; [PATCH] Should 'comint-term-environment' be
 connection-aware?
Date: Thu, 28 Oct 2021 08:49:13 -0700
[Message part 1 (text/plain, inline)]
On 10/28/2021 1:02 AM, Michael Albinus wrote:
>> +@code{comint-terminfo-terminal} to let you choose a terminal with more
>> +advanced features, as defined in your system's terminfo database.
>> +When @code{system-uses-terminfo} is non-nil, Emacs will use this
>> +option as the value for @env{TERM}.
> 
> "this option" sounds like Emacs uses system-uses-terminfo for TERM, at
> least in my ears. Could you pls rephrase it a little bit?

Looking at it again, I definitely agree. I've tried to reword it without 
making it too much more verbose. How's this?
[0001-Support-setting-comint-terminal-connection-locally.patch (text/plain, attachment)]

Reply sent to Michael Albinus <michael.albinus <at> gmx.de>:
You have taken responsibility. (Thu, 28 Oct 2021 16:50:02 GMT) Full text and rfc822 format available.

Notification sent to Jim Porter <jporterbugs <at> gmail.com>:
bug acknowledged by developer. (Thu, 28 Oct 2021 16:50:02 GMT) Full text and rfc822 format available.

Message #24 received at 51426-done <at> debbugs.gnu.org (full text, mbox):

From: Michael Albinus <michael.albinus <at> gmx.de>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 51426-done <at> debbugs.gnu.org
Subject: Re: bug#51426: 29.0.50; [PATCH] Should 'comint-term-environment' be
 connection-aware?
Date: Thu, 28 Oct 2021 18:48:58 +0200
Version: 29.1

Jim Porter <jporterbugs <at> gmail.com> writes:

Hi Jim,

> Looking at it again, I definitely agree. I've tried to reword it
> without making it too much more verbose. How's this?

Fine. I've committed this in your name to master, slightly
modified. Closing the bug.

What I'm curious about is whether we shall give more guidance using this
feature. The majority of the users don't know connection-local
variables, your example from the initial message might be instructive
for them.

WDYT?

Best regards, Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51426; Package emacs. (Fri, 29 Oct 2021 05:27:02 GMT) Full text and rfc822 format available.

Message #27 received at 51426 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: 51426 <at> debbugs.gnu.org, michael.albinus <at> gmx.de
Subject: Re: bug#51426: 29.0.50; [PATCH] Should 'comint-term-environment' be
 connection-aware?
Date: Thu, 28 Oct 2021 22:26:31 -0700
[Message part 1 (text/plain, inline)]
On 10/28/2021 9:48 AM, Michael Albinus wrote:
> What I'm curious about is whether we shall give more guidance using this
> feature. The majority of the users don't know connection-local
> variables, your example from the initial message might be instructive
> for them.
> 
> WDYT?

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.)

Perhaps it would make sense to mention this in the Tramp manual too, 
such as under the section "Running shell on a remote host". On the other 
hand, setting `system-uses-terminfo' connection-locally only applies to 
Emacs 29+, so it might make that section more confusing to include it 
there. People might expect it to work on older versions of Emacs as well.
[0001-Expand-the-documentation-for-connection-local-variab.patch (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51426; Package emacs. (Fri, 29 Oct 2021 08:22:01 GMT) Full text and rfc822 format available.

Message #30 received at 51426 <at> debbugs.gnu.org (full text, mbox):

From: Michael Albinus <michael.albinus <at> gmx.de>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 51426 <at> debbugs.gnu.org
Subject: Re: bug#51426: 29.0.50; [PATCH] Should 'comint-term-environment' be
 connection-aware?
Date: Fri, 29 Oct 2021 10:21:14 +0200
Jim Porter <jporterbugs <at> gmail.com> writes:

Hi Jim,

> 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?

> Perhaps it would make sense to mention this in the Tramp manual too,
> such as under the section "Running shell on a remote host". On the
> other hand, setting `system-uses-terminfo' connection-locally only
> applies to Emacs 29+, so it might make that section more confusing to
> include it there. People might expect it to work on older versions of
> Emacs as well.

I believe we can leave it as it is. There are other connection-local
variables, understood by Tramp, and not mentioned in the Tramp manual.

Best regards, Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51426; Package emacs. (Fri, 29 Oct 2021 16:40:02 GMT) Full text and rfc822 format available.

Message #33 received at 51426 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Michael Albinus <michael.albinus <at> gmx.de>
Cc: 51426 <at> debbugs.gnu.org
Subject: Re: bug#51426: 29.0.50; [PATCH] Should 'comint-term-environment' be
 connection-aware?
Date: Fri, 29 Oct 2021 09:39:15 -0700
[Message part 1 (text/plain, inline)]
On 10/29/2021 1:21 AM, Michael Albinus wrote:
> Jim Porter <jporterbugs <at> gmail.com> 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'.
[0001-Expand-the-documentation-for-connection-local-variab.patch (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51426; Package emacs. (Sat, 30 Oct 2021 15:44:01 GMT) Full text and rfc822 format available.

Message #36 received at 51426 <at> debbugs.gnu.org (full text, mbox):

From: Michael Albinus <michael.albinus <at> gmx.de>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 51426 <at> debbugs.gnu.org
Subject: Re: bug#51426: 29.0.50; [PATCH] Should 'comint-term-environment' be
 connection-aware?
Date: Sat, 30 Oct 2021 17:43:24 +0200
Jim Porter <jporterbugs <at> gmail.com> writes:

Hi Jim,

>> 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'.

Thanks. I've pushed your patch almost as-it-is to master (adding a
missing space).

Best regards, Michael.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 28 Nov 2021 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 199 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.