emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Morgan Smith <morgan.j.smith@outlook.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: `org-element-cache-map' misses elements at end of buffer
Date: Sun, 21 Apr 2024 12:06:56 -0400	[thread overview]
Message-ID: <CH3PR84MB3424F819427E03418F5E4AF7C5132@CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <875xwbq6mb.fsf@localhost> (Ihor Radchenko's message of "Sun, 21 Apr 2024 11:48:12 +0000")

[-- Attachment #1: Type: text/plain, Size: 530 bytes --]

Ihor Radchenko <yantar92@posteo.net> writes:

>
> Hmm. :after-element keyword logic is broken. It does not account for the
> case when :after-element is past the START point.
>
> It is the time to refactor this function yet again.
> (a tricky endeavour considering all the edge cases we can encounter when
> there are changes in buffer while `org-element-cache-map' is mapping
> over it).

See attached for a way to break :from-pos as well.  I would like to help
refactor but studying this function is a little dizzying for me.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-test-org-element-cache-map-Add-test-for-from-pos.patch --]
[-- Type: text/x-patch, Size: 1632 bytes --]

From eb37560b9c94bed6e91d6834462173d0a6d7d44b Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
Date: Fri, 19 Apr 2024 10:46:28 -0400
Subject: [PATCH] test-org-element/cache-map: Add test for :from-pos

* testing/lisp/test-org-element.el (test-org-element/cache-map): Add
test for :from-pos.
---
 testing/lisp/test-org-element.el | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index ad4ff1ce9..a0dbc726e 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -4994,7 +4994,21 @@ Text
    (equal
     '(org-data headline section drawer paragraph)
     (org-test-with-temp-text "* headline\n:DRAWER:\nparagraph\n:END:"
-      (org-element-cache-map #'car :granularity 'element)))))
+      (org-element-cache-map #'car :granularity 'element))))
+  (should
+   (equal
+    ;; This fails returning '(paragraph paragraph) because it returns
+    ;; the paragraph under "headline".  This is because at
+    ;; org-element.el:8028 we travel up the parents of drawer trying
+    ;; to find a paragraph.
+    '(paragraph)
+    (org-test-with-temp-text "* headline\nparagraph\n<point>** subheading\n:DRAWER:\nparagraph\n:END:\n"
+      (let ((subheading (org-element-at-point)))
+        (org-element-cache-map
+         #'car
+         :granularity 'element
+         :restrict-elements '(paragraph)
+         :from-pos (org-element-contents-begin subheading)))))))
 
 (ert-deftest test-org-element/cache ()
   "Test basic expectations and common pitfalls for cache."
-- 
2.41.0


  reply	other threads:[~2024-04-21 16:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 13:33 `org-element-cache-map' misses elements at end of buffer Morgan Smith
2024-04-19 11:39 ` Morgan Smith
2024-04-21 11:48   ` Ihor Radchenko
2024-04-21 16:06     ` Morgan Smith [this message]
2024-04-21 17:31       ` Ihor Radchenko
2024-04-19 13:29 ` 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=CH3PR84MB3424F819427E03418F5E4AF7C5132@CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM \
    --to=morgan.j.smith@outlook.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).