branch: externals/org commit 942a7320d00620c9c10bdd65d52ca5d77009bc8e Author: Morgan Smith <morgan.j.sm...@outlook.com> Commit: Ihor Radchenko <yanta...@posteo.net>
org-element-cache-map: Fix edge case when we move to not-yet-cached element * lisp/org-element.el (org-element-cache-map): Make sure that there is always a cached element where we move START position. * testing/lisp/test-org-element.el (test-org-element/cache-map): New test. Co-authored-by: Morgan Smith <morgan.j.sm...@outlook.com> --- lisp/org-element.el | 7 +++++-- testing/lisp/test-org-element.el | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index ed036a3ffe..ccca973d00 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -8292,8 +8292,11 @@ the cache." ;; Reached LIMIT-COUNT. Abort. (when (and limit-count (>= count-predicate-calls-match - limit-count)) - (cache-walk-abort))) + limit-count)) + (cache-walk-abort)) + ;; Make sure that we have a cached + ;; element at the new STAR. + (when start (element-match-at-point))) ;; Check if the buffer or cache has been modified. (unless (org-with-base-buffer nil (and (eq modified-tic org-element--cache-change-tic) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 8b2cf16429..ad4ff1ce9b 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -4983,6 +4983,18 @@ Text ;;; Test Cache. +(ert-deftest test-org-element/cache-map () + "Test `org-element-cache-map'." + (org-test-with-temp-text "* headline\n:DRAWER:\nparagraph\n:END:\n* headline 2" + (should + (equal + '(org-data headline section drawer paragraph headline) + (org-element-cache-map #'car :granularity 'element)))) + (should + (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))))) (ert-deftest test-org-element/cache () "Test basic expectations and common pitfalls for cache."