From fe99f45ecf0fdd8ef1c3c36431199a3bb215fbac Mon Sep 17 00:00:00 2001 From: Kat Huang Date: Sat, 26 Aug 2023 14:06:56 -0600 Subject: [PATCH] [Emacs] Add daily journal entry functionality to kat-mode --- dotfiles/emacs.d/kat-mode.org | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/dotfiles/emacs.d/kat-mode.org b/dotfiles/emacs.d/kat-mode.org index 46ba0062..f6f4af5b 100644 --- a/dotfiles/emacs.d/kat-mode.org +++ b/dotfiles/emacs.d/kat-mode.org @@ -63,3 +63,36 @@ This makes evil-mode play nice with org-fc #+begin_src emacs-lisp (auto-save-visited-mode +1) #+end_src +* org daily journal entries +#+begin_src emacs-lisp +(defun imalison:journal-filepath-for-date (&optional date) + (interactive (list (org-read-date))) + (let ((date-str (or date (format-time-string "%Y-%m-%d")))) + (imalison:join-paths + org-directory "journal" (concat date-str ".org")))) + +(defun imalison:open-todays-org-journal () + (interactive) + (imalison:open-org-journal (format-time-string "%Y-%m-%d"))) + +(defun imalison:get-journal-template () + (with-temp-buffer + (insert-file-contents (imalison:join-paths org-directory "templates" "daily-journal-template.org")) + (buffer-string))) + +(defun imalison:open-org-journal (&optional date) + (interactive (list (org-read-date nil nil nil "Select a date:"))) + (let* ((filepath (imalison:journal-filepath-for-date date)) + (file-existed (file-exists-p filepath)) + (date-str (or date (format-time-string "%Y-%m-%d"))) + (time-vals (append '(0 0 0) (nthcdr 3 (parse-time-string date-str)))) + (original-format-time-string (symbol-function 'format-time-string))) + (find-file filepath) + (when (not file-existed) + (cl-letf (((symbol-function 'format-time-string) + (lambda (format-string &optional _time _universal) + (funcall original-format-time-string format-string (apply #'encode-time time-vals))))) + (insert (org-capture-fill-template (imalison:get-journal-template))))))) + +(bind-key "C-c j" 'imalison:open-todays-org-journal) +#+end_src