forked from mirrors/org-mode
org-element-cache-map: Fix when :next-re is provided
* lisp/org-element.el (org-element-cache-map): Fix searching next-re in move-start-to-next-match. The if confition was erroneously always true due to the last `cl-incf'. Do not map over failing entry when next-re did not match and continue-flag is set. Do not move point to next entry before calling FUNC. * testing/lisp/test-org.el (test-org/map-entries): Add new test case.
This commit is contained in:
parent
df1f9be7f8
commit
7319136420
|
@ -7989,10 +7989,10 @@ the cache."
|
||||||
(if org-element--cache-map-statistics
|
(if org-element--cache-map-statistics
|
||||||
(progn
|
(progn
|
||||||
(setq before-time (float-time))
|
(setq before-time (float-time))
|
||||||
(re-search-forward (or (car-safe ,re) ,re) nil 'move)
|
(prog1 (re-search-forward (or (car-safe ,re) ,re) nil 'move)
|
||||||
(cl-incf re-search-time
|
(cl-incf re-search-time
|
||||||
(- (float-time)
|
(- (float-time)
|
||||||
before-time)))
|
before-time))))
|
||||||
(re-search-forward (or (car-safe ,re) ,re) nil 'move)))
|
(re-search-forward (or (car-safe ,re) ,re) nil 'move)))
|
||||||
(unless (or (< (point) (or start -1))
|
(unless (or (< (point) (or start -1))
|
||||||
(and data
|
(and data
|
||||||
|
@ -8176,22 +8176,21 @@ the cache."
|
||||||
(move-start-to-next-match
|
(move-start-to-next-match
|
||||||
(if last-match next-re fail-re)))
|
(if last-match next-re fail-re)))
|
||||||
(when (and (or (not start) (eq (org-element-begin data) start))
|
(when (and (or (not start) (eq (org-element-begin data) start))
|
||||||
(< (org-element-begin data) to-pos))
|
(< (org-element-begin data) to-pos)
|
||||||
|
(not continue-flag))
|
||||||
;; Calculate where next possible element
|
;; Calculate where next possible element
|
||||||
;; starts and update START if needed.
|
;; starts and update START if needed.
|
||||||
(setq start (next-element-start))
|
(setq start (next-element-start))
|
||||||
(goto-char start)
|
(goto-char start)
|
||||||
;; Move START further if possible.
|
;; Move START further if possible.
|
||||||
|
(save-excursion
|
||||||
(when (and next-element-re
|
(when (and next-element-re
|
||||||
;; Do not move if we know for
|
;; Do not move if we know for
|
||||||
;; sure that cache does not
|
;; sure that cache does not
|
||||||
;; contain gaps. Regexp
|
;; contain gaps. Regexp
|
||||||
;; searches are not cheap.
|
;; searches are not cheap.
|
||||||
(not (cache-gapless-p)))
|
(not (cache-gapless-p)))
|
||||||
(move-start-to-next-match next-element-re)
|
(move-start-to-next-match next-element-re)))
|
||||||
;; Make sure that point is at START
|
|
||||||
;; before running FUNC.
|
|
||||||
(goto-char start))
|
|
||||||
;; Try FUNC if DATA matches all the
|
;; Try FUNC if DATA matches all the
|
||||||
;; restrictions. Calculate new START.
|
;; restrictions. Calculate new START.
|
||||||
(when (or (not restrict-elements)
|
(when (or (not restrict-elements)
|
||||||
|
|
|
@ -2855,7 +2855,7 @@ test <point>
|
||||||
(should (org-find-olp '("Headline" "headline8") t))))
|
(should (org-find-olp '("Headline" "headline8") t))))
|
||||||
|
|
||||||
(ert-deftest test-org/map-entries ()
|
(ert-deftest test-org/map-entries ()
|
||||||
"Test `org-map-entries' specifications."
|
"Test `org-map-entries' and `org-element-cache-map' specifications."
|
||||||
(dolist (org-element-use-cache '(t nil))
|
(dolist (org-element-use-cache '(t nil))
|
||||||
;; Full match.
|
;; Full match.
|
||||||
(should
|
(should
|
||||||
|
@ -3097,7 +3097,16 @@ Let’s stop here
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(delete-region (point) (line-beginning-position 2))
|
(delete-region (point) (line-beginning-position 2))
|
||||||
(setq org-map-continue-from (point))))
|
(setq org-map-continue-from (point))))
|
||||||
(buffer-string))))))
|
(buffer-string))))
|
||||||
|
;; :next-re in `org-element-cache-map'
|
||||||
|
(org-test-with-temp-text
|
||||||
|
"* one
|
||||||
|
* TODO two
|
||||||
|
* three
|
||||||
|
* four
|
||||||
|
"
|
||||||
|
(should (equal '("two")
|
||||||
|
(org-element-cache-map (lambda (el) (org-element-property :title el)) :next-re "TODO"))))))
|
||||||
|
|
||||||
(ert-deftest test-org/edit-headline ()
|
(ert-deftest test-org/edit-headline ()
|
||||||
"Test `org-edit-headline' specifications."
|
"Test `org-edit-headline' specifications."
|
||||||
|
|
Loading…
Reference in New Issue