From: Ilya Chernyshov <ichernyshovvv@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] org-datetree.el: Allow datetrees with TODO, priority, tags
Date: Wed, 11 Jan 2023 16:59:26 +0600 [thread overview]
Message-ID: <87sfghqqpu.fsf@gmail.com> (raw)
In-Reply-To: <87o7rald2a.fsf@localhost>
[-- Attachment #1: Type: text/plain, Size: 1152 bytes --]
Ihor Radchenko <yantar92@posteo.net> writes:
> Ilya Chernyshov <ichernyshovvv@gmail.com> writes:
>
>> (defun org-datetree--find-create
>> @@ -169,18 +167,19 @@ component. If INSERT is non-nil and
>> there is no match then it is
>> inserted into the buffer."
>> (when (or month day)
>> (org-narrow-to-subtree))
>> - (let ((re (format regex-template year month day))
>> + (let ((re (format org-complex-heading-regexp-format
>> + (format regex-template year month day)))
>
> These changes make the docstring for `org-datetree--find-create'
> incorrect:
>
> (defun org-datetree--find-create
> (regex-template year &optional month day insert)
> "Find the datetree matched by REGEX-TEMPLATE for YEAR,
> MONTH, or DAY.
> REGEX-TEMPLATE is passed to `format' with YEAR, MONTH, and
> DAY as
> arguments. Match group 1 is compared against the specified
> date
> component. If INSERT is non-nil and there is no match then
> it is
> inserted into the buffer."
>
> Please update the docstring to reflect the new behaviour.
Changed the docs, please review the new patch.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-org-datetree.el-Allow-datetrees-with-TODO-prior.patch --]
[-- Type: text/x-patch, Size: 6787 bytes --]
From 2345abe57d4942a47fd55c2c6f741ef5c2643d47 Mon Sep 17 00:00:00 2001
From: Ilya Chernyshov <ichernyshovvv@gmail.com>
Date: Thu, 15 Dec 2022 02:08:15 +0600
Subject: [PATCH] lisp/org-datetree.el: Allow datetrees with TODO, priority,
tags
* org-datetree.el (org-datetree--find-create,
org-datetree--find-create-group, org-datetree-find-iso-week-create):
Allow finding a datetree with TODO state, priority, tags, statistics
cookies, or COMMENT keyword.
* testing/lisp/test-org-datetree.el
(test-org-datetree/find-date-create,
test-org-datetree/find-iso-week-create): Add tests for a datetree with
tags, TODO or priority keywords.
* etc/ORG-NEWS (Datetree structure headlines can now be complex):
Document the change.
* doc/org-manual.org: Update datetree definition.
---
doc/org-manual.org | 3 ++-
etc/ORG-NEWS | 7 +++++++
lisp/org-datetree.el | 35 ++++++++++++++++++-------------
testing/lisp/test-org-datetree.el | 16 ++++++++++++++
4 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index f3b77ebad..f816f8725 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -22507,7 +22507,8 @@ level.
,*** 2022-10-08 Saturday
#+end_example
-Tags are allowed in the tree structure.
+TODO state, priority, tags, statistics cookies, and COMMENT keywords
+are allowed in the tree structure.
[fn:31] This is always the other, not the user. See the variable
~org-link-from-user-regexp~.
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index c5d9bdf6e..0c9c7bf91 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -55,6 +55,13 @@ document header:
,#+LATEX_HEADER: \DefineVerbatimEnvironment{lstlisting}{Verbatim}{...whatever...}
#+END_src
+** New features
+*** Datetree structure headlines can now be complex
+
+~org-datetree--find-create~ function can now find datetree
+headlines with TODO state, priority, tags, statistics cookies, or
+COMMENT keyword
+
* Version 9.6
** Important announcements and breaking changes
diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el
index 035ef047a..22d9760b0 100644
--- a/lisp/org-datetree.el
+++ b/lisp/org-datetree.el
@@ -99,15 +99,14 @@ If time-period is month, then group entries by month."
(month (calendar-extract-month d))
(day (calendar-extract-day d)))
(org-datetree--find-create
- "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\
-\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)"
+ "\\([12][0-9]\\{3\\}\\)"
year)
(org-datetree--find-create
- "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$"
+ "%d-\\([01][0-9]\\) \\w+"
year month)
(when (eq time-grouping 'day)
(org-datetree--find-create
- "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$"
+ "%d-%02d-\\([0123][0-9]\\) \\w+"
year month day)))))
;;;###autoload
@@ -147,40 +146,48 @@ will be built under the headline at point."
(week (nth 0 iso-date)))
;; ISO 8601 week format is %G-W%V(-%u)
(org-datetree--find-create
- "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\
-\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)"
+ "\\([12][0-9]\\{3\\}\\)"
weekyear nil nil
(format-time-string "%G" time))
(org-datetree--find-create
- "^\\*+[ \t]+%d-W\\([0-5][0-9]\\)$"
+ "%d-W\\([0-5][0-9]\\)"
weekyear week nil
(format-time-string "%G-W%V" time))
;; For the actual day we use the regular date instead of ISO week.
(org-datetree--find-create
- "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$"
+ "%d-%02d-\\([0123][0-9]\\) \\w+"
year month day))))
(defun org-datetree--find-create
(regex-template year &optional month day insert)
"Find the datetree matched by REGEX-TEMPLATE for YEAR, MONTH, or DAY.
-REGEX-TEMPLATE is passed to `format' with YEAR, MONTH, and DAY as
-arguments. Match group 1 is compared against the specified date
+
+The result of `format' with REGEX-TEMPLATE as format string and
+YEAR, MONTH, and DAY as arguments is passed to `format' with
+`org-complex-heading-regexp-format' as format string to find a
+datetree:
+
+ (format org-complex-heading-regexp-format
+ (format regex-template year month day))
+
+Match group 1 in REGEX-TEMPLATE is compared against the specified date
component. If INSERT is non-nil and there is no match then it is
inserted into the buffer."
(when (or month day)
(org-narrow-to-subtree))
- (let ((re (format regex-template year month day))
+ (let ((re (format org-complex-heading-regexp-format
+ (format regex-template year month day)))
match)
(goto-char (point-min))
(while (and (setq match (re-search-forward re nil t))
- (goto-char (match-beginning 1))
- (< (string-to-number (match-string 1)) (or day month year))))
+ (goto-char (match-beginning 5))
+ (< (string-to-number (match-string 5)) (or day month year))))
(cond
((not match)
(goto-char (point-max))
(unless (bolp) (insert "\n"))
(org-datetree-insert-line year month day insert))
- ((= (string-to-number (match-string 1)) (or day month year))
+ ((= (string-to-number (match-string 5)) (or day month year))
(beginning-of-line))
(t
(beginning-of-line)
diff --git a/testing/lisp/test-org-datetree.el b/testing/lisp/test-org-datetree.el
index 59ef8c33b..bd06462f2 100644
--- a/testing/lisp/test-org-datetree.el
+++ b/testing/lisp/test-org-datetree.el
@@ -58,6 +58,14 @@
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-date-create '(3 29 2012)))
(org-trim (buffer-string)))))
+ ;; Do not create new day node when one exists.
+ (should
+ (string-match
+ "\\`\\* DONE 2012 :tag1:tag2:\n\n\\*\\* TODO 2012-03 .*\n\n\\*\\*\\* \\[#A\\] 2012-03-29 .*\\'"
+ (org-test-with-temp-text "* DONE 2012 :tag1:tag2:\n\n** TODO 2012-03 month\n\n*** [#A] 2012-03-29 day :tag3:"
+ (let ((org-datetree-add-timestamp nil))
+ (org-datetree-find-date-create '(3 29 2012)))
+ (org-trim (buffer-string)))))
;; Sort new entry in right place.
(should
(string-match
@@ -163,6 +171,14 @@
(let ((org-datetree-add-timestamp nil))
(org-datetree-find-iso-week-create '(12 31 2014)))
(org-trim (buffer-string)))))
+ ;; Do not create new day node when one exists.
+ (should
+ (string-match
+ "\\`\\* TODO \\[#B\\] 2015\n\n\\*\\* 2015-W01 :tag1:\n\n\\*\\*\\* 2014-12-31 .*\\'"
+ (org-test-with-temp-text "* TODO [#B] 2015\n\n** 2015-W01 :tag1:\n\n*** 2014-12-31 day"
+ (let ((org-datetree-add-timestamp nil))
+ (org-datetree-find-iso-week-create '(12 31 2014)))
+ (org-trim (buffer-string)))))
;; Sort new entry in right place.
(should
(string-match
--
2.39.0
[-- Attachment #3: Type: text/plain, Size: 15 bytes --]
--
Best,
Ilya
next prev parent reply other threads:[~2023-01-11 11:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-04 20:20 [PATCH] org-datetree.el: Allow datetrees with TODO, priority, tags Ilya Chernyshov
2023-01-05 10:00 ` Ihor Radchenko
2023-01-05 18:40 ` Ilya Chernyshov
2023-01-07 12:54 ` Ihor Radchenko
2023-01-11 10:59 ` Ilya Chernyshov [this message]
2023-01-13 11:29 ` Ilya Chernyshov
2023-01-21 9:31 ` Ihor Radchenko
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=87sfghqqpu.fsf@gmail.com \
--to=ichernyshovvv@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@posteo.net \
/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).