[Emacs] Generalize kat's org-mode journal system so I can use it too

This commit is contained in:
2025-01-02 16:07:08 -07:00
parent 05e135d61d
commit 718cf756b9
2 changed files with 49 additions and 34 deletions

View File

@@ -58,41 +58,11 @@ This makes evil-mode play nice with org-fc
(file+datetree "~/org/weekly_reviews.org")
(file "~/org/weekly_review_template.org")))))
#+end_src
** Daily Journal Entries
** Journal
#+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)
(setq imalison:journal-template-filepath
(imalison:join-paths org-directory "templates" "daily-journal-template.org"))
#+end_src
** Insert a link to a task selected from agenda
#+begin_src emacs-lisp
(defun imalison:insert-link-to-agenda ()

View File

@@ -594,6 +594,43 @@ specific time, they should appear in the agenda at that time!
(defun imalison:make-org-linked-todo-template ()
(imalison:make-org-todo-template "[#C] %? %A"))
#+end_src
*** Journal
#+begin_src emacs-lisp :tangle org-config-config.el
(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")))
(defvar imalison:journal-template-filepath
(imalison:join-paths org-directory "capture-templates" "journal.org"))
(defun imalison:get-journal-template ()
(with-temp-buffer
(insert-file-contents imalison:journal-template-filepath)
(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
*** Templates
#+begin_src emacs-lisp :tangle org-config-config.el
(use-package org-capture
@@ -632,7 +669,15 @@ SCHEDULED: %^t
:PROPERTIES:
:CREATED: %U
:STYLE: habit
:END:")))
:END:"))
(add-to-list 'org-capture-templates
'("w" "Weekly Planning and Self Assesment"
plain
(function (lambda ()
(find-file (let ((date (format-time-string "%Y-%m-%d")))
(expand-file-name (concat date ".org")
"~/org/weekly")))))
(file "~/org/capture-templates/weekly.org"))))
#+end_src
** Babel
#+begin_src emacs-lisp :tangle org-config-config.el