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

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

Jim Porter <jporterbugs@gmail.com> writes:

Hi Jim,

Thanks your the example file, it is a pleasure to work on something like this!

> 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.

Well, your example code has some problems:

- connection-local-criteria-for-default-directory returns nil for a
  local default directory. In order to handle this case, I have added
  eshell-connection-local-criteria-for-default-directory.

- You cannot use the same profile for different criteria, unless you
  intend the same settings. Therefore, I have added
  eshell-connection-local-profile.

- If you change settings in eshell-get-path or eshell-set-path, you must
  tell this to the connection-local variables machinery. I've extended
  both functions accordingly.

Now your ert test passes for me. Changed connection-local.el added.

Best regards, Michael.


[-- Attachment #2: connection-local.el --]
[-- Type: text/plain, Size: 3743 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)

(defsubst eshell-connection-local-criteria-for-default-directory ()
  (or (connection-local-criteria-for-default-directory 'eshell)
      '(:application eshell :machine local)))

(defsubst eshell-connection-local-profile ()
  (intern (concat "eshell-connection-local-profile-"
		  (or (file-remote-p default-directory) "local"))))

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

(connection-local-set-profiles
 '(:application 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
     (eshell-connection-local-criteria-for-default-directory))
    (prog1
	(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))))
      ;; Set connection-local-variable.
      (connection-local-set-profile-variables
       (eshell-connection-local-profile)
       `((eshell-path-env-list . ,eshell-path-env-list)))
      (connection-local-set-profiles
       (eshell-connection-local-criteria-for-default-directory)
       (eshell-connection-local-profile)))))

(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
     (eshell-connection-local-criteria-for-default-directory))
    (prog1
	(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))))
      ;; Set connection-local-variable.
      (connection-local-set-profile-variables
       (eshell-connection-local-profile)
       `((eshell-path-env-list . ,eshell-path-env-list)))
      (connection-local-set-profiles
       (eshell-connection-local-criteria-for-default-directory)
       (eshell-connection-local-profile)))))

(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 18:28 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
2022-10-07 18:28                       ` Michael Albinus [this message]
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=87fsfzh4if.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=57556@debbugs.gnu.org \
    --cc=jporterbugs@gmail.com \
    /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).