From: Stefan Kangas Date: Sun, 7 Aug 2022 11:14:20 +0000 (+0200) Subject: Improve how url-http displays status messages X-Git-Tag: emacs-29.0.90~1447^2~347 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=321f33a2b111c3c0ea1246ffa705d2cc9e8e9242;p=emacs.git 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'. --- diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el index 125f8436f68..94ef156108c 100644 --- a/lisp/url/url-http.el +++ b/lisp/url/url-http.el @@ -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")) diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el index 48ea947faba..147a643c9fd 100644 --- a/lisp/url/url-util.el +++ b/lisp/url/url-util.el @@ -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)))))