all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Augusto Stoffel <arstoffel@gmail.com>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: Buffer-local process environments
Date: Sun, 09 May 2021 07:06:11 +0200	[thread overview]
Message-ID: <87y2co4hto.fsf@gmail.com> (raw)
In-Reply-To: 87wns9glm1.fsf@gmx.de

[-- Attachment #1: Type: text/plain, Size: 2826 bytes --]

On Sat,  8 May 2021 at 19:51, Michael Albinus <michael.albinus@gmx.de> wrote:

Hi Michael,

> We have already a white list, which is tramp-remote-process-environment.
> I'm reluctant to add package specific entries there by default, it would
> be an endless story. PAGER is included as being a general purpose
> environment variable, BZR_LOG and HGPLAIN are not. If packages believe
> they shall be added, this could be done in vc-bzr.el or vc-hg.el. Tramp
> is a stupid library, it shouldn't try to be clever.

Fair enough.  Let's cross out the first idea then.

>> 2. Introduce a blacklist of variables that are never exported to a
>>    remote.  This can be done by extending
>>    `tramp-remote-process-environment' to follow the same convention of
>>    `process-environment' that an entry of the form VAR, without the
>>    =VALUE, means removing the variable.
>
> There are already such variables to be unset. These are the variables
> without any value, like "HISTORY="

This only works for entries in the default toplevel value of
`process-environment'.  Not for things added buffer-locally or
in a let-binding.

The heuristic that every env var which is not in the default toplevel
value of `process-environment' will be exported to the remote works
pretty well.  But it needs a simple way to be overridden, since it can't
read the user's mind.

> TERM is handled special. All Tramp connections add "TERM=dumb",
> hard-coded. Since this shall not be changed by a user, it isn't
> configurable here.

Not all connections add "TERM=dumb".  Here's a counterexample:

    (let ((default-directory "/sudo::/")
          (process-environment `("TERM=dumber"
                                 ,@process-environment)))
      (shell-command "echo $TERM" t))
    => dumber

How do I tell Tramp not to export TERM=dumber to the remote in this
case?

To be clear: this may be a dumb example, but there are plenty of
interesting use-cases involving PATH, PYTHONPATH, and so on, which are
analogous.  How can I set PYTHONPATH buffer-locally, but disallow Tramp
to export this variable to a remote?

>>    As another example, python.el would append "PYTHONPATH" and
>>    "PYTHONHOME" globally to `tramp-remote-process-environment', since
>>    these variables hold directory names.
>
> Yes, if python.el developers prefer that. However, I doubt, that this
> value is always the same for all different remote hosts, the value might
> differ depending on the OS the remote host is running.

That's precisely what I meant: you *do not* want to export those variables
to a remote.  But currently Tramp effectively forbids anyone to set
PYTHONPATH buffer-locally, because this will cause them to be exported.

My suggestion is easier to implement than explain.  So let me repeat it
in the form of a little (possibly incomplete) patch:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: tramp-env.patch --]
[-- Type: text/x-patch, Size: 1208 bytes --]

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 015f458a63..3749f84e21 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3938,21 +3938,23 @@ tramp-handle-make-process
 		       (when (string-match-p "=" elt) elt))
 		     tramp-remote-process-environment))
 	       ;; We use as environment the difference to toplevel
 	       ;; `process-environment'.
 	       (env (dolist (elt process-environment env)
 		      (when
 			  (and
 			   (string-match-p "=" elt)
 			   (not
 			    (member
-			     elt (default-toplevel-value 'process-environment))))
+			     elt (default-toplevel-value 'process-environment)))
+                           (not (member (car (split-string elt "="))
+                                        tramp-remote-process-environment)))
 			(setq env (cons elt env)))))
 	       (env (setenv-internal
 		     env "INSIDE_EMACS" (tramp-inside-emacs) 'keep))
 	       (env (mapcar #'tramp-shell-quote-argument (delq nil env)))
 	       ;; Quote command.
 	       (command (mapconcat #'tramp-shell-quote-argument command " "))
 	       ;; Set cwd and environment variables.
 	       (command
 	        (append `("cd" ,localname "&&" "(" "env") env `(,command ")"))))
 

  reply	other threads:[~2021-05-09  5:06 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-29 10:56 Buffer-local process environments Augusto Stoffel
2021-04-29 12:30 ` Eli Zaretskii
2021-04-29 12:40   ` Augusto Stoffel
2021-04-29 12:52     ` Eli Zaretskii
2021-04-29 13:06       ` Augusto Stoffel
2021-04-29 14:02 ` Stefan Monnier
2021-04-29 17:26   ` Augusto Stoffel
2021-04-29 17:34     ` Michael Albinus
2021-04-30  7:29       ` Augusto Stoffel
2021-04-30  7:48         ` Michael Albinus
2021-04-30 15:19           ` Augusto Stoffel
2021-04-30 15:51             ` Michael Albinus
2021-05-02  6:13               ` Augusto Stoffel
2021-05-08 17:51                 ` Michael Albinus
2021-05-09  5:06                   ` Augusto Stoffel [this message]
2021-05-09 16:38                     ` Michael Albinus
2021-08-28 12:28                       ` [PATCH] " Augusto Stoffel
2021-08-28 12:37                         ` Eli Zaretskii
2021-08-28 12:55                           ` Augusto Stoffel
2021-09-01 10:42                             ` Stephen Leake
2021-09-01 10:56                               ` Augusto Stoffel
2021-09-01 22:38                                 ` Stephen Leake
2021-09-02  7:14                                   ` Augusto Stoffel
2021-09-06 15:17                                     ` Stephen Leake
2021-08-28 14:06                           ` Arthur Miller
2021-08-28 14:33                             ` Eli Zaretskii
2021-08-28 15:27                               ` Arthur Miller
2021-08-28 15:38                                 ` Eli Zaretskii
2021-08-28 16:48                                   ` Arthur Miller
2021-08-28 15:39                                 ` Augusto Stoffel
2021-08-28 16:43                                   ` Arthur Miller
2021-08-28 12:47                         ` Michael Albinus
2021-08-28 12:59                           ` Augusto Stoffel
2021-08-28 13:18                             ` Michael Albinus
2021-08-28 13:54                               ` Augusto Stoffel
2021-08-28 14:05                               ` Stefan Monnier
2021-08-28 15:19                                 ` Augusto Stoffel
2021-04-30 15:32           ` Augusto Stoffel
2021-04-30 15:55             ` Michael Albinus
2021-04-29 15:37 ` Michael Albinus
2021-04-29 17:31   ` Augusto Stoffel
2021-04-29 17:44     ` Michael Albinus
2021-04-30  7:00       ` Augusto Stoffel
2021-04-30  7:25         ` Michael Albinus
2021-05-02 13:45 ` Stephen Leake

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

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

  git send-email \
    --in-reply-to=87y2co4hto.fsf@gmail.com \
    --to=arstoffel@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=michael.albinus@gmx.de \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.