3

Dashboard can display images on startup. I was wondering how would I give it latest xkcd comic from xkcd-mode?

3
  • 1
    What's "dashboard" ?
    – phils
    Feb 9, 2019 at 3:49
  • if this what you mean, it's better to ask that feature (or hints to implement) from the maintainer.
    – azzamsa
    Feb 9, 2019 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
    – A_P
    Feb 11, 2019 at 15:26

1 Answer 1

6

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.

1
  • I had to change (setq dashboard-banner-official-png last-xkcd-png)to (setq dashboard-startup-banner last-xkcd-png) to get it working. May 23, 2021 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.