Whitespace change.
[emacs.git] / lisp / net / tramp-ftp.el
blob3be891a49f8040f82963582540e72ad2ac657d41
1 ;;; tramp-ftp.el --- Tramp convenience functions for Ange-FTP and EFS -*- coding: iso-8859-1; -*-
3 ;; Copyright (C) 2002, 2003, 2004 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)
13 ;; any later version.
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.
25 ;;; Commentary:
27 ;; Convenience functions for calling Ange-FTP from Tramp.
28 ;; Most of them are displaced from tramp.el.
30 ;;; Code:
32 (require 'tramp)
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")))
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 ()
52 "Turn Ange-FTP off.
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)
67 (eval-after-load "ange-ftp" '(tramp-disable-ange-ftp))
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)
75 ;; ... and add it to the method list.
76 (add-to-list 'tramp-methods (cons tramp-ftp-method nil))
78 ;; Add some defaults for `tramp-default-method-alist'
79 (add-to-list 'tramp-default-method-alist
80 (list "\\`ftp\\." "" tramp-ftp-method))
81 (add-to-list 'tramp-default-method-alist
82 (list "" "\\`\\(anonymous\\|ftp\\)\\'" tramp-ftp-method))
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"))))
90 (defun tramp-ftp-file-name-handler (operation &rest args)
91 "Invoke the Ange-FTP handler for OPERATION.
92 First arg specifies the OPERATION, second arg is a list of arguments to
93 pass to the OPERATION."
94 (save-match-data
95 (or (boundp 'ange-ftp-name-format)
96 (require '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 ;; ange-ftp uses `ange-ftp-ftp-name-arg' and `ange-ftp-ftp-name-res'
103 ;; for optimization in `ange-ftp-ftp-name'. If Tramp wasn't active,
104 ;; there could be incorrect values from previous calls in case the
105 ;; "ftp" method is used in the Tramp file name. So we unset
106 ;; those values.
107 (ange-ftp-ftp-name-arg "")
108 (ange-ftp-ftp-name-res nil))
109 (cond
110 ;; If argument is a symlink, `file-directory-p' and `file-exists-p'
111 ;; call the traversed file recursively. So we cannot disable the
112 ;; file-name-handler this case.
113 ((memq operation '(file-directory-p file-exists-p))
114 (apply 'ange-ftp-hook-function operation args))
115 ;; Normally, the handlers must be discarded
116 (t (let* ((inhibit-file-name-handlers
117 (list 'tramp-file-name-handler
118 'tramp-completion-file-name-handler
119 (and (eq inhibit-file-name-operation operation)
120 inhibit-file-name-handlers)))
121 (inhibit-file-name-operation operation))
122 (apply 'ange-ftp-hook-function operation args)))))))
124 (defun tramp-ftp-file-name-p (filename)
125 "Check if it's a filename that should be forwarded to Ange-FTP."
126 (let ((v (tramp-dissect-file-name filename)))
127 (string=
128 (tramp-find-method
129 (tramp-file-name-multi-method v)
130 (tramp-file-name-method v)
131 (tramp-file-name-user v)
132 (tramp-file-name-host v))
133 tramp-ftp-method)))
135 (add-to-list 'tramp-foreign-file-name-handler-alist
136 (cons 'tramp-ftp-file-name-p 'tramp-ftp-file-name-handler))
138 (provide 'tramp-ftp)
140 ;;; TODO:
142 ;; * In case of "/ftp:host:file" this works only for functions which
143 ;; are defined in `tramp-file-name-handler-alist'. Call has to be
144 ;; pretended in `tramp-file-name-handler' otherwise.
145 ;; Furthermore, there are no backup files on FTP hosts.
146 ;; Worth further investigations.
147 ;; * Map /multi:ssh:out@gate:ftp:kai@real.host:/path/to.file
148 ;; on Ange-FTP gateways.
150 ;;; arch-tag: 759fb338-5c63-4b99-bd36-b4d59db91cff
151 ;;; tramp-ftp.el ends here