emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Morgan Smith <morgan.j.smith@outlook.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] lisp/org-element.el: Add repeater-deadline support to org-element
Date: Thu, 11 Apr 2024 13:24:40 +0000	[thread overview]
Message-ID: <874jc8yquf.fsf@localhost> (raw)
In-Reply-To: <CH3PR84MB34244E14B200D207C687925FC5062@CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM>

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

      reply	other threads:[~2024-04-11 13:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=874jc8yquf.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=morgan.j.smith@outlook.com \
    /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).