diff options
| author | Stefan Monnier | 2012-09-29 23:26:52 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2012-09-29 23:26:52 -0400 |
| commit | 23855148a2706fe5adeac444abfc2d1e71d911f8 (patch) | |
| tree | bef3e5c7e8b8d72712b2c6c3b426c5fb962b8ffb | |
| parent | 38a30d64628c84690467008888984d14683f9c9d (diff) | |
| download | emacs-23855148a2706fe5adeac444abfc2d1e71d911f8.tar.gz emacs-23855148a2706fe5adeac444abfc2d1e71d911f8.zip | |
* lisp/url/url-handlers.el (url-file-handler): Don't assume any url-FOO
function is a good handler for FOO.
(url-copy-file, url-file-local-copy, url-insert-file-contents)
(url-file-name-completion, url-file-name-all-completions)
(url-handlers-create-wrapper): Explicitly register as handler.
| -rw-r--r-- | lisp/url/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/url/url-handlers.el | 31 |
2 files changed, 29 insertions, 10 deletions
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index 279db5ee3e4..a00d748a4a4 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2012-09-30 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * url-handlers.el (url-file-handler): Don't assume any url-FOO function | ||
| 4 | is a good handler for FOO. | ||
| 5 | (url-copy-file, url-file-local-copy, url-insert-file-contents) | ||
| 6 | (url-file-name-completion, url-file-name-all-completions) | ||
| 7 | (url-handlers-create-wrapper): Explicitly register as handler. | ||
| 8 | |||
| 1 | 2012-09-29 Bastien Guerry <bzg@gnu.org> | 9 | 2012-09-29 Bastien Guerry <bzg@gnu.org> |
| 2 | 10 | ||
| 3 | * url-util.el (url-insert-entities-in-string) | 11 | * url-util.el (url-insert-entities-in-string) |
diff --git a/lisp/url/url-handlers.el b/lisp/url/url-handlers.el index f731f614d13..796980afbd5 100644 --- a/lisp/url/url-handlers.el +++ b/lisp/url/url-handlers.el | |||
| @@ -137,11 +137,13 @@ like URLs \(Gnus is particularly bad at this\)." | |||
| 137 | "Function called from the `file-name-handler-alist' routines. | 137 | "Function called from the `file-name-handler-alist' routines. |
| 138 | OPERATION is what needs to be done (`file-exists-p', etc). ARGS are | 138 | OPERATION is what needs to be done (`file-exists-p', etc). ARGS are |
| 139 | the arguments that would have been passed to OPERATION." | 139 | the arguments that would have been passed to OPERATION." |
| 140 | (let ((fn (or (get operation 'url-file-handlers) | 140 | (let ((fn (get operation 'url-file-handlers)) |
| 141 | (intern-soft (format "url-%s" operation)))) | ||
| 142 | (val nil) | 141 | (val nil) |
| 143 | (hooked nil)) | 142 | (hooked nil)) |
| 144 | (if (and fn (fboundp fn)) | 143 | (if (and (not fn) (intern-soft (format "url-%s" operation)) |
| 144 | (fboundp (intern-soft (format "url-%s" operation)))) | ||
| 145 | (error "Missing URL handler mapping for %s" operation)) | ||
| 146 | (if fn | ||
| 145 | (setq hooked t | 147 | (setq hooked t |
| 146 | val (save-match-data (apply fn args))) | 148 | val (save-match-data (apply fn args))) |
| 147 | (setq hooked nil | 149 | (setq hooked nil |
| @@ -249,6 +251,7 @@ A prefix arg makes KEEP-TIME non-nil." | |||
| 249 | (mm-save-part-to-file handle newname) | 251 | (mm-save-part-to-file handle newname) |
| 250 | (kill-buffer buffer) | 252 | (kill-buffer buffer) |
| 251 | (mm-destroy-parts handle))) | 253 | (mm-destroy-parts handle))) |
| 254 | (put 'copy-file 'url-file-handlers 'url-copy-file) | ||
| 252 | 255 | ||
| 253 | ;;;###autoload | 256 | ;;;###autoload |
| 254 | (defun url-file-local-copy (url &rest ignored) | 257 | (defun url-file-local-copy (url &rest ignored) |
| @@ -258,6 +261,7 @@ accessible." | |||
| 258 | (let ((filename (make-temp-file "url"))) | 261 | (let ((filename (make-temp-file "url"))) |
| 259 | (url-copy-file url filename 'ok-if-already-exists) | 262 | (url-copy-file url filename 'ok-if-already-exists) |
| 260 | filename)) | 263 | filename)) |
| 264 | (put 'file-local-copy 'url-file-handlers 'url-file-local-copy) | ||
| 261 | 265 | ||
| 262 | (defun url-insert (buffer &optional beg end) | 266 | (defun url-insert (buffer &optional beg end) |
| 263 | "Insert the body of a URL object. | 267 | "Insert the body of a URL object. |
| @@ -300,22 +304,29 @@ They count bytes from the beginning of the body." | |||
| 300 | ;; usual heuristic/rules that we apply to files. | 304 | ;; usual heuristic/rules that we apply to files. |
| 301 | (decode-coding-inserted-region start (point) url visit beg end replace)) | 305 | (decode-coding-inserted-region start (point) url visit beg end replace)) |
| 302 | (list url (car size-and-charset)))))) | 306 | (list url (car size-and-charset)))))) |
| 307 | (put 'insert-file-contents 'url-file-handlers 'url-insert-file-contents) | ||
| 303 | 308 | ||
| 304 | (defun url-file-name-completion (url directory &optional predicate) | 309 | (defun url-file-name-completion (url directory &optional predicate) |
| 305 | (error "Unimplemented")) | 310 | (error "Unimplemented")) |
| 311 | (put 'file-name-completion 'url-file-handlers 'url-file-name-completion) | ||
| 306 | 312 | ||
| 307 | (defun url-file-name-all-completions (file directory) | 313 | (defun url-file-name-all-completions (file directory) |
| 308 | (error "Unimplemented")) | 314 | (error "Unimplemented")) |
| 315 | (put 'file-name-all-completions | ||
| 316 | 'url-file-handlers 'url-file-name-all-completions) | ||
| 309 | 317 | ||
| 310 | ;; All other handlers map onto their respective backends. | 318 | ;; All other handlers map onto their respective backends. |
| 311 | (defmacro url-handlers-create-wrapper (method args) | 319 | (defmacro url-handlers-create-wrapper (method args) |
| 312 | `(defun ,(intern (format "url-%s" method)) ,args | 320 | `(progn |
| 313 | ,(format "URL file-name-handler wrapper for `%s' call.\n---\n%s" method | 321 | (defun ,(intern (format "url-%s" method)) ,args |
| 314 | (or (documentation method t) "No original documentation.")) | 322 | ,(format "URL file-name-handler wrapper for `%s' call.\n---\n%s" method |
| 315 | (setq url (url-generic-parse-url url)) | 323 | (or (documentation method t) "No original documentation.")) |
| 316 | (when (url-type url) | 324 | (setq url (url-generic-parse-url url)) |
| 317 | (funcall (url-scheme-get-property (url-type url) (quote ,method)) | 325 | (when (url-type url) |
| 318 | ,@(remove '&rest (remove '&optional args)))))) | 326 | (funcall (url-scheme-get-property (url-type url) (quote ,method)) |
| 327 | ,@(remove '&rest (remove '&optional args))))) | ||
| 328 | (unless (get ',method 'url-file-handlers) | ||
| 329 | (put ',method 'url-file-handlers ',(intern (format "url-%s" method)))))) | ||
| 319 | 330 | ||
| 320 | (url-handlers-create-wrapper file-exists-p (url)) | 331 | (url-handlers-create-wrapper file-exists-p (url)) |
| 321 | (url-handlers-create-wrapper file-attributes (url &optional id-format)) | 332 | (url-handlers-create-wrapper file-attributes (url &optional id-format)) |