Jon-Michael Deldin

BMX, bike trials, & software from the Pacific Northwest

Showing sunrise and sunset information in Emacs

As days get shorter and shorter, I find myself wondering when the sun will set at whichever skatepark I plan on visiting. In the past, Googling “sunrise|sunset <location>” sufficed, but I wanted something that ran locally and automatically on my Linux machine, and like any Emacs user, I wanted it to run inside Emacs. As it turns out, this functionality is already built into Emacs’ diary feature.

The finished product

Screenshot of Emacs showing sunrise and sunset times in an agenda buffer.
The Pacific Northwest certainly has its perks, but short, gray days are not one of them.


  1. If you haven’t set Org-mode up already, you should edit your ~/.emacs.d/init.el and add the following lines:
    (setq org-directory "/tmp/org")
    (setq org-agenda-files (file-expand-wildcards org-directory))
  2. Specify your latitude and longitude in the next chunk. You can use Google Maps or LatLong to find out:
    (setq calendar-latitude 47.9790)
    (setq calendar-longitude -122.2021)
    (setq calendar-location-name "Everett, WA")
  3. Modify one of your Org agenda files specified in #1, e.g., /tmp/
    * Calendar
  4. Save/reload your init file, then execute M-x org-agenda, press a. Tip: To see the sunrise/sunset times for the entire year (and to get depressed about winter): M-x org-agenda RET a v y
* * *