emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] lisp/org-element.el: Add repeater-deadline support to org-element
@ 2024-04-03 21:21 Morgan Smith
  2024-04-04 16:51 ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Morgan Smith @ 2024-04-03 21:21 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Morgan Smith

* lisp/org-element.el (org-element-timestamp-parser,
org-element-timestamp-interpreter): Add support for repeater
deadlines.  Adds two new properties: ':repeater-deadline-value' and
':repeater-deadline-unit'.

* testing/lisp/test-org-element.el (test-org-element/timestamp-parser,
test-org-element/timestamp-interpreter): Test support for repeater
deadlines.
---

Hello!

I would like to add some features to org-habit (something I have tried
unsuccessfully in the past).  Before I do that, I would like to switch
org-habit over to the org-element api.  Before I do that, I would like to
extend org-element to support the org-habit syntax.

Let me know what you think!  All the tests pass on my machine.

Thanks,

Morgan

 lisp/org-element.el              | 58 +++++++++++++++++++++-----------
 testing/lisp/test-org-element.el | 38 +++++++++++++++++++--
 2 files changed, 74 insertions(+), 22 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index f4eec1695..8d3b8ce44 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4288,12 +4288,13 @@ Assume point is at the target."
   "Parse time stamp at point, if any.
 
 When at a time stamp, return a new syntax node of `timestamp' type
-containing `:type', `:range-type', `:raw-value', `:year-start', `:month-start',
-`:day-start', `:hour-start', `:minute-start', `:year-end',
-`:month-end', `:day-end', `:hour-end', `:minute-end',
+containing `:type', `:range-type', `:raw-value', `:year-start',
+`:month-start', `:day-start', `:hour-start', `:minute-start',
+`:year-end', `:month-end', `:day-end', `:hour-end', `:minute-end',
 `:repeater-type', `:repeater-value', `:repeater-unit',
-`:warning-type', `:warning-value', `:warning-unit', `:begin', `:end'
-and `:post-blank' properties.  Otherwise, return nil.
+`:repeater-deadline-value', `:repeater-deadline-unit', `:warning-type',
+`:warning-value', `:warning-unit', `:begin', `:end' and `:post-blank'
+properties.  Otherwise, return nil.
 
 Assume point is at the beginning of the timestamp."
   (when (looking-at-p org-element--timestamp-regexp)
@@ -4326,20 +4327,28 @@ Assume point is at the beginning of the timestamp."
                           (date-end 'daterange)
                           (time-range 'timerange)
                           (t nil)))
-	     (repeater-props
-	      (and (not diaryp)
-		   (string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)"
-				 raw-value)
-		   (list
-		    :repeater-type
-		    (let ((type (match-string 1 raw-value)))
-		      (cond ((equal "++" type) 'catch-up)
-			    ((equal ".+" type) 'restart)
-			    (t 'cumulate)))
-		    :repeater-value (string-to-number (match-string 2 raw-value))
-		    :repeater-unit
-		    (pcase (string-to-char (match-string 3 raw-value))
-		      (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year)))))
+             (repeater-props
+              (and (not diaryp)
+                   (string-match
+                    "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)/?\\([0-9]+\\)?\\([hdwmy]\\)?"
+                    raw-value)
+                   (nconc
+                    (list
+                     :repeater-type
+                     (let ((type (match-string 1 raw-value)))
+                       (cond ((equal "++" type) 'catch-up)
+                             ((equal ".+" type) 'restart)
+                             (t 'cumulate)))
+                     :repeater-value (string-to-number (match-string 2 raw-value))
+                     :repeater-unit
+                     (pcase (string-to-char (match-string 3 raw-value))
+                       (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year)))
+                    (when (and (match-string 4 raw-value) (match-string 5 raw-value))
+                      (list
+                       :repeater-deadline-value (string-to-number (match-string 4 raw-value))
+                       :repeater-deadline-unit
+                       (pcase (string-to-char (match-string 5 raw-value))
+                         (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year)))))))
 	     (warning-props
 	      (and (not diaryp)
 		   (string-match "\\(-\\)?-\\([0-9]+\\)\\([hdwmy]\\)" raw-value)
@@ -4407,7 +4416,16 @@ Assume point is at the beginning of the timestamp."
 	             (let ((val (org-element-property :repeater-value timestamp)))
 	               (and val (number-to-string val)))
 	             (pcase (org-element-property :repeater-unit timestamp)
-	               (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y"))))
+	               (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y"))
+                     (let ((deadline-value (org-element-property :repeater-deadline-value timestamp))
+                           (deadline-unit (org-element-property :repeater-deadline-unit timestamp)))
+                       (if (and deadline-value deadline-unit)
+                           (concat
+                            "/"
+                            (number-to-string deadline-value)
+                            (pcase deadline-unit
+                              (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y")))
+                         ""))))
                    (range-type (org-element-property :range-type timestamp))
                    (warning-string
 	            (concat
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index c49dc80d1..ddd601690 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -3208,11 +3208,18 @@ Outside list"
      (let ((timestamp (org-element-context)))
        (or (org-element-property :hour-end timestamp)
 	   (org-element-property :minute-end timestamp)))))
-  ;; With repeater, warning delay and both.
+  ;; With repeater, repeater deadline, warning delay and combinations.
   (should
    (eq 'catch-up
        (org-test-with-temp-text "<2012-03-29 Thu ++1y>"
 	 (org-element-property :repeater-type (org-element-context)))))
+  (should
+   (equal '(catch-up 2 year)
+       (org-test-with-temp-text "<2012-03-29 Thu ++1y/2y>"
+         (let ((ts (org-element-context)))
+           (list (org-element-property :repeater-type ts)
+                 (org-element-property :repeater-deadline-value ts)
+                 (org-element-property :repeater-deadline-unit ts))))))
   (should
    (eq 'first
        (org-test-with-temp-text "<2012-03-29 Thu --1y>"
@@ -3223,6 +3230,14 @@ Outside list"
 	    (let ((ts (org-element-context)))
 	      (list (org-element-property :repeater-type ts)
 		    (org-element-property :warning-type ts))))))
+  (should
+   (equal '(cumulate all 2 year)
+          (org-test-with-temp-text "<2012-03-29 Thu +1y/2y -1y>"
+            (let ((ts (org-element-context)))
+              (list (org-element-property :repeater-type ts)
+                    (org-element-property :warning-type ts)
+                    (org-element-property :repeater-deadline-value ts)
+                    (org-element-property :repeater-deadline-unit ts))))))
   ;; :range-type property
   (should
    (eq
@@ -3963,7 +3978,7 @@ DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu
   ;; Diary.
   (should (equal (org-test-parse-and-interpret "<%%diary-float t 4 2>")
 		 "<%%diary-float t 4 2>\n"))
-  ;; Timestamp with repeater interval, with delay, with both.
+  ;; Timestamp with repeater interval, repeater deadline, with delay, with combinations.
   (should
    (string-match "<2012-03-29 .* \\+1y>"
 		 (org-test-parse-and-interpret "<2012-03-29 thu. +1y>")))
@@ -3975,6 +3990,15 @@ DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu
        (:type active :year-start 2012 :month-start 3 :day-start 29
 	      :repeater-type cumulate :repeater-value 1 :repeater-unit year))
      nil)))
+  (should
+   (string-match
+    "<2012-03-29 .* \\+1y/2y>"
+    (org-element-timestamp-interpreter
+     '(timestamp
+       (:type active :year-start 2012 :month-start 3 :day-start 29
+              :repeater-type cumulate :repeater-value 1 :repeater-unit year
+              :repeater-deadline-value 2 :repeater-deadline-unit year))
+     nil)))
   (should
    (string-match
     "<2012-03-29 .* -1y>"
@@ -3992,6 +4016,16 @@ DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu
 	      :warning-type all :warning-value 1 :warning-unit year
 	      :repeater-type cumulate :repeater-value 1 :repeater-unit year))
      nil)))
+  (should
+   (string-match
+    "<2012-03-29 .* \\+1y/2y -1y>"
+    (org-element-timestamp-interpreter
+     '(timestamp
+       (:type active :year-start 2012 :month-start 3 :day-start 29
+              :warning-type all :warning-value 1 :warning-unit year
+              :repeater-type cumulate :repeater-value 1 :repeater-unit year
+              :repeater-deadline-value 2 :repeater-deadline-unit year))
+     nil)))
   ;; Timestamp range with repeater interval
   (should
    (string-match "<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
-- 
2.41.0



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

* Re: [PATCH] lisp/org-element.el: Add repeater-deadline support to org-element
  2024-04-03 21:21 [PATCH] lisp/org-element.el: Add repeater-deadline support to org-element Morgan Smith
@ 2024-04-04 16:51 ` Ihor Radchenko
  2024-04-04 21:08   ` Morgan Smith
  0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2024-04-04 16:51 UTC (permalink / raw)
  To: Morgan Smith; +Cc: emacs-orgmode

Morgan Smith <Morgan.J.Smith@outlook.com> writes:

> I would like to add some features to org-habit (something I have tried
> unsuccessfully in the past).  Before I do that, I would like to switch
> org-habit over to the org-element api.  Before I do that, I would like to
> extend org-element to support the org-habit syntax.
>
> Let me know what you think!  All the tests pass on my machine.

This is a welcome addition. Thanks!

Please also add etc/ORG-NEWS entry - it is org-element API change.

In addition to changes in Org git, you also need to update
https://orgmode.org/worg/org-syntax.html#Timestamps and
https://orgmode.org/worg/dev/org-element-api.html
(the page source is at https://git.sr.ht/~bzg/worg)

> +                   (string-match
> +                    "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)/?\\([0-9]+\\)?\\([hdwmy]\\)?"

This will match timestamps like <2012-03-29 Thu +1y2y>. You may instead
use shy group \(?:...\)? around the whole /2y regexp match. (Or even
rewrite the regexp via rx for better readability, while we are on it).

> +                     (let ((deadline-value (org-element-property :repeater-deadline-value timestamp))
> +                           (deadline-unit (org-element-property :repeater-deadline-unit timestamp)))

This is slightly confusing, because "deadline" has multiple meanings in
Org. repeater-deadline-value/unit would be more readable as the variable name.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: [PATCH] lisp/org-element.el: Add repeater-deadline support to org-element
  2024-04-04 16:51 ` Ihor Radchenko
@ 2024-04-04 21:08   ` Morgan Smith
  2024-04-07 11:33     ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Morgan Smith @ 2024-04-04 21:08 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

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

Hello,

Thanks for the review!

See two patches attached.  One for org and one for worg.  Tests still
pass on my end.

Ihor Radchenko <yantar92@posteo.net> writes:

> Please also add etc/ORG-NEWS entry - it is org-element API change.

Done

> In addition to changes in Org git, you also need to update
> https://orgmode.org/worg/org-syntax.html#Timestamps and
> https://orgmode.org/worg/dev/org-element-api.html(the page source is at https://git.sr.ht/~bzg/worg)

Done.  Sort of.  My change in org-syntax.org now implies that a repeater
must come before a delay.  I don't know what syntax to use that doesn't
make that implication.  Although I don't see the harm in telling people
to put the repeater first.

> This will match timestamps like <2012-03-29 Thu +1y2y>. You may instead
> use shy group \(?:...\)? around the whole /2y regexp match. (Or even
> rewrite the regexp via rx for better readability, while we are on it).

Done.  It's my first time using rx though.  I don't know if I should be
compiling it or something for performance?

> This is slightly confusing, because "deadline" has multiple meanings in
> Org. repeater-deadline-value/unit would be more readable as the variable name.

Done


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Document-repeater-deadline-syntax-and-element-api.patch --]
[-- Type: text/x-patch, Size: 4129 bytes --]

From b285023ca107f7c0fc8b89f7f636cf96bd217207 Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
Date: Thu, 4 Apr 2024 16:49:31 -0400
Subject: [PATCH] Document repeater deadline syntax and element api

* dev/org-element-api.org (Timestamp): Add ':repeater-deadline-unit'
and ':repeater-deadline-value'.
* org-syntax.org (Timestamps): Separate definition of repeater and
delay.  Add repeater deadline to repeater definition.
---
 dev/org-element-api.org |  5 +++++
 org-syntax.org          | 32 +++++++++++++++++++-------------
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/dev/org-element-api.org b/dev/org-element-api.org
index ffcda274..9d57238b 100644
--- a/dev/org-element-api.org
+++ b/dev/org-element-api.org
@@ -706,6 +706,11 @@ ** Timestamp
   (symbol: ~year~, ~month~, ~week~, ~day~, ~hour~ or ~nil~).
 - ~:repeater-value~ :: Value of shift, if a repeater is defined
   (integer or ~nil~).
+- ~:repeater-deadline-unit~ :: Unit of shift, if a repeater deadline
+  is defined (symbol: ~year~, ~month~, ~week~, ~day~, ~hour~ or
+  ~nil~).
+- ~:repeater-deadline-value~ :: Value of shift, if a repeater deadline
+  is defined (integer or ~nil~).
 - ~:type~ :: Type of timestamp (symbol: ~active~, ~active-range~,
   ~diary~, ~inactive~, ~inactive-range~).
 - ~:range-type~ :: Type of range (symbol: ~daterange~, ~timerange~ or
diff --git a/org-syntax.org b/org-syntax.org
index bdd372d1..cf477655 100644
--- a/org-syntax.org
+++ b/org-syntax.org
@@ -1743,13 +1743,13 @@ ** Timestamps
 Timestamps are structured according to one of the seven following patterns:
 
 #+begin_example
-<%%(SEXP)>                                                     (diary)
-<DATE TIME REPEATER-OR-DELAY>                                  (active)
-[DATE TIME REPEATER-OR-DELAY]                                  (inactive)
-<DATE TIME REPEATER-OR-DELAY>--<DATE TIME REPEATER-OR-DELAY>   (active range)
-<DATE TIME-TIME REPEATER-OR-DELAY>                             (active range)
-[DATE TIME REPEATER-OR-DELAY]--[DATE TIME REPEATER-OR-DELAY]   (inactive range)
-[DATE TIME-TIME REPEATER-OR-DELAY]                             (inactive range)
+<%%(SEXP)>                                               (diary)
+<DATE TIME REPEATER DELAY>                               (active)
+[DATE TIME REPEATER DELAY]                               (inactive)
+<DATE TIME REPEATER DELAY>--<DATE TIME REPEATER DELAY>   (active range)
+<DATE TIME-TIME REPEATER DELAY>                          (active range)
+[DATE TIME REPEATER DELAY]--[DATE TIME REPEATER DELAY]   (inactive range)
+[DATE TIME-TIME REPEATER DELAY]                          (inactive range)
 #+end_example
 
 + SEXP :: A string consisting of any characters but =>= and =\n=.
@@ -1763,20 +1763,26 @@ ** Timestamps
 + TIME (optional) :: An instance of the pattern =H:MM= where =H=
   represents a one to two digit number (and can start with =0=), and =M=
   represents a single digit.
-+ REPEATER-OR-DELAY (optional) :: An instance of the following pattern:
++ REPEATER (optional) :: An instance of the following pattern:
   #+begin_example
 MARK VALUE UNIT
+MARK VALUE UNIT/VALUE UNIT
   #+end_example
   Where MARK, VALUE and UNIT are not separated by whitespace characters.
   - MARK :: Either the string =+= (cumulative type), =++= (catch-up type),
-    or =.+= (restart type) when forming a repeater, and either =-= (all
-    type) or =--= (first type) when forming a warning delay.
+    or =.+= (restart type).
+  - VALUE :: A number
+  - UNIT :: Either the character =h= (hour), =d= (day), =w= (week), =m=
+    (month), or =y= (year)
++ DELAY (optional) :: An instance of the following pattern:
+  #+begin_example
+MARK VALUE UNIT
+  #+end_example
+  Where MARK, VALUE and UNIT are not separated by whitespace characters.
+  - MARK :: Either  =-= (all type) or =--= (first type).
   - VALUE :: A number
   - UNIT :: Either the character =h= (hour), =d= (day), =w= (week), =m=
     (month), or =y= (year)
-
-There can be two instances of =REPEATER-OR-DELAY= in the timestamp: one
-as a repeater and one as a warning delay.
 
 *Examples*
 
-- 
2.41.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-lisp-org-element.el-Add-repeater-deadline-support-to.patch --]
[-- Type: text/x-patch, Size: 10335 bytes --]

From 35af811225918d7bb19e54c1c0a6fb4858c8a33f Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
Date: Wed, 3 Apr 2024 16:30:42 -0400
Subject: [PATCH] lisp/org-element.el: Add repeater-deadline support to
 org-element

* lisp/org-element.el (org-element-timestamp-parser,
org-element-timestamp-interpreter): Add support for repeater
deadlines.  Adds two new properties: ':repeater-deadline-value' and
':repeater-deadline-unit'.

* testing/lisp/test-org-element.el (test-org-element/timestamp-parser,
test-org-element/timestamp-interpreter): Test support for repeater
deadlines.

* etc/ORG-NEWS: Add relevant news.
---
 etc/ORG-NEWS                     | 14 +++++++
 lisp/org-element.el              | 67 ++++++++++++++++++++++----------
 testing/lisp/test-org-element.el | 38 +++++++++++++++++-
 3 files changed, 97 insertions(+), 22 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index fff4f47de..ef205c228 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -512,6 +512,20 @@ timestamp object.  Possible values: ~timerange~, ~daterange~, ~nil~.
 ~org-element-timestamp-interpreter~ takes into account this property
 and returns an appropriate timestamp string.
 
+**** New properties =:repeater-deadline-value= and =:repeater-deadline-unit= for org-element timestamp object
+
+~org-element-timestamp-parser~ now adds =:repeater-deadline-value= and
+=:repeater-deadline-unit= properties to each timestamp object that has
+a repeater deadline.
+
+Possible values for =:repeater-deadline-value=: ~positive integer~, ~nil~.
+
+Possible values for =:repeater-deadline-unit=: ~hour~, ~day~, ~week~,
+~month~, ~year~.
+
+~org-element-timestamp-interpreter~ takes into account these properties
+and returns an appropriate timestamp string.
+
 **** =org-link= store functions are passed an ~interactive?~ argument
 
 The ~:store:~ functions set for link types using
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 8e5416d8b..79eb5eb29 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4288,12 +4288,13 @@ Assume point is at the target."
   "Parse time stamp at point, if any.
 
 When at a time stamp, return a new syntax node of `timestamp' type
-containing `:type', `:range-type', `:raw-value', `:year-start', `:month-start',
-`:day-start', `:hour-start', `:minute-start', `:year-end',
-`:month-end', `:day-end', `:hour-end', `:minute-end',
+containing `:type', `:range-type', `:raw-value', `:year-start',
+`:month-start', `:day-start', `:hour-start', `:minute-start',
+`:year-end', `:month-end', `:day-end', `:hour-end', `:minute-end',
 `:repeater-type', `:repeater-value', `:repeater-unit',
-`:warning-type', `:warning-value', `:warning-unit', `:begin', `:end'
-and `:post-blank' properties.  Otherwise, return nil.
+`:repeater-deadline-value', `:repeater-deadline-unit', `:warning-type',
+`:warning-value', `:warning-unit', `:begin', `:end' and `:post-blank'
+properties.  Otherwise, return nil.
 
 Assume point is at the beginning of the timestamp."
   (when (looking-at-p org-element--timestamp-regexp)
@@ -4326,20 +4327,35 @@ Assume point is at the beginning of the timestamp."
                           (date-end 'daterange)
                           (time-range 'timerange)
                           (t nil)))
-	     (repeater-props
-	      (and (not diaryp)
-		   (string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)"
-				 raw-value)
-		   (list
-		    :repeater-type
-		    (let ((type (match-string 1 raw-value)))
-		      (cond ((equal "++" type) 'catch-up)
-			    ((equal ".+" type) 'restart)
-			    (t 'cumulate)))
-		    :repeater-value (string-to-number (match-string 2 raw-value))
-		    :repeater-unit
-		    (pcase (string-to-char (match-string 3 raw-value))
-		      (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year)))))
+             (repeater-props
+              (and (not diaryp)
+                   (string-match
+                    (rx
+                     (group (or "+" "++" ".+"))
+                     (group (+ digit))
+                     (group (or "h" "d" "w" "m" "y"))
+                     (\?
+                      "/"
+                      (group (+ digit))
+                      (group (or "h" "d" "w" "m" "y"))))
+                    raw-value)
+                   (nconc
+                    (list
+                     :repeater-type
+                     (let ((type (match-string 1 raw-value)))
+                       (cond ((equal "++" type) 'catch-up)
+                             ((equal ".+" type) 'restart)
+                             (t 'cumulate)))
+                     :repeater-value (string-to-number (match-string 2 raw-value))
+                     :repeater-unit
+                     (pcase (string-to-char (match-string 3 raw-value))
+                       (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year)))
+                    (when (and (match-string 4 raw-value) (match-string 5 raw-value))
+                      (list
+                       :repeater-deadline-value (string-to-number (match-string 4 raw-value))
+                       :repeater-deadline-unit
+                       (pcase (string-to-char (match-string 5 raw-value))
+                         (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year)))))))
 	     (warning-props
 	      (and (not diaryp)
 		   (string-match "\\(-\\)?-\\([0-9]+\\)\\([hdwmy]\\)" raw-value)
@@ -4407,7 +4423,18 @@ Assume point is at the beginning of the timestamp."
 	             (let ((val (org-element-property :repeater-value timestamp)))
 	               (and val (number-to-string val)))
 	             (pcase (org-element-property :repeater-unit timestamp)
-	               (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y"))))
+	               (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y"))
+                     (let ((repeater-deadline-value
+                            (org-element-property :repeater-deadline-value timestamp))
+                           (repeater-deadline-unit
+                            (org-element-property :repeater-deadline-unit timestamp)))
+                       (if (and repeater-deadline-value repeater-deadline-unit)
+                           (concat
+                            "/"
+                            (number-to-string repeater-deadline-value)
+                            (pcase repeater-deadline-unit
+                              (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y")))
+                         ""))))
                    (range-type (org-element-property :range-type timestamp))
                    (warning-string
 	            (concat
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index c49dc80d1..ddd601690 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -3208,11 +3208,18 @@ Outside list"
      (let ((timestamp (org-element-context)))
        (or (org-element-property :hour-end timestamp)
 	   (org-element-property :minute-end timestamp)))))
-  ;; With repeater, warning delay and both.
+  ;; With repeater, repeater deadline, warning delay and combinations.
   (should
    (eq 'catch-up
        (org-test-with-temp-text "<2012-03-29 Thu ++1y>"
 	 (org-element-property :repeater-type (org-element-context)))))
+  (should
+   (equal '(catch-up 2 year)
+       (org-test-with-temp-text "<2012-03-29 Thu ++1y/2y>"
+         (let ((ts (org-element-context)))
+           (list (org-element-property :repeater-type ts)
+                 (org-element-property :repeater-deadline-value ts)
+                 (org-element-property :repeater-deadline-unit ts))))))
   (should
    (eq 'first
        (org-test-with-temp-text "<2012-03-29 Thu --1y>"
@@ -3223,6 +3230,14 @@ Outside list"
 	    (let ((ts (org-element-context)))
 	      (list (org-element-property :repeater-type ts)
 		    (org-element-property :warning-type ts))))))
+  (should
+   (equal '(cumulate all 2 year)
+          (org-test-with-temp-text "<2012-03-29 Thu +1y/2y -1y>"
+            (let ((ts (org-element-context)))
+              (list (org-element-property :repeater-type ts)
+                    (org-element-property :warning-type ts)
+                    (org-element-property :repeater-deadline-value ts)
+                    (org-element-property :repeater-deadline-unit ts))))))
   ;; :range-type property
   (should
    (eq
@@ -3963,7 +3978,7 @@ DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu
   ;; Diary.
   (should (equal (org-test-parse-and-interpret "<%%diary-float t 4 2>")
 		 "<%%diary-float t 4 2>\n"))
-  ;; Timestamp with repeater interval, with delay, with both.
+  ;; Timestamp with repeater interval, repeater deadline, with delay, with combinations.
   (should
    (string-match "<2012-03-29 .* \\+1y>"
 		 (org-test-parse-and-interpret "<2012-03-29 thu. +1y>")))
@@ -3975,6 +3990,15 @@ DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu
        (:type active :year-start 2012 :month-start 3 :day-start 29
 	      :repeater-type cumulate :repeater-value 1 :repeater-unit year))
      nil)))
+  (should
+   (string-match
+    "<2012-03-29 .* \\+1y/2y>"
+    (org-element-timestamp-interpreter
+     '(timestamp
+       (:type active :year-start 2012 :month-start 3 :day-start 29
+              :repeater-type cumulate :repeater-value 1 :repeater-unit year
+              :repeater-deadline-value 2 :repeater-deadline-unit year))
+     nil)))
   (should
    (string-match
     "<2012-03-29 .* -1y>"
@@ -3992,6 +4016,16 @@ DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu
 	      :warning-type all :warning-value 1 :warning-unit year
 	      :repeater-type cumulate :repeater-value 1 :repeater-unit year))
      nil)))
+  (should
+   (string-match
+    "<2012-03-29 .* \\+1y/2y -1y>"
+    (org-element-timestamp-interpreter
+     '(timestamp
+       (:type active :year-start 2012 :month-start 3 :day-start 29
+              :warning-type all :warning-value 1 :warning-unit year
+              :repeater-type cumulate :repeater-value 1 :repeater-unit year
+              :repeater-deadline-value 2 :repeater-deadline-unit year))
+     nil)))
   ;; Timestamp range with repeater interval
   (should
    (string-match "<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
-- 
2.41.0


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

* Re: [PATCH] lisp/org-element.el: Add repeater-deadline support to org-element
  2024-04-04 21:08   ` Morgan Smith
@ 2024-04-07 11:33     ` Ihor Radchenko
  2024-04-10 21:46       ` Morgan Smith
  0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2024-04-07 11:33 UTC (permalink / raw)
  To: Morgan Smith; +Cc: emacs-orgmode

Morgan Smith <Morgan.J.Smith@outlook.com> writes:

> See two patches attached.  One for org and one for worg.  Tests still
> pass on my end.

Thanks!

>> In addition to changes in Org git, you also need to update
>> https://orgmode.org/worg/org-syntax.html#Timestamps and
>> https://orgmode.org/worg/dev/org-element-api.html(the page source is at https://git.sr.ht/~bzg/worg)
>
> Done.  Sort of.  My change in org-syntax.org now implies that a repeater
> must come before a delay.  I don't know what syntax to use that doesn't
> make that implication.  Although I don't see the harm in telling people
> to put the repeater first.

We can simply leave the previous REPEATER-OR-DELAY, but expand on it
that REPEATER-OR-DELAY is an instance of REPEATER or an instance of
DELAY. Does it make sense?

>> This will match timestamps like <2012-03-29 Thu +1y2y>. You may instead
>> use shy group \(?:...\)? around the whole /2y regexp match. (Or even
>> rewrite the regexp via rx for better readability, while we are on it).
>
> Done.  It's my first time using rx though.  I don't know if I should be
> compiling it or something for performance?

`rx' is a macro. It will be expanded during compilation.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: [PATCH] lisp/org-element.el: Add repeater-deadline support to org-element
  2024-04-07 11:33     ` Ihor Radchenko
@ 2024-04-10 21:46       ` Morgan Smith
  2024-04-11 13:24         ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Morgan Smith @ 2024-04-10 21:46 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

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

Apologies for the delay.  I had lots of social events surrounding the
solar eclipse.  The eclipse was really cool, I do recommend.

See two patches attached again.  All tests pass on my computer.

I decided to add an extra `let' statement to my changes to
`org-element-timestamp-parser'.  I think it adds a touch of clarity and
maybe performance.

Ihor Radchenko <yantar92@posteo.net> writes:

>> My change in org-syntax.org now implies that a repeater
>> must come before a delay.  I don't know what syntax to use that doesn't
>> make that implication.  Although I don't see the harm in telling people
>> to put the repeater first.
>
> We can simply leave the previous REPEATER-OR-DELAY, but expand on it
> that REPEATER-OR-DELAY is an instance of REPEATER or an instance of
> DELAY. Does it make sense?

Done.

>> Done.  It's my first time using rx though.  I don't know if I should be
>> compiling it or something for performance?
>
> `rx' is a macro. It will be expanded during compilation.

Thank you for the piece of mind.  I'll have to use `rx' more often :).


Thanks for the reviews!  I'll start switching org-habit over to the
element API soon.  I've already played with that a bit


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-org-element.el-Add-repeater-deadline-support-to.patch --]
[-- Type: text/x-patch, Size: 10496 bytes --]

From 582d4e7372c005f098f213b496de6f85c0c11d2f Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
Date: Wed, 3 Apr 2024 16:30:42 -0400
Subject: [PATCH] lisp/org-element.el: Add repeater-deadline support to
 org-element

* lisp/org-element.el (org-element-timestamp-parser,
org-element-timestamp-interpreter): Add support for repeater
deadlines.  Adds two new properties: ':repeater-deadline-value' and
':repeater-deadline-unit'.

* testing/lisp/test-org-element.el (test-org-element/timestamp-parser,
test-org-element/timestamp-interpreter): Test support for repeater
deadlines.

* etc/ORG-NEWS: Add relevant news.
---
 etc/ORG-NEWS                     | 14 +++++++
 lisp/org-element.el              | 70 +++++++++++++++++++++++---------
 testing/lisp/test-org-element.el | 38 ++++++++++++++++-
 3 files changed, 100 insertions(+), 22 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index aeb7ffd4b..2b418cd3c 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -512,6 +512,20 @@ timestamp object.  Possible values: ~timerange~, ~daterange~, ~nil~.
 ~org-element-timestamp-interpreter~ takes into account this property
 and returns an appropriate timestamp string.
 
+**** New properties =:repeater-deadline-value= and =:repeater-deadline-unit= for org-element timestamp object
+
+~org-element-timestamp-parser~ now adds =:repeater-deadline-value= and
+=:repeater-deadline-unit= properties to each timestamp object that has
+a repeater deadline.
+
+Possible values for =:repeater-deadline-value=: ~positive integer~, ~nil~.
+
+Possible values for =:repeater-deadline-unit=: ~hour~, ~day~, ~week~,
+~month~, ~year~.
+
+~org-element-timestamp-interpreter~ takes into account these properties
+and returns an appropriate timestamp string.
+
 **** =org-link= store functions are passed an ~interactive?~ argument
 
 The ~:store:~ functions set for link types using
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 8e5416d8b..49a312694 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4288,12 +4288,13 @@ Assume point is at the target."
   "Parse time stamp at point, if any.
 
 When at a time stamp, return a new syntax node of `timestamp' type
-containing `:type', `:range-type', `:raw-value', `:year-start', `:month-start',
-`:day-start', `:hour-start', `:minute-start', `:year-end',
-`:month-end', `:day-end', `:hour-end', `:minute-end',
+containing `:type', `:range-type', `:raw-value', `:year-start',
+`:month-start', `:day-start', `:hour-start', `:minute-start',
+`:year-end', `:month-end', `:day-end', `:hour-end', `:minute-end',
 `:repeater-type', `:repeater-value', `:repeater-unit',
-`:warning-type', `:warning-value', `:warning-unit', `:begin', `:end'
-and `:post-blank' properties.  Otherwise, return nil.
+`:repeater-deadline-value', `:repeater-deadline-unit', `:warning-type',
+`:warning-value', `:warning-unit', `:begin', `:end' and `:post-blank'
+properties.  Otherwise, return nil.
 
 Assume point is at the beginning of the timestamp."
   (when (looking-at-p org-element--timestamp-regexp)
@@ -4326,20 +4327,38 @@ Assume point is at the beginning of the timestamp."
                           (date-end 'daterange)
                           (time-range 'timerange)
                           (t nil)))
-	     (repeater-props
-	      (and (not diaryp)
-		   (string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)"
-				 raw-value)
-		   (list
-		    :repeater-type
-		    (let ((type (match-string 1 raw-value)))
-		      (cond ((equal "++" type) 'catch-up)
-			    ((equal ".+" type) 'restart)
-			    (t 'cumulate)))
-		    :repeater-value (string-to-number (match-string 2 raw-value))
-		    :repeater-unit
-		    (pcase (string-to-char (match-string 3 raw-value))
-		      (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year)))))
+             (repeater-props
+              (and (not diaryp)
+                   (string-match
+                    (rx
+                     (group (or "+" "++" ".+"))
+                     (group (+ digit))
+                     (group (or "h" "d" "w" "m" "y"))
+                     (\?
+                      "/"
+                      (group (+ digit))
+                      (group (or "h" "d" "w" "m" "y"))))
+                    raw-value)
+                   (nconc
+                    (list
+                     :repeater-type
+                     (let ((type (match-string 1 raw-value)))
+                       (cond ((equal "++" type) 'catch-up)
+                             ((equal ".+" type) 'restart)
+                             (t 'cumulate)))
+                     :repeater-value (string-to-number (match-string 2 raw-value))
+                     :repeater-unit
+                     (pcase (string-to-char (match-string 3 raw-value))
+                       (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year)))
+
+                    (let ((repeater-deadline-value (match-string 4 raw-value))
+                          (repeater-deadline-unit (match-string 5 raw-value)))
+                      (when (and repeater-deadline-value repeater-deadline-unit)
+                        (list
+                         :repeater-deadline-value (string-to-number repeater-deadline-value)
+                         :repeater-deadline-unit
+                         (pcase (string-to-char repeater-deadline-unit)
+                           (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (_ 'year))))))))
 	     (warning-props
 	      (and (not diaryp)
 		   (string-match "\\(-\\)?-\\([0-9]+\\)\\([hdwmy]\\)" raw-value)
@@ -4407,7 +4426,18 @@ Assume point is at the beginning of the timestamp."
 	             (let ((val (org-element-property :repeater-value timestamp)))
 	               (and val (number-to-string val)))
 	             (pcase (org-element-property :repeater-unit timestamp)
-	               (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y"))))
+	               (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y"))
+                     (let ((repeater-deadline-value
+                            (org-element-property :repeater-deadline-value timestamp))
+                           (repeater-deadline-unit
+                            (org-element-property :repeater-deadline-unit timestamp)))
+                       (if (and repeater-deadline-value repeater-deadline-unit)
+                           (concat
+                            "/"
+                            (number-to-string repeater-deadline-value)
+                            (pcase repeater-deadline-unit
+                              (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y")))
+                         ""))))
                    (range-type (org-element-property :range-type timestamp))
                    (warning-string
 	            (concat
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index c49dc80d1..ddd601690 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -3208,11 +3208,18 @@ Outside list"
      (let ((timestamp (org-element-context)))
        (or (org-element-property :hour-end timestamp)
 	   (org-element-property :minute-end timestamp)))))
-  ;; With repeater, warning delay and both.
+  ;; With repeater, repeater deadline, warning delay and combinations.
   (should
    (eq 'catch-up
        (org-test-with-temp-text "<2012-03-29 Thu ++1y>"
 	 (org-element-property :repeater-type (org-element-context)))))
+  (should
+   (equal '(catch-up 2 year)
+       (org-test-with-temp-text "<2012-03-29 Thu ++1y/2y>"
+         (let ((ts (org-element-context)))
+           (list (org-element-property :repeater-type ts)
+                 (org-element-property :repeater-deadline-value ts)
+                 (org-element-property :repeater-deadline-unit ts))))))
   (should
    (eq 'first
        (org-test-with-temp-text "<2012-03-29 Thu --1y>"
@@ -3223,6 +3230,14 @@ Outside list"
 	    (let ((ts (org-element-context)))
 	      (list (org-element-property :repeater-type ts)
 		    (org-element-property :warning-type ts))))))
+  (should
+   (equal '(cumulate all 2 year)
+          (org-test-with-temp-text "<2012-03-29 Thu +1y/2y -1y>"
+            (let ((ts (org-element-context)))
+              (list (org-element-property :repeater-type ts)
+                    (org-element-property :warning-type ts)
+                    (org-element-property :repeater-deadline-value ts)
+                    (org-element-property :repeater-deadline-unit ts))))))
   ;; :range-type property
   (should
    (eq
@@ -3963,7 +3978,7 @@ DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu
   ;; Diary.
   (should (equal (org-test-parse-and-interpret "<%%diary-float t 4 2>")
 		 "<%%diary-float t 4 2>\n"))
-  ;; Timestamp with repeater interval, with delay, with both.
+  ;; Timestamp with repeater interval, repeater deadline, with delay, with combinations.
   (should
    (string-match "<2012-03-29 .* \\+1y>"
 		 (org-test-parse-and-interpret "<2012-03-29 thu. +1y>")))
@@ -3975,6 +3990,15 @@ DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu
        (:type active :year-start 2012 :month-start 3 :day-start 29
 	      :repeater-type cumulate :repeater-value 1 :repeater-unit year))
      nil)))
+  (should
+   (string-match
+    "<2012-03-29 .* \\+1y/2y>"
+    (org-element-timestamp-interpreter
+     '(timestamp
+       (:type active :year-start 2012 :month-start 3 :day-start 29
+              :repeater-type cumulate :repeater-value 1 :repeater-unit year
+              :repeater-deadline-value 2 :repeater-deadline-unit year))
+     nil)))
   (should
    (string-match
     "<2012-03-29 .* -1y>"
@@ -3992,6 +4016,16 @@ DEADLINE: <2012-03-29 thu.> SCHEDULED: <2012-03-29 thu.> CLOSED: [2012-03-29 thu
 	      :warning-type all :warning-value 1 :warning-unit year
 	      :repeater-type cumulate :repeater-value 1 :repeater-unit year))
      nil)))
+  (should
+   (string-match
+    "<2012-03-29 .* \\+1y/2y -1y>"
+    (org-element-timestamp-interpreter
+     '(timestamp
+       (:type active :year-start 2012 :month-start 3 :day-start 29
+              :warning-type all :warning-value 1 :warning-unit year
+              :repeater-type cumulate :repeater-value 1 :repeater-unit year
+              :repeater-deadline-value 2 :repeater-deadline-unit year))
+     nil)))
   ;; Timestamp range with repeater interval
   (should
    (string-match "<2012-03-29 .* \\+1y>--<2012-03-30 .* \\+1y>"
-- 
2.41.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-Document-repeater-deadline-syntax-and-element-api.patch --]
[-- Type: text/x-patch, Size: 2982 bytes --]

From db69967bed986d96a6d246cd66d6d53b0a63f922 Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
Date: Thu, 4 Apr 2024 16:49:31 -0400
Subject: [PATCH] Document repeater deadline syntax and element api

* dev/org-element-api.org (Timestamp): Add ':repeater-deadline-unit'
and ':repeater-deadline-value'.
* org-syntax.org (Timestamps): Separate definition of repeater and
delay.  Add repeater deadline to repeater definition.
---
 dev/org-element-api.org |  5 +++++
 org-syntax.org          | 20 ++++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/dev/org-element-api.org b/dev/org-element-api.org
index ffcda274..9d57238b 100644
--- a/dev/org-element-api.org
+++ b/dev/org-element-api.org
@@ -706,6 +706,11 @@ ** Timestamp
   (symbol: ~year~, ~month~, ~week~, ~day~, ~hour~ or ~nil~).
 - ~:repeater-value~ :: Value of shift, if a repeater is defined
   (integer or ~nil~).
+- ~:repeater-deadline-unit~ :: Unit of shift, if a repeater deadline
+  is defined (symbol: ~year~, ~month~, ~week~, ~day~, ~hour~ or
+  ~nil~).
+- ~:repeater-deadline-value~ :: Value of shift, if a repeater deadline
+  is defined (integer or ~nil~).
 - ~:type~ :: Type of timestamp (symbol: ~active~, ~active-range~,
   ~diary~, ~inactive~, ~inactive-range~).
 - ~:range-type~ :: Type of range (symbol: ~daterange~, ~timerange~ or
diff --git a/org-syntax.org b/org-syntax.org
index bdd372d1..0967ae98 100644
--- a/org-syntax.org
+++ b/org-syntax.org
@@ -1763,20 +1763,28 @@ ** Timestamps
 + TIME (optional) :: An instance of the pattern =H:MM= where =H=
   represents a one to two digit number (and can start with =0=), and =M=
   represents a single digit.
-+ REPEATER-OR-DELAY (optional) :: An instance of the following pattern:
++ REPEATER-OR-DELAY (optional) :: An instance of a single REPEATER and/or an
+  instance of a single DELAY in any order.
++ REPEATER (optional) :: An instance of the following pattern:
   #+begin_example
 MARK VALUE UNIT
+MARK VALUE UNIT/VALUE UNIT
   #+end_example
   Where MARK, VALUE and UNIT are not separated by whitespace characters.
   - MARK :: Either the string =+= (cumulative type), =++= (catch-up type),
-    or =.+= (restart type) when forming a repeater, and either =-= (all
-    type) or =--= (first type) when forming a warning delay.
+    or =.+= (restart type).
+  - VALUE :: A number
+  - UNIT :: Either the character =h= (hour), =d= (day), =w= (week), =m=
+    (month), or =y= (year)
++ DELAY (optional) :: An instance of the following pattern:
+  #+begin_example
+MARK VALUE UNIT
+  #+end_example
+  Where MARK, VALUE and UNIT are not separated by whitespace characters.
+  - MARK :: Either  =-= (all type) or =--= (first type).
   - VALUE :: A number
   - UNIT :: Either the character =h= (hour), =d= (day), =w= (week), =m=
     (month), or =y= (year)
-
-There can be two instances of =REPEATER-OR-DELAY= in the timestamp: one
-as a repeater and one as a warning delay.
 
 *Examples*
 
-- 
2.41.0


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

* Re: [PATCH] lisp/org-element.el: Add repeater-deadline support to org-element
  2024-04-10 21:46       ` Morgan Smith
@ 2024-04-11 13:24         ` Ihor Radchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2024-04-11 13:24 UTC (permalink / raw)
  To: Morgan Smith; +Cc: emacs-orgmode

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

Morgan Smith <morgan.j.smith@outlook.com> writes:

> See two patches attached again.  All tests pass on my computer.

Thanks!
Applied, onto main, with amendments (see the attached diffs).
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=66e307b41
https://git.sr.ht/~bzg/worg/commit/f1486f42


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: amendments.diff --]
[-- Type: text/x-patch, Size: 3249 bytes --]

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 2b418cd3c..e61bd6988 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -516,7 +516,9 @@ and returns an appropriate timestamp string.
 
 ~org-element-timestamp-parser~ now adds =:repeater-deadline-value= and
 =:repeater-deadline-unit= properties to each timestamp object that has
-a repeater deadline.
+a repeater deadline.  For example, in =<2012-03-29 Thu ++1y/2y>=, =2y=
+is the repeater deadline with a value of =2= and unit of =y=.  See
+"5.3.3 Tracking your habits" section in the manual.
 
 Possible values for =:repeater-deadline-value=: ~positive integer~, ~nil~.
 
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 49a312694..e7561f16f 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4331,13 +4331,13 @@ (defun org-element-timestamp-parser ()
               (and (not diaryp)
                    (string-match
                     (rx
-                     (group (or "+" "++" ".+"))
-                     (group (+ digit))
-                     (group (or "h" "d" "w" "m" "y"))
-                     (\?
+                     (group-n 1 (or "+" "++" ".+"))
+                     (group-n 2 (+ digit))
+                     (group-n 3 (any "hdwmy"))
+                     (optional
                       "/"
-                      (group (+ digit))
-                      (group (or "h" "d" "w" "m" "y"))))
+                      (group-n 4 (+ digit))
+                      (group-n 5 (any "hdwmy"))))
                     raw-value)
                    (nconc
                     (list
@@ -4427,17 +4427,15 @@ (defun org-element-timestamp-interpreter (timestamp _)
 	               (and val (number-to-string val)))
 	             (pcase (org-element-property :repeater-unit timestamp)
 	               (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y"))
-                     (let ((repeater-deadline-value
-                            (org-element-property :repeater-deadline-value timestamp))
-                           (repeater-deadline-unit
-                            (org-element-property :repeater-deadline-unit timestamp)))
-                       (if (and repeater-deadline-value repeater-deadline-unit)
-                           (concat
-                            "/"
-                            (number-to-string repeater-deadline-value)
-                            (pcase repeater-deadline-unit
-                              (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y")))
-                         ""))))
+                     (when-let ((repeater-deadline-value
+                                 (org-element-property :repeater-deadline-value timestamp))
+                                (repeater-deadline-unit
+                                 (org-element-property :repeater-deadline-unit timestamp)))
+                       (concat
+                        "/"
+                        (number-to-string repeater-deadline-value)
+                        (pcase repeater-deadline-unit
+                          (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y"))))))
                    (range-type (org-element-property :range-type timestamp))
                    (warning-string
 	            (concat

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: amendments-worg.diff --]
[-- Type: text/x-patch, Size: 1692 bytes --]

diff --git a/org-syntax.org b/org-syntax.org
index c8eb7f77..70a46dcf 100644
--- a/org-syntax.org
+++ b/org-syntax.org
@@ -1776,8 +1776,8 @@ ** Timestamps
 + TIME (optional) :: An instance of the pattern =H:MM= where =H=
   represents a one to two digit number (and can start with =0=), and =M=
   represents a single digit.
-+ REPEATER-OR-DELAY (optional) :: An instance of a single REPEATER and/or an
-  instance of a single DELAY in any order.
++ REPEATER-OR-DELAY (optional) :: An instance of a single =REPEATER= and/or an
+  instance of a single =DELAY= in any order.
 + REPEATER (optional) :: An instance of the following pattern:
   #+begin_example
 MARK VALUE UNIT
@@ -1786,18 +1786,18 @@ ** Timestamps
   Where MARK, VALUE and UNIT are not separated by whitespace characters.
   - MARK :: Either the string =+= (cumulative type), =++= (catch-up type),
     or =.+= (restart type).
-  - VALUE :: A number
+  - VALUE :: A number.
   - UNIT :: Either the character =h= (hour), =d= (day), =w= (week), =m=
-    (month), or =y= (year)
+    (month), or =y= (year).
 + DELAY (optional) :: An instance of the following pattern:
   #+begin_example
 MARK VALUE UNIT
   #+end_example
   Where MARK, VALUE and UNIT are not separated by whitespace characters.
   - MARK :: Either  =-= (all type) or =--= (first type).
-  - VALUE :: A number
+  - VALUE :: A number.
   - UNIT :: Either the character =h= (hour), =d= (day), =w= (week), =m=
-    (month), or =y= (year)
+    (month), or =y= (year).
 
 *Examples*
 
@@ -1807,6 +1807,7 @@ ** Timestamps
 [2004-08-24 Tue]--[2004-08-26 Thu]
 <2012-02-08 Wed 20:00 ++1d>
 <2030-10-05 Sat +1m -3d>
+<2012-03-29 Thu ++1y/2y>
 #+end_example
 
 ** Text Markup

[-- Attachment #4: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

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

end of thread, other threads:[~2024-04-11 13:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-03 21:21 [PATCH] lisp/org-element.el: Add repeater-deadline support to org-element Morgan Smith
2024-04-04 16:51 ` Ihor Radchenko
2024-04-04 21:08   ` Morgan Smith
2024-04-07 11:33     ` Ihor Radchenko
2024-04-10 21:46       ` Morgan Smith
2024-04-11 13:24         ` Ihor Radchenko

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