aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Malabarba2015-11-15 21:28:37 +0000
committerArtur Malabarba2015-11-15 21:35:06 +0000
commit7cc233e1e3da297882c006c1f07c628fbd4e94d5 (patch)
tree569440df0ffd3eb688c5956a7d6354b1f83f1713
parent5f9153faaf767a039620a0a05a8ad0373cb24070 (diff)
downloademacs-7cc233e1e3da297882c006c1f07c628fbd4e94d5.tar.gz
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
-rw-r--r--lisp/emacs-lisp/package.el16
-rw-r--r--lisp/url/url-handlers.el42
2 files changed, 32 insertions, 26 deletions
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index fba07a6801e..d811db9579f 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1165,16 +1165,16 @@ BODY (does not apply to errors signaled by ERROR-FORM).
1165 (when-let ((er (plist-get status :error))) 1165 (when-let ((er (plist-get status :error)))
1166 (error "Error retrieving: %s %S" url er)) 1166 (error "Error retrieving: %s %S" url er))
1167 (unless (search-forward-regexp "^\r?\n\r?" nil 'noerror) 1167 (unless (search-forward-regexp "^\r?\n\r?" nil 'noerror)
1168 (rest-error 'rest-unintelligible-result)) 1168 (error "Error retrieving: %s %S" url "incomprehensible buffer"))
1169 (delete-region (point-min) (point)) 1169 (with-temp-buffer
1170 ,@body) 1170 (url-insert-buffer-contents b url)
1171 (when (buffer-live-p b) 1171 (kill-buffer b)
1172 (kill-buffer b))))))) 1172 (goto-char (point-min))
1173 ,@body)))))))
1173 (if ,async 1174 (if ,async
1174 (wrap-errors (url-retrieve url callback nil 'silent)) 1175 (wrap-errors (url-retrieve url callback nil 'silent))
1175 (let ((buffer (wrap-errors (url-retrieve-synchronously url 'silent)))) 1176 (with-current-buffer (wrap-errors (url-retrieve-synchronously url 'silent))
1176 (with-current-buffer buffer 1177 (funcall callback nil))))
1177 (funcall callback nil)))))
1178 (wrap-errors (with-temp-buffer 1178 (wrap-errors (with-temp-buffer
1179 (let ((url (expand-file-name ,file ,url-1))) 1179 (let ((url (expand-file-name ,file ,url-1)))
1180 (unless (file-name-absolute-p url) 1180 (unless (file-name-absolute-p url)
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."
309 309
310(defvar url-http-codes) 310(defvar url-http-codes)
311 311
312(defun url-insert-buffer-contents (buffer url &optional visit beg end replace)
313 "Insert the contents of BUFFER into current buffer.
314This is like `url-insert', but also decodes the current buffer as
315if it had been inserted from a file named URL."
316 (if visit (setq buffer-file-name url))
317 (save-excursion
318 (let* ((start (point))
319 (size-and-charset (url-insert buffer beg end)))
320 (kill-buffer buffer)
321 (when replace
322 (delete-region (point-min) start)
323 (delete-region (point) (point-max)))
324 (unless (cadr size-and-charset)
325 ;; If the headers don't specify any particular charset, use the
326 ;; usual heuristic/rules that we apply to files.
327 (decode-coding-inserted-region (point-min) (point) url
328 visit beg end replace))
329 (let ((inserted (car size-and-charset)))
330 (when (fboundp 'after-insert-file-set-coding)
331 (let ((insval (after-insert-file-set-coding inserted visit)))
332 (if insval (setq inserted insval))))
333 (list url inserted)))))
334
312;;;###autoload 335;;;###autoload
313(defun url-insert-file-contents (url &optional visit beg end replace) 336(defun url-insert-file-contents (url &optional visit beg end replace)
314 (let ((buffer (url-retrieve-synchronously url))) 337 (let ((buffer (url-retrieve-synchronously url)))
@@ -323,24 +346,7 @@ They count bytes from the beginning of the body."
323 (kill-buffer buffer) 346 (kill-buffer buffer)
324 ;; Signal file-error per http://debbugs.gnu.org/16733. 347 ;; Signal file-error per http://debbugs.gnu.org/16733.
325 (signal 'file-error (list url desc)))))) 348 (signal 'file-error (list url desc))))))
326 (if visit (setq buffer-file-name url)) 349 (url-insert-buffer-contents buffer url visit beg end replace)))
327 (save-excursion
328 (let* ((start (point))
329 (size-and-charset (url-insert buffer beg end)))
330 (kill-buffer buffer)
331 (when replace
332 (delete-region (point-min) start)
333 (delete-region (point) (point-max)))
334 (unless (cadr size-and-charset)
335 ;; If the headers don't specify any particular charset, use the
336 ;; usual heuristic/rules that we apply to files.
337 (decode-coding-inserted-region start (point) url
338 visit beg end replace))
339 (let ((inserted (car size-and-charset)))
340 (when (fboundp 'after-insert-file-set-coding)
341 (let ((insval (after-insert-file-set-coding inserted visit)))
342 (if insval (setq inserted insval))))
343 (list url inserted))))))
344 350
345(put 'insert-file-contents 'url-file-handlers 'url-insert-file-contents) 351(put 'insert-file-contents 'url-file-handlers 'url-insert-file-contents)
346 352