emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs/lisp/net tramp-compat.el


From: Michael Albinus
Subject: [Emacs-diffs] emacs/lisp/net tramp-compat.el
Date: Wed, 02 Sep 2009 11:15:37 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Michael Albinus <albinus>       09/09/02 11:15:37

Modified files:
        lisp/net       : tramp-compat.el 

Log message:
        * 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.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/net/tramp-compat.el?cvsroot=emacs&r1=1.13&r2=1.14

Patches:
Index: tramp-compat.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/net/tramp-compat.el,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- tramp-compat.el     22 Jun 2009 21:07:27 -0000      1.13
+++ tramp-compat.el     2 Sep 2009 11:15:36 -0000       1.14
@@ -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\").




reply via email to

[Prev in Thread] Current Thread [Next in Thread]