Augusto Stoffel <[email protected]> writes:

Hi,

>> After looking at "Integration with other Emacs packages", I am
>> under the impression, that I have to implement my own variant of
>> `with-environment-variables', which not just binds a modified
>> `process-environment`, but does the same for
>> `tramp-remote-process-environment'.
>
> I don't think so.  If you want to unconditionally add some env vars to a
> process (whether it's local or remote), you should let-bind a modified
> process-environment list but _not_ set it.  (This rules out the option
> to use cl-letf.)
>
>> I feel I am being told that I am "holding it wrong".
>
> with-environment-variables would be the right thing to use.

Indeed. The following code snippets work (replace my test machine "/sshx:ford:")

--8<---------------cut here---------------start------------->8---
;; Synchronous
(with-environment-variables (("TEST_TRAMP" "good"))
  (let ((default-directory "/sshx:ford:"))
    (message "%s" (shell-command-to-string "echo \"${TEST_TRAMP:-bad}\""))))

;; Asynchronous
(with-environment-variables (("TEST_TRAMP" "good"))
  (let ((default-directory "/sshx:ford:")
        (shell-file-name "/bin/sh"))
    (with-temp-buffer
      (let ((proc (async-shell-command
                   "echo \"${TEST_TRAMP:-bad}\"" (current-buffer))))
        (while (or (accept-process-output proc nil nil t)
                   (process-live-p proc))))
      (message "%s" (buffer-substring-no-properties (point-min) (point-max))))))

;; Asynchronous with tramp-direct-async-process
(with-environment-variables (("TEST_TRAMP" "good"))
  (let ((default-directory "/sshx:ford:")
        (shell-file-name "/bin/sh")
        (tramp-direct-async-process t))
    (with-temp-buffer
      (let ((proc (async-shell-command
                   "echo \"${TEST_TRAMP:-bad}\"" (current-buffer))))
        (while (or (accept-process-output proc nil nil t)
                   (process-live-p proc))))
      (message "%s" (buffer-substring-no-properties (point-min) (point-max))))))
--8<---------------cut here---------------end--------------->8---

> But OP claims Magit would be calling setq-local on process-environment
> at some point, which with-environment-variables clearly doesn't do.

Sic! Perhaps we shall say it explicitly in the manual.

>> Michael, I need more guidance. Thanks.
>> Jonas

Best regards, Michael.

Reply via email to