Browse Source

org-element-cache-map: Fix an edge case with org-element-cache-continue-from

* lisp/org-element.el (org-element-cache-map): Make sure that START is
never set to -1.  It may cause infinite loops in some scenarios.
* testing/lisp/test-org.el (test-org/map-entries): Add a test catching
the reported situation.

Reported in https://list.orgmode.org/CADywB5JHAyPX99Vr02SvAqiMTD+7ss4VWVipOhKfm=iGirDPhA@mail.gmail.com/T/#t
Ihor Radchenko 3 năm trước cách đây
mục cha
commit
dc4b2772e3
2 tập tin đã thay đổi với 16 bổ sung2 xóa
  1. 3 2
      lisp/org-element.el
  2. 13 0
      testing/lisp/test-org.el

+ 3 - 2
lisp/org-element.el

@@ -7580,14 +7580,15 @@ the cache."
                               ;; inside an element.  We want to move
                               ;; it to real beginning then despite
                               ;; START being larger.
-                              (setq start -1)
+                              (setq start nil)
                               (move-start-to-next-match nil)
                               ;; The new element may now start before
                               ;; or at already processed position.
                               ;; Make sure that we continue from an
                               ;; element past already processed
                               ;; place.
-                              (when (and (<= start (org-element-property :begin data))
+                              (when (and start
+                                         (<= start (org-element-property :begin data))
                                          (not org-element-cache-map-continue-from))
                                 (goto-char start)
                                 (setq data (element-match-at-point))

+ 13 - 0
testing/lisp/test-org.el

@@ -2414,6 +2414,19 @@ SCHEDULED: <2014-03-04 tue.>"
                (lambda ()
                  (org-cut-subtree)
                  (setq org-map-continue-from (point))))
+              (buffer-string))))
+  (should
+   (string= "* H1\n* H2\n* H3\n"
+            (org-test-with-temp-text "* H1\n* H2\n* H3\n* H4"
+              (org-map-entries
+               (lambda ()
+                 (when (string= "H4"
+                                (org-element-property
+                                 :raw-value (org-element-at-point)))
+                   (org-cut-subtree)
+                   (setq org-map-continue-from
+                         (org-element-property
+                          :begin (org-element-at-point))))))
               (buffer-string)))))
 
 (ert-deftest test-org/edit-headline ()