I'm trying to make a 'class' template for org-capture.
What I want is to easily make this kind of entry:
* TODO <course>: Week <week> Lecture <number>
SCHEDULED: %^T
** TODO prepare for class: <course>-<week>-<number>
SCHEDULED: <two days before T> DEADLINE: <one day before T>
** TODO review class: <course>-<week>-<number>
SCHEDULED: <one day after T> DEADLINE: <two days after T>
Currently, I have this template.
(setq org-capture-templates
'(
("c" "Class" entry (file "~/sydbox/personal/workflow/class.txt")
"* TODO %^{Course}: Week %^{Week} Lecture %^{Number}\n SCHEDULED: %(org-insert-time-stamp (org-read-date nil t nil nil nil \" \"))\n location: %^{location} %?\n** TODO %\\1: prepare lecture %\\3 from week %\\2\n DEADLINE: %(org-insert-time-stamp (org-read-date nil t \"-1d\")) SCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"-2d\"))\n** TODO %\\1: review lecture %\\3 from week %\\2\n DEADLINE: %(org-insert-time-stamp (org-read-date nil t \"+2d\")) SCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+1d\"))\n")
("e" "Exercise session" entry (file "~/sydbox/personal/workflow/class.txt")
))
However, now I have no idea how to input the dates. The date and time of the course should be prompted for (_only_once_).
The following code works for me. It first defines a custom function to create the template (org-capture-class
), which calculates the date as necessary and is easier on the eyes than the in-line string (note that it relies on cl-lib
, so make sure that's loaded). It then calls that function in the template itself, niling out if any of the fields are empty (updated in response to comment):
(defun org-capture-class ()
"Capture a class template for org-capture."
(cl-labels ((update (date days)
(format-time-string
(car org-time-stamp-formats)
(seconds-to-time (+ (time-to-seconds date)
(* days 86400))))))
(let ((course (read-string "Course: " nil nil '(nil)))
(week (read-string "Week: " nil nil '(nil)))
(lecture (read-string "Lecture No.: " nil nil '(nil)))
(date (org-read-date nil t))
(location (read-string "Location: " nil nil '(nil))))
(when (and course week lecture date location)
(concat (format "* TODO %s: Week %s Lecture %s\n"
course week lecture)
(format " SCHEDULED: %s\n" (update date 0))
(format " Location: %s %%?\n" location)
(format "** TODO %s: prepare lecture %s from week %s\n"
course lecture week)
(format " DEADLINE: %s SCHEDULED: %s\n"
(update date -1) (update date -2))
(format "** TODO %s: review lecture %s from week %s\n"
course lecture week)
(format " DEADLINE: %s SCHEDULED: %s\n"
(update date 2) (update date 1)))))))
(setq org-capture-templates
'(("c" "Class" entry
(file "~/sydbox/personal/workflow/class.txt")
#'org-capture-class)
("e" "Exercise session" entry
(file "~/sydbox/personal/workflow/class.txt"))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With