2015-03-15 18:21:04 +00:00
|
|
|
;;; url-handlers.el --- file-name-handler stuff for URL loading -*- lexical-binding:t -*-
|
2004-04-12 20:43:39 +00:00
|
|
|
|
2015-01-01 22:26:41 +00:00
|
|
|
;; Copyright (C) 1996-1999, 2004-2015 Free Software Foundation, Inc.
|
2004-04-12 20:43:39 +00:00
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;; Keywords: comm, data, processes, hypermedia
|
|
|
|
|
2004-04-12 20:43:39 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2008-05-06 04:29:13 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2004-04-12 20:43:39 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 04:29:13 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
2004-04-12 20:43:39 +00:00
|
|
|
;; GNU Emacs 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.
|
2008-05-06 04:29:13 +00:00
|
|
|
|
2004-04-12 20:43:39 +00:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 04:29:13 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2004-04-12 20:43:39 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2004-12-11 22:06:00 +00:00
|
|
|
;; (require 'url)
|
2007-12-01 22:04:57 +00:00
|
|
|
(require 'url-parse)
|
2004-12-11 22:06:00 +00:00
|
|
|
;; (require 'url-util)
|
|
|
|
(eval-when-compile (require 'mm-decode))
|
|
|
|
;; (require 'mailcap)
|
|
|
|
;; The following are autoloaded instead of `require'd to avoid eagerly
|
|
|
|
;; loading all of URL when turning on url-handler-mode in the .emacs.
|
|
|
|
(autoload 'url-expand-file-name "url-expand" "Convert url to a fully specified url, and canonicalize it.")
|
|
|
|
(autoload 'mm-dissect-buffer "mm-decode" "Dissect the current buffer and return a list of MIME handles.")
|
|
|
|
(autoload 'url-scheme-get-property "url-methods" "Get property of a URL SCHEME.")
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2013-05-22 07:30:44 +00:00
|
|
|
;; Always used after mm-dissect-buffer and defined in the same file.
|
|
|
|
(declare-function mm-save-part-to-file "mm-decode" (handle file))
|
|
|
|
(declare-function mm-destroy-parts "mm-decode" (handles))
|
|
|
|
;; mm-decode loads mm-bodies.
|
|
|
|
(declare-function mm-decode-string "mm-bodies" (string charset))
|
|
|
|
;; mm-decode loads mail-parse.
|
|
|
|
(declare-function mail-content-type-get "mail-parse" (ct attribute))
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;; Implementation status
|
|
|
|
;; ---------------------
|
|
|
|
;; Function Status
|
|
|
|
;; ------------------------------------------------------------
|
|
|
|
;; add-name-to-file Needs DAV Bindings
|
|
|
|
;; copy-file Broken (assumes 1st item is URL)
|
|
|
|
;; delete-directory Finished (DAV)
|
|
|
|
;; delete-file Finished (DAV)
|
|
|
|
;; diff-latest-backup-file
|
2014-08-07 11:49:36 +00:00
|
|
|
;; directory-file-name unnecessary
|
2004-04-04 01:21:46 +00:00
|
|
|
;; directory-files Finished (DAV)
|
|
|
|
;; dired-call-process
|
|
|
|
;; dired-compress-file
|
|
|
|
;; dired-uncache
|
|
|
|
;; expand-file-name Finished
|
|
|
|
;; file-accessible-directory-p
|
|
|
|
;; file-attributes Finished, better with DAV
|
|
|
|
;; file-directory-p Needs DAV, finished
|
|
|
|
;; file-executable-p Finished
|
|
|
|
;; file-exists-p Finished
|
|
|
|
;; file-local-copy
|
|
|
|
;; file-modes
|
|
|
|
;; file-name-all-completions Finished (DAV)
|
|
|
|
;; file-name-as-directory
|
|
|
|
;; file-name-completion Finished (DAV)
|
|
|
|
;; file-name-directory
|
|
|
|
;; file-name-nondirectory
|
|
|
|
;; file-name-sans-versions why?
|
|
|
|
;; file-newer-than-file-p
|
|
|
|
;; file-ownership-preserved-p No way to know
|
|
|
|
;; file-readable-p Finished
|
|
|
|
;; file-regular-p !directory_p
|
2008-02-06 20:34:23 +00:00
|
|
|
;; file-remote-p Finished
|
2004-04-04 01:21:46 +00:00
|
|
|
;; file-symlink-p Needs DAV bindings
|
|
|
|
;; file-truename Needs DAV bindings
|
|
|
|
;; file-writable-p Check for LOCK?
|
|
|
|
;; find-backup-file-name why?
|
|
|
|
;; get-file-buffer why?
|
|
|
|
;; insert-directory Use DAV
|
|
|
|
;; insert-file-contents Finished
|
|
|
|
;; load
|
|
|
|
;; make-directory Finished (DAV)
|
|
|
|
;; make-symbolic-link Needs DAV bindings
|
|
|
|
;; rename-file Finished (DAV)
|
|
|
|
;; set-file-modes Use mod_dav specific executable flag?
|
|
|
|
;; set-visited-file-modtime Impossible?
|
|
|
|
;; shell-command Impossible?
|
|
|
|
;; unhandled-file-name-directory
|
|
|
|
;; vc-registered Finished (DAV)
|
|
|
|
;; verify-visited-file-modtime
|
|
|
|
;; write-region
|
|
|
|
|
2012-06-13 16:25:03 +00:00
|
|
|
(defvar url-handler-regexp) ; defined below to avoid recursive load (revno:108572)
|
|
|
|
|
2012-06-12 05:47:14 +00:00
|
|
|
;;;###autoload
|
2012-06-12 10:00:53 +00:00
|
|
|
(define-minor-mode url-handler-mode
|
|
|
|
"Toggle using `url' library for URL filenames (URL Handler mode).
|
|
|
|
With a prefix argument ARG, enable URL Handler mode if ARG is
|
|
|
|
positive, and disable it otherwise. If called from Lisp, enable
|
|
|
|
the mode if ARG is omitted or nil."
|
|
|
|
:global t :group 'url
|
|
|
|
;; Remove old entry, if any.
|
|
|
|
(setq file-name-handler-alist
|
|
|
|
(delq (rassq 'url-file-handler file-name-handler-alist)
|
|
|
|
file-name-handler-alist))
|
|
|
|
(if url-handler-mode
|
|
|
|
(push (cons url-handler-regexp 'url-file-handler)
|
|
|
|
file-name-handler-alist)))
|
|
|
|
|
2014-04-01 12:41:56 +00:00
|
|
|
(defcustom url-handler-regexp "\\`\\(https?\\|ftp\\|file\\|nfs\\|ssh\\|scp\\|rsync\\|telnet\\)://"
|
2012-06-12 05:47:14 +00:00
|
|
|
"Regular expression for URLs handled by `url-handler-mode'.
|
|
|
|
When URL Handler mode is enabled, this regular expression is
|
|
|
|
added to `file-name-handler-alist'.
|
|
|
|
|
|
|
|
Some valid URL protocols just do not make sense to visit
|
2015-09-17 23:08:20 +00:00
|
|
|
interactively \(about, data, info, irc, mailto, etc.). This
|
2012-06-12 05:47:14 +00:00
|
|
|
regular expression avoids conflicts with local files that look
|
2015-09-17 23:08:20 +00:00
|
|
|
like URLs \(Gnus is particularly bad at this)."
|
2012-06-12 05:47:14 +00:00
|
|
|
:group 'url
|
|
|
|
:type 'regexp
|
2014-09-29 18:14:08 +00:00
|
|
|
:version "25.1"
|
2012-06-12 05:47:14 +00:00
|
|
|
:set (lambda (symbol value)
|
|
|
|
(let ((enable url-handler-mode))
|
|
|
|
(url-handler-mode 0)
|
|
|
|
(set-default symbol value)
|
|
|
|
(if enable
|
|
|
|
(url-handler-mode)))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(defun url-run-real-handler (operation args)
|
|
|
|
(let ((inhibit-file-name-handlers (cons 'url-file-handler
|
|
|
|
(if (eq operation inhibit-file-name-operation)
|
|
|
|
inhibit-file-name-handlers)))
|
|
|
|
(inhibit-file-name-operation operation))
|
|
|
|
(apply operation args)))
|
|
|
|
|
2014-05-09 12:49:30 +00:00
|
|
|
(defvar url-file-handler-load-in-progress nil
|
|
|
|
"Check for recursive load.")
|
|
|
|
|
2008-01-07 06:52:19 +00:00
|
|
|
;;;###autoload
|
2004-04-04 01:21:46 +00:00
|
|
|
(defun url-file-handler (operation &rest args)
|
|
|
|
"Function called from the `file-name-handler-alist' routines.
|
|
|
|
OPERATION is what needs to be done (`file-exists-p', etc). ARGS are
|
|
|
|
the arguments that would have been passed to OPERATION."
|
2014-05-09 12:49:30 +00:00
|
|
|
;; Avoid recursive load.
|
|
|
|
(if (and load-in-progress url-file-handler-load-in-progress)
|
|
|
|
(url-run-real-handler operation args)
|
2014-05-12 06:59:30 +00:00
|
|
|
(let ((url-file-handler-load-in-progress load-in-progress))
|
|
|
|
;; Check, whether there are arguments we want pass to Tramp.
|
|
|
|
(if (catch :do
|
|
|
|
(dolist (url (cons default-directory args))
|
|
|
|
(and (member
|
|
|
|
(url-type (url-generic-parse-url (and (stringp url) url)))
|
|
|
|
url-tramp-protocols)
|
|
|
|
(throw :do t))))
|
|
|
|
(apply 'url-tramp-file-handler operation args)
|
|
|
|
;; Otherwise, let's do the job.
|
|
|
|
(let ((fn (get operation 'url-file-handlers))
|
|
|
|
(val nil)
|
|
|
|
(hooked nil))
|
|
|
|
(if (and (not fn) (intern-soft (format "url-%s" operation))
|
|
|
|
(fboundp (intern-soft (format "url-%s" operation))))
|
|
|
|
(error "Missing URL handler mapping for %s" operation))
|
|
|
|
(if fn
|
|
|
|
(setq hooked t
|
|
|
|
val (save-match-data (apply fn args)))
|
|
|
|
(setq hooked nil
|
|
|
|
val (url-run-real-handler operation args)))
|
|
|
|
(url-debug 'handlers "%s %S%S => %S" (if hooked "Hooked" "Real")
|
|
|
|
operation args val)
|
|
|
|
val)))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(defun url-file-handler-identity (&rest args)
|
|
|
|
;; Identity function
|
|
|
|
(car args))
|
|
|
|
|
|
|
|
;; These are operations that we can fully support
|
|
|
|
(put 'file-readable-p 'url-file-handlers 'url-file-exists-p)
|
|
|
|
(put 'substitute-in-file-name 'url-file-handlers 'url-file-handler-identity)
|
|
|
|
(put 'file-name-absolute-p 'url-file-handlers (lambda (&rest ignored) t))
|
|
|
|
(put 'expand-file-name 'url-file-handlers 'url-handler-expand-file-name)
|
2006-03-29 08:00:09 +00:00
|
|
|
(put 'directory-file-name 'url-file-handlers 'url-handler-directory-file-name)
|
2008-01-21 17:16:52 +00:00
|
|
|
(put 'unhandled-file-name-directory 'url-file-handlers 'url-handler-unhandled-file-name-directory)
|
2008-02-06 20:34:23 +00:00
|
|
|
(put 'file-remote-p 'url-file-handlers 'url-handler-file-remote-p)
|
2006-03-29 08:00:09 +00:00
|
|
|
;; (put 'file-name-as-directory 'url-file-handlers 'url-handler-file-name-as-directory)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
;; These are operations that we do not support yet (DAV!!!)
|
|
|
|
(put 'file-writable-p 'url-file-handlers 'ignore)
|
|
|
|
(put 'file-symlink-p 'url-file-handlers 'ignore)
|
2005-06-10 21:14:10 +00:00
|
|
|
;; Just like for ange-ftp: let's not waste time trying to look for RCS/foo,v
|
|
|
|
;; files and such since we can't do anything clever with them anyway.
|
|
|
|
(put 'vc-registered 'url-file-handlers 'ignore)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(defun url-handler-expand-file-name (file &optional base)
|
2006-03-29 08:00:09 +00:00
|
|
|
;; When we see "/foo/bar" in a file whose working dir is "http://bla/bla",
|
|
|
|
;; there are two interpretations possible: either it's a local "/foo/bar"
|
|
|
|
;; or it's "http:/bla/foo/bar". When working with URLs, the second
|
|
|
|
;; interpretation is the right one, but when working with Emacs file
|
|
|
|
;; names, the first is preferred.
|
2004-04-04 01:21:46 +00:00
|
|
|
(if (file-name-absolute-p file)
|
|
|
|
(expand-file-name file "/")
|
|
|
|
(url-expand-file-name file base)))
|
|
|
|
|
2006-03-29 08:00:09 +00:00
|
|
|
;; directory-file-name and file-name-as-directory are kind of hard to
|
|
|
|
;; implement really right for URLs since URLs can have repeated / chars.
|
|
|
|
;; We'd want the following behavior:
|
|
|
|
;; idempotence: (d-f-n (d-f-n X) == (d-f-n X)
|
|
|
|
;; idempotence: (f-n-a-d (f-n-a-d X) == (f-n-a-d X)
|
|
|
|
;; reversible: (d-f-n (f-n-a-d (d-f-n X))) == (d-f-n X)
|
|
|
|
;; reversible: (f-n-a-d (d-f-n (f-n-a-d X))) == (f-n-a-d X)
|
|
|
|
(defun url-handler-directory-file-name (dir)
|
|
|
|
;; When there's more than a single /, just don't touch the slashes at all.
|
|
|
|
(if (string-match "//\\'" dir) dir
|
|
|
|
(url-run-real-handler 'directory-file-name (list dir))))
|
|
|
|
|
2008-01-21 17:16:52 +00:00
|
|
|
(defun url-handler-unhandled-file-name-directory (filename)
|
2008-02-06 14:43:05 +00:00
|
|
|
(let ((url (url-generic-parse-url filename)))
|
|
|
|
(if (equal (url-type url) "file")
|
|
|
|
;; `file' URLs are actually local. The filename part may be ""
|
|
|
|
;; which really stands for "/".
|
|
|
|
;; FIXME: maybe we should check that the host part is "" or "localhost"
|
|
|
|
;; or some name that represents the local host?
|
2015-10-29 01:00:50 +00:00
|
|
|
(or (file-name-as-directory (url-filename url)) "/")
|
2008-02-06 14:43:05 +00:00
|
|
|
;; All other URLs are not expected to be directly accessible from
|
|
|
|
;; a local process.
|
|
|
|
nil)))
|
2008-01-21 17:16:52 +00:00
|
|
|
|
2015-03-15 18:21:04 +00:00
|
|
|
(defun url-handler-file-remote-p (filename &optional identification _connected)
|
2008-02-06 20:34:23 +00:00
|
|
|
(let ((url (url-generic-parse-url filename)))
|
|
|
|
(if (and (url-type url) (not (equal (url-type url) "file")))
|
|
|
|
;; Maybe we can find a suitable check for CONNECTED. For now,
|
|
|
|
;; we ignore it.
|
|
|
|
(cond
|
|
|
|
((eq identification 'method) (url-type url))
|
|
|
|
((eq identification 'user) (url-user url))
|
|
|
|
((eq identification 'host) (url-host url))
|
|
|
|
((eq identification 'localname) (url-filename url))
|
|
|
|
(t (url-recreate-url
|
|
|
|
(url-parse-make-urlobj (url-type url) (url-user url) nil
|
|
|
|
(url-host url) (url-port url)))))
|
|
|
|
;; If there is no URL type, or it is a "file://" URL, the
|
|
|
|
;; filename is expected to be non remote. A more subtle check
|
|
|
|
;; for "file://" URLs could be applied, as said in
|
|
|
|
;; `url-handler-unhandled-file-name-directory'.
|
|
|
|
nil)))
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;; The actual implementation
|
|
|
|
;;;###autoload
|
2009-09-13 21:21:40 +00:00
|
|
|
(defun url-copy-file (url newname &optional ok-if-already-exists
|
2015-03-15 18:21:04 +00:00
|
|
|
_keep-time _preserve-uid-gid)
|
2004-04-04 01:21:46 +00:00
|
|
|
"Copy URL to NEWNAME. Both args must be strings.
|
|
|
|
Signals a `file-already-exists' error if file NEWNAME already exists,
|
|
|
|
unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil.
|
|
|
|
A number as third arg means request confirmation if NEWNAME already exists.
|
|
|
|
This is what happens in interactive use with M-x.
|
|
|
|
Fourth arg KEEP-TIME non-nil means give the new file the same
|
|
|
|
last-modified time as the old one. (This works on only some systems.)
|
2009-09-13 21:21:40 +00:00
|
|
|
Fifth arg PRESERVE-UID-GID is ignored.
|
2004-04-04 01:21:46 +00:00
|
|
|
A prefix arg makes KEEP-TIME non-nil."
|
|
|
|
(if (and (file-exists-p newname)
|
|
|
|
(not ok-if-already-exists))
|
|
|
|
(error "Opening output file: File already exists, %s" newname))
|
|
|
|
(let ((buffer (url-retrieve-synchronously url))
|
|
|
|
(handle nil))
|
|
|
|
(if (not buffer)
|
|
|
|
(error "Opening input file: No such file or directory, %s" url))
|
2004-09-20 21:27:10 +00:00
|
|
|
(with-current-buffer buffer
|
2004-04-04 01:21:46 +00:00
|
|
|
(setq handle (mm-dissect-buffer t)))
|
|
|
|
(mm-save-part-to-file handle newname)
|
|
|
|
(kill-buffer buffer)
|
|
|
|
(mm-destroy-parts handle)))
|
2012-09-30 03:26:52 +00:00
|
|
|
(put 'copy-file 'url-file-handlers 'url-copy-file)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun url-file-local-copy (url &rest ignored)
|
|
|
|
"Copy URL into a temporary file on this machine.
|
|
|
|
Returns the name of the local copy, or nil, if FILE is directly
|
|
|
|
accessible."
|
2006-03-29 08:00:09 +00:00
|
|
|
(let ((filename (make-temp-file "url")))
|
2006-08-25 20:44:49 +00:00
|
|
|
(url-copy-file url filename 'ok-if-already-exists)
|
2004-04-04 01:21:46 +00:00
|
|
|
filename))
|
2012-09-30 03:26:52 +00:00
|
|
|
(put 'file-local-copy 'url-file-handlers 'url-file-local-copy)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2006-04-26 20:37:58 +00:00
|
|
|
(defun url-insert (buffer &optional beg end)
|
|
|
|
"Insert the body of a URL object.
|
|
|
|
BUFFER should be a complete URL buffer as returned by `url-retrieve'.
|
|
|
|
If the headers specify a coding-system, it is applied to the body before it is inserted.
|
|
|
|
Returns a list of the form (SIZE CHARSET), where SIZE is the size in bytes
|
|
|
|
of the inserted text and CHARSET is the charset that was specified in the header,
|
|
|
|
or nil if none was found.
|
|
|
|
BEG and END can be used to only insert a subpart of the body.
|
|
|
|
They count bytes from the beginning of the body."
|
|
|
|
(let* ((handle (with-current-buffer buffer (mm-dissect-buffer t)))
|
|
|
|
(data (with-current-buffer (mm-handle-buffer handle)
|
|
|
|
(if beg
|
|
|
|
(buffer-substring (+ (point-min) beg)
|
|
|
|
(if end (+ (point-min) end) (point-max)))
|
|
|
|
(buffer-string))))
|
|
|
|
(charset (mail-content-type-get (mm-handle-type handle)
|
|
|
|
'charset)))
|
|
|
|
(mm-destroy-parts handle)
|
|
|
|
(if charset
|
|
|
|
(insert (mm-decode-string data (mm-charset-to-coding-system charset)))
|
|
|
|
(insert data))
|
|
|
|
(list (length data) charset)))
|
|
|
|
|
2014-06-26 04:27:18 +00:00
|
|
|
(defvar url-http-codes)
|
2014-06-26 04:00:56 +00:00
|
|
|
|
2015-12-25 18:04:55 +00:00
|
|
|
;;;###autoload
|
2015-11-15 21:28:37 +00:00
|
|
|
(defun url-insert-buffer-contents (buffer url &optional visit beg end replace)
|
|
|
|
"Insert the contents of BUFFER into current buffer.
|
|
|
|
This is like `url-insert', but also decodes the current buffer as
|
|
|
|
if it had been inserted from a file named URL."
|
|
|
|
(if visit (setq buffer-file-name url))
|
|
|
|
(save-excursion
|
|
|
|
(let* ((start (point))
|
|
|
|
(size-and-charset (url-insert buffer beg end)))
|
|
|
|
(kill-buffer buffer)
|
|
|
|
(when replace
|
|
|
|
(delete-region (point-min) start)
|
|
|
|
(delete-region (point) (point-max)))
|
|
|
|
(unless (cadr size-and-charset)
|
|
|
|
;; If the headers don't specify any particular charset, use the
|
|
|
|
;; usual heuristic/rules that we apply to files.
|
|
|
|
(decode-coding-inserted-region (point-min) (point) url
|
|
|
|
visit beg end replace))
|
|
|
|
(let ((inserted (car size-and-charset)))
|
|
|
|
(when (fboundp 'after-insert-file-set-coding)
|
|
|
|
(let ((insval (after-insert-file-set-coding inserted visit)))
|
|
|
|
(if insval (setq inserted insval))))
|
|
|
|
(list url inserted)))))
|
|
|
|
|
2004-04-04 01:21:46 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defun url-insert-file-contents (url &optional visit beg end replace)
|
2006-04-26 20:37:58 +00:00
|
|
|
(let ((buffer (url-retrieve-synchronously url)))
|
2014-03-26 15:21:17 +00:00
|
|
|
(unless buffer (signal 'file-error (list url "No Data")))
|
|
|
|
(with-current-buffer buffer
|
2014-06-26 04:00:56 +00:00
|
|
|
;; XXX: This is HTTP/S specific and should be moved to url-http
|
|
|
|
;; instead. See http://debbugs.gnu.org/17549.
|
|
|
|
(when (bound-and-true-p url-http-response-status)
|
|
|
|
(unless (and (>= url-http-response-status 200)
|
|
|
|
(< url-http-response-status 300))
|
|
|
|
(let ((desc (nth 2 (assq url-http-response-status url-http-codes))))
|
2014-03-26 15:21:17 +00:00
|
|
|
(kill-buffer buffer)
|
2014-06-26 04:00:56 +00:00
|
|
|
;; Signal file-error per http://debbugs.gnu.org/16733.
|
2014-03-26 15:21:17 +00:00
|
|
|
(signal 'file-error (list url desc))))))
|
2015-11-15 21:28:37 +00:00
|
|
|
(url-insert-buffer-contents buffer url visit beg end replace)))
|
2014-06-26 04:00:56 +00:00
|
|
|
|
2012-09-30 03:26:52 +00:00
|
|
|
(put 'insert-file-contents 'url-file-handlers 'url-insert-file-contents)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2015-05-12 06:51:58 +00:00
|
|
|
(defun url-file-name-completion (url _directory &optional _predicate)
|
2013-07-31 04:19:09 +00:00
|
|
|
;; Even if it's not implemented, it's not an error to ask for completion,
|
|
|
|
;; in case it's available (bug#14806).
|
|
|
|
;; (error "Unimplemented")
|
|
|
|
url)
|
2012-09-30 03:26:52 +00:00
|
|
|
(put 'file-name-completion 'url-file-handlers 'url-file-name-completion)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2015-05-12 06:51:58 +00:00
|
|
|
(defun url-file-name-all-completions (_file _directory)
|
2013-07-31 04:19:09 +00:00
|
|
|
;; Even if it's not implemented, it's not an error to ask for completion,
|
|
|
|
;; in case it's available (bug#14806).
|
|
|
|
;; (error "Unimplemented")
|
|
|
|
nil)
|
2012-09-30 03:26:52 +00:00
|
|
|
(put 'file-name-all-completions
|
|
|
|
'url-file-handlers 'url-file-name-all-completions)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
;; All other handlers map onto their respective backends.
|
|
|
|
(defmacro url-handlers-create-wrapper (method args)
|
2012-09-30 03:26:52 +00:00
|
|
|
`(progn
|
|
|
|
(defun ,(intern (format "url-%s" method)) ,args
|
|
|
|
,(format "URL file-name-handler wrapper for `%s' call.\n---\n%s" method
|
|
|
|
(or (documentation method t) "No original documentation."))
|
|
|
|
(setq url (url-generic-parse-url url))
|
|
|
|
(when (url-type url)
|
|
|
|
(funcall (url-scheme-get-property (url-type url) (quote ,method))
|
|
|
|
,@(remove '&rest (remove '&optional args)))))
|
|
|
|
(unless (get ',method 'url-file-handlers)
|
|
|
|
(put ',method 'url-file-handlers ',(intern (format "url-%s" method))))))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(url-handlers-create-wrapper file-exists-p (url))
|
2004-04-16 22:00:40 +00:00
|
|
|
(url-handlers-create-wrapper file-attributes (url &optional id-format))
|
2004-04-04 01:21:46 +00:00
|
|
|
(url-handlers-create-wrapper file-symlink-p (url))
|
|
|
|
(url-handlers-create-wrapper file-writable-p (url))
|
|
|
|
(url-handlers-create-wrapper file-directory-p (url))
|
|
|
|
(url-handlers-create-wrapper file-executable-p (url))
|
2005-10-20 14:17:14 +00:00
|
|
|
(url-handlers-create-wrapper directory-files (url &optional full match nosort))
|
|
|
|
(url-handlers-create-wrapper file-truename (url &optional counter prev-dirs))
|
2004-04-04 01:21:46 +00:00
|
|
|
|
2004-04-16 22:00:40 +00:00
|
|
|
(add-hook 'find-file-hook 'url-handlers-set-buffer-mode)
|
2004-04-04 01:21:46 +00:00
|
|
|
|
|
|
|
(defun url-handlers-set-buffer-mode ()
|
|
|
|
"Set correct modes for the current buffer if visiting a remote file."
|
|
|
|
(and (stringp buffer-file-name)
|
|
|
|
(string-match url-handler-regexp buffer-file-name)
|
|
|
|
(auto-save-mode 0)))
|
|
|
|
|
|
|
|
(provide 'url-handlers)
|
2004-04-04 04:44:10 +00:00
|
|
|
|
2004-04-12 20:43:39 +00:00
|
|
|
;;; url-handlers.el ends here
|