Dashboard can display images on startup. I was wondering how would I give it latest xkcd comic from xkcd-mode?
Asked
Active
Viewed 402 times
3
-
1What's "dashboard" ? – phils Feb 09 '19 at 03:49
-
if [this](https://github.com/rakanalh/emacs-dashboard) what you mean, it's better to ask that feature (or hints to implement) from the maintainer. – azzamsa Feb 09 '19 at 10:56
-
@phils dashboard is a startup screen that allows you to customize what you want to see on start up (recent projectile projects, files, agenda, etc.) [source](https://github.com/rakanalh/emacs-dashboard) – A_P Feb 11 '19 at 15:26
1 Answers
5
xkcd-mode
uses ~/.emacs.d/xkcd/
to cache the images, xkcd-cache-dir
.
So, you just need to set dashboard image variable, dashboard-banner-official-png
, as the last cached image, xkcd-latest
, and consider that dashboard only accepts png images.
(require 'xkcd)
;; to update cached xkcd
(with-temp-buffer
(xkcd)
(xkcd-kill-buffer))
;; setting dashboard image (png)
(let ((last-xkcd-png (concat xkcd-cache-dir (number-to-string xkcd-latest) ".png")))
(if (file-exists-p last-xkcd-png)
(setq dashboard-banner-official-png last-xkcd-png)))
If you want to get random xkcd comic, you can use:
(require 'xkcd)
;; to get a rand comic and to set dashboard image (png)
(let ((rand-id-xkcd nil))
(with-temp-buffer
(setq rand-id-xkcd (string-to-number (xkcd-rand)))
(xkcd-kill-buffer))
(let ((last-xkcd-png (concat xkcd-cache-dir (number-to-string rand-id-xkcd) ".png")))
(if (file-exists-p last-xkcd-png)
(setq dashboard-banner-official-png last-xkcd-png))))
If you also want to change dashboard text below the image, dashboard-banner-logo-title
, just change (xkcd)
for (setq dashboard-banner-logo-title (xkcd))
or (setq rand-id-xkcd (string-to-number (xkcd-rand)))
for (setq rand-id-xkcd (string-to-number (setq dashboard-banner-logo-title (xkcd-rand))))
.
Don't forget to put this after dashboard config in your init file.

adl
- 636
- 3
- 6
-
I had to change `(setq dashboard-banner-official-png last-xkcd-png)`to `(setq dashboard-startup-banner last-xkcd-png)` to get it working. – lukascbossert May 23 '21 at 21:56