changeset 94436:0918f4a758d2

* net/tramp.el (tramp-mode): New defcustom. (tramp-file-name-handler, tramp-completion-file-name-handler): Use it. (tramp-replace-environment-variables): Handle "$$".
author Michael Albinus <michael.albinus@gmx.de>
date Mon, 28 Apr 2008 19:07:26 +0000
parents 9b442839cb2e
children 7780b9720eb9
files lisp/net/tramp.el
diffstat 1 files changed, 42 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/net/tramp.el	Mon Apr 28 18:33:06 2008 +0000
+++ b/lisp/net/tramp.el	Mon Apr 28 19:07:26 2008 +0000
@@ -150,6 +150,14 @@
   :group 'files
   :version "22.1")
 
+;; Maybe we need once a real Tramp mode, with key bindings etc.
+;;;###autoload
+(defcustom tramp-mode t
+  "*Whether Tramp is enabled.
+If it is set to nil, all remote file names are used literally."
+  :group 'tramp
+  :type 'boolean)
+
 (defcustom tramp-verbose 3
   "*Verbosity level for Tramp.
 Any level x includes messages for all levels 1 .. x-1.  The levels are
@@ -3574,12 +3582,15 @@
 (defun tramp-replace-environment-variables (filename)
   "Replace environment variables in FILENAME.
 Return the string with the replaced variables."
-  (when (string-match "$\\w+" filename)
-    (setq filename
-	  (replace-match
-	   (substitute-in-file-name (match-string 0 filename))
-	   t nil filename)))
-  filename)
+  (save-match-data
+    (let ((idx (string-match "$\\w+" filename)))
+      ;; `$' is coded as `$$'.
+      (when (and idx (or (zerop idx) (not (eq ?$ (aref filename (1- idx))))))
+	(setq filename
+	      (replace-match
+	       (substitute-in-file-name (match-string 0 filename))
+	       t nil filename)))
+      filename)))
 
 (defun tramp-handle-substitute-in-file-name (filename)
   "Like `substitute-in-file-name' for Tramp files.
@@ -4486,26 +4497,29 @@
 (defun tramp-file-name-handler (operation &rest args)
   "Invoke Tramp file name handler.
 Falls back to normal file name handler if no Tramp file name handler exists."
-  (save-match-data
-    (let* ((filename
-	    (tramp-replace-environment-variables
-	     (apply 'tramp-file-name-for-operation operation args)))
-	   (completion (tramp-completion-mode-p))
-	   (foreign (tramp-find-foreign-file-name-handler filename)))
-      (with-parsed-tramp-file-name filename nil
-	(cond
-	 ;; When we are in completion mode, some operations shouldn't be
-	 ;; handled by backend.
-	 ((and completion (zerop (length localname))
-	       (memq operation '(file-exists-p file-directory-p)))
-	  t)
-	 ((and completion (zerop (length localname))
-	       (memq operation '(file-name-as-directory)))
-	  filename)
-	 ;; Call the backend function.
-	 (foreign (apply foreign operation args))
-	 ;; Nothing to do for us.
-	 (t (tramp-run-real-handler operation args)))))))
+  (if tramp-mode
+      (save-match-data
+	(let* ((filename
+		(tramp-replace-environment-variables
+		 (apply 'tramp-file-name-for-operation operation args)))
+	       (completion (tramp-completion-mode-p))
+	       (foreign (tramp-find-foreign-file-name-handler filename)))
+	  (with-parsed-tramp-file-name filename nil
+	    (cond
+	     ;; When we are in completion mode, some operations
+	     ;; shouldn't be handled by backend.
+	     ((and completion (zerop (length localname))
+		   (memq operation '(file-exists-p file-directory-p)))
+	      t)
+	     ((and completion (zerop (length localname))
+		   (memq operation '(file-name-as-directory)))
+	      filename)
+	     ;; Call the backend function.
+	     (foreign (apply foreign operation args))
+	     ;; Nothing to do for us.
+	     (t (tramp-run-real-handler operation args))))))
+    ;; When `tramp-mode' is not enabled, we don't do anything.
+    (tramp-run-real-handler operation args)))
 
 ;; In Emacs, there is some concurrency due to timers.  If a timer
 ;; interrupts Tramp and wishes to use the same connection buffer as
@@ -4559,7 +4573,8 @@
   ;; would otherwise use backslash.
   (let ((directory-sep-char ?/)
 	(fn (assoc operation tramp-completion-file-name-handler-alist)))
-    (if fn
+    ;; When `tramp-mode' is not enabled, we don't do anything.
+    (if (and fn tramp-mode)
 	(save-match-data (apply (cdr fn) args))
       (tramp-completion-run-real-handler operation args)))))