11 March 2025 8:00 AM (emacs)
I really enjoy reading the EmacsWiki. It helped me a lot when I first started using Emacs. It's a great resource with so much information.
Since it's been so important to me I figured I should look at some pages and if there was anything I could update, contribute. To help with this I wanted to show a random page on my Emacs Dashboard. Thankfully the EmacsWiki has a nice function for this: Random Page.
I've incorporated this into a widget for my dashboard:
(defun oni-dashboard-insert-random-wiki-page (_) "Insert a link to a random Emacs Wiki page." (dashboard-insert-heading "Today's Wiki page:" "w") (insert "\n ") (dashboard-insert-shortcut 'random-wiki-page "w" "Today's Wiki page:") (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)))) (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))))))) 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))
Now every time I load the dashboard (generally once per day) a wiki page url and title are asynchronously loaded and shown. It'll also show Loading...
while it's doing its work so I know it's doing something, and because it's asynchronous it doesn't cause my session to block while waiting for the wiki to respond. That last part was especially nice when EmacsWiki went down for a few days due to increased levels of bots trying to crawl the site.
It's very messy, I should clean it up.