]> git.eshelyaron.com Git - emacs.git/commitdiff
Cleanup.
authorMichael Albinus <michael.albinus@gmx.de>
Thu, 3 Dec 2009 11:34:11 +0000 (11:34 +0000)
committerMichael Albinus <michael.albinus@gmx.de>
Thu, 3 Dec 2009 11:34:11 +0000 (11:34 +0000)
* eshell/em-unix.el (top): Require 'esh-opt and 'pcomplete.
(eshell/su, eshell/sudo): Require 'tramp.  Fix problems reading
arguments.  Expand `default-directory'.

* net/tramp.el (tramp-handle-file-remote-p): Expand FILENAME for
the benefit of returning an expanded localname.
(tramp-tramp-file-p): Handle the case NAME is not a string.

lisp/ChangeLog
lisp/eshell/em-unix.el
lisp/net/tramp.el

index 73e4706853aca9cecb08825e88f78a9c9ba830d7..6703d9077530f61d9e924cbf4aa9a64619ee3356 100644 (file)
@@ -1,3 +1,14 @@
+2009-12-03  Michael Albinus  <michael.albinus@gmx.de>
+
+       Cleanup.
+       * eshell/em-unix.el (top): Require 'esh-opt and 'pcomplete.
+       (eshell/su, eshell/sudo): Require 'tramp.  Fix problems reading
+       arguments.  Expand `default-directory'.
+
+       * net/tramp.el (tramp-handle-file-remote-p): Expand FILENAME for
+       the benefit of returning an expanded localname.
+       (tramp-tramp-file-p): Handle the case NAME is not a string.
+
 2009-12-03  Dan Nicolaescu  <dann@ics.uci.edu>
 
        Add support for bzr shelve/unshelve.
index dfd72f6b2ac0991e9a970267190d6e1a04d2db02..7de13d0b8acc5388b7d3e0817c07a05d5b185af0 100644 (file)
@@ -37,6 +37,8 @@
 ;;; Code:
 
 (require 'eshell)
+(require 'esh-opt)
+(require 'pcomplete)
 
 ;;;###autoload
 (eshell-defgroup eshell-unix nil
@@ -1048,10 +1050,11 @@ Show wall-clock time elapsed during execution of COMMAND.")
 
 (defun eshell/su (&rest args)
   "Alias \"su\" to call Tramp."
+  (require 'tramp)
   (setq args (eshell-stringify-list (eshell-flatten-list args)))
-  (let (login)
+  (let ((orig-args (copy-tree args)))
     (eshell-eval-using-options
-     "sudo" args
+     "su" args
      '((?h "help" nil nil "show this usage screen")
        (?l "login" nil login "provide a login environment")
        (?  nil nil login "provide a login environment")
@@ -1062,13 +1065,18 @@ Become another USER during a login session.")
                  (host (or (file-remote-p default-directory 'host)
                            "localhost"))
                  (dir (or (file-remote-p default-directory 'localname)
-                          default-directory)))
+                          (expand-file-name default-directory))))
              (eshell-for arg args
                (if (string-equal arg "-") (setq login t) (setq user arg)))
+             ;; `eshell-eval-using-options' does not handle "-".
+             (if (member "-" orig-args) (setq login t))
              (if login (setq dir "~/"))
              (if (and (file-remote-p default-directory)
-                      (not (string-equal
-                            user (file-remote-p default-directory 'user))))
+                      (or
+                       (not (string-equal
+                             "su" (file-remote-p default-directory 'method)))
+                       (not (string-equal
+                             user (file-remote-p default-directory 'user)))))
                  (add-to-list
                   'tramp-default-proxies-alist
                   (list host user (file-remote-p default-directory))))
@@ -1079,8 +1087,9 @@ Become another USER during a login session.")
 
 (defun eshell/sudo (&rest args)
   "Alias \"sudo\" to call Tramp."
+  (require 'tramp)
   (setq args (eshell-stringify-list (eshell-flatten-list args)))
-  (let (user)
+  (let ((orig-args (copy-tree args)))
     (eshell-eval-using-options
      "sudo" args
      '((?h "help" nil nil "show this usage screen")
@@ -1089,19 +1098,26 @@ Become another USER during a login session.")
        :usage "[(-u | --user) USER] COMMAND
 Execute a COMMAND as the superuser or another USER.")
      (throw 'eshell-external
-           (let* ((user (or user "root"))
-                  (host (or (file-remote-p default-directory 'host)
-                            "localhost"))
-                  (dir (or (file-remote-p default-directory 'localname)
-                           default-directory)))
+           (let ((user (or user "root"))
+                 (host (or (file-remote-p default-directory 'host)
+                           "localhost"))
+                 (dir (or (file-remote-p default-directory 'localname)
+                          (expand-file-name default-directory))))
+             ;; `eshell-eval-using-options' reads options of COMMAND.
+             (while (and (stringp (car orig-args))
+                         (member (car orig-args) '("-u" "--user")))
+               (setq orig-args (cddr orig-args)))
              (if (and (file-remote-p default-directory)
-                      (not (string-equal
-                            user (file-remote-p default-directory 'user))))
+                      (or
+                       (not (string-equal
+                             "sudo" (file-remote-p default-directory 'method)))
+                       (not (string-equal
+                             user (file-remote-p default-directory 'user)))))
                  (add-to-list
                   'tramp-default-proxies-alist
                   (list host user (file-remote-p default-directory))))
              (let ((default-directory (format "/sudo:%s@%s:%s" user host dir)))
-               (eshell-named-command (car args) (cdr args))))))))
+               (eshell-named-command (car orig-args) (cdr orig-args))))))))
 
 (put 'eshell/sudo 'eshell-no-numeric-conversions t)
 
index 678c8cc22e0bea47ab18ecbaacfe85141262644e..f3297ed13f5293b42575cdefb6d5c40e9438ed5a 100644 (file)
@@ -4629,7 +4629,7 @@ Lisp error raised when PROGRAM is nil is trapped also, returning 1."
 (defun tramp-handle-file-remote-p (filename &optional identification connected)
   "Like `file-remote-p' for Tramp files."
   (when (tramp-tramp-file-p filename)
-    (with-parsed-tramp-file-name filename nil
+    (with-parsed-tramp-file-name (expand-file-name filename) nil
       (and (or (not connected)
               (let ((p (tramp-get-connection-process v)))
                 (and p (processp p) (memq (process-status p) '(run open)))))
@@ -7709,9 +7709,9 @@ Not actually used.  Use `(format \"%o\" i)' instead?"
           (string-to-number (match-string 2 host))))))
 
 (defun tramp-tramp-file-p (name)
-  "Return t if NAME is a Tramp file."
+  "Return t if NAME is a string with Tramp file name syntax."
   (save-match-data
-    (string-match tramp-file-name-regexp name)))
+    (and (stringp name) (string-match tramp-file-name-regexp name))))
 
 (defun tramp-find-method (method user host)
   "Return the right method string to use.