emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 907d11f: Use connection-local setting for tramp-rem


From: Michael Albinus
Subject: [Emacs-diffs] master 907d11f: Use connection-local setting for tramp-remote-path
Date: Wed, 27 Mar 2019 11:28:15 -0400 (EDT)

branch: master
commit 907d11fc5372e899c89739f79c653eed055450cf
Author: Michael Albinus <address@hidden>
Commit: Michael Albinus <address@hidden>

    Use connection-local setting for tramp-remote-path
    
    * doc/misc/tramp.texi (Remote programs): Mention connection-local
    settings for `tramp-remote-path'.
    
    * lisp/net/tramp-sh.el (tramp-get-remote-path): Expand connection-local
    variables.
---
 doc/misc/tramp.texi  |  33 +++++++++++
 lisp/net/tramp-sh.el | 165 ++++++++++++++++++++++++++-------------------------
 2 files changed, 117 insertions(+), 81 deletions(-)

diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index ea6ad15..ac5aa68 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -1979,6 +1979,39 @@ preserves the path value, which can be used to update
 shell supports the login argument @samp{-l}.
 @end defopt
 
+Starting with Emacs 26, @code{tramp-remote-path} can be set per host
+via connection-local
address@hidden
+variables, @xref{Connection Variables, , , emacs}.
address@hidden ifinfo
address@hidden
+variables.
address@hidden ifnotinfo
+You could define your own search directories like this:
+
address@hidden
address@hidden
+(connection-local-set-profile-variables 'remote-path-with-bin
+   '((tramp-remote-path . ("~/bin" tramp-default-remote-path))))
address@hidden group
+
address@hidden
+(connection-local-set-profile-variables 'remote-path-with-apply-pub-bin
+   '((tramp-remote-path . ("/appli/pub/bin" tramp-default-remote-path))))
address@hidden group
+
address@hidden
+(connection-local-set-profiles
+   '(:application tramp :machine "randomhost") 'remote-path-with-bin)
address@hidden group
+
address@hidden
+(connection-local-set-profiles
+   '(:application tramp :user "anotheruser" :machine "anotherhost")
+     'remote-path-with-apply-pub-bin)
address@hidden group
address@hidden 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
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 2b4399f..edd9af4 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -5314,87 +5314,90 @@ Return ATTR."
 (defun tramp-get-remote-path (vec)
   "Compile list of remote directories for $PATH.
 Nonexistent directories are removed from spec."
-  (with-tramp-connection-property
-      ;; When `tramp-own-remote-path' is in `tramp-remote-path', we
-      ;; cache the result for the session only.  Otherwise, the result
-      ;; is cached persistently.
-      (if (memq 'tramp-own-remote-path tramp-remote-path)
-         (tramp-get-connection-process vec)
-       vec)
-      "remote-path"
-    (let* ((remote-path (copy-tree tramp-remote-path))
-          (elt1 (memq 'tramp-default-remote-path remote-path))
-          (elt2 (memq 'tramp-own-remote-path remote-path))
-          (default-remote-path
-            (when elt1
-              (or
-               (tramp-send-command-and-read
-                vec "echo \\\"`getconf PATH 2>/dev/null`\\\"" 'noerror)
-               ;; Default if "getconf" is not available.
-               (progn
-                 (tramp-message
-                  vec 3
-                  "`getconf PATH' not successful, using default value \"%s\"."
-                  "/bin:/usr/bin")
-                 "/bin:/usr/bin"))))
-          (own-remote-path
-           ;; The login shell could return more than just the $PATH
-           ;; string.  So we use `tramp-end-of-heredoc' as marker.
-           (when elt2
-             (or
-              (tramp-send-command-and-read
-               vec
-               (format
-                "%s %s %s 'echo %s \\\"$PATH\\\"'"
-                (tramp-get-method-parameter vec 'tramp-remote-shell)
-                (mapconcat
-                 #'identity
-                 (tramp-get-method-parameter vec 'tramp-remote-shell-login)
-                 " ")
-                (mapconcat
-                 #'identity
-                 (tramp-get-method-parameter vec 'tramp-remote-shell-args)
-                 " ")
-                (tramp-shell-quote-argument tramp-end-of-heredoc))
-               'noerror (regexp-quote tramp-end-of-heredoc))
-              (progn
-                (tramp-message
-                 vec 2 "Could not retrieve `tramp-own-remote-path'")
-                nil)))))
-
-      ;; Replace place holder `tramp-default-remote-path'.
-      (when elt1
-       (setcdr elt1
-               (append
-                 (split-string (or default-remote-path "") ":" 'omit)
-                (cdr elt1)))
-       (setq remote-path (delq 'tramp-default-remote-path remote-path)))
-
-      ;; Replace place holder `tramp-own-remote-path'.
-      (when elt2
-       (setcdr elt2
-               (append
-                 (split-string (or own-remote-path "") ":" 'omit)
-                (cdr elt2)))
-       (setq remote-path (delq 'tramp-own-remote-path remote-path)))
-
-      ;; Remove double entries.
-      (setq elt1 remote-path)
-      (while (consp elt1)
-       (while (and (car elt1) (setq elt2 (member (car elt1) (cdr elt1))))
-         (setcar elt2 nil))
-       (setq elt1 (cdr elt1)))
-
-      ;; Remove non-existing directories.
-      (delq
-       nil
-       (mapcar
-       (lambda (x)
-         (and
-          (stringp x)
-          (file-directory-p (tramp-make-tramp-file-name vec x 'nohop))
-          x))
-       remote-path)))))
+  (with-current-buffer (tramp-get-connection-buffer vec)
+    ;; Expand connection-local variables.
+    (tramp-set-connection-local-variables vec)
+    (with-tramp-connection-property
+       ;; When `tramp-own-remote-path' is in `tramp-remote-path', we
+       ;; cache the result for the session only.  Otherwise, the
+       ;; result is cached persistently.
+       (if (memq 'tramp-own-remote-path tramp-remote-path)
+           (tramp-get-connection-process vec)
+         vec)
+       "remote-path"
+      (let* ((remote-path (copy-tree tramp-remote-path))
+            (elt1 (memq 'tramp-default-remote-path remote-path))
+            (elt2 (memq 'tramp-own-remote-path remote-path))
+            (default-remote-path
+              (when elt1
+                (or
+                 (tramp-send-command-and-read
+                  vec "echo \\\"`getconf PATH 2>/dev/null`\\\"" 'noerror)
+                 ;; Default if "getconf" is not available.
+                 (progn
+                   (tramp-message
+                    vec 3
+                    "`getconf PATH' not successful, using default value 
\"%s\"."
+                    "/bin:/usr/bin")
+                   "/bin:/usr/bin"))))
+            (own-remote-path
+             ;; The login shell could return more than just the $PATH
+             ;; string.  So we use `tramp-end-of-heredoc' as marker.
+             (when elt2
+               (or
+                (tramp-send-command-and-read
+                 vec
+                 (format
+                  "%s %s %s 'echo %s \\\"$PATH\\\"'"
+                  (tramp-get-method-parameter vec 'tramp-remote-shell)
+                  (mapconcat
+                   #'identity
+                   (tramp-get-method-parameter vec 'tramp-remote-shell-login)
+                   " ")
+                  (mapconcat
+                   #'identity
+                   (tramp-get-method-parameter vec 'tramp-remote-shell-args)
+                   " ")
+                  (tramp-shell-quote-argument tramp-end-of-heredoc))
+                 'noerror (regexp-quote tramp-end-of-heredoc))
+                (progn
+                  (tramp-message
+                   vec 2 "Could not retrieve `tramp-own-remote-path'")
+                  nil)))))
+
+       ;; Replace place holder `tramp-default-remote-path'.
+       (when elt1
+         (setcdr elt1
+                 (append
+                   (split-string (or default-remote-path "") ":" 'omit)
+                  (cdr elt1)))
+         (setq remote-path (delq 'tramp-default-remote-path remote-path)))
+
+       ;; Replace place holder `tramp-own-remote-path'.
+       (when elt2
+         (setcdr elt2
+                 (append
+                   (split-string (or own-remote-path "") ":" 'omit)
+                  (cdr elt2)))
+         (setq remote-path (delq 'tramp-own-remote-path remote-path)))
+
+       ;; Remove double entries.
+       (setq elt1 remote-path)
+       (while (consp elt1)
+         (while (and (car elt1) (setq elt2 (member (car elt1) (cdr elt1))))
+           (setcar elt2 nil))
+         (setq elt1 (cdr elt1)))
+
+       ;; Remove non-existing directories.
+       (delq
+        nil
+        (mapcar
+         (lambda (x)
+           (and
+            (stringp x)
+            (file-directory-p (tramp-make-tramp-file-name vec x 'nohop))
+            x))
+         remote-path))))))
 
 (defun tramp-get-remote-locale (vec)
   "Determine remote locale, supporting UTF8 if possible."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]