unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: 57556@debbugs.gnu.org
Subject: bug#57556: 28.1; Eshell not finding executables in PATH when tramp-integration loaded
Date: Thu, 6 Oct 2022 20:19:26 -0700	[thread overview]
Message-ID: <00448968-481d-9bdd-b0c8-7bc3d04e5d60@gmail.com> (raw)
In-Reply-To: <87wn9iehl1.fsf@gmx.de>

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

On 10/2/2022 1:48 AM, Michael Albinus wrote:
> Yes. with-connection-local-variables is designed to provide those
> variables inside the BODY only. And you have used nil as CRITERIA in
> connection-local-set-profiles, which means you get the same variables
> for every kind of default-directory, which means you don't use
> connection-local variables at all :-)
> 
> What you need is a permanent setting of variables. Something like
> 
> (connection-local-set-profiles
>   (connection-local-criteria-for-default-directory 'eshell)
>   'eshell-connection-local-profile)
> 
> (let ((enable-connection-local-variables t)
>        connection-local-variables-alist) ;; I'm not sure this is needed.
>    (hack-connection-local-variables-apply
>     (connection-local-criteria-for-default-directory 'eshell))
>    ;; The body.
>    ...)

Hmm, I've tried this a few different ways, and I haven't been able to 
get it to work the way it should. Maybe I'm just missing something?

Attached is a minimal test case I've extracted to show the issue I'm 
having. It seems the problem is that, while I can update the path in 
'eshell-set-path' with no problem, when I call 'eshell-get-path' again, 
'hack-connection-local-variables-apply' resets 'eshell-path-env-list' to 
nil, so the modified path is lost.

Do you have any ideas about what I'm doing wrong? Or maybe 
connection-local variables aren't supposed to be used this way. All the 
documentation I see on them involves setting variables to constant 
values, not updating them in-place over the life of a program.

[-- Attachment #2: connection-local.el --]
[-- Type: text/plain, Size: 2779 bytes --]

;;; -*- lexical-binding:t -*-

;; Run these tests with:
;;  emacs -Q --batch -l ~/etc/emacs/connection-local.el \
;;        --eval '(ert-run-tests-batch-and-exit t)'

(require 'tramp)
(require 'ert)
(require 'ert-x)

(defvar-local eshell-path-env-list nil)

(connection-local-set-profile-variables
 'eshell-connection-local-profile
 '((eshell-path-env-list . nil)))

(connection-local-set-profiles
 (connection-local-criteria-for-default-directory 'eshell)
 'eshell-connection-local-profile)

(defun eshell-get-path ()
  "Return $PATH as a list."
  (let ((enable-connection-local-variables t)
        connection-local-variables-alist) ;; I'm not sure this is needed.
    (hack-connection-local-variables-apply
     (connection-local-criteria-for-default-directory 'eshell))
    (or eshell-path-env-list
        ;; If not already cached, get the path from `exec-path',
        ;; removing the last element, which is `exec-directory'.
        (setq eshell-path-env-list (butlast (exec-path))))))

(defun eshell-set-path (path)
  "Set the Eshell $PATH to PATH.
PATH can be either a list of directories or a string of
directories separated by `path-separator'."
  (let ((enable-connection-local-variables t)
        connection-local-variables-alist) ;; I'm not sure this is needed.
    (hack-connection-local-variables-apply
     (connection-local-criteria-for-default-directory 'eshell))
    (setq eshell-path-env-list
          (if (listp path)
              path
            ;; Don't use `parse-colon-path' here, since we don't want
            ;; the additonal translations it does on each element.
            (split-string path (path-separator))))))

(ert-deftest esh-var-test/path-var/preserve-across-hosts ()
  "Test that $PATH can be set independently on multiple hosts."
  ;; Test the initial value of the local $PATH.
  (should (equal (eshell-get-path) (butlast (exec-path))))

  ;; Set the local $PATH and make sure it retains the value we set.
  (should (equal (eshell-set-path "/local/path") '("/local/path")))
  (should (equal (eshell-get-path) '("/local/path")))      ; FAIL

  (let ((default-directory ert-remote-temporary-file-directory))
    ;; Test the initial value of the remote $PATH.
    (should (equal (eshell-get-path) (butlast (exec-path))))

    ;; Set the remote $PATH and make sure it retains the value we set.
    (should (equal (eshell-set-path "/remote/path") '("/remote/path")))
    (should (equal (eshell-get-path) '("/remote/path"))))  ; FAIL

  ;; Make sure we get the local $PATH we set above.
  (should (equal (eshell-get-path) '("/local/path")))      ; FAIL

  ;; Make sure we get the remote $PATH we set above.
  (let ((default-directory ert-remote-temporary-file-directory))
    (should (equal (eshell-get-path) '("/remote/path"))))) ; FAIL

  reply	other threads:[~2022-10-07  3:19 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-03  5:03 bug#57556: 28.1; Eshell not finding executables in PATH when tramp-integration loaded Colton Lewis via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-03 12:26 ` Lars Ingebrigtsen
2022-09-18 11:18 ` Michael Albinus
2022-09-18 18:54   ` Jim Porter
2022-09-18 19:07     ` Michael Albinus
2022-09-22 17:23       ` Colton Lewis via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-22 17:55         ` Michael Albinus
2022-09-30  3:54           ` Jim Porter
2022-10-01 20:25             ` Michael Albinus
2022-10-01 22:02               ` Jim Porter
2022-10-02  5:34                 ` Jim Porter
2022-10-02  8:48                   ` Michael Albinus
2022-10-07  3:19                     ` Jim Porter [this message]
2022-10-07 18:28                       ` Michael Albinus
2022-10-08 22:09                         ` Jim Porter
2022-10-09 18:01                           ` Michael Albinus
2022-10-13  4:11                             ` Jim Porter
2022-10-13  6:35                               ` Eli Zaretskii
2022-10-14  1:29                                 ` Jim Porter
2022-10-14  6:17                                   ` Eli Zaretskii
2022-10-14 12:28                                   ` Michael Albinus
2022-10-14 12:27                               ` Michael Albinus
2022-10-14 20:53                                 ` Jim Porter
2022-10-15 10:38                                   ` Michael Albinus
2022-10-15 23:33                                     ` Jim Porter
2022-10-16 17:00                                       ` Michael Albinus
2022-10-16 23:01                                         ` Jim Porter
2022-10-16 20:51                                   ` Richard Stallman
2022-10-16 23:07                                     ` Jim Porter
2022-10-18  1:51                                       ` Jim Porter
2022-10-10  9:15                           ` Michael Albinus
2022-10-02  8:55                 ` Michael Albinus

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=00448968-481d-9bdd-b0c8-7bc3d04e5d60@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=57556@debbugs.gnu.org \
    --cc=michael.albinus@gmx.de \
    /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).