emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Do something useful with ".+" and hours repeaters
@ 2020-04-05 13:58 Nicolas Goaziou
  2020-04-05 16:54 ` Kyle Meyer
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2020-04-05 13:58 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Do something useful with ".+" and hours repeaters
  2020-04-05 13:58 Do something useful with ".+" and hours repeaters Nicolas Goaziou
@ 2020-04-05 16:54 ` Kyle Meyer
  2020-04-06 13:23   ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Kyle Meyer @ 2020-04-05 16:54 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> WDYT?

Makes sense to me.  I have one nitpick on the actual change:

> +		      ;; 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)

You could use floor's DIVISOR argument:

    (floor (- (org-time-stamp-to-now ts t)) 60)

Many such spots in Emacs's tree have been adjusted by Paul Eggert, and
the ones touching Org files have been ported back.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Do something useful with ".+" and hours repeaters
  2020-04-05 16:54 ` Kyle Meyer
@ 2020-04-06 13:23   ` Nicolas Goaziou
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Goaziou @ 2020-04-06 13:23 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

Hello,

Kyle Meyer <kyle@kyleam.com> writes:

> You could use floor's DIVISOR argument:
>
>     (floor (- (org-time-stamp-to-now ts t)) 60)

Good catch! I keep forgetting about this argument.

I added tests, mentioned the change in ORG-NEWS, and applied the patch.

I hesitated using the UPDOWN optional argument from
`org-timestamp-change' (i.e., obey to
`org-time-stamp-rounding-minutes'), but eventually decided to ignore it
for now. We can always reconsider this later on.

Thank you.

Regards,

-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-06 14:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-05 13:58 Do something useful with ".+" and hours repeaters Nicolas Goaziou
2020-04-05 16:54 ` Kyle Meyer
2020-04-06 13:23   ` Nicolas Goaziou

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).