changeset 66135:5a1bac1c915b

* net/tramp.el (tramp-completion-mode): New defvar. Used in `tramp-completion-mode' for checking if we are in completion mode. (tramp-completion-handle-file-name-all-completions): Reorder code in order to complete for file names only in case there are no method/user/host completions. This is necessary for cooperation with ido. Reported by Kim F. Storm <storm@cua.dk>.
author Michael Albinus <michael.albinus@gmx.de>
date Mon, 17 Oct 2005 04:46:46 +0000
parents b4d414f000c1
children aacff8293f4b
files lisp/ChangeLog lisp/net/tramp.el
diffstat 2 files changed, 81 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Oct 17 02:35:03 2005 +0000
+++ b/lisp/ChangeLog	Mon Oct 17 04:46:46 2005 +0000
@@ -1,3 +1,12 @@
+2005-10-17  Michael Albinus  <michael.albinus@gmx.de>
+
+	* net/tramp.el (tramp-completion-mode): New defvar.  Used in
+	`tramp-completion-mode' for checking if we are in completion mode.
+	(tramp-completion-handle-file-name-all-completions): Reorder code
+	in order to complete for file names only in case there are no
+	method/user/host completions.  This is necessary for cooperation
+	with ido.  Reported by Kim F. Storm  <storm@cua.dk>.
+
 2005-10-16  Chong Yidong  <cyd@stupidchicken.com>
 
 	* longlines.el (longlines-search-forward)
--- a/lisp/net/tramp.el	Mon Oct 17 02:35:03 2005 +0000
+++ b/lisp/net/tramp.el	Mon Oct 17 04:46:46 2005 +0000
@@ -4384,6 +4384,7 @@
 (defun tramp-completion-mode (file)
   "Checks whether method / user name / host name completion is active."
   (cond
+   (tramp-completion-mode t)
    ((not tramp-unified-filenames) t)
    ((string-match "^/.*:.*:$" file) nil)
    ((string-match
@@ -4434,70 +4435,83 @@
   (substring
    file (length (tramp-completion-handle-file-name-directory file))))
 
+(defvar tramp-completion-mode nil
+  "If non-nil, we are in file name completion mode.")
+
 ;; Method, host name and user name completion.
 ;; `tramp-completion-dissect-file-name' returns a list of
 ;; tramp-file-name structures. For all of them we return possible completions.
 (defun tramp-completion-handle-file-name-all-completions (filename directory)
   "Like `file-name-all-completions' for partial tramp files."
 
-  (let*
-      ((fullname (concat directory filename))
-       ;; local files
-       (result
-	(if (tramp-completion-mode fullname)
-	    (tramp-run-real-handler
-	     'file-name-all-completions (list filename directory))
-	  (tramp-completion-run-real-handler
-	   'file-name-all-completions (list filename directory))))
-       ;; possible completion structures
-       (v (tramp-completion-dissect-file-name fullname)))
-
-    (while v
-      (let* ((car (car v))
-	     (multi-method (tramp-file-name-multi-method car))
-	     (method (tramp-file-name-method car))
-	     (user (tramp-file-name-user car))
-	     (host (tramp-file-name-host car))
-	     (localname (tramp-file-name-localname car))
-	     (m (tramp-find-method multi-method method user host))
-	     (tramp-current-user user) ; see `tramp-parse-passwd'
-	     all-user-hosts)
-
-	(unless (or multi-method ;; Not handled (yet).
-		    localname)        ;; Nothing to complete
-
-	  (if (or user host)
-
-	    ;; Method dependent user / host combinations
-	    (progn
-	      (mapcar
-	       (lambda (x)
-		 (setq all-user-hosts
-		       (append all-user-hosts
-			       (funcall (nth 0 x) (nth 1 x)))))
-	       (tramp-get-completion-function m))
-
-	      (setq result (append result
-	        (mapcar
-		 (lambda (x)
-		   (tramp-get-completion-user-host
-		    method user host (nth 0 x) (nth 1 x)))
-		 (delq nil all-user-hosts)))))
-
-	    ;; Possible methods
-	    (setq result
-		  (append result (tramp-get-completion-methods m)))))
-
-      (setq v (delq car v))))
-
-    ;;; unify list, remove nil elements
-    (let (result1)
-      (while result
-	(let ((car (car result)))
-	  (when car (add-to-list 'result1 car))
-	  (setq result (delq car result))))
-
-      result1)))
+  (unwind-protect
+      ;; We need to reset `tramp-completion-mode'.
+      (progn
+	(setq tramp-completion-mode t)
+	(let*
+	    ((fullname (concat directory filename))
+	     ;; possible completion structures
+	     (v (tramp-completion-dissect-file-name fullname))
+	     result result1)
+
+	  (while v
+	    (let* ((car (car v))
+		   (multi-method (tramp-file-name-multi-method car))
+		   (method (tramp-file-name-method car))
+		   (user (tramp-file-name-user car))
+		   (host (tramp-file-name-host car))
+		   (localname (tramp-file-name-localname car))
+		   (m (tramp-find-method multi-method method user host))
+		   (tramp-current-user user) ; see `tramp-parse-passwd'
+		   all-user-hosts)
+
+	      (unless (or multi-method ;; Not handled (yet).
+			  localname)   ;; Nothing to complete
+
+		(if (or user host)
+
+		    ;; Method dependent user / host combinations
+		    (progn
+		      (mapcar
+		       (lambda (x)
+			 (setq all-user-hosts
+			       (append all-user-hosts
+				       (funcall (nth 0 x) (nth 1 x)))))
+		       (tramp-get-completion-function m))
+
+		      (setq result (append result
+	                (mapcar
+			 (lambda (x)
+			   (tramp-get-completion-user-host
+			    method user host (nth 0 x) (nth 1 x)))
+			 (delq nil all-user-hosts)))))
+
+		  ;; Possible methods
+		  (setq result
+			(append result (tramp-get-completion-methods m)))))
+
+	      (setq v (cdr v))))
+
+	  ;; unify list, remove nil elements
+	  (while result
+	    (let ((car (car result)))
+	      (when car (add-to-list 'result1 car))
+	      (setq result (cdr result))))
+
+	  ;; Complete local parts
+	  (append
+	   result1
+	   (condition-case nil
+	       (if result1
+		   ;; "/ssh:" does not need to be expanded as hostname.
+		   (tramp-run-real-handler
+		    'file-name-all-completions (list filename directory))
+		 ;; No method/user/host found to be expanded.
+		 (tramp-completion-run-real-handler
+		  'file-name-all-completions (list filename directory)))
+	     (error nil)))))
+    ;; unwindform
+    (setq tramp-completion-mode nil)))
 
 ;; Method, host name and user name completion for a file.
 (defun tramp-completion-handle-file-name-completion (filename directory)