4

I would like to use org-capture to quickly store appointments in a journal file, and add a timestamp so that the appointment appears in my agenda. I'm using the following template:

;; excerpted from my .emacs-custom.el
(custom-set-variables
  '(org-capture-templates
        ("a" "Appointment" entry
         (file+olp+datetree "~/org/journal.org")
         "* %?
%T" :time-prompt t))))

This almost works. file+olp+datetree automatically places the new appointment at the correct spot in a date-tree, I am prompted for the actual date and time to use due to :time-prompt t, and the item has a time stamp inserted via the %T in the template.

The only hitch is that if I enter a time range (as for a meeting that will take 30 minutes):

<2019-09-18 Wed 12:30-13:00> 

The time is truncated in my item to:

<2019-09-18 Wed 12:30> 

So I have to manually add the time range myself.

Looking into the source code, it looks like org-capture-set-target-location explicitly cuts off the second part of a time range. That makes sense for the date-tree headings, but it breaks my scheduled timestamp.

Before I start hacking away at the org source code, I wonder if there's a way to accomplish this more directly. Specifically, what I would like:

  1. Get a prompt for a date and time, which could include a time range.
  2. Fill in an org entry, which includes the time I selected as a timestamp.
  3. Store the entry in a date-tree structure in an org file.

What I don't want is to enter the date twice (once for the date-tree, once for the schedule), or to manually fix the date after the entry is created.

To clarify, I want the items stored in a date-tree structure so I can browse through this one file to review my past and coming appointments. I want to add the time stamp so the entries will appear in my org-agenda at the appropriate time and date.

5
  • 1
    I don't use date ranges or even a current version of org-mode for that matter, but the manual includes a second type of date range format such as <2004-08-23 Mon>--<2004-08-26 Thu>. Perhaps that alternative format using two time stamps connected with a two dashes could suffice ....
    – lawlist
    Commented Sep 10, 2019 at 1:43
  • @lawlist I'm not really concerned about the format - your alternative is fine for me. However, the main problem is that with either format I have to manually correct the time after org-capture trims the range off.
    – Tyler
    Commented Sep 10, 2019 at 13:26
  • The following seems to work as you have described: (setq org-capture-templates '(("a" "Appointment" entry (file+olp+datetree "~/org/journal.org") "* %?\n%^t")))
    – lawlist
    Commented Sep 10, 2019 at 16:46
  • @lawlist almost - with that template, I get prompted for the date first, to determine where in the date-tree the entry will go, and then prompted again for the timestamp for the item. I want to enter the date (with time range) once, and have the resulting entry get filed in the date-tree with the correct timestamp.
    – Tyler
    Commented Sep 10, 2019 at 17:43
  • @Tyler It's been a while, but I've been faced with the same question. Did you manage to resolve it? Commented Jun 25, 2022 at 23:43

1 Answer 1

3

I've managed to make a workaround for the same problem, which at least does not require putting the same date twice:

("m" "Meeting" entry (file+datetree "calendar.org")
    ,(concat "* %? :meeting:\n"
             "<%<%Y-%m-%d %a %^{Time}>>")
    :time-prompt t)
  1. The template asks to provide a date for the date tree. Just put the date, w/o time range.
  2. It prompts to enter the "Time". Unfortunately, it isn't validated, just raw text. Enter something like: "11:00-12:00". The nice thing is the rest of the date template will be auto-populated from the previous step.

In the end, we will have a valid timestamp in the proper date tree place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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