emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: emacs-orgmode@gnu.org
Subject: Do something useful with ".+" and hours repeaters
Date: Sun, 05 Apr 2020 15:58:33 +0200	[thread overview]
Message-ID: <87k12uavau.fsf@nicolasgoaziou.fr> (raw)

[-- Attachment #1: Type: text/plain, Size: 385 bytes --]

Hello,

Someone on #org-mode (sorry, I cannot remember the nickname) reported
that ".+" repeater style was not handling properly (not handling at all,
actually) hours spans.

As a reminder, ".+" means "repeat, starting from today as the base
date". With hours, it seems logical to "repeat, starting from now as the
base date". The attached patch does that.

WDYT?

-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix ".+" repeater style for hour span --]
[-- Type: text/x-diff, Size: 1905 bytes --]

From 19ee311eb35bc4cde08e61bc485a679df2d584dd Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Sun, 5 Apr 2020 15:47:45 +0200
Subject: [PATCH] Handle ".+" repeater style for hours

* lisp/org.el (org-auto-repeat-maybe): Handle ".+" repeater style for
hours.
* doc/org-manual.org (Repeated tasks): Add an example.
---
 doc/org-manual.org |  4 ++++
 lisp/org.el        | 11 ++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 5f55e9bd5..ee054a744 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -6337,6 +6337,10 @@ special repeaters =++= and =.+=.  For example:
 ,** TODO Check the batteries in the smoke detectors
    DEADLINE: <2005-11-01 Tue .+1m>
    Marking this DONE will shift the date to one month after today.
+
+,** TODO Play a major third while pushing the bird through the door
+   DEADLINE: <2019-04-05 08:00 Sun .+1h>
+   Marking this DONE shifts the date to exactly one hour from now.
 #+end_example
 
 #+vindex: org-agenda-skip-scheduled-if-deadline-is-shown
diff --git a/lisp/org.el b/lisp/org.el
index 06891b8bd..b9742514d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10146,9 +10146,14 @@ This function is run automatically after each state change to a DONE state."
 			(repeater-type (match-string 1 ts)))
 		    (cond
 		     ((equal "." repeater-type)
-		      ;; Shift starting date to today.
-		      (org-timestamp-change (- (org-today) (time-to-days time))
-					    'day))
+		      ;; Shift starting date to today, or now if
+		      ;; repeater is by hours.
+		      (if (equal what "h")
+			  (org-timestamp-change
+			   (floor (/ (- (org-time-stamp-to-now ts t)) 60))
+			   'minute)
+			(org-timestamp-change (- (org-today) (time-to-days time))
+					      'day)))
 		     ((equal "+" repeater-type)
 		      (let ((nshiftmax 10)
 			    (nshift 0))
-- 
2.26.0


             reply	other threads:[~2020-04-05 13:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-05 13:58 Nicolas Goaziou [this message]
2020-04-05 16:54 ` Do something useful with ".+" and hours repeaters Kyle Meyer
2020-04-06 13:23   ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k12uavau.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).