Subject: Re: bug#61748: 27.2; Eglot should use shell-file-name when launching the language server for a remote file

From: João Távora <[email-masked]>
Date: Tue, 28 Feb 2023 16:28:11 +0000

On Tue, Feb 28, 2023 at 3:50 PM Michael Albinus <[email-masked]> wrote:
>
> João Távora <[email-masked]> writes:
>
> Hi João,
>
> >> I don't expect a user to solve it. And a user shouldn't expect that
> >> changing a variable is sufficient.
> >
> > I respectfully but diametrically disagree here.
> >
> > Here's an untested patch that could solve this.  It can probably
> > be made smarter by only invalidating the cache when a change
> > to the variable is detected.
>
> Hmm. It will delay startup of remote processes, if tramp-remote-path
> doesn't change for different processes. Perhaps it is negligable, but at
> least for slow connections people will be hit by this.
>
> I'll play with it. Perhaps there is a smarter version of it, as you say.

Here's another still untested but smarter patch.  Caches fully
on until user messes with tramp-remote-path, else immediately
flushed.

diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 56436d32970..335d718b139 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -2316,10 +2316,7 @@ Remote programs
 @end lisp

 When remote search paths are changed, local @value{tramp} caches must
-be recomputed.  To force @value{tramp} to recompute afresh, call
-@kbd{M-x tramp-cleanup-this-connection @key{RET}} or friends
-(@pxref{Cleanup remote connections}).
-
+be recomputed, but not by the user, so don't worry about this.

 @node Remote shell setup
 @section Remote shell setup hints
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index ec8437176db..ef618855584 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -5571,10 +5571,18 @@ tramp-check-remote-uname
   "Check whether REGEXP matches the connection property \"uname\"."
   (string-match-p regexp (tramp-get-connection-property vec "uname" "")))

+(defvar tramp-last-used-remote-path nil)
+
 (defun tramp-get-remote-path (vec)
   "Compile list of remote directories for PATH.
 Nonexistent directories are removed from spec."
   (with-current-buffer (tramp-get-connection-buffer vec)
+    (when (not (equal tramp-last-used-remote-path tramp-remote-path))
+      ;; If user has tweaked `tramp-remote-path', flush any caches
+      ;; bug#61748.
+      (dolist (v (list vec (tramp-get-process vec)))
+        (tramp-flush-connection-property v "remote-path")))
+      (setq tramp-last-used-remote-path tramp-remote-path))
     ;; Expand connection-local variables.
     (tramp-set-connection-local-variables vec)
     (with-tramp-connection-property