Taking org-agenda documentation to the next level
For those of you that use org-agenda, and have likewise lost your minds w.r.t. life documentation (I'm right there with you), I wrote a function to save my agenda buffer on the first opening per day. That way, I can refer to my agenda from a given day and look back at what I was doing for work/life when I'm 80.
The function saves to a designated directory, and I put a 0.1 second wait on it because without that the buffer was getting saved before it was populated, leading to empty files.
#+begin_src emacs-lisp
;; Save agenda to archive when opening for the first time in a day
(defun my/save-agenda-on-open ()
"Save the current agenda as an org file in the `~/org/agenda_archive/' directory when opened.
If the file for the current date already exists, do nothing."
(let* ((date (format-time-string "%Y%m%d")) ; Format the date as YYYYMMDD
(file-name (concat "~/org/agenda_archive/agenda_" date ".org"))) ; Create file name
(unless (file-exists-p file-name) ; Check if the file already exists
(run-at-time "0.1 sec" nil ; Schedule the save function to run after a short delay
(lambda ()
(with-current-buffer (current-buffer) ; Write to the current agenda buffer
(write-region (point-min) (point-max) file-name))))))) ; Save contents to file
(add-hook 'org-agenda-mode-hook 'my/save-agenda-on-open) ; Run on agenda open
#+end_src
If anyone knows how I might be able to save these agendas so that I can re-open them with the agenda formatting/text highlighting for things like habits and keywords (rather than just as an org buffer) that would be amazing!
Any feedback on this would be very much appreciated - I'm a physicist, not a programmer.