Please help me keep url-retrieve from spamming my *Messages* buffer.
Jason Martens <[email protected]>
| Newsgroups | gmane.emacs.devel |
|---|---|
| Message-ID | <CAK6x1F1-m8U2nN=F=V5bxvParXgzrmvNoD426A8jvxcKH1eBEw@mail.gmail.com> |
Hello all,
So, I have this script which fetchs JSON data at 30 second intervals using
url-retrieve, and I keep receiving the message 'Contacting host:
www.radiofrance.fr:443' in the minibuffer at every poll. It happens _just_
often enough to be distracting.
I tried to silence it by setting SILENT in url-retrieve and tryint to
rebind `url-lazy-message' with cl-letf, but she no work. This happens in
both 30.2 and 31.0.90. 31 is a few weeks, old, though.
Is there a supported way to suppress the connection messages? I'd like to
allow error messages to still go through, but beggars can't be choosers.
Here's the function (and flame away if you want, I'm still learning
emacs-lisp);
(defun fip-radio--fetch-json ()
"Fetch live metadata from the Radio France API for the current station."
(interactive)
(let* ((station-meta (cdr (assoc fip-radio--current-station
fip-radio-stations)))
(station-id (cdr (assoc 'id station-meta))))
(cond
((not station-id)
(message "FIP Radio: No station ID found for %s"
fip-radio--current-station))
((string-equal station-id "non")
(fip-radio--display-no-metadata-buffer))
;; Now we can fetch.
(t
(let ((url (format "https://api.radiofrance.fr/livemeta/pull/%s"
station-id)))
(cl-letf (((symbol-function #'url-lazy-message)
(lambda (&rest _) nil)))
(url-retrieve
url
(lambda (status)
(unwind-protect
(unless (plist-get status :error)
(goto-char (point-min))
(re-search-forward "^$" nil 'move)
(let* ((raw-json
(buffer-substring-no-properties
(point) (point-max)))
(decoded-json
(decode-coding-string raw-json 'utf-8))
(track-data
(fip-radio--parse-now-playing decoded-json)))
(when track-data
(fip-radio--process-track-data track-data))))
(kill-buffer (current-buffer))))
nil t nil)))))))
--
Jason Martens
[email protected]