Make the dashboard wiki page loading asynchronous

This commit is contained in:
Tom Willemse 2023-10-13 14:43:15 -07:00
parent b6ae70a86b
commit 1f92565b73

View file

@ -43,21 +43,30 @@
(dashboard-insert-heading "Today's Wiki page:" "w") (dashboard-insert-heading "Today's Wiki page:" "w")
(insert "\n ") (insert "\n ")
(dashboard-insert-shortcut 'random-wiki-page "w" "Today's Wiki page:") (dashboard-insert-shortcut 'random-wiki-page "w" "Today's Wiki page:")
(let ((info (with-current-buffer (url-retrieve-synchronously "https://www.emacswiki.org/emacs?action=random") (let ((text-beginning-marker (point-marker)))
(prog1 (cons (url-recreate-url url-current-object) (insert "Loading...")
(url-retrieve "https://www.emacswiki.org/emacs?action=random"
(lambda (&rest _args)
(let ((info (prog1 (cons (url-recreate-url url-current-object)
(progn (progn
(search-forward "<title>") (search-forward "<title>")
(let ((beginning (point))) (let ((beginning (point)))
(search-forward "</title>") (search-forward "</title>")
(forward-char -8) (forward-char -8)
(buffer-substring-no-properties beginning (point))))) (buffer-substring-no-properties beginning (point)))))
(kill-buffer))))) (kill-buffer))))
(message "Got: %s" info) (with-current-buffer (marker-buffer text-beginning-marker)
(let ((inhibit-read-only t))
(save-excursion
(goto-char (marker-position text-beginning-marker))
(delete-char 10)
(widget-create 'url-link (widget-create 'url-link
:format (format "%%[%s%%]" (cdr info)) :format (format "%%[%s%%]" (cdr info))
:button-suffix "" :button-suffix ""
:button-prefix "" :button-prefix ""
(car info)))) (car info)))))))
nil
t)))
(add-to-list 'dashboard-item-generators '(random-wiki-page . oni-dashboard-insert-random-wiki-page)) (add-to-list 'dashboard-item-generators '(random-wiki-page . oni-dashboard-insert-random-wiki-page))
(add-to-list 'dashboard-items '(random-wiki-page)) (add-to-list 'dashboard-items '(random-wiki-page))