*** empty log message ***
[emacs.git] / lisp / net / tramp-ftp.el
blob07a756c3523b3918912a906cd85774cc5fa09646
1 ;;; tramp-ftp.el --- Tramp convenience functions for Ange-FTP and EFS -*- coding: iso-8859-1; -*-
3 ;; Copyright (C) 2002, 2003 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 (and maybe EFS, later on)
28 ;; from Tramp. 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 (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
105 ;; file-name-handler this case.
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)))))))
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)))
128 (add-to-list 'tramp-foreign-file-name-handler-alist
129 (cons 'tramp-ftp-file-name-p 'tramp-ftp-file-name-handler))
131 (provide 'tramp-ftp)
133 ;;; TODO:
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
137 ;; pretended in `tramp-file-name-handler' otherwise.
138 ;; Furthermore, there are no backup files on FTP hosts.
139 ;; Worth further investigations.
141 ;;; tramp-ftp.el ends here