Emacs and Astrobotany (publ. 2024-06-21)
I gave Astrobotany a try this last week. It is kind of fun, but I quickly realized I didn't want to manually water my plant each day. Emacs to the rescue! First I needed a function to water the plant:
(defun water-plant ()
(interactive)
(message "watering plant")
(start-process "gmni" nil "gmni"
"-I"
"-E" (concat plant-cert ":" plant-key)
"gemini://astrobotany.mozz.us/app/plant/water"))
This requires gmni to be installed. It uses the appropriate cert and key from the corresponding identity generated by lagrange.
(defvar plant-cert "/home/christopher/.config/lagrange/idents/<snip>.crt")
(defvar plant-key "/home/christopher/.config/lagrange/idents/<snip>.key")
Emacs has a timer library, so I just need some code in the init.el to start a timer:
(run-at-time "04:00" 86400 'water-plant)
That will run at 4am every morning so long as Emacs is running, which for me is pretty much 24x7. There is an oddity in the design of run-at-time, such that if the time of day is already past 4am when run-at-time is called (i.e., when the init.el file is loaded) then water-plant will immediately be run once. So the plant gets an extra watering every time I restart Emacs. But fortunately in Astrobotany watering attempts are automatically cancelled if the plant is already 100% hydrated.
Here are the public links to my plant:
Your plant
Your plant (with color)
I also wrote a little function to view the plant inside Emacs, so that I wouldn't have to bother switching over to Lagrange:
(defun view-plant ()
(interactive)
(get-buffer-create "*plant*")
(with-current-buffer "*plant*" (erase-buffer))
(call-process "gmni" nil "*plant*" nil
"-E" (concat plant-cert ":" plant-key)
"gemini://astrobotany.mozz.us/app/plant")
(switch-to-buffer "*plant*")
(goto-line 29 "*plant*")
(view-mode t))
The lines at the end basically scroll down a bit to get the plant in view, and then it switches the buffer over to view-mode so I can just press "q" to close the buffer.
Copyright
This work © 2024 by Christopher Howard is licensed under Attribution-ShareAlike 4.0 International.
CC BY-SA 4.0 Deed