From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Buffer-local process environments Date: Sat, 28 Aug 2021 14:28:59 +0200 Message-ID: <87lf4lkb1w.fsf_-_@gmail.com> References: <87eeets6jf.fsf@gmail.com> <8735v99f4i.fsf@gmail.com> <87y2d1xada.fsf@gmx.de> <877dkkcjrj.fsf@gmail.com> <87tunoyzzd.fsf@gmx.de> <87eeerby1n.fsf@gmail.com> <87a6pfepo6.fsf@gmx.de> <874kflmzn3.fsf@gmail.com> <87wns9glm1.fsf@gmx.de> <87y2co4hto.fsf@gmail.com> <87v97reubc.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30649"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) To: Michael Albinus , Stefan Monnier , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Aug 28 14:29:50 2021 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 1mJxT2-0007qN-Nx for ged-emacs-devel@m.gmane-mx.org; Sat, 28 Aug 2021 14:29:48 +0200 Original-Received: from localhost ([::1]:54108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJxT1-0004yW-5s for ged-emacs-devel@m.gmane-mx.org; Sat, 28 Aug 2021 08:29:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJxSL-0004IX-Is for emacs-devel@gnu.org; Sat, 28 Aug 2021 08:29:06 -0400 Original-Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:34620) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mJxSJ-0005hO-T1 for emacs-devel@gnu.org; Sat, 28 Aug 2021 08:29:05 -0400 Original-Received: by mail-wr1-x432.google.com with SMTP id h13so14771847wrp.1 for ; Sat, 28 Aug 2021 05:29:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=hCLjJJSw/YwdnUhcAr++j9/vDdtFOH0fdxqicOXPzGU=; b=hJvA1EmcsESWWGYmtazOz+DSl1cVPlIzK+J7XOoXFaVSRysJ08MBJnzY5L8HINgg2K mw9ZE5FCjvQ9T80A1flA+l+JrKYR4I1sQZd+oYLo56Hg66lGX3FzdOBagC7WXPznf+v1 SIbLxIp6DD9qjske2V9XrmoGG2mr1Fed9qDnFO/DMIVNo/a8vFVcP6WU/Ee9rdNVXlai gM/ogV0hjzLIdk/Cw7kw4ilFTFNuGjWx5dFKqqJ4/7xHugiOaUGDfizUfk65iEFAjBng WmMoeGOvBEv1PTePVfpjGCwaE8tkDMZc6XF9WGWGh0BF6aoxlLaKvlfCir0ox+4DumNR KDUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=hCLjJJSw/YwdnUhcAr++j9/vDdtFOH0fdxqicOXPzGU=; b=Mh1Os54GJvCVTgHq1HudvhFGGawQ0Al6MJOibq//BidAfaTga6IBH0HjrCxuY9TLWA ZqELHX25Afx8pZAi54egXn52ws8okmzlL6+NUksqIcVo9JHW6BmDNooVJd2CSUB9MqVi C8wSGtSYxF8/Iw0l3di5J+VmVPGWPiN4qQLmUnD0gImXilnaAZU11BHc6HgvzU5VFh/G GtSml66ekqG4eTAN2u9kfhj9VFhsMNWtEOzLyzIitZDZQKrY6s6cyZpQ2Y4XNVZFu/rc zt+AYTh93rumZVkSoM7dyxaJ5Th/YqhEzxbANlIuXN++5HEr401PpmHnMhJDwMj9MzOC G0LA== X-Gm-Message-State: AOAM533oTGbO4L2LXBUw9LQbYrO/xakrEdu7m9g7hOR3QBvXsOfZ4IAx nCBlR5Yr+LUOALvrfqO1N+omEyzhQBMHyA== X-Google-Smtp-Source: ABdhPJwiAmfTGmCp6LF+RSvGofAPi4pvJe6eYbsvS59hgmkNNEhxdIeewFxH+WZQy6wYgfqA0aFI5g== X-Received: by 2002:adf:ba08:: with SMTP id o8mr15901100wrg.234.1630153741755; Sat, 28 Aug 2021 05:29:01 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::ae3f]) by smtp.gmail.com with ESMTPSA id k17sm15783663wmj.0.2021.08.28.05.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Aug 2021 05:29:01 -0700 (PDT) In-Reply-To: <87v97reubc.fsf@gmx.de> (Michael Albinus's message of "Sun, 09 May 2021 18:38:31 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=arstoffel@gmail.com; helo=mail-wr1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:273286 Archived-At: --=-=-= Content-Type: text/plain After sleeping on this (for quite a while), I'm pretty confident that the attached patch gives `compile' a sensible behavior in the presence of a buffer-local `process-environment'. Specifically, whenever `compile' is called from a buffer where `process-environment' is local, the *compilation* buffer inherits the original buffer's `process-environment' and `exec-path'. When `process-environment' is not local in the buffer from which `compile' is called, any local values of those two variables are killed in the *compilation* buffer as well. (There's no check for buffer-localness of `exec-path' because it's usually misguided to keep it out of sync with PATH.) Concerning possible interactions with Tramp, I think the conclusion from what Michael said previously is: if your buffer is remote, then don't mess with `process-environment' and set `tramp-remote-process-environment' instead. If that is a requirement imposed on the user, then this patch is free of conflicts with Tramp by decree. Still, there is one case, which might be quite specific to my personal workflow, where I get a problematic interaction with Tramp. I'm often editing files locally that I can only compile or run on a heavy-duty remote host. So I call, from those local buffers (let ((default-directory "/ssh:remote-host:/path/to/mirror/of/project")) (compile "make")) With the attached patch, a buffer-local PATH value will leak to the remote machine, which is almost surely the wrong thing to do. I've suggested one solution for this on the Tramp side (using `tramp-process-environment' itself to block certain variables from being exported to the remote). I believe Michael wasn't convinced this is a good idea. In any case, there's another solution to this problem, which is to replace the above by (let ((default-directory "/ssh:remote-host:/path/to/mirror/of/project")) (process-environment (default-value 'process-environment)) (compile "make")) This is an okay hurdle to introduce, because it is already needed anyway for functions that starts a process _without_ changing buffers first, such as `shell-command'. I hope this makes sense to everybody and can be merged. I'd also hope that the present handling of env vars can serve as a model to be adopted by most commands that switch buffers and then start a process in this new buffer, such as the `run-` commands. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Make-compile-respect-buffer-local-process-environmen.patch >From e46913ec1f0e3f839dd8a36022095587b1962ac5 Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Thu, 29 Apr 2021 12:45:04 +0200 Subject: [PATCH] Make 'compile' respect buffer-local process environment * lisp/progmodes/compile.el (compilation-start): Use `process-environment' from original buffer in the compilation process. --- lisp/progmodes/compile.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index af7b8292b7..1c11b7707e 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -1783,6 +1783,8 @@ compilation-start (replace-regexp-in-string "-mode\\'" "" (symbol-name mode)))) (thisdir default-directory) (thisenv compilation-environment) + (bufferenv (when (local-variable-p 'process-environment) + (cons exec-path process-environment))) outwin outbuf) (with-current-buffer (setq outbuf @@ -1850,6 +1852,11 @@ compilation-start ;; NB: must be done after (funcall mode) as that resets local variables (setq-local compilation-directory thisdir) (setq-local compilation-environment thisenv) + (if bufferenv + (setq-local exec-path (car bufferenv) + process-environment (cdr bufferenv)) + (kill-local-variable 'exec-path) + (kill-local-variable 'process-environment)) (if highlight-regexp (setq-local compilation-highlight-regexp highlight-regexp)) (if (or compilation-auto-jump-to-first-error -- 2.31.1 --=-=-=--