From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id +HHwGIhJwWM6egAAbAwnHQ (envelope-from ) for ; Fri, 13 Jan 2023 13:07:36 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id WJaUGIhJwWO22wAAauVa8A (envelope-from ) for ; Fri, 13 Jan 2023 13:07:36 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id DF95824314 for ; Fri, 13 Jan 2023 13:07:35 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGIpZ-0002NC-3z; Fri, 13 Jan 2023 07:06:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGIpX-0002MK-6u for emacs-orgmode@gnu.org; Fri, 13 Jan 2023 07:06:43 -0500 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pGIpV-0007Pn-1b for emacs-orgmode@gnu.org; Fri, 13 Jan 2023 07:06:42 -0500 Received: by mail-lf1-x12a.google.com with SMTP id bp15so32813260lfb.13 for ; Fri, 13 Jan 2023 04:06:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=8zNcHW0Oemexe5331QyBAWRPy/SpofhCo9FtJ3+j3BI=; b=EoQubm1HNglwBPgmtRghFO0Fo+aADs0u8LKvC2YTmSLsrozrrj+6Y9J+yFHtaF8YEr HbfAeEF41a6EaOoTUsJWKF5rbeySg5rxCi1Gcb6BFZOH2nYlL9h41RRBmrOuP0rsDWZ3 bGrQq4yfJjUnrD+I5YD0AaH/KUXakyUJQKwU8qDwxCQzKjGMnCnCUoDm9dxlV87VQ3JD FQhbIhyZ6xJN7oUw5GgOasny3Vkt/uH4kWgzePs99gCXqtyDR4rXa4FXkJVIbnt3RxWE u+YQJUv7WyBjxySK9dDwDvYN6PmZfjqLyejAM6OF3AqE66ByT/WbvbGSyeQ0HkM+4C2c vzGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8zNcHW0Oemexe5331QyBAWRPy/SpofhCo9FtJ3+j3BI=; b=XQy1gTgfY+gLHO/0/aMG/5gRYjIkruluqxYbvrYxPvnwPIrhCvk6THzmpuJXKkpe9H Lcwb0c2b8BkTkvNwEznp1IQkGyWohn9nWOTsDitq0qWIlCv1BhOzU8EpwYkxLRBjgG5i 98zF+nOufZ7wDctd5V5I8mR49IQADkIv/Xr4pTkmK4O5c+pE0olbll1pQglAyrQ4TJxC /ZQAlUUIPPc26iwJJKo13OH2aqFJnjO7LS7Tq/7XnlRyy/G4a/7ioSwTBsYo+xo7b8qt 8lOT41voMin7pejCcsxbt1ZZ5z8MHIVyUx+/NT2KNbrOuL9wL/Bv8y3piFmhA7dwfEdM 4fyQ== X-Gm-Message-State: AFqh2ko+GqWG/CtGPkCxIkut+j4ug6yoNiAWOCllnuH+A64OT4yk4eo0 oH2U5iB6n+79RmThYsEKdwAj26s8LWg= X-Google-Smtp-Source: AMrXdXt5H1M8ZgMLzn6JdWpxOsACZUb/nfLkbHnUSNYPwRXkmx1cjshz98C1KUM1v6IYZuyGo/bkHA== X-Received: by 2002:a05:6512:2390:b0:4b5:649a:9105 with SMTP id c16-20020a056512239000b004b5649a9105mr28825628lfv.65.1673611598158; Fri, 13 Jan 2023 04:06:38 -0800 (PST) Received: from laptop ([95.182.104.17]) by smtp.gmail.com with ESMTPSA id m6-20020a195206000000b004d2375472fdsm69391lfb.4.2023.01.13.04.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 04:06:37 -0800 (PST) References: <87zgaxfgi3.fsf@localhost> <87pmbsrfak.fsf@gmail.com> <87o7rald2a.fsf@localhost> User-agent: mu4e 1.8.13; emacs 30.0.50 From: Ilya Chernyshov To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] org-datetree.el: Allow datetrees with TODO, priority, tags Date: Fri, 13 Jan 2023 17:29:24 +0600 In-reply-to: <87o7rald2a.fsf@localhost> Message-ID: <878ri6oczb.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::12a; envelope-from=ichernyshovvv@gmail.com; helo=mail-lf1-x12a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1673611656; a=rsa-sha256; cv=none; b=SUkHxKPQK+xBBDp/8bRNsSegpZJEMYi/JGyGLBajgwv9Z/Cf85ihJRfEBW6wvT2x2oEN0k 21ssEVq+wQDgHbX3dq0VpZYnywcgzv8Hiy3tOqbgJJWY1R4LAbbcFT4BDh2ifXIomyEkZ2 D6aRbiaa5ZAQve4RJBS4UDAcfiO1ewZHDxSYFaEuRMKA7Bxt+biKdIe8VsGOyKwvGgbCRx PyMPYPPD5kYfI/Nkp7ePmwJHSxh7T9HOXfGOnmiqArJml3bcGG//ZOtaTJ/NeNPQDzAmGr A8oyWCdxBErkQfNghKsfqbvuuIez93S802g+PYPwG1XOI00Ylo6lT8w0q5a3rA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EoQubm1H; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1673611656; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=8zNcHW0Oemexe5331QyBAWRPy/SpofhCo9FtJ3+j3BI=; b=OpKaDoo5WOEa2Wv2s36SEsDzyRWWIR1cUc7B+KxDMC4Qv3+/3nV9sDKbC7l4NQV7Jpp/sc TnK9DuYNm6v5GGqsCF88ztruuie4yEC7bPXm4RVlDPF/euUr0JTAIk6YJitcs3Oxc9Nr3n 4jHoaZafFW9Di4uam20tY73Ih+BSS1oqlXau/Tvo2hkroknbaO9vcMsjcLuimzXistcmyo rffYEram0hYOm+O2jSqN3EKOh9TkDkiUiTweIz3gmIcLJ5BNpFEP0b1wn1FR0jCw/GnVk/ S56b4PVkB6qzZdwtmITSQ0CbSGPZgoGlLNGlG/Pl9bjO1otSHjkYXJuVGFyclw== X-Migadu-Spam-Score: -4.75 X-Spam-Score: -4.75 X-Migadu-Queue-Id: DF95824314 X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EoQubm1H; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com X-TUID: EEUlg8NGDztN --=-=-= Content-Type: text/plain; format=flowed Ihor Radchenko writes: > Ilya Chernyshov 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. Hi! Since the last patch, I've made the following changes, thanks to your recommendations in Matrix chat: 1. Added a new optional argument MATCH-TITLE to `org-datetree--find-create' that controls whether to match REGEX-TEMPLATE against heading title inside complex heading (the match is done via `org-complex-heading-regexp-format') or to match REGEX-TEMPLATE against the whole heading line(old behavior). That way, we won't break old calls to the function. 2. Added `replace-match' call that renames the first implicitly numbered match group inside REGEX-TEMPLATE to first explicitly numbered one. The replace is performed only if MATCH-TITLE is non-nil(that is, `org-complex-heading-regexp-format' is used). That way we ensure that even if in the future `org-complex-heading-regexp-format' will be changed (the number of match groups will be different), we can get access to the right group matching a date component without modifying the source code of the function. Is there a better way to ensure that? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-org-datetree.el-Allow-datetrees-with-TODO-prior.patch >From 481d8b4049f09cf880b584635a778e976a609f5c Mon Sep 17 00:00:00 2001 From: Ilya Chernyshov 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): Add optional argument MATCH-TITLE that controls whether to match REGEX-TEMPLATE against heading title inside complex heading or to match REGEX-TEMPLATE against the whole heading line. * org-datetree.el (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 | 6 ++++ lisp/org-datetree.el | 57 ++++++++++++++++++++----------- testing/lisp/test-org-datetree.el | 16 +++++++++ 4 files changed, 61 insertions(+), 21 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..0aeb76f2f 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -55,6 +55,12 @@ document header: ,#+LATEX_HEADER: \DefineVerbatimEnvironment{lstlisting}{Verbatim}{...whatever...} #+END_src +** New features +*** Datetree structure headlines can now be complex + +TODO state, priority, tags, statistics cookies, and COMMENT keywords +are allowed in the tree structure. + * Version 9.6 ** Important announcements and breaking changes diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el index 035ef047a..8a617e90c 100644 --- a/lisp/org-datetree.el +++ b/lisp/org-datetree.el @@ -99,16 +99,15 @@ 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-*$\\)" - year) + "\\([12][0-9]\\{3\\}\\)" + year nil nil nil t) (org-datetree--find-create - "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" - year month) + "%d-\\([01][0-9]\\) \\w+" + year month nil nil t) (when (eq time-grouping 'day) (org-datetree--find-create - "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" - year month day))))) + "%d-%02d-\\([0123][0-9]\\) \\w+" + year month day nil t))))) ;;;###autoload (defun org-datetree-find-iso-week-create (d &optional keep-restriction) @@ -147,33 +146,51 @@ 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-*$\\)" - weekyear nil nil - (format-time-string "%G" time)) + "\\([12][0-9]\\{3\\}\\)" + weekyear nil nil (format-time-string "%G" time) t) (org-datetree--find-create - "^\\*+[ \t]+%d-W\\([0-5][0-9]\\)$" - weekyear week nil - (format-time-string "%G-W%V" time)) + "%d-W\\([0-5][0-9]\\)" + weekyear week nil (format-time-string "%G-W%V" time) t) ;; For the actual day we use the regular date instead of ISO week. (org-datetree--find-create - "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" - year month day)))) + "%d-%02d-\\([0123][0-9]\\) \\w+" year month day nil t)))) (defun org-datetree--find-create - (regex-template year &optional month day insert) + (regex-template year &optional month day insert match-title) "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 +arguments. + +If MATCH-TITLE is non-nil, REGEX-TEMPLATE is matched against +heading title and the exact regexp matched against heading line is: + + (format org-complex-heading-regexp-format + (format regex-template year month day)) + +If MATCH-TITLE is nil, the regexp matched against heading line is +REGEX-TEMPLATE: + + (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)) + ;; ensure that the first match group in REGEX-TEMPLATE + ;; is the first inside `org-complex-heading-regexp-format' + (when (and match-title + (not (string-match-p "\\\\(\\?1:" regex-template)) + (string-match "\\\\(" regex-template)) + (setq regex-template (replace-match "\\(?1:" nil t regex-template))) + (let ((re (if match-title + (format org-complex-heading-regexp-format + (format regex-template year month day)) + (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)) + (goto-char (match-beginning 1)) (< (string-to-number (match-string 1)) (or day month year)))) (cond ((not match) 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 --=-=-= Content-Type: text/plain; format=flowed -- Best, Ilya --=-=-=--