From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Multi-tty Date: Fri, 08 Nov 2024 13:43:05 +0200 Message-ID: <865xoyoss6.fsf@gnu.org> References: <8634k3qpie.fsf@gnu.org> <87r07nl2gf.fsf@gmail.com> <868qtup0s5.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12241"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, rpluim@gmail.com, emacs-devel@gnu.org To: Gerd =?utf-8?Q?M=C3=B6llmann?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 08 12:43:59 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t9NPC-00030c-UY for ged-emacs-devel@m.gmane-mx.org; Fri, 08 Nov 2024 12:43:59 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t9NOg-00067V-FY; Fri, 08 Nov 2024 06:43:26 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9NOZ-00067A-TB for emacs-devel@gnu.org; Fri, 08 Nov 2024 06:43:20 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t9NOZ-0004Yi-K9; Fri, 08 Nov 2024 06:43:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=3JaCvNacD+9pD8hMMRYr1iL3EV30UHi/wrWaqi/sTzY=; b=qu8Eg4PmwYrIStzV12bb 7qCesyTD45+yd5HgORZOyGA7zYVSbGvsONUFI8aH8krzF7E1Dl2GSvOiAFmMA01XeAPDYOYFtDy2j 6mI7o+BkeYPyqGnYK9uZ9MCzbwIYnYvXU4/Ip7rxAOt6xCj4EzAjO7FFxfpbApv1w+354zZW90yIu E/+sleCkoz/hINQSxuCrWZoE/DKnnfs0hAfBsO/C2SkCtgrqovKMEAoaAJBhbxqOWOQRQOR6jLN/l x4AvIE/4Ezrl4u3hICZG8VuudWjCrx+vqFaQ6A1X491gkGsOIp7WPhF41t1hHVOINMLAX8BmHHitX q5puvkWgoEdruA==; In-Reply-To: (message from Gerd =?utf-8?Q?M?= =?utf-8?Q?=C3=B6llmann?= on Fri, 08 Nov 2024 10:42:58 +0100) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325269 Archived-At: > From: Gerd Möllmann > Cc: Stefan Monnier , rpluim@gmail.com, > emacs-devel@gnu.org > Date: Fri, 08 Nov 2024 10:42:58 +0100 > > Gerd Möllmann writes: > > > Eli Zaretskii writes: > > > >>> From: Gerd Möllmann > >>> Cc: Eli Zaretskii , 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.