emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matthieu Caneill <matt@brokenwa.re>
To: emacs-orgmode@gnu.org
Subject: [PATCH] org-element-cache-map: Fix handling of continue-from
Date: Fri, 27 Jan 2023 00:18:43 +0100	[thread overview]
Message-ID: <Y9MKUzWWbErLFhmq@brokenwa.re> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1409 bytes --]

Hi,

I'm hit by the following bug in `org-element-cache-map'. When I use
`tags' or `tags-todo' in an agenda, with the option
`(org-tags-match-list-sublevels nil)', all sub-elements of a matching
item are correctly skipped except the last one.

It can be reproduced with the following org file:

  * TODO Parent

  ** TODO Child 1

  ** TODO Child 2

and the following agenda:

  (setq org-agenda-custom-commands
        '(
          ("t" "Test"
           (
            (tags-todo "-foo" ((org-tags-match-list-sublevels nil)))
            (tags "-foo" ((org-tags-match-list-sublevels nil)))
            )
           ((org-agenda-files '("~/org/test.org"))))))

With `(org-tags-match-list-sublevels t)', I correctly see all 3
elements. With `(org-tags-match-list-sublevels nil)', I see Parent and
Child 2. This wasn't the case on an older version of org-element that
didn't make use of the cache.

I understand the option `org-tags-match-list-sublevels' is
semi-deprecated in favor of proper tag inheritance
configuration. However, to the best of my understanding, I can't
accomplish "list all todo items except those tagged with foo, and skip
children of matching entries" with tag inheritance.

Patch is attached. Happy to iterate over it in case my understanding
of this rather complex function is flawed. I tested it on my org
files, and would of course appreciate if others could test.

Best,
--
Matthieu

[-- Attachment #1.2: 0001-org-element-cache-map-Fix-handling-of-continue-from.patch --]
[-- Type: text/x-diff, Size: 2988 bytes --]

From 5d0e2beb9c8b8a239c41dab2f3b44d1fe83bff0c Mon Sep 17 00:00:00 2001
From: Matthieu Caneill <matt@brokenwa.re>
Date: Thu, 26 Jan 2023 23:51:05 +0100
Subject: [PATCH] org-element-cache-map: Fix handling of continue-from

* lisp/org-element.el (org-element-cache-map): When the receiving
  function sets `org-element-cache-map-continue-from', value of START
  should be set accordingly.

* lisp/org.el (org-scan-tags): Reset `org-map-continue-from' for every
  iteration, and set it to the end of the element when sub-elements
  should be skipped following `org-tags-match-list-sublevels'.

TINYCHANGE
---
 lisp/org-element.el | 3 ++-
 lisp/org.el         | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index a3d909290..0a1d31bee 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -7700,7 +7700,8 @@ the cache."
                               ;; If FUNC moved point forward, update
                               ;; START.
                               (when org-element-cache-map-continue-from
-                                (goto-char org-element-cache-map-continue-from))
+                                (goto-char org-element-cache-map-continue-from)
+                                (setq start org-element-cache-map-continue-from))
                               (when (> (point) start)
                                 (move-start-to-next-match nil))
                               ;; Drop nil.
diff --git a/lisp/org.el b/lisp/org.el
index ac2acfefb..dc9b7da7f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11010,6 +11010,7 @@ headlines matching this string."
 		                   org-outline-regexp))))
             (org-element-cache-map
              (lambda (el)
+               (setq org-map-continue-from nil)
                (goto-char (org-element-property :begin el))
                (setq todo (org-element-property :todo-keyword el)
                      level (org-element-property :level el)
@@ -11084,7 +11085,6 @@ headlines matching this string."
                        'type (concat "tagsmatch" ts-date-type))
 	             (push txt rtn))
 	            ((functionp action)
-	             (setq org-map-continue-from nil)
 	             (save-excursion
 		       (setq rtn1 (funcall action))
 		       (push rtn1 rtn)))
@@ -11092,7 +11092,8 @@ headlines matching this string."
 
 	           ;; if we are to skip sublevels, jump to end of subtree
 	           (unless org-tags-match-list-sublevels
-	             (goto-char (1- (org-element-property :end el))))))
+	             (goto-char (1- (org-element-property :end el)))
+                     (setq org-map-continue-from (org-element-property :end el)))))
                ;; Get the correct position from where to continue
 	       (when org-map-continue-from
                  (setq org-element-cache-map-continue-from org-map-continue-from)
-- 
2.30.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

             reply	other threads:[~2023-01-26 23:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-26 23:18 Matthieu Caneill [this message]
2023-01-30  9:07 ` [PATCH] org-element-cache-map: Fix handling of continue-from 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=Y9MKUzWWbErLFhmq@brokenwa.re \
    --to=matt@brokenwa.re \
    --cc=emacs-orgmode@gnu.org \
    /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).