From b6ae70a86b73ca9e0cce114232c02c317385dd67 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 12 Oct 2023 21:59:45 -0700 Subject: [PATCH] Add a random EmacsWiki page to my dashboard --- oni/home/services/emacs/oni-dashboard.el | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/oni/home/services/emacs/oni-dashboard.el b/oni/home/services/emacs/oni-dashboard.el index a0a1767..b08be37 100644 --- a/oni/home/services/emacs/oni-dashboard.el +++ b/oni/home/services/emacs/oni-dashboard.el @@ -38,6 +38,29 @@ :button-suffix "" (string-trim-right (car element))))) +(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 ((info (with-current-buffer (url-retrieve-synchronously "https://www.emacswiki.org/emacs?action=random") + (prog1 (cons (url-recreate-url url-current-object) + (progn + (search-forward "") + (let ((beginning (point))) + (search-forward "") + (forward-char -8) + (buffer-substring-no-properties beginning (point))))) + (kill-buffer))))) + (message "Got: %s" info) + (widget-create 'url-link + :format (format "%%[%s%%]" (cdr info)) + :button-suffix "" + :button-prefix "" + (car info)))) + +(add-to-list 'dashboard-item-generators '(random-wiki-page . oni-dashboard-insert-random-wiki-page)) +(add-to-list 'dashboard-items '(random-wiki-page)) (require 'org-roam) (add-to-list 'dashboard-item-generators '(random-note . oni-dashboard-insert-random-note)) (add-to-list 'dashboard-items '(random-note))