4

I can insert a date 2-days from now with:

C c . and then +2 or +2d among many other possibilities.

What is the equivalent for time? What can I use instead of +2d for inserting a date+time in two hours (or whatever other time from now). I tried +2h and +2:00, but no luck.

3

No, not quite. You can type a timestamp with a range in it like 11:30+2 to get <2015-11-10 Tue 11:30-13:30>; perhaps that could suffice.

You could edit (or rather redefine) the function org-read-date-analyze so that it supports "+2h" in addition to "+2d". The function is quite long, so I won't include the whole thing here, but if you look at line 16653 of lisp/org/org.el (at least in my version, might have moved up or down since) you'll see this section:

(deltan
 (setq futurep nil)
 (unless deltadef
   (let ((now (decode-time (current-time))))
     (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
 (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
       ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
       ((equal deltaw "m") (setq month (+ month deltan)))
       ((equal deltaw "y") (setq year (+ year deltan)))))

When you type something like "+2d" deltan gets set to the integer part and deltaw to the suffix. This clause first checks that deltan has a value. Tf it does then it first sets the variables day, months, and year then uses the suffix to choose which one to modify.

This function ultimately returns (list second minute hour day month year), so we can just extend this clause to modifiy of the hour variable as well. There is, however, a wrinkle. We must also set a dynamic variable in order to signal to our caller that the user explicitly entered a time, otherwise the caller will ignore the time information and just insert a date stamp:

(deltan
 (setq futurep nil)
 (unless deltadef
   (let ((now (decode-time (current-time))))
     (setq hour (nth 2 now) day (nth 3 now) month (nth 4 now) year (nth 5 now))))
 (cond ((equal deltaw "h")
        (setq org-time-was-given t)
        (setq hour (+ hour deltan)))
       (member deltaw '("d" "")) (setq day (+ day deltan)))
       ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
       ((equal deltaw "m") (setq month (+ month deltan)))
       ((equal deltaw "y") (setq year (+ year deltan)))))

I've tested this locally and it works just fine.

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.