For this, I use the [[https://github.com/tkf/emacs-request][request]] package (and I’ll use this elsewhere too) and the =dashboard= project (defined below) will incorporate it:
#+begin_src emacs-lisp
(use-package request
:init
(defvar ha-dad-joke nil "Holds the latest dad joke.")
:config
(defun ha-dad-joke ()
"Display a random dad joke."
(interactive)
(message (ha--dad-joke)))
(defun ha--dad-joke ()
"Return string containing a dad joke from www.icanhazdadjoke.com."
(setq ha-dad-joke nil) ; Clear out old joke
(ha--dad-joke-request)
(ha--dad-joke-wait))
(defun ha--dad-joke-wait ()
(while (not ha-dad-joke)
(sit-for 1))
(unless ha-dad-joke
(ha--dad-joke-wait))
ha-dad-joke)
(defun ha--dad-joke-request ()
(request "https://icanhazdadjoke.com"
:sync t
:complete (cl-function
(lambda (&key data &allow-other-keys)
(setq ha-dad-joke data))))))
#+end_src
** Dashboard
The [[https://github.com/emacs-dashboard/emacs-dashboard][emacs-dashboard]] project makes a nicer startup screen.
Simple function to display a file in the top-right corner (if the file exists):
#+begin_src emacs-lisp
(defun ha-show-learn-this ()
""
(interactive)
(let ((filename "~/other/hamacs/learn-this.org")
(curr-win (get-buffer-window (buffer-name))))
(when (file-exists-p filename)
(split-window-below 15)
(select-window curr-win)
(find-file filename))))
#+end_src
* Altogether
The =dashboard= project hooks to [[help:emacs-startup-hook][emacs-startup-hook]] and this =ha-dashboard= function hooks to dashboard’s [[help:dashboard-after-initialize-hook][dashboard-after-initialize-hook]]:
#+begin_src emacs-lisp
(defun ha-dashboard ()
"Shows the extra stuff with the dashboard."
(interactive)
(let ((width (thread-first (window-total-width)
(/ 3)
(* 2))))
(split-window-right width)
(cheatsheet-show)
(ha-show-learn-this)))
#+end_src
* Technical Artifacts :noexport:
Let's =provide= a name so we can =require= this file:
#+begin_src emacs-lisp :exports none
(provide 'ha-dashboard)
;;; ha-dashboard.el ends here
#+end_src
#+DESCRIPTION: configuring Emacs to show a startup screen.
#+PROPERTY: header-args:sh :tangle no
#+PROPERTY: header-args:emacs-lisp :tangle yes
#+PROPERTY: header-args :results none :eval no-export :comments no mkdirp yes