1 ;;; tramp-ftp.el --- Tramp convenience functions for Ange-FTP and EFS -*- coding: iso-8859-1; -*-
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <Michael.Albinus@alcatel.de>
6 ;; Keywords: comm, processes
8 ;; This file is part of GNU Emacs.
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)
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.
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.
27 ;; Convenience functions for calling Ange-FTP (and maybe EFS, later on)
28 ;; from Tramp. Most of them are displaced from tramp.el
37 ;; Emacs 19.34 compatibility hack -- is this needed?
38 (or (>= emacs-major-version
20)
41 ;; Disable Ange-FTP from file-name-handler-alist.
42 ;; To handle EFS, the following functions need to be dealt with:
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
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 ()
53 This is useful for unified remoting. See
54 `tramp-file-name-structure-unified' and
55 `tramp-file-name-structure-separate' for details. Requests suitable
56 for 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'.
60 This function is not needed in Emacsen which include Tramp, but is
61 present 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)
68 ;; Define FTP method ...
69 (defcustom tramp-ftp-method
"ftp"
70 "*When this method name is used, forward all calls to Ange-FTP."
74 ;; ... and add it to the method list.
75 (add-to-list 'tramp-methods
(cons tramp-ftp-method nil
))
77 ;; Add some defaults for `tramp-default-method-alist'
78 (add-to-list 'tramp-default-method-alist
79 '("\\`ftp\\." "" tramp-ftp-method
))
80 (add-to-list 'tramp-default-method-alist
81 '("" "\\`\\(anonymous\\|ftp\\)\\'" tramp-ftp-method
))
83 ;; Add completion function for FTP method.
84 (unless (memq system-type
'(windows-nt))
85 (tramp-set-completion-function
87 '((tramp-parse-netrc "~/.netrc"))))
89 (defun tramp-ftp-file-name-handler (operation &rest args
)
90 "Invoke the Ange-FTP handler for OPERATION.
91 First arg specifies the OPERATION, second arg is a list of arguments to
92 pass to the OPERATION."
94 (or (boundp 'ange-ftp-name-format
)
95 (and (require 'ange-ftp
)
96 (tramp-disable-ange-ftp)))
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 (inhibit-file-name-handlers
103 (list 'tramp-file-name-handler
104 'tramp-completion-file-name-handler
105 (and (eq inhibit-file-name-operation operation
)
106 inhibit-file-name-handlers
)))
107 (inhibit-file-name-operation operation
))
108 (apply 'ange-ftp-hook-function operation args
))))
110 (defun tramp-ftp-file-name-p (filename)
111 "Check if it's a filename that should be forwarded to Ange-FTP."
112 (let ((v (tramp-dissect-file-name filename
)))
115 (tramp-file-name-multi-method v
)
116 (tramp-file-name-method v
)
117 (tramp-file-name-user v
)
118 (tramp-file-name-host v
))
121 (add-to-list 'tramp-foreign-file-name-handler-alist
122 (cons 'tramp-ftp-file-name-p
'tramp-ftp-file-name-handler
))
128 ;; * In case of "/ftp:host:file" this works only for functions which
129 ;; are defined in `tramp-file-name-handler-alist'. Call has to be
130 ;; pretended in `tramp-file-name-handler' otherwise. Looks like
131 ;; `ange-ftp-completion-hook-function' and `ange-ftp-hook-function'
132 ;; are active temporarily in `file-name-handler-alist'.
133 ;; Furthermore, there are no backup files on FTP hosts this case.
134 ;; Worth further investigations.
136 ;;; tramp-ftp.el ends here