Make the dashboard wiki page loading asynchronous
This commit is contained in:
parent
b6ae70a86b
commit
1f92565b73
1 changed files with 24 additions and 15 deletions
|
@ -43,21 +43,30 @@
|
|||
(dashboard-insert-heading "Today's Wiki page:" "w")
|
||||
(insert "\n ")
|
||||
(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")
|
||||
(prog1 (cons (url-recreate-url url-current-object)
|
||||
(let ((text-beginning-marker (point-marker)))
|
||||
(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
|
||||
(search-forward "<title>")
|
||||
(let ((beginning (point)))
|
||||
(search-forward "</title>")
|
||||
(forward-char -8)
|
||||
(buffer-substring-no-properties beginning (point)))))
|
||||
(kill-buffer)))))
|
||||
(message "Got: %s" info)
|
||||
(kill-buffer))))
|
||||
(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
|
||||
:format (format "%%[%s%%]" (cdr info))
|
||||
:button-suffix ""
|
||||
: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-items '(random-wiki-page))
|
||||
|
|
Loading…
Reference in a new issue