From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.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 mGWmM2mXvmPVeQAAbAwnHQ (envelope-from ) for ; Wed, 11 Jan 2023 12:03:05 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id aGenM2mXvmMhEAAA9RJhRA (envelope-from ) for ; Wed, 11 Jan 2023 12:03:05 +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 613822882C for ; Wed, 11 Jan 2023 12:03:05 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pFYsM-0006hc-4O; Wed, 11 Jan 2023 06:02:34 -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 1pFYsJ-0006g2-Fl for emacs-orgmode@gnu.org; Wed, 11 Jan 2023 06:02:32 -0500 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pFYsH-00035E-7b for emacs-orgmode@gnu.org; Wed, 11 Jan 2023 06:02:31 -0500 Received: by mail-lf1-x129.google.com with SMTP id j17so22963739lfr.3 for ; Wed, 11 Jan 2023 03:02:28 -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=24tectv1aEswc3ojs0sIHz3GfSJMwJ1OFidUBFPtrT8=; b=bzZtycUkeLsSlCRWrV4b+jCgZwmwLpmgehi3b6VD9JDDVUEmoVbptbBxVA0Zjq4a9h 7Jlpqr1+Ncr9Q+kr1S77J5ESm6sBW/drNkv3FdMCvtPOLMpaweTTxWBIXYmv0Z1BSqPq fu/GB8HYcLRbDzVGPRULG8HbnsqO83zg5NikuRY9ofyB6zap+ZejlHNP4mOh1tSH6J3Z +fST4U3UDDHLXbox1QJcQ/hkw90TxB2sf4tq2DbJ97aVNKtsDRvl5wSgIJjPGQrWTCoB PtLZoQ3Ie7oRFWRBrMy32aJFzGJ7MbjUlP+Y9cVjm/Gp1wKBaK6Bt5F0QugQ1/d2+aVY Ty5A== 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=24tectv1aEswc3ojs0sIHz3GfSJMwJ1OFidUBFPtrT8=; b=HTJewmNZFTaqmqgXXHkFefW/qcSM9cOGvh1Sjg0hfiXSgnYQsR8H9oHJnBnHLkGnaK wCdRy86CCeFPipPHpRQsx55pDWWv7wjBHb0d6UY03gk1oWyltU3IXlBpQiqGCUvy5DRa hZBTBsykYokgblgwkW6Bya5Mf9AgIVl65oDoR2hjRPjCp0lmK5Yz0lVDZkhNlqMrA0nP 75+GROriQ5Fm1OqebrdRrdDl8kVZ5fzvCBka9XAxbthrE8XjUUWpNGdNrJHcDkN17Fp+ poj9sesBteLwncSwprovo3cS6MXtpCY/pvb+PIybOOryyjWI8hN43+DNfK2s3/dLFtVs 1Ezw== X-Gm-Message-State: AFqh2kpyf8GRQlS8l//b2K58tjdAdHMGjzmMkaqXlUpmiT04Hr3TkXzx CO4qtN5R7TC7kvU2px9vXA26R3lN8wpZuQ== X-Google-Smtp-Source: AMrXdXtMEUzrORpYP8LrFuHATNXckksQuGsrjQquJHuUBhYCN7fC3B2EDVsfwQJSmTq8cnvzPtGz4Q== X-Received: by 2002:a05:6512:21c6:b0:4af:e55a:dc69 with SMTP id d6-20020a05651221c600b004afe55adc69mr23917469lft.4.1673434946856; Wed, 11 Jan 2023 03:02:26 -0800 (PST) Received: from laptop ([95.46.137.200]) by smtp.gmail.com with ESMTPSA id j11-20020a056512344b00b004cafd4cc1fdsm2666189lfr.5.2023.01.11.03.02.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 03:02:26 -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: Wed, 11 Jan 2023 16:59:26 +0600 In-reply-to: <87o7rald2a.fsf@localhost> Message-ID: <87sfghqqpu.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::129; envelope-from=ichernyshovvv@gmail.com; helo=mail-lf1-x129.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-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=bzZtycUk; 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-Seal: i=1; s=key1; d=yhetil.org; t=1673434985; a=rsa-sha256; cv=none; b=YmN2xAm3s2GfxlUcq+lyL8luVCQP5Vm+7nt1j1cvZ/aXKyEKvIgGXPoTQX3eXreJY/jYSK rx2pVudT1SdKrENbUD41U+JAVJqXjB1dxZkTN9Hme3UDDdXhpStyH0W3O5plI6R0Z+RP5S LUfKuhIzxMEs7/66VqJfXeHuObysMQcQwPriiRsvRTAZ2EA37Kl+npvZFTAPYjSdcGDyJg TS5dFYjP7VAEIhp5NrQShLOHzeGqL8h2fld2JcRBvGtP9dR4f1iKpPHYKTdrALTO5GMi7+ PwEbLcRyRWr8RZLUlzZHsuvsY4OqnKy1iuyTLsZFa+PFSdZWru9VhzrSCKAYmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1673434985; 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=24tectv1aEswc3ojs0sIHz3GfSJMwJ1OFidUBFPtrT8=; b=IebjC+NH59LZ94Q4/RtZl8C7Y1I22N5DehcEpuCGyBXw/FoEd/ava+kFLKfOM6nMLzJo7r EqiT5Jc2Wg/IBiinxvyGF/ZZ2SwdMUnHFQARjiAMPjf6PibV9YvVi6TnSyfNPslLiCzYlr lvwz27L5ilzJpHRO7Q2L4+hhxD64/AgDV8x9WBUzPI3r73p52nBBPBE10WTkTptgrtl22p wp00YpwLUDLmzWkbAg0w31iHPN60iQi5+XEJ18wFZ3Joayl2owQ40lYRjJNU5jzGubge4a Umknx5U4v5n5sDr1mmcab8KS3VqWBmOqM5kcM9qkjtnG1VeQjNY1vH7cyP89qQ== X-Migadu-Queue-Id: 613822882C X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=bzZtycUk; 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-Migadu-Spam-Score: -8.23 X-Spam-Score: -8.23 X-TUID: QXCvyWQHy0oB --=-=-= 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. Changed the docs, please review the new patch. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-org-datetree.el-Allow-datetrees-with-TODO-prior.patch >From 2345abe57d4942a47fd55c2c6f741ef5c2643d47 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, 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 --=-=-= Content-Type: text/plain; format=flowed -- Best, Ilya --=-=-=--