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
Steps
- 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))
- 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")
- Modify one of your Org agenda files specified in #1, e.g.,
/tmp/test.org
:* Calendar %%(diary-sunrise-sunset)
- Save/reload your init file, then execute
M-x org-agenda
, pressa
. 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