Improve how url-http displays status messages

* lisp/url/url-util.el (url-display-message): New function.
(url-display-percentage): Make obsolete in favor of
url-display-message.

* lisp/url/url-http.el
(url-http-content-length-after-change-function):
Prefer 'url-display-message' to 'url-display-percentage'.
(url-http-content-length-after-change-function)
(url-http-chunked-encoding-after-change-function):
Remove ineffectual calls to 'url-display-percentage'.
This commit is contained in:
Stefan Kangas 2022-08-07 13:14:20 +02:00
parent 91f4ea2fa4
commit 321f33a2b1
2 changed files with 9 additions and 16 deletions

View file

@ -1046,19 +1046,15 @@ More sophisticated percentage downloaded, etc.
Also does minimal parsing of HTTP headers and will actually cause
the callback to be triggered."
(if url-http-content-type
(url-display-percentage
(url-display-message
"Reading [%s]... %s of %s (%d%%)"
(url-percentage (- nd url-http-end-of-headers)
url-http-content-length)
url-http-content-type
(funcall byte-count-to-string-function (- nd url-http-end-of-headers))
(funcall byte-count-to-string-function url-http-content-length)
(url-percentage (- nd url-http-end-of-headers)
url-http-content-length))
(url-display-percentage
(url-display-message
"Reading... %s of %s (%d%%)"
(url-percentage (- nd url-http-end-of-headers)
url-http-content-length)
(funcall byte-count-to-string-function (- nd url-http-end-of-headers))
(funcall byte-count-to-string-function url-http-content-length)
(url-percentage (- nd url-http-end-of-headers)
@ -1067,7 +1063,6 @@ the callback to be triggered."
(if (> (- nd url-http-end-of-headers) url-http-content-length)
(progn
;; Found the end of the document! Wheee!
(url-display-percentage nil nil)
(url-lazy-message "Reading... done.")
(if (url-http-parse-headers)
(url-http-activate-callback)))))
@ -1097,13 +1092,6 @@ the end of the document."
;; one after-change-function call.
(while read-next-chunk
(setq no-initial-crlf (= 0 url-http-chunked-counter))
(if url-http-content-type
(url-display-percentage nil
"Reading [%s]... chunk #%d"
url-http-content-type url-http-chunked-counter)
(url-display-percentage nil
"Reading... chunk #%d"
url-http-chunked-counter))
(url-http-debug "Reading chunk %d (%d %d %d)"
url-http-chunked-counter st nd length)
(setq regexp (if no-initial-crlf
@ -1161,7 +1149,6 @@ the end of the document."
;; Found the end of the document! Wheee!
(url-http-debug "Saw end of stream chunk!")
(setq read-next-chunk nil)
(url-display-percentage nil nil)
;; Every chunk, even the last 0-length one, is
;; terminated by CRLF. Skip it.
(if (not (looking-at "\r?\n"))

View file

@ -189,12 +189,18 @@ Will not do anything if `url-show-status' is nil."
'file-size-human-readable "24.4")
;;;###autoload
(defun url-display-percentage (fmt _perc &rest args)
(defun url-display-message (fmt &rest args)
"Like `message', but do nothing if `url-show-status' is nil."
(when (and url-show-status
(not (and url-current-object (url-silent url-current-object)))
fmt)
(apply #'message fmt args)))
;;;###autoload
(defun url-display-percentage (fmt _perc &rest args)
(declare (obsolete url-display-message "29.1"))
(url-display-message fmt args))
;;;###autoload
(defun url-percentage (x y)
(round (* 100 (/ x (float y)))))