diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2015-11-15 21:28:37 +0000 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2015-11-15 21:35:06 +0000 |
commit | 7cc233e1e3da297882c006c1f07c628fbd4e94d5 (patch) | |
tree | 569440df0ffd3eb688c5956a7d6354b1f83f1713 /lisp/url/url-handlers.el | |
parent | 5f9153faaf767a039620a0a05a8ad0373cb24070 (diff) | |
download | emacs-7cc233e1e3da297882c006c1f07c628fbd4e94d5.tar.gz emacs-7cc233e1e3da297882c006c1f07c628fbd4e94d5.tar.bz2 emacs-7cc233e1e3da297882c006c1f07c628fbd4e94d5.zip |
* lisp/emacs-lisp/package.el: Fix a decoding issue
(package--with-response-buffer): Use `url-insert-buffer-contents'.
The previous code had some issues with decoding. Refactoring that
function allows us to use the decoding from url-handlers while still
treating both sync and async requests the same.
* lisp/url/url-handlers.el (url-insert-file-contents): Move some code to
`url-insert-buffer-contents'.
(url-insert-buffer-contents): New function
Diffstat (limited to 'lisp/url/url-handlers.el')
-rw-r--r-- | lisp/url/url-handlers.el | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/lisp/url/url-handlers.el b/lisp/url/url-handlers.el index a5d9f37b5ee..bafe3e52725 100644 --- a/lisp/url/url-handlers.el +++ b/lisp/url/url-handlers.el @@ -309,6 +309,29 @@ They count bytes from the beginning of the body." (defvar url-http-codes) +(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))))) + ;;;###autoload (defun url-insert-file-contents (url &optional visit beg end replace) (let ((buffer (url-retrieve-synchronously url))) @@ -323,24 +346,7 @@ They count bytes from the beginning of the body." (kill-buffer buffer) ;; Signal file-error per http://debbugs.gnu.org/16733. (signal 'file-error (list url desc)))))) - (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 start (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)))))) + (url-insert-buffer-contents buffer url visit beg end replace))) (put 'insert-file-contents 'url-file-handlers 'url-insert-file-contents) |