Commit 2a570576 authored by Stefan Monnier's avatar Stefan Monnier

* lisp/emacs-lisp/package.el: Reduce macrology in ...with-response-buffer

(package--with-response-buffer-1): New function, extracted from
package--with-response-buffer.
(package--with-response-buffer): Use it.
parent 3dcacb09
Pipeline #1726 failed with stage
in 50 minutes and 16 seconds
...@@ -1197,45 +1197,48 @@ errors signaled by ERROR-FORM or by BODY). ...@@ -1197,45 +1197,48 @@ errors signaled by ERROR-FORM or by BODY).
(declare (indent defun) (debug t)) (declare (indent defun) (debug t))
(while (keywordp (car body)) (while (keywordp (car body))
(setq body (cdr (cdr body)))) (setq body (cdr (cdr body))))
(macroexp-let2* nil ((url-1 url) `(package--with-response-buffer-1 ,url (lambda () ,@body)
(noerror-1 noerror)) :file ,file
(let ((url-sym (make-symbol "url")) :async ,async
(b-sym (make-symbol "b-sym"))) :error-function (lambda () ,error-form)
`(cl-macrolet ((unless-error (body-2 &rest before-body) :noerror ,noerror))
(let ((err (make-symbol "err")))
`(with-temp-buffer (cl-defun package--with-response-buffer-1 (url body &key async file error-function noerror &allow-other-keys)
(when (condition-case ,err (cl-macrolet ((unless-error (body &rest before-body)
(progn ,@before-body t) (let ((err (make-symbol "err")))
,(list 'error ',error-form `(with-temp-buffer
(list 'unless ',noerror-1 (when (condition-case ,err
`(signal (car ,err) (cdr ,err))))) (progn ,@before-body t)
,@body-2))))) (error (funcall error-function)
(if (string-match-p "\\`https?:" ,url-1) (unless noerror
(let ((,url-sym (concat ,url-1 ,file))) (signal (car ,err) (cdr ,err)))))
(if ,async (funcall ,body))))))
(unless-error nil (if (string-match-p "\\`https?:" url)
(url-retrieve ,url-sym (let ((url (concat url file)))
(lambda (status) (if async
(let ((,b-sym (current-buffer))) (unless-error #'ignore
(require 'url-handlers) (url-retrieve url
(unless-error ,body (lambda (status)
(when-let* ((er (plist-get status :error))) (let ((b (current-buffer)))
(error "Error retrieving: %s %S" ,url-sym er)) (require 'url-handlers)
(with-current-buffer ,b-sym (unless-error body
(goto-char (point-min)) (when-let* ((er (plist-get status :error)))
(unless (search-forward-regexp "^\r?\n\r?" nil 'noerror) (error "Error retrieving: %s %S" url er))
(error "Error retrieving: %s %S" ,url-sym "incomprehensible buffer"))) (with-current-buffer b
(url-insert-buffer-contents ,b-sym ,url-sym) (goto-char (point-min))
(kill-buffer ,b-sym) (unless (search-forward-regexp "^\r?\n\r?" nil 'noerror)
(goto-char (point-min))))) (error "Error retrieving: %s %S" url "incomprehensible buffer")))
nil (url-insert-buffer-contents b url)
'silent)) (kill-buffer b)
(unless-error ,body (url-insert-file-contents ,url-sym)))) (goto-char (point-min)))))
(unless-error ,body nil
(let ((url (expand-file-name ,file ,url-1))) 'silent))
(unless (file-name-absolute-p url) (unless-error body (url-insert-file-contents url))))
(error "Location %s is not a url nor an absolute file name" url)) (unless-error body
(insert-file-contents url)))))))) (let ((url (expand-file-name file url)))
(unless (file-name-absolute-p url)
(error "Location %s is not a url nor an absolute file name" url))
(insert-file-contents url))))))
(define-error 'bad-signature "Failed to verify signature") (define-error 'bad-signature "Failed to verify signature")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment