New directory
[bpt/emacs.git] / lisp / net / tramp-ftp.el
CommitLineData
4007ba5b
KG
1;;; tramp-ftp.el --- Tramp convenience functions for Ange-FTP and EFS -*- coding: iso-8859-1; -*-
2
8daea7fc 3;; Copyright (C) 2002, 2003 Free Software Foundation, Inc.
4007ba5b
KG
4
5;; Author: Michael Albinus <Michael.Albinus@alcatel.de>
6;; Keywords: comm, processes
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
24
25;;; Commentary:
26
27;; Convenience functions for calling Ange-FTP (and maybe EFS, later on)
8daea7fc 28;; from Tramp. Most of them are displaced from tramp.el.
4007ba5b
KG
29
30;;; Code:
31
32(require 'tramp)
33
34(eval-when-compile
35 (require 'cl)
36 (require 'custom)
37 ;; Emacs 19.34 compatibility hack -- is this needed?
38 (or (>= emacs-major-version 20)
39 (load "cl-seq")))
40
41;; Disable Ange-FTP from file-name-handler-alist.
42;; To handle EFS, the following functions need to be dealt with:
43;;
44;; * dired-before-readin-hook contains efs-dired-before-readin
45;; * file-name-handler-alist contains efs-file-handler-function
46;; and efs-root-handler-function and efs-sifn-handler-function
47;; * find-file-hooks contains efs-set-buffer-mode
48;;
49;; But it won't happen for EFS since the XEmacs maintainers
50;; don't want to use a unified filename syntax.
51(defun tramp-disable-ange-ftp ()
52 "Turn Ange-FTP off.
53This is useful for unified remoting. See
54`tramp-file-name-structure-unified' and
55`tramp-file-name-structure-separate' for details. Requests suitable
56for Ange-FTP will be forwarded to Ange-FTP. Also see the variables
57`tramp-ftp-method', `tramp-default-method', and
58`tramp-default-method-alist'.
59
60This function is not needed in Emacsen which include Tramp, but is
61present for backward compatibility."
62 (let ((a1 (rassq 'ange-ftp-hook-function file-name-handler-alist))
63 (a2 (rassq 'ange-ftp-completion-hook-function file-name-handler-alist)))
64 (setq file-name-handler-alist
65 (delete a1 (delete a2 file-name-handler-alist)))))
66(tramp-disable-ange-ftp)
8daea7fc 67(eval-after-load "ange-ftp" '(tramp-disable-ange-ftp))
4007ba5b
KG
68
69;; Define FTP method ...
70(defcustom tramp-ftp-method "ftp"
71 "*When this method name is used, forward all calls to Ange-FTP."
72 :group 'tramp
73 :type 'string)
74
75;; ... and add it to the method list.
76(add-to-list 'tramp-methods (cons tramp-ftp-method nil))
77
78;; Add some defaults for `tramp-default-method-alist'
79(add-to-list 'tramp-default-method-alist
8daea7fc 80 (list "\\`ftp\\." "" tramp-ftp-method))
4007ba5b 81(add-to-list 'tramp-default-method-alist
8daea7fc 82 (list "" "\\`\\(anonymous\\|ftp\\)\\'" tramp-ftp-method))
4007ba5b
KG
83
84;; Add completion function for FTP method.
85(unless (memq system-type '(windows-nt))
86 (tramp-set-completion-function
87 tramp-ftp-method
88 '((tramp-parse-netrc "~/.netrc"))))
89
90(defun tramp-ftp-file-name-handler (operation &rest args)
91 "Invoke the Ange-FTP handler for OPERATION.
92First arg specifies the OPERATION, second arg is a list of arguments to
93pass to the OPERATION."
94 (save-match-data
95 (or (boundp 'ange-ftp-name-format)
8daea7fc 96 (require 'ange-ftp))
83bbd71b
KG
97 (let ((ange-ftp-name-format
98 (list (nth 0 tramp-file-name-structure)
99 (nth 3 tramp-file-name-structure)
100 (nth 2 tramp-file-name-structure)
101 (nth 4 tramp-file-name-structure))))
102 (cond
103 ;; If argument is a symlink, 'file-directory-p` and 'file-exists-p`
104 ;; call the traversed file recursively. So we cannot disable the
b25a52cc 105 ;; file-name-handler this case.
83bbd71b
KG
106 ((memq operation '(file-directory-p file-exists-p))
107 (apply 'ange-ftp-hook-function operation args))
108 ;; Normally, the handlers must be discarded
109 (t (let* ((inhibit-file-name-handlers
110 (list 'tramp-file-name-handler
111 'tramp-completion-file-name-handler
112 (and (eq inhibit-file-name-operation operation)
113 inhibit-file-name-handlers)))
114 (inhibit-file-name-operation operation))
115 (apply 'ange-ftp-hook-function operation args)))))))
4007ba5b
KG
116
117(defun tramp-ftp-file-name-p (filename)
118 "Check if it's a filename that should be forwarded to Ange-FTP."
119 (let ((v (tramp-dissect-file-name filename)))
120 (string=
121 (tramp-find-method
122 (tramp-file-name-multi-method v)
123 (tramp-file-name-method v)
124 (tramp-file-name-user v)
125 (tramp-file-name-host v))
126 tramp-ftp-method)))
127
128(add-to-list 'tramp-foreign-file-name-handler-alist
129 (cons 'tramp-ftp-file-name-p 'tramp-ftp-file-name-handler))
130
131(provide 'tramp-ftp)
132
133;;; TODO:
134
135;; * In case of "/ftp:host:file" this works only for functions which
136;; are defined in `tramp-file-name-handler-alist'. Call has to be
83bbd71b
KG
137;; pretended in `tramp-file-name-handler' otherwise.
138;; Furthermore, there are no backup files on FTP hosts.
4007ba5b
KG
139;; Worth further investigations.
140
141;;; tramp-ftp.el ends here