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

  • 1
    What's "dashboard" ? – phils Feb 9 '19 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 '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 – A_P Feb 11 '19 at 15:26

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

;; 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))
    (setq rand-id-xkcd (string-to-number (xkcd-rand)))
  (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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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