diff options
| author | Michael Albinus | 2014-04-01 14:41:56 +0200 |
|---|---|---|
| committer | Michael Albinus | 2014-04-01 14:41:56 +0200 |
| commit | 8def287539f38f1f95ef54e866b80f44c9c76b5b (patch) | |
| tree | a5ebe25499294828455287ebe95aa3afad8ab9bd | |
| parent | a7ab7bc038e1e53f4e8e4b65125b5c64c548c407 (diff) | |
| download | emacs-8def287539f38f1f95ef54e866b80f44c9c76b5b.tar.gz emacs-8def287539f38f1f95ef54e866b80f44c9c76b5b.zip | |
Pass some protocols to Tramp, like ssh and friends.
* url-tramp.el: New file.
* url-handlers.el (url-handler-regexp): Add ssh, scp, rsync and telnet.
Add :version.
(url-file-handler): Call `url-tramp-file-handler' if appropriate.
| -rw-r--r-- | lisp/url/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/url/url-handlers.el | 40 | ||||
| -rw-r--r-- | lisp/url/url-tramp.el | 79 |
3 files changed, 112 insertions, 15 deletions
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index bb7025bf6ae..486c6649c00 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2014-04-01 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * url-tramp.el: New file. | ||
| 4 | |||
| 5 | * url-handlers.el (url-handler-regexp): Add ssh, scp, rsync and telnet. | ||
| 6 | Add :version. | ||
| 7 | (url-file-handler): Call `url-tramp-file-handler' if appropriate. | ||
| 8 | |||
| 1 | 2014-03-28 Glenn Morris <rgm@gnu.org> | 9 | 2014-03-28 Glenn Morris <rgm@gnu.org> |
| 2 | 10 | ||
| 3 | * url-vars.el (url-bug-address): Make into an obsolete alias. | 11 | * url-vars.el (url-bug-address): Make into an obsolete alias. |
diff --git a/lisp/url/url-handlers.el b/lisp/url/url-handlers.el index ecf56e786b5..9a05746ebff 100644 --- a/lisp/url/url-handlers.el +++ b/lisp/url/url-handlers.el | |||
| @@ -112,7 +112,7 @@ the mode if ARG is omitted or nil." | |||
| 112 | (push (cons url-handler-regexp 'url-file-handler) | 112 | (push (cons url-handler-regexp 'url-file-handler) |
| 113 | file-name-handler-alist))) | 113 | file-name-handler-alist))) |
| 114 | 114 | ||
| 115 | (defcustom url-handler-regexp "\\`\\(https?\\|ftp\\|file\\|nfs\\)://" | 115 | (defcustom url-handler-regexp "\\`\\(https?\\|ftp\\|file\\|nfs\\|ssh\\|scp\\|rsync\\|telnet\\)://" |
| 116 | "Regular expression for URLs handled by `url-handler-mode'. | 116 | "Regular expression for URLs handled by `url-handler-mode'. |
| 117 | When URL Handler mode is enabled, this regular expression is | 117 | When URL Handler mode is enabled, this regular expression is |
| 118 | added to `file-name-handler-alist'. | 118 | added to `file-name-handler-alist'. |
| @@ -123,6 +123,7 @@ regular expression avoids conflicts with local files that look | |||
| 123 | like URLs \(Gnus is particularly bad at this\)." | 123 | like URLs \(Gnus is particularly bad at this\)." |
| 124 | :group 'url | 124 | :group 'url |
| 125 | :type 'regexp | 125 | :type 'regexp |
| 126 | :version "24.5" | ||
| 126 | :set (lambda (symbol value) | 127 | :set (lambda (symbol value) |
| 127 | (let ((enable url-handler-mode)) | 128 | (let ((enable url-handler-mode)) |
| 128 | (url-handler-mode 0) | 129 | (url-handler-mode 0) |
| @@ -142,20 +143,29 @@ like URLs \(Gnus is particularly bad at this\)." | |||
| 142 | "Function called from the `file-name-handler-alist' routines. | 143 | "Function called from the `file-name-handler-alist' routines. |
| 143 | OPERATION is what needs to be done (`file-exists-p', etc). ARGS are | 144 | OPERATION is what needs to be done (`file-exists-p', etc). ARGS are |
| 144 | the arguments that would have been passed to OPERATION." | 145 | the arguments that would have been passed to OPERATION." |
| 145 | (let ((fn (get operation 'url-file-handlers)) | 146 | ;; Check, whether there are arguments we want pass to Tramp. |
| 146 | (val nil) | 147 | (if (catch :do |
| 147 | (hooked nil)) | 148 | (dolist (url (cons default-directory args)) |
| 148 | (if (and (not fn) (intern-soft (format "url-%s" operation)) | 149 | (and (member |
| 149 | (fboundp (intern-soft (format "url-%s" operation)))) | 150 | (url-type (url-generic-parse-url (and (stringp url) url))) |
| 150 | (error "Missing URL handler mapping for %s" operation)) | 151 | url-tramp-protocols) |
| 151 | (if fn | 152 | (throw :do t)))) |
| 152 | (setq hooked t | 153 | (apply 'url-tramp-file-handler operation args) |
| 153 | val (save-match-data (apply fn args))) | 154 | ;; Otherwise, let's do the job. |
| 154 | (setq hooked nil | 155 | (let ((fn (get operation 'url-file-handlers)) |
| 155 | val (url-run-real-handler operation args))) | 156 | (val nil) |
| 156 | (url-debug 'handlers "%s %S%S => %S" (if hooked "Hooked" "Real") | 157 | (hooked nil)) |
| 157 | operation args val) | 158 | (if (and (not fn) (intern-soft (format "url-%s" operation)) |
| 158 | val)) | 159 | (fboundp (intern-soft (format "url-%s" operation)))) |
| 160 | (error "Missing URL handler mapping for %s" operation)) | ||
| 161 | (if fn | ||
| 162 | (setq hooked t | ||
| 163 | val (save-match-data (apply fn args))) | ||
| 164 | (setq hooked nil | ||
| 165 | val (url-run-real-handler operation args))) | ||
| 166 | (url-debug 'handlers "%s %S%S => %S" (if hooked "Hooked" "Real") | ||
| 167 | operation args val) | ||
| 168 | val))) | ||
| 159 | 169 | ||
| 160 | (defun url-file-handler-identity (&rest args) | 170 | (defun url-file-handler-identity (&rest args) |
| 161 | ;; Identity function | 171 | ;; Identity function |
diff --git a/lisp/url/url-tramp.el b/lisp/url/url-tramp.el new file mode 100644 index 00000000000..83cedd1d62c --- /dev/null +++ b/lisp/url/url-tramp.el | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | ;;; url-tramp.el --- file-name-handler magic invoking Tramp for some protocols | ||
| 2 | |||
| 3 | ;; Copyright (C) 2014 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Michael Albinus <michael.albinus@gmx.de> | ||
| 6 | ;; Keywords: comm, data, processes, hypermedia | ||
| 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 3 of the License, or | ||
| 13 | ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;;; Code: | ||
| 26 | |||
| 27 | (require 'url-parse) | ||
| 28 | (require 'tramp) | ||
| 29 | (require 'password-cache) | ||
| 30 | |||
| 31 | ;;;###autoload | ||
| 32 | (defcustom url-tramp-protocols '("ftp" "ssh" "scp" "rsync" "telnet") | ||
| 33 | "List of URL protocols the work is handled by Tramp. | ||
| 34 | They must also be covered by `url-handler-regexp'." | ||
| 35 | :group 'url | ||
| 36 | :version "24.5" | ||
| 37 | :type '(list string)) | ||
| 38 | |||
| 39 | (defun url-tramp-convert-url-to-tramp (url) | ||
| 40 | "Convert URL to a Tramp file name." | ||
| 41 | (let ((obj (url-generic-parse-url (and (stringp url) url)))) | ||
| 42 | (if (member (url-type obj) url-tramp-protocols) | ||
| 43 | (progn | ||
| 44 | (if (url-password obj) | ||
| 45 | (password-cache-add | ||
| 46 | (tramp-make-tramp-file-name | ||
| 47 | (url-type obj) (url-user obj) (url-host obj) "") | ||
| 48 | (url-password obj)) | ||
| 49 | (tramp-make-tramp-file-name | ||
| 50 | (url-type obj) (url-user obj) (url-host obj) (url-filename obj)))) | ||
| 51 | url))) | ||
| 52 | |||
| 53 | (defun url-tramp-convert-tramp-to-url (file) | ||
| 54 | "Convert FILE, a Tramp file name, to a URL." | ||
| 55 | (let ((obj (ignore-errors (tramp-dissect-file-name file)))) | ||
| 56 | (if (member (tramp-file-name-method obj) url-tramp-protocols) | ||
| 57 | (url-recreate-url | ||
| 58 | (url-parse-make-urlobj | ||
| 59 | (tramp-file-name-method obj) | ||
| 60 | (tramp-file-name-user obj) | ||
| 61 | nil ; password. | ||
| 62 | (tramp-file-name-host obj) | ||
| 63 | nil ; port. | ||
| 64 | (tramp-file-name-localname obj) | ||
| 65 | nil nil t)) ; target attributes fullness. | ||
| 66 | file))) | ||
| 67 | |||
| 68 | ;;;###autoload | ||
| 69 | (defun url-tramp-file-handler (operation &rest args) | ||
| 70 | "Function called from the `file-name-handler-alist' routines. | ||
| 71 | OPERATION is what needs to be done. ARGS are the arguments that | ||
| 72 | would have been passed to OPERATION." | ||
| 73 | (let ((default-directory (url-tramp-convert-url-to-tramp default-directory)) | ||
| 74 | (args (mapcar 'url-tramp-convert-url-to-tramp args))) | ||
| 75 | (url-tramp-convert-tramp-to-url (apply operation args)))) | ||
| 76 | |||
| 77 | (provide 'url-tramp) | ||
| 78 | |||
| 79 | ;;; url-tramp.el ends here | ||