unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: monnier@iro.umontreal.ca, rpluim@gmail.com, emacs-devel@gnu.org
Subject: Re: Multi-tty
Date: Fri, 08 Nov 2024 13:43:05 +0200	[thread overview]
Message-ID: <865xoyoss6.fsf@gnu.org> (raw)
In-Reply-To: <m21pzmawnx.fsf@gmail.com> (message from Gerd Möllmann on Fri, 08 Nov 2024 10:42:58 +0100)

> From: Gerd Möllmann <gerd.moellmann@gmail.com>
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>,  rpluim@gmail.com,
>   emacs-devel@gnu.org
> Date: Fri, 08 Nov 2024 10:42:58 +0100
> 
> Gerd Möllmann <gerd.moellmann@gmail.com> writes:
> 
> > Eli Zaretskii <eliz@gnu.org> writes:
> >
> >>> From: Gerd Möllmann <gerd.moellmann@gmail.com>
> >>> Cc: Eli Zaretskii <eliz@gnu.org>,  emacs-devel@gnu.org
> >>> Date: Fri, 08 Nov 2024 09:18:05 +0100
> >>> 
> >>> >     Eli> This is simply not supported, never was.  The environment variables
> >>> >     Eli> are not per-terminal, so their effect is global, and the way we
> >>> >     Eli> process them (and have no other way) is that the environment variables
> >>> >     Eli> override what terminfo tells us.
> >>> >
> >>> > They do, but then they change the settings in the per-terminal
> >>> > tty_display_info, no? Or am I misreading init_tty? Certainly
> >>> >
> >>> > TERM=xterm-mono emacsclient -tty
> >>> >
> >>> > gives me a mono emacs.
> >>> 
> >>> And TERN works because emacsclient picks it up and sends its value as
> >>> part of the frame creation command to the server. In the server, it is
> >>> then passed down to make_terminal_frame as a frame parameter which
> >>> itself uses it for init_tty.
> >>
> >> Yes, exactly.  But TERM is special in this sense.
> >
> > Right.
> >
> >>> A pretty easy fix would be to make the environment that we got from
> >>> emacsclient anyway another frame parameter. Then init_tty wouldn't have
> >>> to use getenv to get the value of COLORTERM.
> >>
> >> I'm not sure this is easy.  The general problem of environment
> >> variables being terminal-specific (_not_ frame-specific!) was
> >> discussed at length around the introduction of multi-tty into Emacs,
> >> but AFAIR the decision was eventually to leave that unsolved, due to
> >> non-trivial difficulties whose details I no longer recall.  You may
> >> wish looking up those discussions, around 2003 to 2007 (look for
> >> messages posted by Károly Lőrentey, who implemented multi-tty in
> >> Emacs).  Or maybe Stefan remembers those discussions better.
> >
> > I wouldn't try to "fix" the general handling of environment variables,
> > if that's even possible, which I kind of doubt as you do, I think. I'd
> > just replace the getenv("COLORTERM") with some lookup of COLORTERM in
> > what emacsclient sent to the server.
> 
> And all that's necessary is
> 
> modified   src/term.c
> @@ -4383,7 +4383,7 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
>  	   (de-facto standard introduced by tmux) or if	requested by
>  	   the COLORTERM environment variable.  */
>  	else if ((tigetflag ("Tc") > 0)
> -		 || ((bg = getenv ("COLORTERM")) != NULL
> +		 || ((bg = egetenv ("COLORTERM")) != NULL
>  		     && strcasecmp (bg, "truecolor") == 0))
>  	  {
>  	    tty->TS_set_foreground = "\033[%?%p1%{8}%<%t3%p1%d%e38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d%;m";
> 
> A one character change, isn't that funny :-).
> 
> It works because server.el puts COLORTERM in process-environment
> already, in server-with-environment.

process-environment is not supposed to affect Emacs, it's there to
affect sub-processes of Emacs.

This is exactly the crux of the problem of supporting per-terminal
environment variables.



  parent reply	other threads:[~2024-11-08 11:43 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07  9:53 Multi-tty Gerd Möllmann
2024-11-07 10:58 ` Multi-tty Eli Zaretskii
2024-11-07 11:15   ` Multi-tty Robert Pluim
2024-11-07 11:38     ` Multi-tty Gerd Möllmann
2024-11-07 11:47     ` Multi-tty Eli Zaretskii
2024-11-08  8:18     ` Multi-tty Gerd Möllmann
2024-11-08  8:28       ` Multi-tty Gerd Möllmann
2024-11-08  8:50       ` Multi-tty Eli Zaretskii
2024-11-08  9:16         ` Multi-tty Gerd Möllmann
2024-11-08  9:42           ` Multi-tty Gerd Möllmann
2024-11-08 10:17             ` Multi-tty Robert Pluim
2024-11-08 11:09               ` Multi-tty Gerd Möllmann
2024-11-08 11:49                 ` Multi-tty Eli Zaretskii
2024-11-08 11:43             ` Eli Zaretskii [this message]
2024-11-08 11:41           ` Multi-tty Eli Zaretskii
2024-11-08 11:49             ` Multi-tty Gerd Möllmann
2024-11-08 12:03               ` Multi-tty Eli Zaretskii
2024-11-08 12:25                 ` Multi-tty Gerd Möllmann
2024-11-08 12:11               ` Multi-tty Robert Pluim
2024-11-08 12:29                 ` Multi-tty Gerd Möllmann
2024-11-08 13:53               ` Multi-tty Stefan Monnier
2024-11-08 13:55                 ` Multi-tty Eli Zaretskii
2024-11-08 14:05                 ` Multi-tty Gerd Möllmann
2024-11-08 14:11                   ` Multi-tty Gerd Möllmann
2024-11-08 15:42                     ` Multi-tty Yuri Khan
2024-11-08 13:55             ` Multi-tty Stefan Monnier
2024-11-08 14:24               ` Multi-tty Robert Pluim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=865xoyoss6.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=gerd.moellmann@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    --cc=rpluim@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).