changeset 104808:90ec0abf1017

* net/tramp-compat.el (top): Autoload used functions from tramp.el. (file-remote-p, process-file, start-file-process, set-file-times) (tramp-compat-file-attributes): Compatibility functions shall not call directly `tramp-handle-*', because this would bypass the locking mechanism. (tramp-compat-number-sequence): New defun.
author Michael Albinus <michael.albinus@gmx.de>
date Wed, 02 Sep 2009 11:15:36 +0000
parents 509a5b989179
children 23afd425bd15
files lisp/net/tramp-compat.el
diffstat 1 files changed, 54 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/net/tramp-compat.el	Wed Sep 02 11:13:42 2009 +0000
+++ b/lisp/net/tramp-compat.el	Wed Sep 02 11:15:36 2009 +0000
@@ -42,6 +42,9 @@
       (require 'timer-funcs)
     (require 'timer))
 
+  (autoload 'tramp-tramp-file-p "tramp")
+  (autoload 'tramp-file-name-handler "tramp")
+
   ;; tramp-util offers integration into other (X)Emacs packages like
   ;; compile.el, gud.el etc.  Not necessary in Emacs 23.
   (eval-after-load "tramp"
@@ -99,24 +102,46 @@
   (unless (fboundp 'font-lock-add-keywords)
     (defalias 'font-lock-add-keywords 'ignore))
 
+  ;; The following functions cannot be aliases of the corresponding
+  ;; `tramp-handle-*' functions, because this would bypass the locking
+  ;; mechanism.
+
   ;; `file-remote-p' has been introduced with Emacs 22.  The version
   ;; of XEmacs is not a magic file name function (yet); this is
   ;; corrected in tramp-util.el.  Here it is sufficient if the
   ;; function exists.
   (unless (fboundp 'file-remote-p)
-    (defalias 'file-remote-p 'tramp-handle-file-remote-p))
+    (defalias 'file-remote-p
+      (lambda (file &optional identification connected)
+	(when (tramp-tramp-file-p file)
+	  (tramp-file-name-handler
+	   'file-remote-p file identification connected)))))
 
   ;; `process-file' exists since Emacs 22.
   (unless (fboundp 'process-file)
-    (defalias 'process-file 'tramp-handle-process-file))
+    (defalias 'process-file
+      (lambda (program &optional infile buffer display &rest args)
+	(when (tramp-tramp-file-p default-directory)
+	  (apply
+	   'tramp-file-name-handler
+	   'process-file program infile buffer display args)))))
 
   ;; `start-file-process' is new in Emacs 23.
   (unless (fboundp 'start-file-process)
-    (defalias 'start-file-process 'tramp-handle-start-file-process))
+    (defalias 'start-file-process
+      (lambda (name buffer program &rest program-args)
+	(when (tramp-tramp-file-p default-directory)
+	  (apply
+	   'tramp-file-name-handler
+	   'start-file-process name buffer program program-args)))))
 
   ;; `set-file-times' is also new in Emacs 23.
   (unless (fboundp 'set-file-times)
-    (defalias 'set-file-times 'tramp-handle-set-file-times)))
+    (defalias 'set-file-times
+      (lambda (filename &optional time)
+	(when (tramp-tramp-file-p filename)
+	  (tramp-file-name-handler
+	   'set-file-times filename time))))))
 
 (defsubst tramp-compat-line-end-position ()
   "Return point at end of line (compat function).
@@ -197,10 +222,8 @@
   (cond
    ((or (null id-format) (eq id-format 'integer))
     (file-attributes filename))
-   ;; FIXME: shouldn't that be tramp-file-p or somesuch?
-   ((file-remote-p filename)
-    (funcall (symbol-function 'tramp-handle-file-attributes)
-	     filename id-format))
+   ((tramp-tramp-file-p filename)
+    (tramp-file-name-handler 'file-attributes filename id-format))
    (t (condition-case nil
 	  (funcall (symbol-function 'file-attributes) filename id-format)
 	(error (file-attributes filename))))))
@@ -219,7 +242,7 @@
 ;; `copy-tree' is a built-in function in XEmacs.  In Emacs 21, it is
 ;; an autoloaded function in cl-extra.el.  Since Emacs 22, it is part
 ;; of subr.el.  There are problems when autoloading, therefore we test
-;; for `subrp' and `symbol-file'.  Implementation is taken from Emacs23.
+;; for `subrp' and `symbol-file'.  Implementation is taken from Emacs 23.
 (defun tramp-compat-copy-tree (tree)
   "Make a copy of TREE (compat function)."
   (if (or (subrp 'copy-tree) (symbol-file 'copy-tree))
@@ -233,6 +256,28 @@
 	(setq tree (cdr tree)))
       (nconc (nreverse result) tree))))
 
+;; `number-sequence' has been introduced in Emacs 22.  Implementation
+;; is taken from Emacs 23.
+(defun tramp-compat-number-sequence (from &optional to inc)
+  "Return a sequence of numbers from FROM to TO as a list (compat function)."
+  (if (or (subrp 'number-sequence) (symbol-file 'number-sequence))
+      (funcall (symbol-function 'number-sequence) from to inc)
+    (if (or (not to) (= from to))
+	(list from)
+      (or inc (setq inc 1))
+      (when (zerop inc) (error "The increment can not be zero"))
+      (let (seq (n 0) (next from))
+	(if (> inc 0)
+	    (while (<= next to)
+	      (setq seq (cons next seq)
+		    n (1+ n)
+		    next (+ from (* n inc))))
+	  (while (>= next to)
+	    (setq seq (cons next seq)
+		  n (1+ n)
+		  next (+ from (* n inc)))))
+	(nreverse seq)))))
+
 (defun tramp-compat-split-string (string pattern)
   "Like `split-string' but omit empty strings.
 In Emacs, (split-string \"/foo/bar\" \"/\") returns (\"foo\" \"bar\").