From: Michael Albinus Date: Mon, 7 Jan 2013 09:25:34 +0000 (+0100) Subject: * net/tramp.el (tramp-default-host-alist): New defcustom. X-Git-Tag: emacs-24.3.90~173^2~7^2~389 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b49eebcc079d00ea9f428a786e57988195f154a6;p=emacs.git * net/tramp.el (tramp-default-host-alist): New defcustom. (tramp-find-host): Use it. (tramp-eshell-directory-change): Moved from tramp-sh.el. Add to `eshell-directory-change-hook'. * net/tramp-adb.el (top): Add adb specific entry in `tramp-default-host-alist'. (tramp-adb-file-name-host): Remove function. (tramp-adb-execute-adb-command, tramp-adb-maybe-open-connection): Use `tramp-file-name-host' instead of `tramp-adb-file-name-host'. * net/tramp-sh.el : Move eshell integration code to tramp.el. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9425ca5cdc2..03b83277010 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,18 @@ +2013-01-07 Michael Albinus + + * net/tramp.el (tramp-default-host-alist): New defcustom. + (tramp-find-host): Use it. + (tramp-eshell-directory-change): Moved from tramp-sh.el. Add to + `eshell-directory-change-hook'. + + * net/tramp-adb.el (top): Add adb specific entry in + `tramp-default-host-alist'. + (tramp-adb-file-name-host): Remove function. + (tramp-adb-execute-adb-command, tramp-adb-maybe-open-connection): + Use `tramp-file-name-host' instead of `tramp-adb-file-name-host'. + + * net/tramp-sh.el : Move eshell integration code to tramp.el. + 2013-01-06 Jürgen Hötzel * net/tramp-adb.el (tramp-methods): Add `tramp-tmpdir' entry. @@ -5,7 +20,7 @@ 2013-01-06 Michael Albinus * net/tramp-adb.el (tramp-adb-ls-toolbox-regexp): The file size can - consist of mor than one digit. + consist of more than one digit. (tramp-adb-file-name-handler-alist): Use `tramp-handle-file-exists-p' consistently. (tramp-adb-file-name-handler): Don't tweak `tramp-default-host'. diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index bb9ff015ac3..c6aec52bd07 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -66,8 +66,12 @@ "[[:space:]]+\\(.*\\)$")) ; \6 filename ;;;###tramp-autoload -(add-to-list 'tramp-methods `(,tramp-adb-method - (tramp-tmpdir "/data/local/tmp"))) +(add-to-list 'tramp-methods + `(,tramp-adb-method + (tramp-tmpdir "/data/local/tmp"))) + +;;;###tramp-autoload +(add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil "")) ;;;###tramp-autoload (eval-after-load 'tramp @@ -937,17 +941,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." ;; Helper functions. -(defun tramp-adb-file-name-host (vec) - "Return host component of VEC. -If it is equal to the default value of `tramp-default-host', `nil' is returned." - (let ((host (tramp-file-name-host vec))) - (unless (equal host (eval (car (get 'tramp-default-host 'standard-value)))) - host))) - (defun tramp-adb-execute-adb-command (vec &rest args) "Returns nil on success error-output on failure." - (when (tramp-adb-file-name-host vec) - (setq args (append (list "-s" (tramp-adb-file-name-host vec)) args))) + (when (> (length (tramp-file-name-host vec)) 0) + (setq args (append (list "-s" (tramp-file-name-host vec)) args))) (with-temp-buffer (prog1 (unless (zerop (apply 'call-process (tramp-adb-program) nil t nil args)) @@ -1048,6 +1045,7 @@ Does not do anything if a connection is already open, but re-opens the connection if a previous connection has died for some reason." (let* ((buf (tramp-get-connection-buffer vec)) (p (get-buffer-process buf)) + (host (tramp-file-name-host vec)) (devices (mapcar 'cadr (tramp-adb-parse-device-names nil)))) (unless (and p (processp p) (memq (process-status p) '(run open))) @@ -1055,21 +1053,17 @@ connection if a previous connection has died for some reason." (when (and p (processp p)) (delete-process p)) (if (not devices) (tramp-error vec 'file-error "No device connected")) - (if (and (tramp-adb-file-name-host vec) - (not (member (tramp-adb-file-name-host vec) devices))) - (tramp-error - vec 'file-error - "Device %s not connected" (tramp-adb-file-name-host vec))) - (if (and (not (eq (length devices) 1)) - (not (tramp-adb-file-name-host vec))) + (if (and (> (length host) 0) (not (member host devices))) + (tramp-error vec 'file-error "Device %s not connected" host)) + (if (and (> (length devices) 1) (zerop (length host))) (tramp-error vec 'file-error "Multiple Devices connected: No Host/Device specified")) (with-tramp-progress-reporter vec 3 "Opening adb shell connection" (let* ((coding-system-for-read 'utf-8-dos) ;is this correct? (process-connection-type tramp-process-connection-type) - (args (if (tramp-adb-file-name-host vec) - (list "-s" (tramp-adb-file-name-host vec) "shell") + (args (if (> (length host) 0) + (list "-s" host "shell") (list "shell"))) (p (let ((default-directory (tramp-compat-temporary-file-directory))) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 79f8d82b02b..d83599a6662 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -5181,34 +5181,6 @@ function cell is returned to be applied on a buffer." (t (format "%s <%%s" coding))))))) -;;; Integration of eshell.el: - -(eval-when-compile - (defvar eshell-path-env)) - -;; eshell.el keeps the path in `eshell-path-env'. We must change it -;; when `default-directory' points to another host. -(defun tramp-eshell-directory-change () - "Set `eshell-path-env' to $PATH of the host related to `default-directory'." - (setq eshell-path-env - (if (file-remote-p default-directory) - (with-parsed-tramp-file-name default-directory nil - (mapconcat - 'identity - (tramp-get-remote-path v) - ":")) - (getenv "PATH")))) - -(eval-after-load "esh-util" - '(progn - (tramp-eshell-directory-change) - (add-hook 'eshell-directory-change-hook - 'tramp-eshell-directory-change) - (add-hook 'tramp-unload-hook - (lambda () - (remove-hook 'eshell-directory-change-hook - 'tramp-eshell-directory-change))))) - (add-hook 'tramp-unload-hook (lambda () (unload-feature 'tramp-sh 'force))) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 7c393622ffc..4c346799dcf 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -381,6 +381,22 @@ Useful for su and sudo methods mostly." :group 'tramp :type 'string) +;;;###tramp-autoload +(defcustom tramp-default-host-alist nil + "Default host to use for specific method/user pairs. +This is an alist of items (METHOD USER HOST). The first matching item +specifies the host to use for a file name which does not specify a +host. METHOD and HOST are regular expressions or nil, which is +interpreted as a regular expression which always matches. If no entry +matches, the variable `tramp-default-host' takes effect. + +If the file name does not specify the method, lookup is done using the +empty string for the method name." + :group 'tramp + :type '(repeat (list (choice :tag "Method regexp" regexp sexp) + (choice :tag " User regexp" regexp sexp) + (choice :tag " Host name" string (const nil))))) + (defcustom tramp-default-proxies-alist nil "Route to be followed for specific host/user pairs. This is an alist of items (HOST USER PROXY). The first matching @@ -918,7 +934,7 @@ See `tramp-file-name-structure' for more explanations.") This regexp should match partial Tramp file names only. Please note that the entry in `file-name-handler-alist' is made when -this file (tramp.el) is loaded. This means that this variable must be set +this file \(tramp.el\) is loaded. This means that this variable must be set before loading tramp.el. Alternatively, `file-name-handler-alist' can be updated after changing this variable. @@ -1163,6 +1179,15 @@ This is USER, if non-nil. Otherwise, do a lookup in "Return the right host string to use. This is HOST, if non-nil. Otherwise, it is `tramp-default-host'." (or (and (> (length host) 0) host) + (let ((choices tramp-default-host-alist) + lhost item) + (while choices + (setq item (pop choices)) + (when (and (string-match (or (nth 0 item) "") (or method "")) + (string-match (or (nth 1 item) "") (or user ""))) + (setq lhost (nth 2 item)) + (setq choices nil))) + lhost) tramp-default-host)) (defun tramp-dissect-file-name (name &optional nodefault) @@ -3861,6 +3886,34 @@ Only works for Bourne-like shells." t t result))) result)))) +;;; Integration of eshell.el: + +(eval-when-compile + (defvar eshell-path-env)) + +;; eshell.el keeps the path in `eshell-path-env'. We must change it +;; when `default-directory' points to another host. +(defun tramp-eshell-directory-change () + "Set `eshell-path-env' to $PATH of the host related to `default-directory'." + (setq eshell-path-env + (if (file-remote-p default-directory) + (with-parsed-tramp-file-name default-directory nil + (mapconcat + 'identity + (tramp-get-connection-property v "remote-path" nil) + ":")) + (getenv "PATH")))) + +(eval-after-load "esh-util" + '(progn + (tramp-eshell-directory-change) + (add-hook 'eshell-directory-change-hook + 'tramp-eshell-directory-change) + (add-hook 'tramp-unload-hook + (lambda () + (remove-hook 'eshell-directory-change-hook + 'tramp-eshell-directory-change))))) + ;; Checklist for `tramp-unload-hook' ;; - Unload all `tramp-*' packages ;; - Reset `file-name-handler-alist'