2

Complete novice here to Emacs and OrgMode. I've created a capture template (.txt file) that takes 1 task and returns a list of 3 subtasks that need to be completed. I have been able to get the template to request a schedule date for the subtask 1 using %^t.

Subtask 2 should be scheduled for the day following the first subtask. Is there a way of doing this simply in the .txt file? I've scoured the internet and tried various tricks but to no avail. I haven't yet figured out a way of making the date a variable and then modifying it in the .txt file. Here is the code currently in the .txt file:

* TODO %^{Task Name?}
** TODO SubTask 1
   SCHEDULED: %^{When schedule Subtask 1?}t
** TODO SubTask 2
   SCHEDULED: ;;would like this to be subtask1 date + 1 d;;
** TODO SubTask 3 

Any help would be much appreciated - Thanks in advance!

2

This seems to work:

* TODO %^{Task Name?}
** TODO SubTask 1
   SCHEDULED: %(org-insert-time-stamp (org-read-date nil t nil "When schedule Subtask 1?"))
** TODO SubTask 2
   SCHEDULED: %(org-insert-time-stamp (time-add (org-read-date nil t org-last-inserted-timestamp) (days-to-time 1)))
** TODO SubTask 3 

Uses %(EXP) to evaluate an elisp expression EXP and replace it with the result. The first expressions prompts you for a date and inserts it. The seconds expressions uses the last inserted time stamp and adds one day.

You could also bind the time to a variable (my-date) locally and use that:

* TODO %^{Task Name?}
** TODO SubTask 1
   SCHEDULED: %(progn (setq-local my-date (org-read-date nil t nil "When schedule Subtask 1?")) (org-insert-time-stamp my-date))
** TODO SubTask 2
   SCHEDULED: %(org-insert-time-stamp (time-add my-date (days-to-time 1)))
** TODO SubTask 3 

In the first expression it prompts for a date with org-read-date and bind it to my-date locally. Then it inserts the time timestamp. In the second expression one day is added to the time tuple bound to my-date and inserted as time stamp.

  • Heyo - thanks for helping out! Both of these above solutions produce the following: SCHEDULED: %![Error: (void-variable "When)] Any idea why I'm getting a void-variable? – kozina_adjacent Jul 23 at 8:05
  • Fantastic! Works like a charm. I'm guessing %(EXP) are evaluated first before anything else in the text file? – kozina_adjacent Jul 23 at 8:40
  • @user93377 From documentation "Since this happens after expanding non-interactive “%-escapes”, those can be used to fill the expression.". Non-interactive probably means without prompting in this context. This would mean after non-prompting and before prompting expansions. – Hubisan Jul 23 at 8:54
  • So I'd have to write another %(EXP) phrase above if I wanted the "What's the name of this Task" asked first, I'm guessing. – kozina_adjacent Jul 23 at 9:13
  • Try it with %(read-string "Task Name? ") instead of %^{Task Name?}. – Hubisan Jul 23 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.