1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
|
;;; -*- coding: iso-2022-7bit; -*-
;;; tramp-efs.el --- Make EFS a foreign method in Tramp
;; Copyright (C) 2003, 2004 Free Software Foundation, Inc.
;; Author: Kai Gro,A_(Bjohann <kai.grossjohann@gmx.net>
;; Keywords: comm, processes
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; This file provides glue between Tramp and EFS. EFS is hooked into
;; Tramp as a foreign method. Most of this file has been snarfed from
;; tramp-ftp.el, which does the same for Tramp and Ange-FTP.
;;; Code:
(require 'tramp)
;; Avoid byte-compiler warnings.
(eval-when-compile
(byte-compiler-options (warnings (- unused-vars))))
(defvar tramp-efs-method "ftp"
"Name of the method invoking EFS.")
;; The EFS name format is somewhat restricted. EFS assumes that the
;; first pair of parentheses is the user and the second is the host.
;; It assumes that there is one character after the host name, and
;; then the localname part follows. See function `efs-ftp-path' for
;; the code. If the first pair of parentheses doesn't match anything,
;; then it assumes that the user is not given. Therefore, we need to
;; be quite careful with the \(...\) constructs we use in our regexes.
(defvar tramp-efs-method-given nil
"Method tag is given in filename.
To be set in `tramp-efs-file-name-handler'.")
(defvar tramp-efs-method-regexp
(concat tramp-prefix-regexp
(regexp-quote tramp-efs-method)
tramp-postfix-single-method-regexp)
"Regexp indicating method tag.")
(defun tramp-efs-path-regexp ()
"Tramp uses this value for `efs-path-regexp'."
(concat tramp-prefix-regexp
(when tramp-efs-method-given
(concat
(regexp-quote tramp-efs-method)
tramp-postfix-single-method-regexp))
"\\(" tramp-user-regexp tramp-postfix-user-regexp "\\)?"
"\\(" tramp-host-with-port-regexp "\\)"
tramp-postfix-host-regexp
"\\(" tramp-localname-regexp "\\)"))
(defun tramp-efs-path-format-string ()
"Tramp uses this value for `efs-path-format-string'."
(concat tramp-prefix-format
(when tramp-efs-method-given
(concat tramp-efs-method tramp-postfix-single-method-format))
"%s" tramp-postfix-user-format
"%s" tramp-postfix-host-format
"%s"))
(defun tramp-efs-path-format-without-user ()
"Tramp uses this value for `efs-path-format-without-user'."
(concat tramp-prefix-format
(when tramp-efs-method-given
(concat tramp-efs-method tramp-postfix-single-method-format))
"%s" tramp-postfix-host-format
"%s"))
(defun tramp-efs-path-user-at-host-format ()
"Tramp uses this value for `efs-path-user-at-host-format'."
(concat "%s" tramp-postfix-user-format
"%s" tramp-postfix-host-format))
(defun tramp-efs-path-host-format ()
"Tramp uses this value for `efs-path-host-format'."
(concat "%s" tramp-postfix-host-format))
(defun tramp-efs-path-root-regexp ()
"Tramp uses this value for `efs-path-root-regexp'."
(concat tramp-prefix-regexp
(when tramp-efs-method-given
(concat
(regexp-quote tramp-efs-method)
tramp-postfix-single-method-regexp))
"\\(" tramp-user-regexp tramp-postfix-user-regexp "\\)?"
"\\(" tramp-host-with-port-regexp "\\)"
tramp-postfix-host-regexp))
;; Still need to do efs-path-root-short-circuit-regexp.
;; Disable EFS from file-name-handler-alist.
;; There is still an entry for efs-sifn-handler-function
;; in file-name-handler-alist that I don't know how to deal with.
(defun tramp-disable-efs ()
"Turn EFS off.
This is useful for unified remoting. See
`tramp-file-name-structure-unified' and
`tramp-file-name-structure-separate' for details. Requests
suitable for EFS will be forwarded to EFS. Also see the
variables `tramp-efs-method', `tramp-default-method', and
`tramp-default-method-alist'.
This function is not needed in Emacsen which include Tramp, but is
present for backward compatibility."
(let ((a1 (rassq 'efs-file-handler-function
file-name-handler-alist))
(a2 (rassq 'efs-root-handler-function
file-name-handler-alist))
(a3 (rassq 'remote-path-file-handler-function
file-name-handler-alist)))
(setq file-name-handler-alist
(delete a1 (delete a2 (delete a3 file-name-handler-alist))))))
(tramp-disable-efs)
(eval-after-load "efs" '(tramp-disable-efs))
(eval-after-load "efs-fnh" '(tramp-disable-efs))
;; Add EFS method to the method list.
(add-to-list 'tramp-methods (cons tramp-efs-method nil))
;; Add some defaults for `tramp-default-method-alist'
(add-to-list 'tramp-default-method-alist
(list "\\`ftp\\." "" tramp-efs-method))
(add-to-list 'tramp-default-method-alist
(list "" "\\`\\(anonymous\\|ftp\\)\\'" tramp-efs-method))
;; Add all XEmacs download sites to `tramp-default-method-alist'. The settings
;; above should be sufficient, but it's better to make it explicitely.
(when (listp package-get-download-sites)
(mapcar (lambda (x)
(when (listp x)
(add-to-list
'tramp-default-method-alist
(list (concat "\\`" (nth 1 x) "\\'")
"\\`anonymous\\'" tramp-efs-method))))
package-get-download-sites))
;; Add completion function for FTP method.
(unless (memq system-type '(windows-nt))
(tramp-set-completion-function
tramp-efs-method
'((tramp-parse-netrc "~/.netrc"))))
(defun tramp-efs-file-name-handler (operation &rest args)
"Invoke the EFS handler for OPERATION .
First arg specifies the OPERATION, second args is a list of arguments to
pass to the OPERATION . "
(save-match-data
(or (boundp 'efs-path-regexp)
(require 'efs-cu))
;; Check whether the method is given in a filename.
(setq tramp-efs-method-given nil)
(mapcar (lambda (x)
(and (stringp x)
(string-match tramp-efs-method-regexp x)
(setq tramp-efs-method-given t)))
args)
(let ((efs-path-regexp (tramp-efs-path-regexp))
(efs-path-format-string (tramp-efs-path-format-string))
(efs-path-format-without-user (tramp-efs-path-format-without-user))
(efs-path-user-at-host-format (tramp-efs-path-user-at-host-format))
(efs-path-host-format (tramp-efs-path-host-format))
(efs-path-root-regexp (tramp-efs-path-root-regexp)))
(cond
;; If argument is a symlink, `file-directory-p' and
;; `file-exists-p' call the traversed file recursively. So we
;; cannot disable the file-name-handler this case.
((memq operation '(file-directory-p file-exists-p))
(apply 'efs-file-handler-function operation args))
;; Normally, the handlers must be discarded
(t (let* ((inhibit-file-name-handlers
(list 'tramp-file-name-handler
'tramp-completion-file-name-handler
(and (eq inhibit-file-name-operation operation)
inhibit-file-name-handlers)))
(inhibit-file-name-operation operation))
(apply 'efs-file-handler-function operation args)))))))
;; This function is called even in case the filename doesn't fit Tramp
;; syntax (see defadvice of `efs-dired-before-readin' and
;; `efs-set-buffer-mode'). So a syntax check must be performed first;
;; otherwise `tramp-dissect-file-name' returns with an error.
(defun tramp-efs-file-name-p (filename)
"Check if it's a filename that should be forwarded to EFS."
(when (string-match (nth 0 tramp-file-name-structure) filename)
(let ((v (tramp-dissect-file-name filename)))
(string=
(tramp-find-method
(tramp-file-name-multi-method v)
(tramp-file-name-method v)
(tramp-file-name-user v)
(tramp-file-name-host v))
tramp-efs-method))))
(add-to-list 'tramp-foreign-file-name-handler-alist
(cons 'tramp-efs-file-name-p 'tramp-efs-file-name-handler))
;; Deal with other EFS hooks.
;; * dired-before-readin-hook contains efs-dired-before-readin
;; * find-file-hooks contains efs-set-buffer-mode
(defadvice efs-dired-before-readin (around tramp-efs activate)
"Do nothing for non-EFS names."
(when (tramp-efs-file-name-p default-directory)
ad-do-it))
(defadvice efs-set-buffer-mode (around tramp-efs activate)
"Do nothing for non-EFS names."
(when (tramp-efs-file-name-p buffer-file-name)
ad-do-it))
(provide 'tramp-efs)
;;; tramp-efs.el ends here
|